Skip to content

Commit ca4cde6

Browse files
committed
Remove k_u, k_v, and mixing length from precomputed quantities
1 parent 5557f30 commit ca4cde6

19 files changed

+372
-230
lines changed

config/model_configs/diagnostic_edmfx_aquaplanet_dense_autodiff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ edmfx_sgs_diffusive_flux: true
1919
moist: equil
2020
cloud_model: "quadrature_sgs"
2121
precip_model: 0M
22-
dt: 120secs
22+
dt: 80secs
2323
t_end: 1hours
2424
toml: [toml/diagnostic_edmfx_0M.toml]

perf/benchmark.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ are_boundschecks_forced = Base.JLOptions().check_bounds == 1
6060
end
6161
@test compare_mem(trials, "Wfact", 0)
6262
@test compare_mem(trials, "ldiv!", 0)
63-
@test compare_mem(trials, "T_imp!", 96)
63+
@test compare_mem(trials, "T_imp!", 19680)
6464
@test compare_mem(trials, "T_exp_T_lim!", 190420)
6565
@test compare_mem(trials, "lim!", 0)
6666
@test compare_mem(trials, "dss!", 0)

perf/flame.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ allocs_limit["flame_diagnostics"] = 10_677_144
4545
allocs_limit["flame_aquaplanet_diagedmf"] = 11_644_128
4646
allocs_limit["flame_aquaplanet_progedmf"] = 774_712
4747
allocs_limit["flame_aquaplanet_progedmf_dense_autodiff"] = 774_712
48-
allocs_limit["flame_diffusion"] = 138_432
48+
allocs_limit["flame_diffusion"] = 153_248
4949
allocs_limit["flame_threaded"] = 2047_736
50-
allocs_limit["flame_callbacks"] = 391_864
50+
allocs_limit["flame_callbacks"] = 450_336
5151
allocs_limit["flame_gravity_wave"] = 581_381_976
5252
# Ideally, we would like to track all the allocations, but this becomes too
5353
# expensive there is too many of them. Here, we set the default sample rate to

perf/jet_test_nfailures.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ using Test
3838
# inference. By increasing this counter, we acknowledge that
3939
# we have introduced an inference failure. We hope to drive
4040
# this number down to 0.
41-
n_allowed_failures = 253
41+
n_allowed_failures = 265
4242
@show n
4343
if n < n_allowed_failures
4444
@info "Please update the n-failures to $n"

reproducibility_tests/ref_counter.jl

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

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

2121

2222
#=
23+
249
24+
- Remove viscosity, diffusivity, and mixing length from precomputed quantities
25+
2326
248
2427
- update deps: climacore 0.14.35
2528

