Skip to content

Commit

Permalink
Cleanup in 0M diagnostic EDMF
Browse files Browse the repository at this point in the history
  • Loading branch information
trontrytel committed Apr 3, 2024
1 parent ba3cf37 commit 40e6a2f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
25 changes: 8 additions & 17 deletions src/cache/diagnostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ function set_diagnostic_edmf_precomputed_quantities_do_integral!(Y, p, t)
ᶜdetrʲs,
ᶠnh_pressure³ʲs,
ᶜS_q_totʲs,
ᶜS_e_totʲs_helper,
) = p.precomputed
(; ᶠu³⁰, ᶜK⁰) = p.precomputed
thermo_params = CAP.thermodynamics_params(params)
Expand Down Expand Up @@ -306,7 +305,6 @@ function set_diagnostic_edmf_precomputed_quantities_do_integral!(Y, p, t)
ᶜdetrʲ = ᶜdetrʲs.:($j)
ᶠnh_pressure³ʲ = ᶠnh_pressure³ʲs.:($j)
ᶜS_q_totʲ = ᶜS_q_totʲs.:($j)
ᶜS_e_totʲ_helper = ᶜS_e_totʲs_helper.:($j)

ρaʲ_level = Fields.field_values(Fields.level(ᶜρaʲ, i))
u³ʲ_halflevel = Fields.field_values(Fields.level(ᶠu³ʲ, i - half))
Expand All @@ -333,8 +331,6 @@ function set_diagnostic_edmf_precomputed_quantities_do_integral!(Y, p, t)
CAP.R_d(params) * CAP.T_surf_ref(params) / CAP.grav(params)
S_q_totʲ_prev_level =
Fields.field_values(Fields.level(ᶜS_q_totʲ, i - 1))
S_e_totʲ_helper_prev_level =
Fields.field_values(Fields.level(ᶜS_e_totʲ_helper, i - 1))
@. entrʲ_prev_level = entrainment(
params,
z_prev_level,
Expand All @@ -358,7 +354,7 @@ function set_diagnostic_edmf_precomputed_quantities_do_integral!(Y, p, t)
p.atmos.edmfx_entr_model,
)

# We don't have an upper limit to entrainment for the first level
# We don't have an upper limit to entrainment for the first level
# (calculated at i=2), as the vertical velocity at the first level is zero
if i > 2
@. entrʲ_prev_level = limit_entrainment(
Expand Down Expand Up @@ -551,12 +547,6 @@ function set_diagnostic_edmf_precomputed_quantities_do_integral!(Y, p, t)
ρaʲu³ʲ_data / sqrt(max(0, u³ʲ_datau³ʲ_data)),
)

@. S_e_totʲ_helper_prev_level =
e_tot_0M_precipitation_sources_helper(
thermo_params,
tsʲ_prev_level,
Φ_prev_level,
)
@. ρaʲu³ʲ_datamse =
(1 / local_geometry_halflevel.J) * (
local_geometry_prev_halflevel.J *
Expand All @@ -579,7 +569,12 @@ function set_diagnostic_edmf_precomputed_quantities_do_integral!(Y, p, t)
(
entrʲ_prev_level * (h_tot_prev_level - K_prev_level) -
detrʲ_prev_level * mseʲ_prev_level +
S_q_totʲ_prev_level * S_e_totʲ_helper_prev_level
S_q_totʲ_prev_level *
e_tot_0M_precipitation_sources_helper(
thermo_params,
tsʲ_prev_level,
Φ_prev_level,
)
)
)
@. mseʲ_level = ifelse(
Expand Down Expand Up @@ -695,7 +690,7 @@ Updates the top boundary condition of precomputed quantities stored in `p` for d
"""
function set_diagnostic_edmf_precomputed_quantities_top_bc!(Y, p, t)
n = n_mass_flux_subdomains(p.atmos.turbconv_model)
(; ᶜentrʲs, ᶜdetrʲs, ᶜS_q_totʲs, ᶜS_e_totʲs_helper) = p.precomputed
(; ᶜentrʲs, ᶜdetrʲs, ᶜS_q_totʲs) = p.precomputed
(; ᶠu³⁰, ᶠu³ʲs, ᶜuʲs, ᶠnh_pressure³ʲs) = p.precomputed

# set values for the top level
Expand All @@ -710,7 +705,6 @@ function set_diagnostic_edmf_precomputed_quantities_top_bc!(Y, p, t)
ᶜentrʲ = ᶜentrʲs.:($j)
ᶜdetrʲ = ᶜdetrʲs.:($j)
ᶜS_q_totʲ = ᶜS_q_totʲs.:($j)
ᶜS_e_totʲ_helper = ᶜS_e_totʲs_helper.:($j)

u³ʲ_halflevel = Fields.field_values(Fields.level(ᶠu³ʲ, i_top + half))
@. u³ʲ_halflevel = CT3(0)
Expand All @@ -728,10 +722,7 @@ function set_diagnostic_edmf_precomputed_quantities_top_bc!(Y, p, t)
@. ᶜuʲ = C123(Y.c.uₕ) + ᶜinterp(C123(ᶠu³ʲ))

S_q_totʲ_level = Fields.field_values(Fields.level(ᶜS_q_totʲ, i_top))
S_e_totʲ_helper_level =
Fields.field_values(Fields.level(ᶜS_e_totʲ_helper, i_top))
@. S_q_totʲ_level = 0
@. S_e_totʲ_helper_level = 0
end
return nothing
end
Expand Down
4 changes: 1 addition & 3 deletions src/cache/precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ function precomputed_quantities(Y, atmos)
ᶜentrʲs = similar(Y.c, NTuple{n, FT}),
ᶜdetrʲs = similar(Y.c, NTuple{n, FT}),
ᶠnh_pressure³ʲs = similar(Y.f, NTuple{n, CT3{FT}}),
ᶜS_q_totʲs = similar(Y.c, NTuple{n, FT}),
ᶜS_q_tot⁰ = similar(Y.c, FT),
ᶜS_e_totʲs_helper = similar(Y.c, NTuple{n, FT}),
ᶠu³⁰ = similar(Y.f, CT3{FT}),
ᶜu⁰ = similar(Y.c, C123{FT}),
ᶜK⁰ = similar(Y.c, FT),
Expand All @@ -134,6 +131,7 @@ function precomputed_quantities(Y, atmos)
ᶜK_u = similar(Y.c, FT),
ᶜK_h = similar(Y.c, FT),
ρatke_flux = similar(Fields.level(Y.f, half), C3{FT}),
precipitation_sgs_quantities...,
) : (;)
vert_diff_quantities = if atmos.vert_diff isa VerticalDiffusion
ᶜK_h = similar(Y.c, FT)
Expand Down
6 changes: 5 additions & 1 deletion src/parameterized_tendencies/microphysics/precipitation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ function precipitation_tendency!(
sum(
p.precomputed.ᶜS_q_totʲs[colidx] *
p.precomputed.ᶜρaʲs[colidx] *
p.precomputed.ᶜS_e_totʲs_helper[colidx],
e_tot_0M_precipitation_sources_helper(
thermo_params,
ᶜtsʲs[colidx],
ᶜΦ[colidx],
)
) +
p.precomputed.ᶜS_q_tot⁰[colidx] *
Y.c.ρ[colidx] *
Expand Down

0 comments on commit 40e6a2f

Please sign in to comment.