Skip to content

Commit 8edcb24

Browse files
Reduce use of ᶜspecific
1 parent 5be90de commit 8edcb24

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/prognostic_equations/hyperdiffusion.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ NVTX.@annotate function prep_hyperdiffusion_tendency!(Yₜ, Y, p, t)
8585

8686
n = n_mass_flux_subdomains(turbconv_model)
8787
diffuse_tke = use_prognostic_tke(turbconv_model)
88-
(; ᶜp, ᶜspecific) = p.precomputed
88+
(; ᶜp) = p.precomputed
8989
(; ᶜ∇²u, ᶜ∇²specific_energy) = p.hyperdiff
9090
if turbconv_model isa PrognosticEDMFX
9191
(; ᶜ∇²uₕʲs, ᶜ∇²uᵥʲs, ᶜ∇²uʲs, ᶜ∇²mseʲs) = p.hyperdiff
@@ -137,7 +137,7 @@ NVTX.@annotate function apply_hyperdiffusion_tendency!(Yₜ, Y, p, t)
137137
diffuse_tke = use_prognostic_tke(turbconv_model)
138138
ᶜJ = Fields.local_geometry_field(Y.c).J
139139
point_type = eltype(Fields.coordinate_field(Y.c))
140-
(; ᶜp, ᶜspecific) = p.precomputed
140+
(; ᶜp) = p.precomputed
141141
(; ᶜ∇²u, ᶜ∇²specific_energy) = p.hyperdiff
142142
if turbconv_model isa PrognosticEDMFX
143143
(; ᶜρa⁰) = p.precomputed
@@ -240,11 +240,13 @@ NVTX.@annotate function prep_tracer_hyperdiffusion_tendency!(Yₜ, Y, p, t)
240240
(; hyperdiff, turbconv_model) = p.atmos
241241
isnothing(hyperdiff) && return nothing
242242

243-
(; ᶜspecific) = p.precomputed
244243
(; ᶜ∇²specific_tracers) = p.hyperdiff
245244

246-
for χ_name in propertynames(ᶜ∇²specific_tracers)
247-
@. ᶜ∇²specific_tracers.:($$χ_name) = wdivₕ(gradₕ(ᶜspecific.:($$χ_name)))
245+
for ρχ_name in filter(is_tracer_var, propertynames(Y.c))
246+
χ_name = specific_name(ρχ_name)
247+
ᶜρχ = getproperty(Y.c, ρχ_name)
248+
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
249+
@. ᶜ∇²specific_tracers.:($$χ_name) = wdivₕ(gradₕ(ᶜχ))
248250
end
249251

250252
if turbconv_model isa PrognosticEDMFX

src/utils/variable_manipulations.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ Arguments:
4242
"""
4343
@inline specific(ρχ, ρ) = ρχ / ρ
4444

45+
#! format: off
46+
@inline specific_name(ρχ_name::Symbol) =
47+
if ρχ_name == :ρe_tot; return :e_tot
48+
elseif ρχ_name == :ρq_tot; return :q_tot
49+
elseif ρχ_name == :ρq_liq; return :q_liq
50+
elseif ρχ_name == :ρq_ice; return :q_ice
51+
elseif ρχ_name == :ρq_rai; return :q_rai
52+
elseif ρχ_name == :ρn_liq; return :n_liq
53+
elseif ρχ_name == :ρn_rai; return :q_rai
54+
elseif ρχ_name == :ρq_sno; return :q_sno
55+
else; error("Uncaught name: $ρχ_name")
56+
end
57+
#! format: on
58+
4559
@inline function specific(ρaχ, ρa, ρχ, ρ, turbconv_model)
4660
# TODO: Replace turbconv_model struct by parameters, and include a_half in
4761
# parameters, not in config

0 commit comments

Comments
 (0)