Skip to content

Commit

Permalink
Add advection Vec equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
lukem12345 committed Sep 5, 2023
1 parent c235acb commit fc8c8f8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
17 changes: 9 additions & 8 deletions docs/src/ascii.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ Some users may have trouble entering unicode characters like ⋆ or ∂ in their

## Vector Calculus Equivalents

| Vec | DEC | How to enter |
| ------- | ---------- | -------------------------- |
| grad | d | grad |
| div | ∘(⋆,d,⋆) | div |
| curl | ∘(d,⋆) | curl |
|| d | \nabla |
| ∇ᵈ | ∘(⋆,d,⋆) | \nabla \<tab\> \\^d \<tab\> |
| ∇x | ∘(d,⋆) | \nabla \<tab\> x |
| Vec | DEC | How to enter |
| -------- | ---------------- | -------------------------- |
| grad | d | grad |
| div | ∘(⋆,d,⋆) | div |
| curl | ∘(d,⋆) | curl |
|| d | \nabla |
| ∇ᵈ | ∘(⋆,d,⋆) | \nabla \<tab\> \\^d \<tab\> |
| ∇x | ∘(d,⋆) | \nabla \<tab\> x |
| adv(X,Y) | ∘(⋆,d,⋆)(X∧Y) | adv |

21 changes: 20 additions & 1 deletion src/decapodeacset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -731,5 +731,24 @@ vec_to_dec_op2 = Pair{Symbol, Symbol}[]
Replace Vector Calculus operators with Discrete Exterior Calculus equivalents.
"""
vec_to_dec!(d::SummationDecapode) = replace_names!(d, vec_to_dec_op1, vec_to_dec_op2)
function vec_to_dec!(d::SummationDecapode)
# Perform simple substitutions.
replace_names!(d, vec_to_dec_op1, vec_to_dec_op2)

# Replace `adv` with divergence of ∧.
advs = incident(d, :adv, :op2)
adv_tgts = d[advs, :res]

# Intermediate wedges.
wedge_tgts = add_parts!(d, :Var, length(adv_tgts), name=map(i -> Symbol("•_adv_$i"), eachindex(advs)), type=:infer)
# Divergences.
add_parts!(d, :Op1, length(adv_tgts), src=wedge_tgts, tgt=adv_tgts, op1=fill([:,:d,:],length(advs)))
# Point advs to the intermediates.
d[collect(advs), :res] = wedge_tgts

# Replace adv with ∧.
d[collect(advs), :op2] = fill(:,length(advs))

d
end

25 changes: 25 additions & 0 deletions test/diag2dwd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1229,5 +1229,30 @@ end
vec_to_dec!(t7)
t7 = contract_operators(t7)
@test only(t7[:op1]) == [:d,:,:d,:]

# Test advection is divergence of wedge product.
t8 = @decapode begin
A == adv(B, C)
end
vec_to_dec!(t8)

@test only(t8[:op1]) == [:,:d,:]
@test only(t8[:op2]) == :

# Test multiple advections.
t9 = @decapode begin
A == adv(B, C)
D == adv(E, F)
end
vec_to_dec!(t9)

t9_expected = @decapode begin
A == (,d,)(B C)
D == (,d,)(E F)
end
t9_expected[incident(t9_expected, Symbol("•1"), :name), :name] = Symbol("•_adv_1")
t9_expected[incident(t9_expected, Symbol("•2"), :name), :name] = Symbol("•_adv_2")
@test is_isomorphic(t9, t9_expected)

end

0 comments on commit fc8c8f8

Please sign in to comment.