Skip to content

Commit 0e35f3d

Browse files
authored
Merge pull request #4088 from CliMA/zs/rm_tke_function
remove tke_exchange and specific_tke
2 parents 458529b + c1866a0 commit 0e35f3d

13 files changed

+22
-120
lines changed

reproducibility_tests/ref_counter.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
273
1+
274
22

33
# **README**
44
#
@@ -20,6 +20,9 @@
2020

2121

2222
#=
23+
274
24+
- Remove unused calculation of TKE exchange in mixing length
25+
2326
273
2427
- Updated deps
2528

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
505505
),
506506
)
507507

508-
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, Y.c.ρ, turbconv_model))
508+
ᶜtke⁰ = @. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))
509509

510510
for i in 2:Spaces.nlevels(axes(Y.c))
511511
ρ_level = Fields.field_values(Fields.level(Y.c.ρ, i))

src/cache/prognostic_edmf_precomputed_quantities.jl

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

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-
27+
ᶜtke⁰ = @. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))
3028
set_sgs_ᶠu₃!(u₃⁰, ᶠu₃⁰, Y, turbconv_model)
3129
set_velocity_quantities!(ᶜu⁰, ᶠu³⁰, ᶜK⁰, ᶠu₃⁰, Y.c.uₕ, ᶠuₕ³)
3230
# @. ᶜK⁰ += ᶜtke⁰
@@ -346,7 +344,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
346344
ᶜlg = Fields.local_geometry_field(Y.c)
347345
ᶠlg = Fields.local_geometry_field(Y.f)
348346
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))
349-
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
347+
ᶜtke⁰ = @. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))
350348

351349
ᶜvert_div = p.scratch.ᶜtemp_scalar
352350
ᶜ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
@@ -67,7 +67,7 @@ import ..turbulent_prandtl_number
6767
import ..smagorinsky_lilly_length
6868
import ..ᶜcompute_eddy_diffusivity_coefficient
6969
import ..ρa⁰
70-
import ..specific_tke
70+
import ..specific
7171
import ..ᶜspecific_env_value
7272

7373

src/diagnostics/edmfx_diagnostics.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ function compute_tke!(
13981398
end
13991399

14001400
ᶜtke = @. lazy(
1401-
specific_tke(state.c.ρ, state.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model),
1401+
specific(state.c.sgs⁰.ρatke, state.c.ρ),
14021402
)
14031403
if isnothing(out)
14041404
return Base.materialize(ᶜtke)
@@ -1574,7 +1574,7 @@ function compute_edt!(
15741574
turbconv_model isa PrognosticEDMFX ?
15751575
(@. lazy(ρa⁰(state.c.ρ, state.c.sgsʲs, turbconv_model))) : state.c.ρ
15761576
ᶜtke⁰ = @. lazy(
1577-
specific_tke(state.c.ρ, state.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model),
1577+
specific(state.c.sgs⁰.ρatke, state.c.ρ),
15781578
)
15791579
ᶜmixing_length_field = ᶜmixing_length(state, cache)
15801580
ᶜK_u = @. lazy(eddy_viscosity(turbconv_params, ᶜtke⁰, ᶜmixing_length_field))
@@ -1663,7 +1663,7 @@ function compute_evu!(
16631663
turbconv_model isa PrognosticEDMFX ?
16641664
(@. lazy(ρa⁰(state.c.ρ, state.c.sgsʲs, turbconv_model))) : state.c.ρ
16651665
ᶜtke⁰ = @. lazy(
1666-
specific_tke(state.c.ρ, state.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model),
1666+
specific(state.c.sgs⁰.ρatke, state.c.ρ),
16671667
)
16681668
ᶜmixing_length_field = ᶜmixing_length(state, cache)
16691669
ᶜK_u = @. lazy(eddy_viscosity(turbconv_params, ᶜtke⁰, ᶜmixing_length_field))

src/prognostic_equations/advection.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
231231
end
232232
ᶜtke⁰ =
233233
advect_tke ?
234-
(@. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))) :
234+
(@. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))) :
235235
nothing
236236
ᶜa_scalar = p.scratch.ᶜtemp_scalar
237237
ᶜω³ = p.scratch.ᶜtemp_CT3

