Skip to content

Commit

Permalink
Only support 0M+equil, 1M+nonequil
Browse files Browse the repository at this point in the history
  • Loading branch information
trontrytel committed Jan 30, 2025
1 parent 77ed048 commit 769f03d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 28 deletions.
6 changes: 2 additions & 4 deletions src/cache/diagnostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
# To be applied in updraft continuity, moisture and energy
# for updrafts and grid mean
if precip_model isa Microphysics0Moment
@. S_q_totʲ_prev_level = q_tot_precipitation_sources(
precip_model,
@. S_q_totʲ_prev_level = q_tot_0M_precipitation_sources(
thermo_params,
microphys_0m_params,
dt,
Expand Down Expand Up @@ -1034,8 +1033,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_precipita
(; q_tot) = p.precomputed.ᶜspecific

# Environment precipitation sources (to be applied to grid mean)
@. ᶜSqₜᵖ⁰ = q_tot_precipitation_sources(
precip_model,
@. ᶜSqₜᵖ⁰ = q_tot_0M_precipitation_sources(
thermo_params,
microphys_0m_params,
dt,
Expand Down
3 changes: 1 addition & 2 deletions src/cache/prognostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_precipitation
# Sources from the updrafts
n = n_mass_flux_subdomains(p.atmos.turbconv_model)
for j in 1:n
@. ᶜSqₜᵖʲs.:($$j) = q_tot_precipitation_sources(
Microphysics0Moment(),
@. ᶜSqₜᵖʲs.:($$j) = q_tot_0M_precipitation_sources(
thp,
cmp,
dt,
Expand Down
19 changes: 17 additions & 2 deletions src/parameterized_tendencies/microphysics/cloud_condensate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@
##### DryModel, EquilMoistModel
#####

cloud_condensate_tendency!(Yₜ, p, _) = nothing
cloud_condensate_tendency!(Yₜ, p, _, _) = nothing

#####
##### NonEquilMoistModel
#####

function cloud_condensate_tendency!(Yₜ, p, ::NonEquilMoistModel)
function cloud_condensate_tendency!(
Yₜ,
p,
::NonEquilMoistModel,
::Union{NoPrecipitation, Microphysics0Moment},
)
error(
"NonEquilMoistModel can only be run with Microphysics1Moment precipitation",
)
end

function cloud_condensate_tendency!(
Yₜ,
p,
::NonEquilMoistModel,
::Microphysics1Moment,
)
(; ᶜts) = p.precomputed
(; params, dt) = p
thp = CAP.thermodynamics_params(params)
Expand Down
17 changes: 3 additions & 14 deletions src/parameterized_tendencies/microphysics/microphysics_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,17 @@ function cloud_sources(cm_params::CMP.CloudIce{FT}, thp, ts, dt) where {FT}
end

"""
q_tot_precipitation_sources(precip_model, thp, cmp, dt, qₜ, ts)
q_tot_0M_precipitation_sources(thp, cmp, dt, qₜ, ts)
- precip_model - a type for precipitation scheme choice
- thp, cmp - structs with thermodynamic and microphysics parameters
- dt - model time step
- qₜ - total water specific humidity
- ts - thermodynamic state (see Thermodynamics.jl package for details)
Returns the qₜ source term due to precipitation formation
defined as Δm_tot / (m_dry + m_tot)
defined as Δm_tot / (m_dry + m_tot) for the 0-moment scheme
"""
function q_tot_precipitation_sources(::NoPrecipitation, thp, cmp, dt, qₜ, ts)
return zero(qₜ)
end
function q_tot_precipitation_sources(
::Microphysics0Moment,
thp,
cmp::CMP.Parameters0M,
dt,
qₜ,
ts,
)
function q_tot_0M_precipitation_sources(thp, cmp::CMP.Parameters0M, dt, qₜ, ts)
return -min(max(qₜ, 0) / dt, -CM0.remove_precipitation(cmp, PP(thp, ts)))
end

Expand Down
60 changes: 55 additions & 5 deletions src/parameterized_tendencies/microphysics/precipitation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function precipitation_cache(Y, precip_model::NoPrecipitation)
surface_snow_flux = zeros(axes(Fields.level(Y.f, half))),
)
end
precipitation_tendency!(Yₜ, Y, p, t, ::NoPrecipitation, _) = nothing
precipitation_tendency!(Yₜ, Y, p, t, _, ::NoPrecipitation, _) = nothing

#####
##### 0-Moment without sgs scheme or with diagnostic/prognostic edmf
Expand All @@ -50,8 +50,7 @@ function compute_precipitation_cache!(Y, p, ::Microphysics0Moment, _)
cm_params = CAP.microphysics_0m_params(params)
thermo_params = CAP.thermodynamics_params(params)
@. ᶜS_ρq_tot =
Y.c.ρ * q_tot_precipitation_sources(
Microphysics0Moment(),
Y.c.ρ * q_tot_0M_precipitation_sources(
thermo_params,
cm_params,
dt,
Expand Down Expand Up @@ -158,10 +157,21 @@ function precipitation_tendency!(
Y,
p,
t,
precip_model::Microphysics0Moment,
::DryModel,
::Microphysics0Moment,
_,
)
(; turbconv_model) = p.atmos
error("Microphysics0Moment precipitation should not be run with DryModel.")
end
function precipitation_tendency!(
Yₜ,
Y,
p,
t,
::EquilMoistModel,
precip_model::Microphysics0Moment,
turbconv_model,
)
(; ᶜS_ρq_tot, ᶜS_ρe_tot) = p.precipitation

# Compute the ρq_tot and ρe_tot precipitation source terms
Expand All @@ -176,6 +186,19 @@ function precipitation_tendency!(

return nothing
end
function precipitation_tendency!(
Yₜ,
Y,
p,
t,
::NonEquilMoistModel,
::Microphysics0Moment,
_,
)
error(
"Microphysics0Moment precipitation and NonEquilibriumMost model precipitation_tendency has not been implemented.",
)
end

#####
##### 1-Moment without sgs scheme
Expand Down Expand Up @@ -333,6 +356,31 @@ function precipitation_tendency!(
Y,
p,
t,
::DryModel,
precip_model::Microphysics1Moment,
_,
)
error("Microphysics1Moment precipitation should not be used with DryModel")
end
function precipitation_tendency!(
Yₜ,
Y,
p,
t,
::EquilMoistModel,
precip_model::Microphysics1Moment,
_,
)
error(
"Microphysics1Moment precipitation and EquilMoistModel precipitation_tendency is not implemented",
)
end
function precipitation_tendency!(
Yₜ,
Y,
p,
t,
::NonEquilMoistModel,
precip_model::Microphysics1Moment,
_,
)
Expand All @@ -357,6 +405,7 @@ function precipitation_tendency!(
Y,
p,
t,
::NonEquilMoistModel,
precip_model::Microphysics1Moment,
turbconv_model::DiagnosticEDMFX,
)
Expand Down Expand Up @@ -396,6 +445,7 @@ function precipitation_tendency!(
Y,
p,
t,
::NonEquilMoistModel,
precip_model::Microphysics1Moment,
turbconv_model::PrognosticEDMFX,
)
Expand Down
8 changes: 7 additions & 1 deletion src/prognostic_equations/remaining_tendency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ NVTX.@annotate function additional_tendency!(Yₜ, Y, p, t)
edmfx_filter_tendency!(Yₜ, Y, p, t, p.atmos.turbconv_model)
edmfx_tke_tendency!(Yₜ, Y, p, t, p.atmos.turbconv_model)
# Non-equilibrium cloud formation
cloud_condensate_tendency!(Yₜ, p, p.atmos.moisture_model)
cloud_condensate_tendency!(
Yₜ,
p,
p.atmos.moisture_model,
p.atmos.precip_model,
)
edmfx_precipitation_tendency!(
Yₜ,
Y,
Expand All @@ -75,6 +80,7 @@ NVTX.@annotate function additional_tendency!(Yₜ, Y, p, t)
Y,
p,
t,
p.atmos.moisture_model,
p.atmos.precip_model,
p.atmos.turbconv_model,
)
Expand Down

0 comments on commit 769f03d

Please sign in to comment.