Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot non-state variables in Decapodes #315

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,24 @@ This IC contains the domain and the initial conditions data.
While these are currently tightly-interlinked with InitialConditionsData, they are formally separated to distinguish between the initial conditions schema and the data it might be parameterized over.
=#
@data InitialConditions begin
Zeroes(r::Domain)
# planar
GaussianIC(r::Rectangle, ξ::GaussianData)
# spherical
# spheric
TaylorVortexIC(d::Sphere, ξ::TaylorVortexData)
SixVortexIC(m::Sphere, data::Any)
end

# DEFAULT METHOD
GaussianIC(r::Rectangle) = GaussianIC(r, GaussianData(r))
GaussianIC(s::Sphere) = GaussianIC(s, GaussianData(s)) # TODO this doesn't work

TaylorVortexIC(d::Sphere) = TaylorVortexIC(d, TaylorVortexData())

# since we need to plot non-state variables, we might need to pass in initial conditions for all variables.
function initial_conditions(json_object::AbstractDict, geometry::Geometry, uuid2symb::Dict{String, Symbol})
ic_specs = json_object[:initialConditions] # this is "C"
dict = Dict([uuid2symb[string(uuid)] => ic_specs[string(uuid)] for uuid ∈ keys(ic_specs)]...)
ic_specs = json_object[:initialConditions] # this is "C"
dict = Dict([uuid2symb[string(uuid)] => haskey(ic_specs, var) ? ic_specs[string(uuid)] : "Default" for uuid ∈ keys(uuid2symb)]...)
initial_conditions(dict, geometry) # the resulting sim will only have (C,) as initial conditions
end

Expand All @@ -59,6 +63,7 @@ function associate(str::String, geometry::Geometry)
@match str begin
"Gaussian" => GaussianIC(geometry.domain)
"TaylorVortex" => TaylorVortexIC(geometry.domain)
"Default" => Zeroes(geometry.domain) # XXX create zeros?
_ => error("$str is not implemented")
end
end
Expand Down Expand Up @@ -87,6 +92,10 @@ function initial_conditions(x::InitialConditions, args...)
throw(ImplError("These initial conditions ($(x)) are"))
end

function initial_conditions(ics::Zeroes, geometry::Geometry)
zeros(nv(geometry.dualmesh))
end

function initial_conditions(ics::GaussianIC, geometry::Geometry)
c_dist = MvNormal(ics.ξ)
c = [pdf(c_dist, [p[1], p[2]]) for p ∈ geometry.dualmesh[:point]]
Expand Down
24 changes: 12 additions & 12 deletions packages/algjulia-service/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,27 @@ end
#= XXX ERRORING
we are trying to index `soln.u[t]` by `Ċ `, but only `C` is present. I think this is because we generating initial conditions based on what was specified to the `initial_conditions` parameter, whereas in the past we were using `infer_state_names` to obtain that.
=#
# @testset "Simulation - Diffusion with Two Variables" begin
@testset "Simulation - Diffusion with Two Variables" begin

# json_string = read(joinpath(@__DIR__, "test_jsons", "diffusion_data_twovars.json"), String);
# @test Set(keys(JSON3.read(json_string))) == KEYS
json_string = read(joinpath(@__DIR__, "test_jsons", "diffusion_data_twovars.json"), String);
@test Set(keys(JSON3.read(json_string))) == KEYS

# system = PodeSystem(json_string);
system = PodeSystem(json_string);

# simulator = evalsim(system.pode)
# f = simulator(system.geometry.dualmesh, system.generate, DiagonalHodge())
simulator = evalsim(system.pode)
f = simulator(system.geometry.dualmesh, system.generate, DiagonalHodge())

# soln = run_sim(f, system.init, 50.0, ComponentArray(k=0.5,));
soln = run_sim(f, system.init, 50.0, ComponentArray(k=0.5,));

# @test soln.retcode == ReturnCode.Success
@test soln.retcode == ReturnCode.Success

# result = SimResult(soln, system);
result = SimResult(soln, system);

# @test typeof(result.state) == Dict{String, Vector{AbstractArray{SVector{3, Float64}}}}
@test typeof(result.state) == Dict{String, Vector{AbstractArray{SVector{3, Float64}}}}

# jvs = JsonValue(result);
jvs = JsonValue(result);

# end
end

@testset "Parsing the Model JSON Object - Diffusion Long Trip" begin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@
},
"id": "01932404-10e5-7128-bb94-835e5d8d643f",
"morType": {
"content": {
"content": "Object",
"content": "Nonscalar",
"tag": "Basic"
},
"tag": "Hom"
},
"name": "",
"over": {
Expand Down
Loading