src/prognostic_equations/eddy_diffusion_closures.jl

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -512,19 +512,13 @@ function ᶜmixing_length(Y, p, property::Val{P} = Val{:master}()) where {P}
512512
z_sfc = Fields.level(Fields.coordinate_field(Y.f).z, Fields.half)
513513
ᶜdz = Fields.Δz_field(axes(Y.c))
514514

515-
turbconv_model = p.atmos.turbconv_model
516-
ᶜρa⁰ =
517-
turbconv_model isa PrognosticEDMFX ?
518-
(@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ
519-
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
515+
ᶜtke⁰ = @. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))
520516
sfc_tke = Fields.level(ᶜtke⁰, 1)
521517

522518
ᶜprandtl_nvec = p.scratch.ᶜtemp_scalar_5
523519
@. ᶜprandtl_nvec =
524520
turbulent_prandtl_number(params, ᶜlinear_buoygrad, ᶜstrain_rate_norm)
525521

526-
ᶜtke_exch = ᶜtke_exchange(Y, p)
527-
528522
ᶜmixing_length_tuple = @. lazy(
529523
mixing_length_lopez_gomez_2020(
530524
params,
@@ -629,62 +623,6 @@ function turbulent_prandtl_number(params, ᶜN²_eff, ᶜstrain_rate_norm)
629623
return min(max(prandtl_nvec, eps_FT), Pr_max)
630624
end
631625

632-
633-
"""
634-
ᶜtke_exchange(Y, p)
635-
636-
Calculates the turbulent kinetic energy (TKE) exchange tendency between the
637-
environment and updrafts due to detrainment.
638-
639-
Arguments:
640-
- `Y`: The prognostic state vector.
641-
- `p`: Cache
642-
643-
Returns:
644-
- The TKE exchange tendency term [m²/s³].
645-
"""
646-
function ᶜtke_exchange(Y, p)
647-
(; turbconv_model) = p.atmos
648-
n = n_mass_flux_subdomains(turbconv_model)
649-
ᶜρa⁰ =
650-
p.atmos.turbconv_model isa PrognosticEDMFX ?
651-
(@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ
652-
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
653-
654-
if p.atmos.turbconv_model isa PrognosticEDMFX
655-
(; ᶜdetrʲs, ᶠu³⁰, ᶠu³ʲs) = p.precomputed
656-
ᶜtke_exch = p.scratch.ᶜtemp_scalar_2
657-
@. ᶜtke_exch = 0
658-
for j in 1:n
659-
@. ᶜtke_exch +=
660-
Y.c.sgsʲs.:($$j).ρa * ᶜdetrʲs.:($$j) / ᶜρa⁰ * (
661-
1 / 2 * norm_sqr(ᶜinterp(ᶠu³⁰) - ᶜinterp(ᶠu³ʲs.:($$j))) -
662-
ᶜtke⁰
663-
)
664-
end
665-
666-
return ᶜtke_exch
667-
elseif p.atmos.turbconv_model isa DiagnosticEDMFX
668-
(; ᶜdetrʲs, ᶠu³⁰, ᶠu³ʲs, ᶜρaʲs) = p.precomputed
669-
ᶜtke_exch = p.scratch.ᶜtemp_scalar_2
670-
@. ᶜtke_exch = 0
671-
for j in 1:n
672-
@. ᶜtke_exch +=
673-
ᶜρaʲs.:($$j) * ᶜdetrʲs.:($$j) / ᶜρa⁰ * (
674-
1 / 2 * norm_sqr(ᶜinterp(ᶠu³⁰) - ᶜinterp(ᶠu³ʲs.:($$j))) -
675-
ᶜtke⁰
676-
)
677-
end
678-
679-
return ᶜtke_exch
680-
# ED only or none-EDMF model does not have updrafts (or detrainment),
681-
# so tke exchange is 0
682-
else
683-
return 0
684-
end
685-
686-
end
687-
688626
"""
689627
blend_scales(
690628
method::AbstractScaleBlending,

src/prognostic_equations/edmfx_sgs_flux.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ function edmfx_sgs_diffusive_flux_tendency!(
394394
(; ρatke_flux) = p.precomputed
395395
ᶠgradᵥ = Operators.GradientC2F()
396396
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))
397-
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
397+
ᶜtke⁰ = @. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))
398398

399399
if p.atmos.edmfx_model.sgs_diffusive_flux isa Val{true}
400400

@@ -535,7 +535,7 @@ function edmfx_sgs_diffusive_flux_tendency!(
535535
(; ᶜu, ᶜts) = p.precomputed
536536
(; ρatke_flux) = p.precomputed
537537
ᶠgradᵥ = Operators.GradientC2F()
538-
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, Y.c.ρ, turbconv_model))
538+
ᶜtke⁰ = @. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))
539539

540540
if p.atmos.edmfx_model.sgs_diffusive_flux isa Val{true}
541541

src/prognostic_equations/edmfx_tke.jl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ function edmfx_tke_tendency!(Yₜ, Y, p, t, turbconv_model::EDOnlyEDMFX)
2929
(; params) = p
3030
(; ᶜstrain_rate_norm, ᶜlinear_buoygrad) = p.precomputed
3131
turbconv_params = CAP.turbconv_params(p.params)
32-
ᶜρa⁰ = Y.c.ρ # EDOnly
33-
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
32+
ᶜtke⁰ = @. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))
3433
ᶜmixing_length_field = p.scratch.ᶜtemp_scalar
3534
ᶜmixing_length_field .= ᶜmixing_length(Y, p)
3635
ᶜK_u = @. lazy(eddy_viscosity(turbconv_params, ᶜtke⁰, ᶜmixing_length_field))
@@ -57,20 +56,13 @@ function edmfx_tke_tendency!(
5756
turbconv_params = CAP.turbconv_params(p.params)
5857
FT = eltype(p.params)
5958
thermo_params = CAP.thermodynamics_params(p.params)
60-
ᶜρa⁰ =
61-
turbconv_model isa PrognosticEDMFX ?
62-
(@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ
6359

6460
if use_prognostic_tke(turbconv_model)
6561
(; ᶜρʲs) = p.precomputed
6662
ᶠz = Fields.coordinate_field(Y.f).z
6763
ᶜmixing_length_field = p.scratch.ᶜtemp_scalar_2
6864
ᶜmixing_length_field .= ᶜmixing_length(Y, p)
69-
ᶜρa⁰ =
70-
turbconv_model isa PrognosticEDMFX ?
71-
(@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ
72-
ᶜtke⁰ =
73-
@. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
65+
ᶜtke⁰ = @. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))
7466
ᶜK_u = @. lazy(
7567
eddy_viscosity(turbconv_params, ᶜtke⁰, ᶜmixing_length_field),
7668
)
@@ -98,6 +90,7 @@ function edmfx_tke_tendency!(
9890
end
9991
# Note: Adding the following tendency breaks bm_aquaplanet_progedmf_dense_autodiff
10092
if turbconv_model isa PrognosticEDMFX
93+
ᶜρa⁰ = @. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))
10194
(; ᶜts⁰) = p.precomputed
10295
ᶜρ⁰ = @. lazy(TD.air_density(thermo_params, ᶜts⁰))
10396
@. Yₜ.c.sgs⁰.ρatke -=

src/prognostic_equations/hyperdiffusion.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ NVTX.@annotate function prep_hyperdiffusion_tendency!(Yₜ, Y, p, t)
114114
@. ᶜ∇²specific_energy = wdivₕ(gradₕ(specific(Y.c.ρe_tot, Y.c.ρ) + ᶜp / Y.c.ρ - ᶜh_ref))
115115

116116
if diffuse_tke
117-
ᶜρa⁰ =
118-
turbconv_model isa PrognosticEDMFX ?
119-
(@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ
120-
ᶜtke⁰ = @. lazy(specific_tke(Y.c.ρ, Y.c.sgs⁰.ρatke, ᶜρa⁰, turbconv_model))
117+
ᶜtke⁰ = @. lazy(specific(Y.c.sgs⁰.ρatke, Y.c.ρ))
121118
(; ᶜ∇²tke⁰) = p.hyperdiff
122119
@. ᶜ∇²tke⁰ = wdivₕ(gradₕ(ᶜtke⁰))
123120
end

0 commit comments

Comments
 (0)