Skip to content

Commit 0f54b24

Browse files
committed
remove ᶜspecific_tke
1 parent b84b28d commit 0f54b24

File tree

8 files changed

+55
-56
lines changed

8 files changed

+55
-56
lines changed

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
359359
specific(Y.c.ρe_tot, Y.c.ρ),
360360
),
361361
)
362-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
362+
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, ᶜρaʲs, turbconv_model))
363+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
363364

364365
for i in 2:Spaces.nlevels(axes(Y.c))
365366
ρ_level = Fields.field_values(Fields.level(Y.c.ρ, i))
@@ -987,9 +988,11 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
987988

988989
if p.atmos.turbconv_model isa DiagnosticEDMFX
989990
(; ᶜρaʲs, ᶠu³ʲs, ᶜdetrʲs, ᶠu³⁰, ᶜu⁰) = p.precomputed
991+
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, ᶜρaʲs, turbconv_model))
990992
elseif p.atmos.turbconv_model isa EDOnlyEDMFX
991993
ᶠu³⁰ = p.precomputed.ᶠu³
992994
ᶜu⁰ = ᶜu
995+
ᶜρa⁰ = Y.c.ρ
993996
end
994997
@. ᶜu⁰ = C123(Y.c.uₕ) + ᶜinterp(C123(ᶠu³⁰)) # Set here, but used in a different function
995998

src/cache/prognostic_edmf_precomputed_quantities.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_environment!(
2424
(; ᶜp, ᶜK) = p.precomputed
2525
(; ᶠu₃⁰, ᶜu⁰, ᶠu³⁰, ᶜK⁰, ᶜts⁰) = p.precomputed
2626

27-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
27+
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))
28+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
29+
2830
set_sgs_ᶠu₃!(u₃⁰, ᶠu₃⁰, Y, turbconv_model)
2931
set_velocity_quantities!(ᶜu⁰, ᶠu³⁰, ᶜK⁰, ᶠu₃⁰, Y.c.uₕ, ᶠuₕ³)
3032
# @. ᶜK⁰ += ᶜtke⁰
@@ -353,8 +355,8 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
353355
ᶜdz = Fields.Δz_field(axes(Y.c))
354356
ᶜlg = Fields.local_geometry_field(Y.c)
355357
ᶠlg = Fields.local_geometry_field(Y.f)
356-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
357358
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))
359+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
358360

359361
ᶜvert_div = p.scratch.ᶜtemp_scalar
360362
ᶜmassflux_vert_div = p.scratch.ᶜtemp_scalar_2

src/diagnostics/edmfx_diagnostics.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,17 @@ function compute_tke!(
11501150
time,
11511151
turbconv_model::Union{EDOnlyEDMFX, PrognosticEDMFX, DiagnosticEDMFX},
11521152
)
1153-
ᶜtke = ᶜspecific_tke(state, cache)
1153+
if turbconv_model isa PrognosticEDMFX
1154+
sgsʲs = state.c.sgsʲs
1155+
elseif turbconv_model isa DiagnosticEDMFX
1156+
(; ᶜρaʲs) = cache.precomputed
1157+
sgsʲs = ᶜρaʲs
1158+
else
1159+
sgsʲs = nothing
1160+
end
1161+
1162+
ᶜρa⁰ = @. lazy(ρa⁰(state.c.ρ, sgsʲs, turbconv_model))
1163+
ᶜtke = @. lazy(specific_tke(state.c.ρ, state.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
11541164
if isnothing(out)
11551165
return Base.materialize(ᶜtke)
11561166
else

src/prognostic_equations/advection.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,18 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
194194
turbconv_model isa EDOnlyEDMFX ? p.precomputed.ᶠu³ :
195195
p.precomputed.ᶠu³⁰
196196
) : nothing
197-
ᶜρa⁰ = advect_tke ? (n > 0 ? (@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : @. lazy(Y.c.ρ)) : nothing
197+
ᶜρa⁰ = advect_tke ? (n > 0 ? (@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ) : nothing
198198
ᶜρ⁰ = if advect_tke
199199
if n > 0
200200
(; ᶜts⁰) = p.precomputed
201201
@. lazy(TD.air_density(thermo_params, ᶜts⁰))
202202
else
203-
@. lazy(Y.c.ρ)
203+
Y.c.ρ
204204
end
205205
else
206206
nothing
207207
end
208-
ᶜtke⁰ = advect_tke ? (ᶜspecific_tke(Y, p)) : nothing
208+
ᶜtke⁰ = advect_tke ? (@. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))) : nothing
209209
ᶜa_scalar = p.scratch.ᶜtemp_scalar
210210
ᶜω³ = p.scratch.ᶜtemp_CT3
211211
ᶠω¹² = p.scratch.ᶠtemp_CT12

src/prognostic_equations/edmfx_sgs_flux.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ function edmfx_sgs_diffusive_flux_tendency!(
401401
(; ᶜmixing_length, ᶜK_u, ᶜK_h, ρatke_flux) = p.precomputed
402402
ᶠgradᵥ = Operators.GradientC2F()
403403
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))
404-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
404+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
405405

