Skip to content

Commit

Permalink
applying comments except for removing :diffusivity
Browse files Browse the repository at this point in the history
  • Loading branch information
quffaro authored and epatters committed Dec 6, 2024
1 parent 6ab81d3 commit e45af96
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 564 deletions.
7 changes: 0 additions & 7 deletions packages/algjulia-service/demos.txt

This file was deleted.

42 changes: 22 additions & 20 deletions packages/algjulia-service/src/decapodes-service/DecapodesService.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,50 @@ include("model.jl") ## model-building (is this actually a diagram of a model?)
struct PodeSystem
pode::SummationDecapode
plotvar::Vector{Symbol}
scalars::Dict{Symbol, Any} # closures # TODO rename scalars => anons
scalars::Dict{Symbol, Any} # closures
geometry::Geometry
init::ComponentArray # TODO Is it always ComponentVector?
generate::Any
uuiddict::Dict{Symbol, String}
end
export PodeSystem

function PodeSystem(json_string::String, args...)
json_object = JSON3.read(json_string)
PodeSystem(json_object, args...)
end

"""
Construct a `PodeSystem` object from a JSON string.
"""
function PodeSystem(json_string::String,hodge=GeometricHodge())
json_object = JSON3.read(json_string);

function PodeSystem(json_object::AbstractDict, hodge=GeometricHodge())
# converts the JSON of (the fragment of) the theory
# into theory of the DEC, valued in Julia
theory = Theory(json_object[:model]);
theory = Theory(json_object[:model])

# this is a diagram in the model of the DEC. it wants to be a decapode!
diagram = json_object[:diagram];
diagram = json_object[:diagram]

# any scalars?
scalars = haskey(json_object, :scalars) ? json_object[:scalars] : [];
scalars = haskey(json_object, :scalars) ? json_object[:scalars] : []

# pode, anons, and vars (UUID => ACSetId)
decapode, anons, vars = Decapode(diagram, theory; scalars=scalars);
decapode, anons, vars = Decapode(diagram, theory; scalars=scalars)
dot_rename!(decapode)
uuid2symb = uuid_to_symb(decapode, vars);
uuid2symb = uuid_to_symb(decapode, vars)

# plotting variables
plotvars = [uuid2symb[uuid] for uuid in json_object[:plotVariables]];
plotvars = [uuid2symb[uuid] for uuid in json_object[:plotVariables]]

# extract the domain in order to create the mesh, dualmesh
geometry = Geometry(json_object);
geometry = Geometry(json_object)

# initialize operators
♭♯_m = ♭♯_mat(geometry.dualmesh);
wedge_dp10 = dec_wedge_product_dp(Tuple{1,0}, geometry.dualmesh);
dual_d1_m = dec_mat_dual_differential(1, geometry.dualmesh);
♭♯_m = ♭♯_mat(geometry.dualmesh)
wedge_dp10 = dec_wedge_product_dp(Tuple{1,0}, geometry.dualmesh)
dual_d1_m = dec_mat_dual_differential(1, geometry.dualmesh)
star0_inv_m = dec_mat_inverse_hodge(0, geometry.dualmesh, hodge)
Δ0 = Δ(0,geometry.dualmesh);
Δ0 = Δ(0,geometry.dualmesh)
#fΔ0 = factorize(Δ0);
function sys_generate(s, my_symbol, hodge=hodge)
op = @match my_symbol begin
Expand All @@ -97,7 +100,7 @@ function PodeSystem(json_string::String,hodge=GeometricHodge())
# end initialize

# initial conditions
u0 = initial_conditions(json_object, geometry, uuid2symb);
u0 = initial_conditions(json_object, geometry, uuid2symb)

# symbol => uuid. we need this to reassociate the var
symb2uuid = Dict([v => k for (k,v) in pairs(uuid2symb)])
Expand All @@ -106,7 +109,7 @@ function PodeSystem(json_string::String,hodge=GeometricHodge())
end
export PodeSystem

points(system::PodeSystem) = collect(values(system.geometry.mesh.subparts.point.m));
points(system::PodeSystem) = collect(values(system.geometry.mesh.subparts.point.m))
indexing_bounds(system::PodeSystem) = indexing_bounds(system.geometry.domain)

