Skip to content

Commit 1981794

Browse files
authored
Merge pull request #3824 from CliMA/cc/ed_cleanup
Refactor and document ED pieces
2 parents 8ac392d + 6e976c5 commit 1981794

13 files changed

+688
-398
lines changed

reproducibility_tests/ref_counter.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
242
1+
243
22

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

2121

2222
#=
23+
243
24+
- Consolidate eddy diffusivity logic in eddy_diffusion_closures.jl and mass flux
25+
logic in mass_flux_closures.jl, update buoyancy calculations to be consistent throughout
26+
(use geopotential gradient instead of g parameter), add helper functions for computing
27+
diffusivity/viscosity, adds l_grid to MixingLength output struct. Includes more docstrings
28+
and comments.
29+
2330
242
2431
- Use ustar^3 surface tke boundary condition
2532

src/ClimaAtmos.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ include(
9494
include(joinpath("prognostic_equations", "hyperdiffusion.jl"))
9595
include(joinpath("prognostic_equations", "gm_sgs_closures.jl"))
9696
include(joinpath("prognostic_equations", "edmf_coriolis.jl"))
97-
include(joinpath("prognostic_equations", "buoyancy_gradients.jl"))
98-
include(joinpath("prognostic_equations", "edmfx_closures.jl"))
97+
include(joinpath("prognostic_equations", "eddy_diffusion_closures.jl"))
98+
include(joinpath("prognostic_equations", "mass_flux_closures.jl"))
9999
include(joinpath("prognostic_equations", "edmfx_entr_detr.jl"))
100100
include(joinpath("prognostic_equations", "edmfx_tke.jl"))
101101
include(joinpath("prognostic_equations", "edmfx_sgs_flux.jl"))

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
304304
(; params) = p
305305
(; dt) = p
306306
dt = float(dt)
307-
(; ᶜΦ) = p.core
307+
(; ᶜΦ, ᶜgradᵥ_ᶠΦ) = p.core
308308
(; ᶜp, ᶠu³, ᶜts, ᶜh_tot, ᶜK) = p.precomputed
309309
(; q_tot) = p.precomputed.ᶜspecific
310310
(;
@@ -434,6 +434,8 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
434434
q_totʲ_prev_level =
435435
Fields.field_values(Fields.level(ᶜq_totʲ, i - 1))
436436
ρʲ_prev_level = Fields.field_values(Fields.level(ᶜρʲ, i - 1))
437+
ᶜgradᵥ_ᶠΦ_prev_level =
438+
Fields.field_values(Fields.level(ᶜgradᵥ_ᶠΦ, i - 1))
437439
tsʲ_prev_level = Fields.field_values(Fields.level(ᶜtsʲ, i - 1))
438440
entrʲ_prev_level = Fields.field_values(Fields.level(ᶜentrʲ, i - 1))
439441
detrʲ_prev_level = Fields.field_values(Fields.level(ᶜdetrʲ, i - 1))
@@ -482,7 +484,12 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
482484
local_geometry_prev_halflevel,
483485
),
484486
TD.relative_humidity(thermo_params, tsʲ_prev_level),
485-
ᶜphysical_buoyancy(thermo_params, ρ_prev_level, ρʲ_prev_level),
487+
vertical_buoyancy_acceleration(
488+
ρ_prev_level,
489+
ρʲ_prev_level,
490+
ᶜgradᵥ_ᶠΦ_prev_level,
491+
local_geometry_prev_halflevel,
492+
),
486493
get_physical_w(
487494
u³_prev_halflevel,
488495
local_geometry_prev_halflevel,
@@ -644,6 +651,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
644651
FT(0), # mass flux divergence is not implemented for diagnostic edmf
645652
w_vert_div_level,
646653
tke_prev_level,
654+
ᶜgradᵥ_ᶠΦ_prev_level,
647655
p.atmos.edmfx_model.detr_model,
648656
)
649657

@@ -952,6 +960,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
952960
ᶜmixing_length,
953961
) = p.precomputed
954962
(; ᶜK_h, ᶜK_u, ρatke_flux) = p.precomputed
963+
turbconv_params = CAP.turbconv_params(params)
955964
thermo_params = CAP.thermodynamics_params(params)
956965
ᶜlg = Fields.local_geometry_field(Y.c)
957966

@@ -1015,10 +1024,8 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
10151024
)
10161025
@. ᶜmixing_length = ᶜmixing_length_tuple.master
10171026

1018-
turbconv_params = CAP.turbconv_params(params)
1019-
c_m = CAP.tke_ed_coeff(turbconv_params)
1020-
@. ᶜK_u = c_m * ᶜmixing_length * sqrt(max(ᶜtke⁰, 0))
1021-
@. ᶜK_h = ᶜK_u / ᶜprandtl_nvec
1027+
@. ᶜK_u = eddy_viscosity(turbconv_params, ᶜtke⁰, ᶜmixing_length)
1028+
@. ᶜK_h = eddy_diffusivity(ᶜK_u, ᶜprandtl_nvec)
10221029

