Skip to content

Commit

Permalink
Added some improvements to naming
Browse files Browse the repository at this point in the history
We now better deal with being passed infer types and added support for dual exterior derivatives.
  • Loading branch information
GeorgeR227 committed Oct 10, 2024
1 parent 7c5155d commit 4f1f327
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
28 changes: 17 additions & 11 deletions src/deca/ThDEC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ export PatScalar
end
export PatVFParams

isForm(x) = @match symtype(x) begin
PatFormParams([_,_,_,_]) => true
_ => false
end

isDualForm(x) = @match symtype(x) begin
PatFormParams([_,d,_,_]) => d
_ => false
Expand Down Expand Up @@ -262,26 +267,27 @@ Base.nameof(s::Union{Parameter, Type{Parameter}}) = :Parameter
Base.nameof(s::Union{Scalar, Type{Scalar}}) = :Scalar
Base.nameof(s::Union{InferredType, Type{InferredType}}) = :infer

sub_dim(s) = as_sub(dim(s))

Base.nameof(::typeof(-), s1, s2) = Symbol("$(sub_dim(s1))-$(sub_dim(s2))")
Base.nameof(::typeof(-), args...) = Symbol("-")

const SUBSCRIPT_DIGIT_0 = ''

as_sub(n::Int) = join(map(d -> SUBSCRIPT_DIGIT_0 + d, digits(n)))
sub_dim(args...) = all(isForm.(args)) ? join(as_sub.(dim.(args))) : ""

function Base.nameof(::typeof(), s1, s2)
Symbol("$(sub_dim(s1))$(sub_dim(s2))")
end
Base.nameof(::typeof(), s1, s2) = Symbol("$(sub_dim(s1, s2))")

Base.nameof(::typeof(∂ₜ), s) = Symbol("∂ₜ($(nameof(s)))")
Base.nameof(::typeof(∂ₜ), s) = Symbol("∂ₜ")

#TODO: Add an option to output d for dual forms, typically d₀ -> dual_d₀
Base.nameof(::typeof(d), s) = Symbol("d$(sub_dim(s))")
function Base.nameof(::typeof(d), s)
dual = isdual(s) ? "dual_" : ""
Symbol("$(dual)d$(sub_dim(s))")
end

#TODO: Add subtypes for the Laplacian
# Base.nameof(::typeof(Δ), s) = Symbol("Δ$(sub_dim(s))")
Base.nameof(::typeof(Δ), s) =
#TODO: Add naming for dual
function Base.nameof(::typeof(Δ), s)
Symbol("Δ$(sub_dim(s))")
end

function Base.nameof(::typeof(★), s)
inv = isdual(s) ? "⁻¹" : ""
Expand Down
22 changes: 10 additions & 12 deletions test/decasymbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ end
@test nameof(symtype(ω)) == :Form1
@test nameof(symtype(η)) == :DualForm2

# TODO: Do we want this style of typed subtraction?
@test nameof(-, symtype(u), symtype(u)) == Symbol("₀-₀")
# TODO: This breaks since this expects the types to have a `dim` function
@test_broken nameof(-, symtype(a), symtype(b)) == Symbol("-")
@test nameof(-, symtype(u)) == Symbol("-")
@test nameof(-, symtype(u), symtype(u)) == Symbol("-")
@test nameof(-, symtype(a), symtype(b)) == Symbol("-")

@test nameof(, symtype(u), symtype(u)) == Symbol("∧₀₀")
@test nameof(, symtype(u), symtype(ω)) == Symbol("∧₀₁")
Expand All @@ -114,15 +113,14 @@ end
# TODO: Do we need a special designation for wedges with duals in them?
@test nameof(, symtype(ω), symtype(η)) == Symbol("∧₁₂")

# TODO: Why is this being named as such?
@test nameof(∂ₜ, symtype(u)) == Symbol("∂ₜ(Form0)")
@test nameof(∂ₜ, symtype(d(u))) == Symbol("∂ₜ(Form1)")
@test nameof(∂ₜ, symtype(u)) == Symbol("∂ₜ")
@test nameof(∂ₜ, symtype(d(u))) == Symbol("∂ₜ")

@test nameof(d, symtype(u)) == Symbol("d₀")
@test_broken nameof(d, symtype(η)) == Symbol("dual_d₂")
@test nameof(d, symtype(η)) == Symbol("dual_d₂")

@test_broken nameof(Δ, symtype(u)) == Symbol("Δ₀")
@test_broken nameof(Δ, symtype(ω)) == Symbol("Δ₁")
@test nameof(Δ, symtype(u)) == Symbol("Δ₀")
@test nameof(Δ, symtype(ω)) == Symbol("Δ₁")

@test nameof(★, symtype(u)) == Symbol("★₀")
@test nameof(★, symtype(ω)) == Symbol("★₁")
Expand Down Expand Up @@ -308,13 +306,13 @@ end
w == (v, u)
end
# Base.nameof doesn't yet support taking InferredTypes
@test_broken with_infers == roundtrip(with_infers)
@test with_infers == roundtrip(with_infers)

Heat = @decapode begin
u::Form0
v::Form0
κ::Constant
∂ₜ(v) == Δ(u)*κ
∂ₜ(v) == Δ(u)*κ
end
infer_types!(Heat)
@test Heat == roundtrip(Heat)
Expand Down

0 comments on commit 4f1f327

Please sign in to comment.