Skip to content

Commit cf2a81a

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

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ Arguments:
4242
"""
4343
@inline specific(ρχ, ρ) = ρχ / ρ
4444

45+
@inline specific_name(ρχ_name::Symbol) =
46+
if ρχ_name == :ρe_tot
47+
return :e_tot
48+
elseif ρχ_name == :ρq_tot
49+
return :q_tot
50+
elseif ρχ_name == :ρq_liq
51+
return :q_liq
52+
elseif ρχ_name == :ρq_ice
53+
return :q_ice
54+
elseif ρχ_name == :ρq_rai
55+
return :n_liq
56+
elseif ρχ_name == :ρn_liq
57+
return :n_rai
58+
elseif ρχ_name == :ρn_rai
59+
return :q_rai
60+
elseif ρχ_name == :ρq_sno
61+
return :q_sno
62+
else
63+
error("Uncaught name: $ρχ_name")
64+
end
65+
4566
@inline function specific(ρaχ, ρa, ρχ, ρ, turbconv_model)
4667
# TODO: Replace turbconv_model struct by parameters, and include a_half in
4768
# parameters, not in config

0 commit comments

Comments
 (0)