From 769f03d8494378bdded710f81fe5e71824b1e5bd Mon Sep 17 00:00:00 2001 From: Anna Jaruga Date: Wed, 29 Jan 2025 10:06:30 -0800 Subject: [PATCH] Only support 0M+equil, 1M+nonequil --- .../diagnostic_edmf_precomputed_quantities.jl | 6 +- .../prognostic_edmf_precomputed_quantities.jl | 3 +- .../microphysics/cloud_condensate.jl | 19 +++++- .../microphysics/microphysics_wrappers.jl | 17 +----- .../microphysics/precipitation.jl | 60 +++++++++++++++++-- .../remaining_tendency.jl | 8 ++- 6 files changed, 85 insertions(+), 28 deletions(-) diff --git a/src/cache/diagnostic_edmf_precomputed_quantities.jl b/src/cache/diagnostic_edmf_precomputed_quantities.jl index 59d88ba0c3..9631799275 100644 --- a/src/cache/diagnostic_edmf_precomputed_quantities.jl +++ b/src/cache/diagnostic_edmf_precomputed_quantities.jl @@ -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, @@ -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, diff --git a/src/cache/prognostic_edmf_precomputed_quantities.jl b/src/cache/prognostic_edmf_precomputed_quantities.jl index c9c6da3a22..595406ced9 100644 --- a/src/cache/prognostic_edmf_precomputed_quantities.jl +++ b/src/cache/prognostic_edmf_precomputed_quantities.jl @@ -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, diff --git a/src/parameterized_tendencies/microphysics/cloud_condensate.jl b/src/parameterized_tendencies/microphysics/cloud_condensate.jl index f4739fb0e6..c7a103c864 100644 --- a/src/parameterized_tendencies/microphysics/cloud_condensate.jl +++ b/src/parameterized_tendencies/microphysics/cloud_condensate.jl @@ -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) diff --git a/src/parameterized_tendencies/microphysics/microphysics_wrappers.jl b/src/parameterized_tendencies/microphysics/microphysics_wrappers.jl index 341a3a26bb..eae951cbb2 100644 --- a/src/parameterized_tendencies/microphysics/microphysics_wrappers.jl +++ b/src/parameterized_tendencies/microphysics/microphysics_wrappers.jl @@ -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 diff --git a/src/parameterized_tendencies/microphysics/precipitation.jl b/src/parameterized_tendencies/microphysics/precipitation.jl index 86606a5253..1d4692c3bd 100644 --- a/src/parameterized_tendencies/microphysics/precipitation.jl +++ b/src/parameterized_tendencies/microphysics/precipitation.jl @@ -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 @@ -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, @@ -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 @@ -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 @@ -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, _, ) @@ -357,6 +405,7 @@ function precipitation_tendency!( Y, p, t, + ::NonEquilMoistModel, precip_model::Microphysics1Moment, turbconv_model::DiagnosticEDMFX, ) @@ -396,6 +445,7 @@ function precipitation_tendency!( Y, p, t, + ::NonEquilMoistModel, precip_model::Microphysics1Moment, turbconv_model::PrognosticEDMFX, ) diff --git a/src/prognostic_equations/remaining_tendency.jl b/src/prognostic_equations/remaining_tendency.jl index 908671a42b..207c0d87eb 100644 --- a/src/prognostic_equations/remaining_tendency.jl +++ b/src/prognostic_equations/remaining_tendency.jl @@ -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, @@ -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, )