406406
if p.atmos.edmfx_model.sgs_diffusive_flux isa Val{true}
407407

@@ -525,7 +525,13 @@ function edmfx_sgs_diffusive_flux_tendency!(
525525
(; ᶜu, ᶜts) = p.precomputed
526526
(; ρatke_flux) = p.precomputed
527527
ᶠgradᵥ = Operators.GradientC2F()
528-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
528+
if turbconv_model isa DiagnosticEDMFX
529+
(; ᶜρaʲs) = p.precomputed
530+
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, ᶜρaʲs, turbconv_model))
531+
elseif turbconv_model isa EDOnlyEDMFX
532+
ᶜρa⁰ = Y.c.ρ
533+
end
534+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
529535

530536
if p.atmos.edmfx_model.sgs_diffusive_flux isa Val{true}
531537

src/prognostic_equations/edmfx_tke.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function edmfx_tke_tendency!(
5959
FT = eltype(p.params)
6060

6161

62-
ᶜρa⁰ = turbconv_model isa PrognosticEDMFX ? (@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : @. lazy(Y.c.ρ)
62+
ᶜρa⁰ = turbconv_model isa PrognosticEDMFX ? (@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ
6363
nh_pressure3_buoyʲs =
6464
turbconv_model isa PrognosticEDMFX ?
6565
p.precomputed.ᶠnh_pressure₃_buoyʲs : p.precomputed.ᶠnh_pressure³_buoyʲs
@@ -101,7 +101,7 @@ function edmfx_tke_tendency!(
101101
# buoyancy production
102102
@. Yₜ.c.sgs⁰.ρatke -= ᶜρa⁰ * ᶜK_h * ᶜlinear_buoygrad
103103

104-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
104+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
105105

106106
# entrainment and detraiment
107107
# using ᶜu⁰ and local geometry results in allocation

src/prognostic_equations/hyperdiffusion.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,16 @@ NVTX.@annotate function prep_hyperdiffusion_tendency!(Yₜ, Y, p, t)
117117
wdivₕ(gradₕ(specific(Y.c.ρe_tot, Y.c.ρ) + ᶜp / Y.c.ρ - ᶜh_ref))
118118

119119
if diffuse_tke
120-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
120+
if turbconv_model isa PrognosticEDMFX
121+
sgsʲs = Y.c.sgsʲs
122+
elseif turbconv_model isa DiagnosticEDMFX
123+
(; ᶜρaʲs) = p.precomputed
124+
sgsʲs = ᶜρaʲs
125+
else
126+
sgsʲs = nothing
127+
end
128+
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, sgsʲs, turbconv_model))
129+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
121130
(; ᶜ∇²tke⁰) = p.hyperdiff
122131
@. ᶜ∇²tke⁰ = wdivₕ(gradₕ(ᶜtke⁰))
123132
end
@@ -154,7 +163,6 @@ NVTX.@annotate function apply_hyperdiffusion_tendency!(Yₜ, Y, p, t)
154163
(; ᶜ∇²uₕʲs, ᶜ∇²uᵥʲs, ᶜ∇²uʲs, ᶜ∇²mseʲs) = p.hyperdiff
155164
end
156165
if use_prognostic_tke(turbconv_model)
157-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
158166
(; ᶜ∇²tke⁰) = p.hyperdiff
159167
end
160168

src/utils/variable_manipulations.jl

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -375,23 +375,12 @@ function ρa⁰(ρ, sgsʲs, turbconv_model)
375375
return env_value(ρ, sgsʲ -> sgsʲ.ρa, sgsʲs)
376376

377377
elseif turbconv_model isa DiagnosticEDMFX
378-
(; ᶜρaʲs) = p.precomputed
379378
return env_value(ρ, ᶜρaʲ -> ᶜρaʲ, sgsʲs)
380379
else
381-
return Y.c.ρ
380+
return ρ
382381
end
383382
end
384383

385-
"""
386-
Arguments:
387-
- `ρ`: The model state, which contains the grid-mean density `Y.c.ρ` and
388-
the draft subdomain states `Y.c.sgsʲs` (for PrognosticEDMFX).
389-
- `sgsʲs`: Y.c.sgsʲs for prognostic of The cache, containing precomputed quantities and turbconv_model.
390-
"""
391-
function ρa⁰(ρ, sgsʲs)
392-
# ρ - Σ ρaʲ
393-
return env_value(ρ, sgsʲ -> sgsʲ.ρa, sgsʲs)
394-
end
395384

396385
"""
397386
ᶜspecific_tke(Y, p)
@@ -404,47 +393,28 @@ fallback value (`ρχ_fallback`) in the limit of small environmental area
404393
fraction.
405394
406395
Arguments:
407-
- `Y`: The state, containing the grid-mean density `ρ` and the environment SGS state `Y.c.sgs⁰`.
408-
- `p`: The cache, containing precomputed quantities and turbconv_model.
396+
- `ρ`: The grid-mean density `ρ` and the environment SGS state `Y.c.sgs⁰`.
397+
- `ρatke`: The cache, containing precomputed quantities and turbconv_model.
398+
- `ρa⁰`: The environment area-weighted density.
409399
410400
Returns:
411401
- The specific TKE of the environment (`tke⁰`).
412402
"""
413-
function ᶜspecific_tke(Y, p)
414-
turbconv_model = p.atmos.turbconv_model
415-
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))
416-
417-
sgs⁰ = Y.c.sgs⁰
403+
function specific_tke(ρ, ρatke, ρa⁰, turbconv_model)
418404

