Skip to content

Commit 85c2bef

Browse files
Make more compile-time friendly
1 parent 21c7e39 commit 85c2bef

File tree

6 files changed

+38
-36
lines changed

6 files changed

+38
-36
lines changed

src/parameterized_tendencies/les_sgs_models/smagorinsky_lilly.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ function horizontal_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::SmagorinskyLill
107107
@. Yₜ.c.ρe_tot += wdivₕ(Y.c.ρ * ᶜD_smag * gradₕ(ᶜh_tot))
108108

109109
## Tracer diffusion and associated mass changes
110-
UU.unrolled_foreach(filter(is_tracer_var, propertynames(Yₜ.c))) do ρχ_name
111-
if ρχ_name != :ρe_tot
110+
UU.unrolled_foreach(propertynames(Yₜ.c)) do ρχ_name
111+
if is_tracer_var(ρχ_name) && ρχ_name != :ρe_tot
112112
ᶜρχ = getproperty(Y.c, ρχ_name)
113113
ᶜρχₜ = getproperty(Yₜ.c, ρχ_name)
114114
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
@@ -161,8 +161,8 @@ function vertical_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::SmagorinskyLilly)
161161
@. Yₜ.c.ρe_tot -= ᶜdivᵥ_ρe_tot(-(ᶠρ * ᶠD_smag * ᶠgradᵥ(ᶜh_tot)))
162162

163163
## Tracer diffusion and associated mass changes
164-
UU.unrolled_foreach(filter(is_tracer_var, propertynames(Yₜ.c))) do ρχ_name
165-
if ρχ_name != :ρe_tot
164+
UU.unrolled_foreach(propertynames(Yₜ.c)) do ρχ_name
165+
if is_tracer_var(ρχ_name) && ρχ_name != :ρe_tot
166166
ᶜρχ = getproperty(Y.c, ρχ_name)
167167
ᶜρχₜ = getproperty(Yₜ.c, ρχ_name)
168168
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))

src/prognostic_equations/advection.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
213213
ᶜρ = Y.c.ρ
214214

215215
# Full vertical advection of passive tracers (like liq, rai, etc) ...
216-
UU.unrolled_foreach(filter(is_tracer_var, propertynames(Yₜ.c))) do ρχ_name
217-
if !(ρχ_name in (:ρe_tot, :ρq_tot))
216+
UU.unrolled_foreach(propertynames(Yₜ.c)) do ρχ_name
217+
if is_tracer_var(ρχ_name) && !(ρχ_name in (:ρe_tot, :ρq_tot))
218218
ᶜρχ = getproperty(Y.c, ρχ_name)
219219
ᶜρχₜ = getproperty(Yₜ.c, ρχ_name)
220220
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))

src/prognostic_equations/hyperdiffusion.jl

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -289,23 +289,25 @@ NVTX.@annotate function apply_tracer_hyperdiffusion_tendency!(Yₜ, Y, p, t)
289289
# by the limiter. Is this a significant problem?
290290
# TODO: Figure out why caching the duplicated tendencies in ᶜtemp_scalar
291291
# triggers allocations.
292-
UU.unrolled_foreach(filter(is_tracer_var, propertynames(Yₜ.c))) do ρχ_name
293-
ᶜρχ = getproperty(Y.c, ρχ_name)
294-
ᶜρχₜ = getproperty(Yₜ.c, ρχ_name)
295-
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
296-
297-
ν₄_scalar = ifelse(
298-
ρχ_name in (:ρq_rai, :ρq_sno, :ρn_rai),
299-
α_hyperdiff_tracer * ν₄_scalar,
300-
ν₄_scalar,
301-
)
302-
ᶜ∇²χ = getproperty(ᶜ∇²specific_tracers, specific_name(ρχ_name))
303-
@. ᶜρχₜ -= ν₄_scalar * wdivₕ(Y.c.ρ * gradₕ(ᶜ∇²χ))
304-
305-
# Exclude contributions from hyperdiffusion of condensate,
306-
# precipitating species from mass tendency.
307-
if ρχ_name == :ρq_tot
308-
@. Yₜ.c.ρ -= ν₄_scalar * wdivₕ(Y.c.ρ * gradₕ(ᶜ∇²χ))
292+
UU.unrolled_foreach(propertynames(Yₜ.c)) do ρχ_name
293+
if is_tracer_var(ρχ_name)
294+
ᶜρχ = getproperty(Y.c, ρχ_name)
295+
ᶜρχₜ = getproperty(Yₜ.c, ρχ_name)
296+
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
297+
298+
ν₄_scalar = ifelse(
299+
ρχ_name in (:ρq_rai, :ρq_sno, :ρn_rai),
300+
α_hyperdiff_tracer * ν₄_scalar,
301+
ν₄_scalar,
302+
)
303+
ᶜ∇²χ = getproperty(ᶜ∇²specific_tracers, specific_name(ρχ_name))
304+
@. ᶜρχₜ -= ν₄_scalar * wdivₕ(Y.c.ρ * gradₕ(ᶜ∇²χ))
305+
306+
# Exclude contributions from hyperdiffusion of condensate,
307+
# precipitating species from mass tendency.
308+
if ρχ_name == :ρq_tot
309+
@. Yₜ.c.ρ -= ν₄_scalar * wdivₕ(Y.c.ρ * gradₕ(ᶜ∇²χ))
310+
end
309311
end
310312
end
311313
if turbconv_model isa PrognosticEDMFX