## SIM HELPERS ##
Expand Down Expand Up @@ -156,7 +159,7 @@ function state_at_time(soln::ODESolution, system::PodeSystem, plotvar::Symbol, t
end

function state_at_time(soln::ODESolution, domain::Rectangle, var::Symbol, t::Int) # last two args can be one Point2
(x, y) = indexing_bounds(domain);
(x, y) = indexing_bounds(domain)
[SVector(i, j, getproperty(soln.u[t], var)[x*(i-1) + j]) for i in 1:x+1, j in 1:y+1]
end

Expand All @@ -167,9 +170,8 @@ function grid(pt3::Point3, grid_size::Vector{Int})
end

function state_at_time(soln::ODESolution, domain::Sphere, var::Symbol, t::Int, points)
l , _ = indexing_bounds(domain); # TODO this is hardcoded to return 100, 100
l , _ = indexing_bounds(domain) # TODO this is hardcoded to return 100, 100
northern_indices = filter(i -> points[i][3] > 0, keys(points))
# TODO we don't have access to points in this function yet. need to pass that in
map(northern_indices) do n
i, j = grid(points[n], [l, l]) # TODO
SVector(i, j, getproperty(soln.u[t], var)[n])
Expand Down
6 changes: 3 additions & 3 deletions packages/algjulia-service/src/decapodes-service/geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct Geometry
dualmesh::HasDeltaSet
end

function Geometry(json_object::JSON3.Object)
function Geometry(json_object::AbstractDict)
mesh_name = Symbol(json_object[:mesh])
domain = PREDEFINED_MESHES[mesh_name]
Geometry(domain)
Expand All @@ -95,14 +95,14 @@ end
# function Geometry(r::Periodic, division::SimplexCenter=Circumcenter()) end

function Geometry(m::Sphere, division::SimplexCenter=Circumcenter())
s = loadmesh(Icosphere(m.dim, m.radius));
s = loadmesh(Icosphere(m.dim, m.radius))
sd = EmbeddedDeltaDualComplex2D{Bool, Float64, Point3{Float64}}(s)
subdivide_duals!(sd, division)
Geometry(m, s, sd)
end

function Geometry(m::UV, division::SimplexCenter=Circumcenter())
s, _, _ = makeSphere(m);
s, _, _ = makeSphere(m)
sd = EmbeddedDeltaDualComplex2D{Bool, Float64, Point3{Float64}}(s)
subdivide_duals!(sd, division)
Geometry(m, s, sd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ GaussianIC(r::Rectangle) = GaussianIC(r, GaussianData(r))
TaylorVortexIC(d::Sphere) = TaylorVortexIC(d, TaylorVortexData())


function initial_conditions(json_object::JSON3.Object, geometry::Geometry, uuid2symb::Dict{String, Symbol})
ic_specs = json_object[:initialConditions]; # this is "C"
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)]...)
initial_conditions(dict, geometry) # the resulting sim will only have (C,) as initial conditions
end
Expand Down Expand Up @@ -99,7 +99,7 @@ end

