From 4f1f3273b0d59f60d27fde4f685ecd8866d32060 Mon Sep 17 00:00:00 2001 From: GeorgeR227 <78235421+GeorgeR227@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:36:39 -0400 Subject: [PATCH] Added some improvements to naming We now better deal with being passed infer types and added support for dual exterior derivatives. --- src/deca/ThDEC.jl | 28 +++++++++++++++++----------- test/decasymbolic.jl | 22 ++++++++++------------ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/deca/ThDEC.jl b/src/deca/ThDEC.jl index 3afdad4..3fc40ae 100644 --- a/src/deca/ThDEC.jl +++ b/src/deca/ThDEC.jl @@ -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 @@ -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) ? "⁻¹" : "" diff --git a/test/decasymbolic.jl b/test/decasymbolic.jl index 0753065..436ceb1 100644 --- a/test/decasymbolic.jl +++ b/test/decasymbolic.jl @@ -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("∧₀₁") @@ -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("★₁") @@ -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)