Skip to content

Commit 88e9fbd

Browse files
committed
remove ᶜspecific_tke
1 parent b557313 commit 88e9fbd

10 files changed

+60
-60
lines changed

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 5 additions & 2 deletions
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))
@@ -992,9 +993,11 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
992993

993994
if p.atmos.turbconv_model isa DiagnosticEDMFX
994995
(; ᶜρaʲs, ᶠu³ʲs, ᶜdetrʲs, ᶠu³⁰, ᶜu⁰) = p.precomputed
996+
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, ᶜρaʲs, turbconv_model))
995997
elseif p.atmos.turbconv_model isa EDOnlyEDMFX
996998
ᶠu³⁰ = p.precomputed.ᶠu³
997999
ᶜu⁰ = ᶜu
1000+
ᶜρa⁰ = Y.c.ρ
9981001
end
9991002
@. ᶜu⁰ = C123(Y.c.uₕ) + ᶜinterp(C123(ᶠu³⁰)) # Set here, but used in a different function
10001003

@@ -1021,7 +1024,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
10211024
@. ᶜprandtl_nvec =
10221025
turbulent_prandtl_number(params, ᶜlinear_buoygrad, ᶜstrain_rate_norm)
10231026

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

10261029
ᶜtke_exch = p.scratch.ᶜtemp_scalar_2
10271030
@. ᶜtke_exch = 0

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⁰
@@ -361,8 +363,8 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
361363
ᶜdz = Fields.Δz_field(axes(Y.c))
362364
ᶜlg = Fields.local_geometry_field(Y.c)
363365
ᶠlg = Fields.local_geometry_field(Y.f)
364-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
365366
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))
367+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
366368

367369
ᶜvert_div = p.scratch.ᶜtemp_scalar
368370
ᶜmassflux_vert_div = p.scratch.ᶜtemp_scalar_2

src/diagnostics/Diagnostics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import ..draft_area
5959
import ..compute_gm_mixing_length!
6060
import ..horizontal_integral_at_boundary
6161
import ..ρa⁰
62-
import ..ᶜspecific_tke
62+
import ..specific_tke
6363
import ..ᶜspecific_env_value
6464

6565
# We need the abbreviations for symbols like curl, grad, and so on

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
@@ -405,7 +405,7 @@ function edmfx_sgs_diffusive_flux_tendency!(
405405
(; ᶜmixing_length, ᶜK_u, ᶜK_h, ρatke_flux) = p.precomputed
406406
ᶠgradᵥ = Operators.GradientC2F()
407407
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))
408-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
408+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
409409

410410
if p.atmos.edmfx_model.sgs_diffusive_flux isa Val{true}
411411
ᶠρaK_h = p.scratch.ᶠtemp_scalar
@@ -513,7 +513,13 @@ function edmfx_sgs_diffusive_flux_tendency!(
513513
(; ᶜu, ᶜmixing_length, ᶜts) = p.precomputed
514514
(; ᶜK_u, ᶜK_h, ρatke_flux) = p.precomputed
515515
ᶠgradᵥ = Operators.GradientC2F()
516-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
516+
if turbconv_model isa DiagnosticEDMFX
517+
(; ᶜρaʲs) = p.precomputed
518+
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, ᶜρaʲs, turbconv_model))
519+
elseif turbconv_model isa EDOnlyEDMFX
520+
ᶜρa⁰ = Y.c.ρ
521+
end
522+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
517523

518524
if p.atmos.edmfx_model.sgs_diffusive_flux isa Val{true}
519525
ᶠρaK_h = p.scratch.ᶠtemp_scalar

src/prognostic_equations/edmfx_tke.jl

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

5252

53-
ᶜρa⁰ = turbconv_model isa PrognosticEDMFX ? (@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : @. lazy(Y.c.ρ)
53+
ᶜρa⁰ = turbconv_model isa PrognosticEDMFX ? (@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ
5454
nh_pressure3_buoyʲs =
5555
turbconv_model isa PrognosticEDMFX ?
5656
p.precomputed.ᶠnh_pressure₃_buoyʲs : p.precomputed.ᶠnh_pressure³_buoyʲs
@@ -77,7 +77,7 @@ function edmfx_tke_tendency!(
7777
# buoyancy production
7878
@. Yₜ.c.sgs⁰.ρatke -= ᶜρa⁰ * ᶜK_h * ᶜlinear_buoygrad
7979

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

8282
# entrainment and detraiment
8383
# 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/prognostic_equations/implicit/manual_sparse_jacobian.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,12 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
625625
(; dt) = p
626626
turbconv_model = p.atmos.turbconv_model
627627
ᶜmixing_length = p.precomputed.ᶜmixing_length
628-
ᶜtke⁰ = ᶜspecific_tke(Y, p)
629628
ᶜρa⁰ =
630-
p.atmos.turbconv_model isa PrognosticEDMFX ? (@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : @. lazy(Y.c.ρ)
629+
p.atmos.turbconv_model isa PrognosticEDMFX ? (@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ
631630
ᶜρatke⁰ = Y.c.sgs⁰.ρatke
632631

632+
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, ᶜρatke⁰, ᶜρa⁰, turbconv_model))
633+
633634
@inline tke_dissipation_rate_tendency(tke⁰, mixing_length) =
634635
tke⁰ >= 0 ? c_d * sqrt(tke⁰) / mixing_length : 1 / float(dt)
635636
@inline ∂tke_dissipation_rate_tendency_∂tke⁰(tke⁰, mixing_length) =

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)