function initial_conditions(ics::TaylorVortexIC, geometry::Geometry)
# TODO prefer not to load `s0` here but che sara sara
s0 = dec_hodge_star(0, geometry.dualmesh, GeometricHodge());
s0 = dec_hodge_star(0, geometry.dualmesh, GeometricHodge())
X = vort_ring(ics, geometry)
du = s0 * X
return du
Expand Down
28 changes: 15 additions & 13 deletions packages/algjulia-service/src/decapodes-service/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export add_to_pode!
function add_to_pode!(d::SummationDecapode,
vars::Dict{String, Int}, # mapping between UUID and ACSet ID
theory::Theory,
content::JSON3.Object,
content::AbstractDict,
nc::Vector{Int},
::ObType)
theory_elem = theory.data[content[:over][:content]] # indexes the theory by UUID
Expand All @@ -24,20 +24,21 @@ function add_to_pode!(d::SummationDecapode,
return d
end

function Base.nameof(theory::Theory, content::JSON3.Object)
function Base.nameof(theory::Theory, content::AbstractDict)
Symbol(theory.data[content[:over][:content]].name)
end

# TODO we are restricted to Op1
function add_to_pode!(d::SummationDecapode,
vars::Dict{String, Int}, # mapping between UUID and ACSet ID
theory::Theory,
content::JSON3.Object,
content::AbstractDict,
scalars::Any,
anons::Dict{Symbol, Any},
::HomType)

dom = content[:dom][:content]; cod = content[:cod][:content]
dom = content[:dom][:content]
cod = content[:cod][:content]
# TODO we need a safe way to fail this
if haskey(vars, dom) && haskey(vars, cod)
# get the name of the Op1 and add it to the theory
Expand All @@ -53,21 +54,23 @@ function add_to_pode!(d::SummationDecapode,
scalar = scalars[Symbol(content[:over][:content])]
push!(anons, op1 => x -> scalar * x)
end
# TODO if scalars were typed correctly, we could probably do away with the !isempty check
end
d
end

""" Decapode(jsondiagram::JSON3.Object, theory::Theory) => SummationDecapode
""" Decapode(diagram::AbstractVector{<:AbstractDict}, theory::Theory) => (::SummationDecapode, ::Dict{Symbol, Any}, ::Dict{String, Int})
This returns a Decapode given a jsondiagram and a theory.
This returns
1. a Decapode
2. a dictionary of symbols mapped to anonymous functions
3. a dictionary of JSON UUIDs mapped to symbols
"""
function Decapode(diagram::AbstractVector{JSON3.Object}, theory::Theory; scalars=[])
function Decapode(diagram::AbstractVector{<:AbstractDict}, theory::Theory; scalars=[])
# initiatize decapode and its mapping between UUIDs and ACSet IDs
pode = SummationDecapode(parse_decapode(quote end));
vars = Dict{String, Int}(); # UUID => ACSetID
nc = [0]; # array is a mutable container
anons = Dict{Symbol, Any}();
pode = SummationDecapode(parse_decapode(quote end))
vars = Dict{String, Int}() # UUID => ACSetID
nc = [0] # array is a mutable container
anons = Dict{Symbol, Any}()
# for each cell in the notebook, add it to the diagram
foreach(diagram) do cell
@match cell begin
Expand All @@ -80,7 +83,6 @@ function Decapode(diagram::AbstractVector{JSON3.Object}, theory::Theory; scalars
return pode, anons, vars
end
export Decapode
# the proper name for this constructor should be "SummationDecapode"

function uuid_to_symb(decapode::SummationDecapode, vars::Dict{String, Int})
Dict([key => (subpart(decapode, vars[key], :name)) for key keys(vars)])
Expand Down
28 changes: 0 additions & 28 deletions packages/algjulia-service/src/decapodes-service/plotting.jl

This file was deleted.

19 changes: 5 additions & 14 deletions packages/algjulia-service/src/decapodes-service/theory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@ function to_theory(theory::ThDecapode, type::HomType, name::String)
"Δ" =>
"Δ⁻¹" => :Δ⁻¹
"d*" || "d̃₁" => :dual_d₁
# \star on LHS
"" => :
"" || "⋆₁" || "★₁" || "★1" => :
"⋆⁻¹" || "⋆₀⁻¹" => :₀⁻¹
# => :⋆₀⁻¹
# \bigstar on LHS
"" || "★⁻¹" => :
# => :⋆₀⁻¹
"diffusivity" => :diffusivity
# new
"d" || "d₀" || "d01" => :d₀
"d12" => :d₁
"⋆1" => :
"⋆2" => :
"♭♯" => :♭♯
"lamb" => :dpsw # dual-primal self-wedge
Expand Down Expand Up @@ -99,19 +93,16 @@ struct Theory{T<:ThDecapode}
end
export Theory

# TODO engooden
Base.show(io::IO, theory::Theory) = show(io, theory.data)

Base.values(theory::Theory) = values(theory.data)

function add_to_theory! end; export add_to_theory!

function add_to_theory!(theory::Theory{T}, content::Any, type::ObType) where T
function add_to_theory!(theory::Theory{T}, content::AbstractDict, type::ObType) where T
push!(theory.data,
content[:id] => TheoryElement(;name=to_theory(T(), type, content[:name])))
end

function add_to_theory!(theory::Theory{T}, content::Any, type::HomType) where T
function add_to_theory!(theory::Theory{T}, content::AbstractDict, type::HomType) where T
push!(theory.data, content[:id] =>
TheoryElement(;name=to_theory(T(), type, content[:name]),
val=HomData(dom=content[:dom][:content],
Expand All @@ -122,8 +113,8 @@ end
# ...an object, we convert its type to a symbol and add it to the theorydict
# ...a morphism, we add it to the theorydict with a field for the ids of its
# domain and codomain to its
function Theory(model::AbstractVector{JSON3.Object})
theory = Theory(ThDecapode());
function Theory(model::AbstractVector{<:AbstractDict})
theory = Theory(ThDecapode())
foreach(model) do cell
@match cell begin
IsObject(content) => add_to_theory!(theory, content, ObType())
Expand Down
Loading

0 comments on commit e45af96

Please sign in to comment.