419-
# no sgs weighting function needed for EDOnlyEDMFX
420-
if turbconv_model isa EDOnlyEDMFX
421-
return @. lazy(specific(sgs⁰.ρatke, ᶜρa⁰))
422-
else
423-
return @. lazy(
424-
specific(
425-
sgs⁰.ρatke, # ρaχ for environment TKE
426-
ᶜρa⁰, # ρa for environment, now computed internally
427-
0, # Fallback ρχ is zero for TKE
428-
Y.c.ρ, # Fallback ρ
429-
turbconv_model,
430-
),
431-
)
432-
end
433-
end
434-
435-
function specific_tke(ᶜρ, ᶜρatke, ᶜρa⁰, turbconv_model)
436-
return specific(
437-
ᶜρatke, # ρaχ for environment TKE
438-
ᶜρa⁰, # ρa for environment, now computed internally
405+
if turbconv_model isa PrognosticEDMFX || turbconv_model isa DiagnosticEDMFX
406+
return specific(
407+
ρatke, # ρaχ for environment TKE
408+
ρa⁰, # ρa for environment, now computed internally
439409
0, # Fallback ρχ is zero for TKE
440-
ᶜρ, # Fallback ρ
410+
ρ, # Fallback ρ
441411
turbconv_model,
442412
)
413+
else
414+
return specific(ρatke, ρa⁰)
415+
end
443416
end
444417

445-
function specific_tke(ᶜρatke, ᶜρa⁰, ::EDOnlyEDMFX)
446-
return specific(ᶜρatke, ᶜρa⁰)
447-
end
448418

449419
"""
450420
ᶜspecific_env_mse(Y, p)

0 commit comments

Comments
 (0)