Skip to content

Commit e59aa7f

Browse files
Merge pull request #2951 from CliMA/ck/buoyancy_grad_perf
Flatten buoyancy_gradients call
2 parents 76c8be1 + b970dd0 commit e59aa7f

File tree

5 files changed

+56
-30
lines changed

5 files changed

+56
-30
lines changed

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -782,16 +782,12 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
782782
BuoyGradMean(),
783783
thermo_params,
784784
moisture_model,
785-
EnvBuoyGradVars(
786-
ᶜts,
787-
projected_vector_buoy_grad_vars(
788-
C3,
789-
p.precomputed.ᶜgradᵥ_θ_virt, # ∂θv∂z_unsat
790-
p.precomputed.ᶜgradᵥ_q_tot, # ∂qt∂z_sat
791-
p.precomputed.ᶜgradᵥ_θ_liq_ice, # ∂θl∂z_sat
792-
ᶜlg,
793-
),
794-
),
785+
ᶜts,
786+
C3,
787+
p.precomputed.ᶜgradᵥ_θ_virt, # ∂θv∂z_unsat
788+
p.precomputed.ᶜgradᵥ_q_tot, # ∂qt∂z_sat
789+
p.precomputed.ᶜgradᵥ_θ_liq_ice, # ∂θl∂z_sat
790+
ᶜlg,
795791
)
796792

797793
# TODO: Currently the shear production only includes vertical gradients

src/cache/precomputed_quantities.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ function precomputed_quantities(Y, atmos)
101101
ᶜentrʲs = similar(Y.c, NTuple{n, FT}),
102102
ᶜdetrʲs = similar(Y.c, NTuple{n, FT}),
103103
ᶠnh_pressure₃ʲs = similar(Y.f, NTuple{n, C3{FT}}),
104+
ᶜgradᵥ_θ_virt⁰ = Fields.Field(C3{FT}, cspace),
105+
ᶜgradᵥ_q_tot⁰ = Fields.Field(C3{FT}, cspace),
106+
ᶜgradᵥ_θ_liq_ice⁰ = Fields.Field(C3{FT}, cspace),
104107
precipitation_sgs_quantities...,
105108
) : (;)
106109
sgs_quantities = (;

src/cache/prognostic_edmf_precomputed_quantities.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,22 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
267267
)
268268
end
269269

270+
(; ᶜgradᵥ_θ_virt⁰, ᶜgradᵥ_q_tot⁰, ᶜgradᵥ_θ_liq_ice⁰) = p.precomputed
270271
# First order approximation: Use environmental mean fields.
272+
@. ᶜgradᵥ_θ_virt⁰ = ᶜgradᵥ(ᶠinterp(TD.virtual_pottemp(thermo_params, ᶜts⁰))) # ∂θv∂z_unsat
273+
@. ᶜgradᵥ_q_tot⁰ = ᶜgradᵥ(ᶠinterp(ᶜq_tot⁰)) # ∂qt∂z_sat
274+
@. ᶜgradᵥ_θ_liq_ice⁰ =
275+
ᶜgradᵥ(ᶠinterp(TD.liquid_ice_pottemp(thermo_params, ᶜts⁰))) # ∂θl∂z_sat
271276
@. ᶜlinear_buoygrad = buoyancy_gradients(
272277
BuoyGradMean(),
273278
thermo_params,
274279
moisture_model,
275-
EnvBuoyGradVars(
276-
ᶜts⁰,
277-
projected_vector_buoy_grad_vars(
278-
C3,
279-
ᶜgradᵥ(ᶠinterp(TD.virtual_pottemp(thermo_params, ᶜts⁰))), # ∂θv∂z_unsat
280-
ᶜgradᵥ(ᶠinterp(ᶜq_tot⁰)), # ∂qt∂z_sat
281-
ᶜgradᵥ(ᶠinterp(TD.liquid_ice_pottemp(thermo_params, ᶜts⁰))), # ∂θl∂z_sat
282-
ᶜlg,
283-
),
284-
),
280+
ᶜts⁰,
281+
C3,
282+
ᶜgradᵥ_θ_virt⁰,
283+
ᶜgradᵥ_q_tot⁰,
284+
ᶜgradᵥ_θ_liq_ice⁰,
285+
ᶜlg,
285286
)
286287

287288
# TODO: Currently the shear production only includes vertical gradients

src/prognostic_equations/buoyancy_gradients.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,36 @@ The dispatch on EnvBuoyGradVars type is performed at the EnvBuoyGradVars constru
3434
used here are consistent for both mean fields and conditional fields obtained from assumed distributions
3535
over the conserved thermodynamic variables.
3636
"""
37+
function buoyancy_gradients end
38+
39+
function buoyancy_gradients(
40+
ebgc::AbstractEnvBuoyGradClosure,
41+
thermo_params,
42+
moisture_model,
43+
ts,
44+
::Type{C3},
45+
∂θv∂z_unsat,
46+
∂qt∂z_sat,
47+
∂θl∂z_sat,
48+
ᶜlg,
49+
) where {C3}
50+
return buoyancy_gradients(
51+
ebgc,
52+
thermo_params,
53+
moisture_model,
54+
EnvBuoyGradVars(
55+
ts,
56+
projected_vector_buoy_grad_vars(
57+
C3,
58+
∂θv∂z_unsat,
59+
∂qt∂z_sat,
60+
∂θl∂z_sat,
61+
ᶜlg,
62+
),
63+
),
64+
)
65+
end
66+
3767
function buoyancy_gradients(
3868
ebgc::AbstractEnvBuoyGradClosure,
3969
thermo_params,

src/prognostic_equations/gm_sgs_closures.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,12 @@ NVTX.@annotate function compute_gm_mixing_length!(ᶜmixing_length, Y, p)
3636
BuoyGradMean(),
3737
thermo_params,
3838
p.atmos.moisture_model,
39-
EnvBuoyGradVars(
40-
ᶜts,
41-
projected_vector_buoy_grad_vars(
42-
C3,
43-
p.precomputed.ᶜgradᵥ_θ_virt, # ∂θv∂z_unsat
44-
p.precomputed.ᶜgradᵥ_q_tot, # ∂qt∂z_sat
45-
p.precomputed.ᶜgradᵥ_θ_liq_ice, # ∂θl∂z_sat
46-
ᶜlg,
47-
),
48-
),
39+
ᶜts,
40+
C3,
41+
p.precomputed.ᶜgradᵥ_θ_virt, # ∂θv∂z_unsat
42+
p.precomputed.ᶜgradᵥ_q_tot, # ∂qt∂z_sat
43+
p.precomputed.ᶜgradᵥ_θ_liq_ice, # ∂θl∂z_sat
44+
ᶜlg,
4945
)
5046

5147
ᶠu = p.scratch.ᶠtemp_C123

0 commit comments

Comments
 (0)