10231030
ρatke_flux_values = Fields.field_values(ρatke_flux)
10241031
ρ_int_values = Fields.field_values(Fields.level(Y.c.ρ, 1))

src/cache/prognostic_edmf_precomputed_quantities.jl

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
360360

361361
(; params) = p
362362
(; dt) = p
363-
(; ᶠgradᵥ_ᶜΦ) = p.core
363+
(; ᶠgradᵥ_ᶜΦ, ᶜgradᵥ_ᶠΦ) = p.core
364364
thermo_params = CAP.thermodynamics_params(params)
365365
turbconv_params = CAP.turbconv_params(params)
366366

@@ -410,7 +410,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
410410
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
411411
get_physical_w(ᶜuʲs.:($$j), ᶜlg),
412412
TD.relative_humidity(thermo_params, ᶜtsʲs.:($$j)),
413-
ᶜphysical_buoyancy(thermo_params, Y.c.ρ, ᶜρʲs.:($$j)),
413+
vertical_buoyancy_acceleration(Y.c.ρ, ᶜρʲs.:($$j), ᶜgradᵥ_ᶠΦ, ᶜlg),
414414
get_physical_w(ᶜu, ᶜlg),
415415
TD.relative_humidity(thermo_params, ᶜts⁰),
416416
FT(0),
@@ -447,7 +447,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
447447
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
448448
get_physical_w(ᶜuʲs.:($$j), ᶜlg),
449449
TD.relative_humidity(thermo_params, ᶜtsʲs.:($$j)),
450-
ᶜphysical_buoyancy(thermo_params, Y.c.ρ, ᶜρʲs.:($$j)),
450+
vertical_buoyancy_acceleration(Y.c.ρ, ᶜρʲs.:($$j), ᶜgradᵥ_ᶠΦ, ᶜlg),
451451
get_physical_w(ᶜu, ᶜlg),
452452
TD.relative_humidity(thermo_params, ᶜts⁰),
453453
FT(0),
@@ -471,7 +471,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
471471
# term is still calculated here as it is used explicitly in the TKE equation.
472472
@. ᶠnh_pressure₃_buoyʲs.:($$j) = ᶠupdraft_nh_pressure_buoyancy(
473473
params,
474-
ᶠbuoyancy(ᶠinterp(Y.c.ρ), ᶠinterp(ᶜρʲs.:($$j)), ᶠgradᵥ_ᶜΦ),
474+
buoyancy(ᶠinterp(Y.c.ρ), ᶠinterp(ᶜρʲs.:($$j)), ᶠgradᵥ_ᶜΦ),
475475
)
476476
end
477477

@@ -493,6 +493,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
493493
ᶜlg,
494494
)
495495

496+
# TODO: Make strain_rate_norm calculation a function in eddy_diffusion_closures
496497
# TODO: Currently the shear production only includes vertical gradients
497498
ᶠu⁰ = p.scratch.ᶠtemp_C123
498499
@. ᶠu⁰ = C123(ᶠinterp(Y.c.uₕ)) + C123(ᶠu³⁰)
@@ -532,23 +533,18 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
532533

533534
@. ᶜmixing_length = ᶜmixing_length_tuple.master
534535

535-
turbconv_params = CAP.turbconv_params(params)
536-
c_m = CAP.tke_ed_coeff(turbconv_params)
537-
@. ᶜK_u = c_m * ᶜmixing_length * sqrt(max(ᶜtke⁰, 0))
538-
@. ᶜK_h = ᶜK_u / ᶜprandtl_nvec
536+
@. ᶜK_u = eddy_viscosity(turbconv_params, ᶜtke⁰, ᶜmixing_length)
537+
@. ᶜK_h = eddy_diffusivity(ᶜK_u, ᶜprandtl_nvec)
539538

540539
ρatke_flux_values = Fields.field_values(ρatke_flux)
541-
ρ_int_values = Fields.field_values(Fields.level(ᶜρa⁰, 1))
542-
u_int_values = Fields.field_values(Fields.level(ᶜu, 1))
540+
ρa_sfc_values = Fields.field_values(Fields.level(ᶜρa⁰, 1)) # TODO: replace by surface value
543541
ustar_values = Fields.field_values(ustar)
544-
int_local_geometry_values =
545-
Fields.field_values(Fields.level(Fields.local_geometry_field(Y.c), 1))
546542
sfc_local_geometry_values = Fields.field_values(
547543
Fields.level(Fields.local_geometry_field(Y.f), half),
548544
)
549545
@. ρatke_flux_values = surface_flux_tke(
550546
turbconv_params,
551-
ρ_int_values,
547+
ρa_sfc_values,
552548
ustar_values,
553549
sfc_local_geometry_values,
554550
)

src/prognostic_equations/buoyancy_gradients.jl

Lines changed: 0 additions & 177 deletions
This file was deleted.

0 commit comments

Comments
 (0)