src/cache/cloud_fraction.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ end
2222
Compute the grid scale cloud fraction based on sub-grid scale properties
2323
"""
2424
NVTX.@annotate function set_cloud_fraction!(Y, p, ::DryModel, _)
25-
(; ᶜmixing_length) = p.precomputed
2625
(; turbconv_model) = p.atmos
2726
FT = eltype(p.params)
28-
if isnothing(turbconv_model)
29-
compute_gm_mixing_length!(ᶜmixing_length, Y, p)
30-
end
27+
3128
p.precomputed.cloud_diagnostics_tuple .=
3229
((; cf = FT(0), q_liq = FT(0), q_ice = FT(0)),)
3330
end
@@ -39,8 +36,9 @@ NVTX.@annotate function set_cloud_fraction!(
3936
)
4037
(; params) = p
4138
(; turbconv_model) = p.atmos
42-
(; ᶜts, ᶜmixing_length, cloud_diagnostics_tuple) = p.precomputed
39+
(; ᶜts, cloud_diagnostics_tuple) = p.precomputed
4340
thermo_params = CAP.thermodynamics_params(params)
41+
4442
if isnothing(turbconv_model)
4543
if p.atmos.call_cloud_diagnostics_per_stage isa
4644
CallCloudDiagnosticsPerStage
@@ -53,7 +51,6 @@ NVTX.@annotate function set_cloud_fraction!(
5351
@. ᶜgradᵥ_θ_liq_ice =
5452
ᶜgradᵥ(ᶠinterp(TD.liquid_ice_pottemp(thermo_params, ᶜts)))
5553
end
56-
compute_gm_mixing_length!(ᶜmixing_length, Y, p)
5754
end
5855
if moist_model isa EquilMoistModel
5956
@. cloud_diagnostics_tuple = make_named_tuple(
@@ -85,7 +82,7 @@ NVTX.@annotate function set_cloud_fraction!(
8582

8683
FT = eltype(params)
8784
thermo_params = CAP.thermodynamics_params(params)
88-
(; ᶜts, ᶜmixing_length, cloud_diagnostics_tuple) = p.precomputed
85+
(; ᶜts, cloud_diagnostics_tuple) = p.precomputed
8986
(; turbconv_model) = p.atmos
9087

9188
if isnothing(turbconv_model)
@@ -100,9 +97,10 @@ NVTX.@annotate function set_cloud_fraction!(
10097
@. ᶜgradᵥ_θ_liq_ice =
10198
ᶜgradᵥ(ᶠinterp(TD.liquid_ice_pottemp(thermo_params, ᶜts)))
10299
end
103-
compute_gm_mixing_length!(ᶜmixing_length, Y, p)
104100
end
105101

102+
ᶜmixing_length = compute_gm_mixing_length(Y, p)
103+
106104
diagnostic_covariance_coeff = CAP.diagnostic_covariance_coeff(params)
107105
@. cloud_diagnostics_tuple = quad_loop(
108106
SG_quad,
@@ -139,20 +137,23 @@ NVTX.@annotate function set_cloud_fraction!(
139137

140138
FT = eltype(params)
141139
thermo_params = CAP.thermodynamics_params(params)
142-
(; ᶜts, ᶜmixing_length, cloud_diagnostics_tuple) = p.precomputed
140+
(; ᶜts, cloud_diagnostics_tuple) = p.precomputed
143141
(; turbconv_model) = p.atmos
144142

145143
# TODO - we should make this default when using diagnostic edmf
146144
# environment
147145
diagnostic_covariance_coeff = CAP.diagnostic_covariance_coeff(params)
148146

147+
ᶜmixing_length_field = p.scratch.ᶜtemp_scalar
148+
ᶜmixing_length_field .= ᶜmixing_length(Y, p)
149+
149150
@. cloud_diagnostics_tuple = quad_loop(
150151
SG_quad,
151152
ᶜts,
152153
Geometry.WVector(p.precomputed.ᶜgradᵥ_q_tot),
153154
Geometry.WVector(p.precomputed.ᶜgradᵥ_θ_liq_ice),
154155
diagnostic_covariance_coeff,
155-
ᶜmixing_length,
156+
ᶜmixing_length_field,
156157
thermo_params,
157158
)
158159

@@ -192,21 +193,24 @@ NVTX.@annotate function set_cloud_fraction!(
192193

193194
FT = eltype(params)
194195
thermo_params = CAP.thermodynamics_params(params)
195-
(; ᶜts⁰, ᶜmixing_length, cloud_diagnostics_tuple) = p.precomputed
196+
(; ᶜts⁰, cloud_diagnostics_tuple) = p.precomputed
196197
(; ᶜρʲs, ᶜtsʲs, ᶜρa⁰, ᶜρ⁰) = p.precomputed
197198
(; turbconv_model) = p.atmos
198199

199200
# TODO - we should make this default when using diagnostic edmf
200201
# environment
201202
diagnostic_covariance_coeff = CAP.diagnostic_covariance_coeff(params)
202203

204+
ᶜmixing_length_field = p.scratch.ᶜtemp_scalar
205+
ᶜmixing_length_field .= ᶜmixing_length(Y, p)
206+
203207
@. cloud_diagnostics_tuple = quad_loop(
204208
SG_quad,
205209
ᶜts⁰,
206210
Geometry.WVector(p.precomputed.ᶜgradᵥ_q_tot⁰),
207211
Geometry.WVector(p.precomputed.ᶜgradᵥ_θ_liq_ice⁰),
208212
diagnostic_covariance_coeff,
209-
ᶜmixing_length,
213+
ᶜmixing_length_field,
210214
thermo_params,
211215
)
212216

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -966,13 +966,8 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
966966
(; ᶜp, ᶜu, ᶜts) = p.precomputed
967967
(; ustar, obukhov_length) = p.precomputed.sfc_conditions
968968
(; ᶜtke⁰) = p.precomputed
969-
(;
970-
ᶜlinear_buoygrad,
971-
ᶜstrain_rate_norm,
972-
ᶜmixing_length_tuple,
973-
ᶜmixing_length,
974-
) = p.precomputed
975-
(; ᶜK_h, ᶜK_u, ρatke_flux) = p.precomputed
969+
(; ᶜlinear_buoygrad, ᶜstrain_rate_norm) = p.precomputed
970+
(; ρatke_flux) = p.precomputed
976971
turbconv_params = CAP.turbconv_params(params)
977972
thermo_params = CAP.thermodynamics_params(params)
978973
ᶜlg = Fields.local_geometry_field(Y.c)
@@ -1004,42 +999,6 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
1004999
ᶜstrain_rate .= compute_strain_rate_center(ᶠu⁰)
10051000
@. ᶜstrain_rate_norm = norm_sqr(ᶜstrain_rate)
10061001

1007-
ᶜprandtl_nvec = p.scratch.ᶜtemp_scalar
1008-
@. ᶜprandtl_nvec =
1009-
turbulent_prandtl_number(params, ᶜlinear_buoygrad, ᶜstrain_rate_norm)
1010-
1011-
ᶜtke_exch = p.scratch.ᶜtemp_scalar_2
1012-
@. ᶜtke_exch = 0
1013-
# using ᶜu⁰ would be more correct, but this is more consistent with the
1014-
# TKE equation, where using ᶜu⁰ results in allocation
1015-
for j in 1:n
1016-
@. ᶜtke_exch +=
1017-
ᶜρaʲs.:($$j) * ᶜdetrʲs.:($$j) / Y.c.ρ *
1018-
(1 / 2 * norm_sqr(ᶜinterp(ᶠu³⁰) - ᶜinterp(ᶠu³ʲs.:($$j))) - ᶜtke⁰)
1019-
end
1020-
1021-
sfc_tke = Fields.level(ᶜtke⁰, 1)
1022-
z_sfc = Fields.level(Fields.coordinate_field(Y.f).z, half)
1023-
@. ᶜmixing_length_tuple = mixing_length(
1024-
params,
1025-
ustar,
1026-
ᶜz,
1027-
z_sfc,
1028-
ᶜdz,
1029-
max(sfc_tke, 0),
1030-
ᶜlinear_buoygrad,
1031-
max(ᶜtke⁰, 0),
1032-
obukhov_length,
1033-
ᶜstrain_rate_norm,
1034-
ᶜprandtl_nvec,
1035-
ᶜtke_exch,
1036-
p.atmos.edmfx_model.scale_blending_method,
1037-
)
1038-
@. ᶜmixing_length = ᶜmixing_length_tuple.master
1039-
1040-
@. ᶜK_u = eddy_viscosity(turbconv_params, ᶜtke⁰, ᶜmixing_length)
1041-
@. ᶜK_h = eddy_diffusivity(ᶜK_u, ᶜprandtl_nvec)
1042-
10431002
ρatke_flux_values = Fields.field_values(ρatke_flux)
10441003
ρ_int_values = Fields.field_values(Fields.level(Y.c.ρ, 1))
10451004
u_int_values = Fields.field_values(Fields.level(ᶜu, 1))

src/cache/precomputed_quantities.jl

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ function precomputed_quantities(Y, atmos)
114114
gs_quantities = (;
115115
ᶜwₜqₜ = similar(Y.c, Geometry.WVector{FT}),
116116
ᶜwₕhₜ = similar(Y.c, Geometry.WVector{FT}),
117-
ᶜmixing_length = similar(Y.c, FT),
118117
ᶜlinear_buoygrad = similar(Y.c, FT),
119118
ᶜstrain_rate_norm = similar(Y.c, FT),
120119
sfc_conditions = similar(Spaces.level(Y.f, half), SCT),
@@ -173,9 +172,6 @@ function precomputed_quantities(Y, atmos)
173172
advective_sgs_quantities =
174173
atmos.turbconv_model isa PrognosticEDMFX ?
175174
(;
176-
ᶜmixing_length_tuple = similar(Y.c, MixingLength{FT}),
177-
ᶜK_u = similar(Y.c, FT),
178-
ᶜK_h = similar(Y.c, FT),
179175
ρatke_flux = similar(Fields.level(Y.f, half), C3{FT}),
180176
bdmr_l = similar(Y.c, BidiagonalMatrixRow{FT}),
181177
bdmr_r = similar(Y.c, BidiagonalMatrixRow{FT}),
@@ -193,11 +189,8 @@ function precomputed_quantities(Y, atmos)
193189
edonly_quantities =
194190
atmos.turbconv_model isa EDOnlyEDMFX ?
195191
(;
196-
ᶜmixing_length_tuple = similar(Y.c, MixingLength{FT}),
197192
ᶜtke⁰ = similar(Y.c, FT),
198-
ᶜK_u = similar(Y.c, FT),
199193
ρatke_flux = similar(Fields.level(Y.f, half), C3{FT}),
200-
ᶜK_h = similar(Y.c, FT),
201194
) : (;)
202195

203196
sgs_quantities = (;
@@ -225,20 +218,9 @@ function precomputed_quantities(Y, atmos)
225218
ᶠu³⁰ = similar(Y.f, CT3{FT}),
226219
ᶜu⁰ = similar(Y.c, C123{FT}),
227220
ᶜK⁰ = similar(Y.c, FT),
228-
ᶜmixing_length_tuple = similar(Y.c, MixingLength{FT}),
229-
ᶜK_u = similar(Y.c, FT),
230-
ᶜK_h = similar(Y.c, FT),
231221
ρatke_flux = similar(Fields.level(Y.f, half), C3{FT}),
232222
precipitation_sgs_quantities...,
233223
) : (;)
234-
vert_diff_quantities =
235-
if atmos.vertical_diffusion isa
236-
Union{VerticalDiffusion, DecayWithHeightDiffusion}
237-
ᶜK_h = similar(Y.c, FT)
238-
(; ᶜK_u = ᶜK_h, ᶜK_h) # ᶜK_u aliases ᶜK_h because they are always equal.
239-
else
240-
(;)
241-
end
242224
smagorinsky_lilly_quantities =
243225
if atmos.smagorinsky_lilly isa SmagorinskyLilly
244226
uvw_vec = UVW(FT(0), FT(0), FT(0))
@@ -259,7 +241,6 @@ function precomputed_quantities(Y, atmos)
259241
advective_sgs_quantities...,
260242
edonly_quantities...,
261243
diagnostic_sgs_quantities...,
262-
vert_diff_quantities...,
263244
sedimentation_quantities...,
264245
precipitation_quantities...,
265246
surface_precip_fluxes...,
@@ -538,12 +519,6 @@ NVTX.@annotate function set_explicit_precomputed_quantities!(Y, p, t)
538519
ᶜgradᵥ(ᶠinterp(TD.liquid_ice_pottemp(thermo_params, ᶜts)))
539520
end
540521

541-
# TODO: It is too slow to calculate mixing length at every timestep
542-
# if isnothing(turbconv_model)
543-
# (; ᶜmixing_length) = p.precomputed
544-
# compute_gm_mixing_length!(ᶜmixing_length, Y, p)
545-
# end
546-
547522
if turbconv_model isa PrognosticEDMFX
548523
set_prognostic_edmf_precomputed_quantities_bottom_bc!(Y, p, t)
549524
set_prognostic_edmf_precomputed_quantities_explicit_closures!(Y, p, t)
@@ -585,19 +560,6 @@ NVTX.@annotate function set_explicit_precomputed_quantities!(Y, p, t)
585560
)
586561
set_precipitation_surface_fluxes!(Y, p, p.atmos.microphysics_model)
587562

588-
if vertical_diffusion isa DecayWithHeightDiffusion
589-
(; ᶜK_h) = p.precomputed
590-
@. ᶜK_h =
591-
$compute_eddy_diffusivity_coefficient(Y.c.ρ, vertical_diffusion)
592-
elseif vertical_diffusion isa VerticalDiffusion
593-
(; ᶜK_h) = p.precomputed
594-
@. ᶜK_h = $compute_eddy_diffusivity_coefficient(
595-
Y.c.uₕ,
596-
ᶜp,
597-
vertical_diffusion,
598-
)
599-
end
600-
601563
# TODO
602564
if call_cloud_diagnostics_per_stage isa CallCloudDiagnosticsPerStage
603565
set_cloud_fraction!(Y, p, moisture_model, cloud_model)

src/cache/prognostic_edmf_precomputed_quantities.jl

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
368368
n = n_mass_flux_subdomains(turbconv_model)
369369

370370
(; ᶜtke⁰, ᶜu, ᶜp, ᶜρa⁰, ᶠu³⁰, ᶜts⁰, ᶜq_tot⁰) = p.precomputed
371-
(;
372-
ᶜmixing_length_tuple,
373-
ᶜmixing_length,
374-
ᶜlinear_buoygrad,
375-
ᶜstrain_rate_norm,
376-
ᶜK_u,
377-
ᶜK_h,
378-
ρatke_flux,
379-
) = p.precomputed
371+
(; ᶜlinear_buoygrad, ᶜstrain_rate_norm, ρatke_flux) = p.precomputed
380372
(;
381373
ᶜuʲs,
382374
ᶜtsʲs,
@@ -501,41 +493,6 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
501493
ᶜstrain_rate .= compute_strain_rate_center(ᶠu⁰)
502494
@. ᶜstrain_rate_norm = norm_sqr(ᶜstrain_rate)
503495

504-
ᶜprandtl_nvec = p.scratch.ᶜtemp_scalar
505-
@. ᶜprandtl_nvec =
506-
turbulent_prandtl_number(params, ᶜlinear_buoygrad, ᶜstrain_rate_norm)
507-
508-
ᶜtke_exch = p.scratch.ᶜtemp_scalar_2
509-
@. ᶜtke_exch = 0
510-
for j in 1:n
511-
ᶠu³ʲ = ᶠu³ʲs.:($j)
512-
@. ᶜtke_exch +=
513-
Y.c.sgsʲs.:($$j).ρa * ᶜdetrʲs.:($$j) / ᶜρa⁰ *
514-
(1 / 2 * norm_sqr(ᶜinterp(ᶠu³⁰) - ᶜinterp(ᶠu³ʲs.:($$j))) - ᶜtke⁰)
515-
end
516-
517-
sfc_tke = Fields.level(ᶜtke⁰, 1)
518-
@. ᶜmixing_length_tuple = mixing_length(
519-
p.params,
520-
ustar,
521-
ᶜz,
522-
z_sfc,
523-
ᶜdz,
524-
max(sfc_tke, eps(FT)),
525-
ᶜlinear_buoygrad,
526-
max(ᶜtke⁰, 0),
527-
obukhov_length,
528-
ᶜstrain_rate_norm,
529-
ᶜprandtl_nvec,
530-
ᶜtke_exch,
531-
p.atmos.edmfx_model.scale_blending_method,
532-
)
533-
534-
@. ᶜmixing_length = ᶜmixing_length_tuple.master
535-
536-
@. ᶜK_u = eddy_viscosity(turbconv_params, ᶜtke⁰, ᶜmixing_length)
537-
@. ᶜK_h = eddy_diffusivity(ᶜK_u, ᶜprandtl_nvec)
538-
539496
ρatke_flux_values = Fields.field_values(ρatke_flux)
540497
ρa_sfc_values = Fields.field_values(Fields.level(ᶜρa⁰, 1)) # TODO: replace by surface value
541498
ustar_values = Fields.field_values(ustar)

src/diagnostics/Diagnostics.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ import ..SlabOceanSST
5656

5757
# functions used to calculate diagnostics
5858
import ..draft_area
59-
import ..compute_gm_mixing_length!
59+
import ..compute_gm_mixing_length
6060
import ..horizontal_integral_at_boundary
61+
import ..ᶜmixing_length
62+
import ..ᶜeddy_diffusivity
63+
import ..ᶜeddy_viscosity
64+
import ..turbulent_prandtl_number
65+
import ..smagorinsky_lilly_length
66+
import ..compute_eddy_diffusivity_coefficient
67+
6168

6269
# We need the abbreviations for symbols like curl, grad, and so on
6370
include(joinpath("..", "utils", "abbreviations.jl"))

0 commit comments

Comments
 (0)