Skip to content

Commit

Permalink
3d curl in vector hyperdiffusion
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Sep 8, 2023
1 parent 4205c01 commit 5a83d63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/cache/temporary_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function temporary_quantities(atmos, center_space, face_space)
ᶠtemp_CT3 = Fields.Field(CT3{FT}, face_space), # ᶠuₕ³
ᶠtemp_CT12 = Fields.Field(CT12{FT}, face_space), # ᶠω¹²
ᶠtemp_CT12ʲs = Fields.Field(NTuple{n, CT12{FT}}, face_space), # ᶠω¹²ʲs
ᶜtemp_C123 = Fields.Field(C123{FT}, center_space), # χ₁₂₃
ᶠtemp_C123 = Fields.Field(C123{FT}, face_space), # χ₁₂₃
ᶜtemp_UVWxUVW = Fields.Field(
typeof(UVW(FT(0), FT(0), FT(0)) * UVW(FT(0), FT(0), FT(0))'),
Expand Down
49 changes: 14 additions & 35 deletions src/prognostic_equations/hyperdiffusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,8 @@ function hyperdiffusion_tendency!(Yₜ, Y, p, t)
end

# Grid scale hyperdiffusion
@. ᶜ∇²u = C123(wgradₕ(divₕ(p.ᶜu)))
# Without the C123(), the right-hand side would be a C1 or C2 in 2D space.
if point_type <: Geometry.Abstract3DPoint
@. p.ᶜtemp_C123 = C123(curlₕ(C12(p.ᶜu))) + C123(curlₕ(C3(p.ᶜu)))
@. ᶜ∇²u -=
C123(wcurlₕ(C12(p.ᶜtemp_C123))) + C123(wcurlₕ(C3(p.ᶜtemp_C123)))
end
@. ᶜ∇²u = C123(wgradₕ(divₕ(p.ᶜu))) - C123(wcurlₕ(C123(curlₕ(p.ᶜu))))

if in propertynames(ᶜspecific)
@. ᶜ∇²specific_energy = wdivₕ(gradₕ(ᶜspecific.θ))
elseif :e_tot in propertynames(ᶜspecific)
Expand All @@ -102,16 +97,9 @@ function hyperdiffusion_tendency!(Yₜ, Y, p, t)
# Sub-grid scale hyperdiffusion
if turbconv_model isa EDMFX
for j in 1:n
@. ᶜ∇²uʲs.:($$j) = C123(wgradₕ(divₕ(p.ᶜuʲs.:($$j))))
# Without the C123(), the right-hand side would be a C1 or C2 in 2D space.
if point_type <: Geometry.Abstract3DPoint
@. p.ᶜtemp_C123 =
C123(curlₕ(C12(p.ᶜuʲs.:($$j)))) +
C123(curlₕ(C3(p.ᶜuʲs.:($$j))))
@. ᶜ∇²uʲs.:($$j) -=
C123(wcurlₕ(C12(p.ᶜtemp_C123))) +
C123(wcurlₕ(C3(p.ᶜtemp_C123)))
end
@. ᶜ∇²uʲs.:($$j) =
C123(wgradₕ(divₕ(p.ᶜuʲs.:($$j)))) -
C123(wcurlₕ(C123(curlₕ(p.ᶜuʲs.:($$j)))))

if in propertynames(ᶜspecificʲs.:($j))
@. ᶜ∇²specific_energyʲs.:($$j) =
Expand Down Expand Up @@ -164,18 +152,13 @@ function hyperdiffusion_tendency!(Yₜ, Y, p, t)
end
end

# Grid scale hyperdiffusion continued
@. Yₜ.c.uₕ -= κ₄ * divergence_damping_factor * C12(wgradₕ(divₕ(ᶜ∇²u)))
# Without the C123(), the right-hand side would be a C1 or C2 in 2D space.
if point_type <: Geometry.Abstract3DPoint
@. p.ᶜtemp_C123 = C123(curlₕ(C12(ᶜ∇²u))) + C123(curlₕ(C3(ᶜ∇²u)))
@. Yₜ.c.uₕ +=
κ₄ *
(C12(wcurlₕ(C12(p.ᶜtemp_C123))) + C12(wcurlₕ(C3(p.ᶜtemp_C123))))
# Reuse the buffer variable here so we don't need an extra one
@. ᶜ∇²uᵥ = C3(wcurlₕ(C12(p.ᶜtemp_C123))) + C3(wcurlₕ(C3(p.ᶜtemp_C123)))
@. Yₜ.f.u₃ += κ₄ * ᶠwinterp(ᶜJ * Y.c.ρ, ᶜ∇²uᵥ)
end
# re-use to store the curl-curl part
@. ᶜ∇²u =
divergence_damping_factor * C123(wgradₕ(divₕ(ᶜ∇²u))) -
C123(wcurlₕ(C123(curlₕ(ᶜ∇²u))))
@. Yₜ.c.uₕ -= κ₄ * C12(ᶜ∇²u)
@. Yₜ.f.u₃ -= κ₄ * ᶠwinterp(ᶜJ * Y.c.ρ, C3(ᶜ∇²u))

ᶜρ_energyₜ = in propertynames(ᶜspecific) ? Yₜ.c.ρθ : Yₜ.c.ρe_tot
@. ᶜρ_energyₜ -= κ₄ * wdivₕ(Y.c.ρ * gradₕ(ᶜ∇²specific_energy))

Expand All @@ -186,12 +169,8 @@ function hyperdiffusion_tendency!(Yₜ, Y, p, t)
if turbconv_model isa EDMFX
for j in 1:n
if point_type <: Geometry.Abstract3DPoint
@. p.ᶜtemp_C123 =
C123(curlₕ(C12(ᶜ∇²uʲs.:($$j)))) +
C123(curlₕ(C3(ᶜ∇²uʲs.:($$j))))
# Reuse the buffer variable here so we don't need an extra one
@. ᶜ∇²uᵥʲs.:($$j) =
C3(wcurlₕ(C12(p.ᶜtemp_C123))) + C3(wcurlₕ(C3(p.ᶜtemp_C123)))
# only need curl-curl part
@. ᶜ∇²uᵥʲs.:($$j) = C3(wcurlₕ(C123(curlₕ(ᶜ∇²uʲs.:($$j)))))
@. Yₜ.f.sgsʲs.:($$j).u₃ +=
κ₄ * ᶠwinterp(ᶜJ * Y.c.ρ, ᶜ∇²uᵥʲs.:($$j))
end
Expand Down

0 comments on commit 5a83d63

Please sign in to comment.