src/prognostic_equations/remaining_tendency.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ NVTX.@annotate function additional_tendency!(Yₜ, Y, p, t)
166166
@. Yₜ.c.ρe_tot += vst_ρe_tot
167167

168168
# TODO: can we write this out explicitly?
169-
UU.unrolled_foreach(filter(is_tracer_var, propertynames(Yₜ.c))) do ρχ_name
170-
if ρχ_name != :ρe_tot
169+
UU.unrolled_foreach(propertynames(Yₜ.c)) do ρχ_name
170+
if is_tracer_var(ρχ_name) && ρχ_name != :ρe_tot
171171
ᶜρχ = getproperty(Y.c, ρχ_name)
172172
ᶜρχₜ = getproperty(Yₜ.c, ρχ_name)
173173
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))

src/prognostic_equations/surface_flux.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ function surface_flux_tendency!(Yₜ, Y, p, t)
115115
btt = boundary_tendency_scalar(ᶜh_tot, sfc_conditions.ρ_flux_h_tot)
116116
@. Yₜ.c.ρe_tot -= btt
117117
ρ_flux_χ = p.scratch.sfc_temp_C3
118-
UU.unrolled_foreach(filter(is_tracer_var, propertynames(Yₜ.c))) do ρχ_name
119-
ᶜρχ = getproperty(Y.c, ρχ_name)
120-
ᶜρχₜ = getproperty(Yₜ.c, ρχ_name)
121-
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
122-
if ρχ_name != :ρe_tot
118+
UU.unrolled_foreach(propertynames(Yₜ.c)) do ρχ_name
119+
if is_tracer_var(ρχ_name) && ρχ_name != :ρe_tot
120+
ᶜρχ = getproperty(Y.c, ρχ_name)
121+
ᶜρχₜ = getproperty(Yₜ.c, ρχ_name)
122+
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
123123
if ρχ_name == :ρq_tot
124124
@. ρ_flux_χ = sfc_conditions.ρ_flux_q_tot
125125
else

src/prognostic_equations/vertical_diffusion_boundary_layer.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ function vertical_diffusion_boundary_layer_tendency!(
9696

9797
ᶜρχₜ_diffusion = p.scratch.ᶜtemp_scalar
9898
ᶜK_h_scaled = p.scratch.ᶜtemp_scalar_2
99-
UU.unrolled_foreach(filter(is_tracer_var, propertynames(Yₜ.c))) do ρχ_name
100-
ᶜρχ = getproperty(Y.c, ρχ_name)
101-
ᶜρχₜ = getproperty(Yₜ.c, ρχ_name)
102-
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
103-
if ρχ_name != :ρe_tot
104-
if χ_name in (:q_rai, :q_sno, :n_rai)
99+
UU.unrolled_foreach(propertynames(Yₜ.c)) do ρχ_name
100+
if is_tracer_var(ρχ_name) && ρχ_name != :ρe_tot
101+
ᶜρχ = getproperty(Y.c, ρχ_name)
102+
ᶜρχₜ = getproperty(Yₜ.c, ρχ_name)
103+
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
104+
if ρχ_name in (:ρq_rai, :ρq_sno, :ρn_rai)
105105
@. ᶜK_h_scaled = α_vert_diff_tracer * ᶜK_h
106106
else
107107
@. ᶜK_h_scaled = ᶜK_h

0 commit comments

Comments
 (0)