From a1730cece34ab49d973be43402414e6417ccc8e5 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Wed, 20 Sep 2023 15:31:19 -0700 Subject: [PATCH 1/2] Remove unused fieldvector --- src/cache/cache.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cache/cache.jl b/src/cache/cache.jl index 5eb642a5c9..94607c0a2b 100644 --- a/src/cache/cache.jl +++ b/src/cache/cache.jl @@ -87,7 +87,6 @@ function default_cache( test, moisture_model = atmos.moisture_model, model_config = atmos.model_config, - Yₜ = similar(Y), # only needed when using increment formulation limiter, ᶜΦ, ᶠgradᵥ_ᶜΦ = ᶠgradᵥ.(ᶜΦ), From e604f1a1e28e785b4f8fa6d4e135f73f8226d75b Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Wed, 20 Sep 2023 20:19:17 -0700 Subject: [PATCH 2/2] Conditionally add precip tendencies --- src/callbacks/callbacks.jl | 2 +- .../microphysics/precipitation.jl | 78 ++++++++++--------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/callbacks/callbacks.jl b/src/callbacks/callbacks.jl index bf0f4fe960..3d8be4b513 100644 --- a/src/callbacks/callbacks.jl +++ b/src/callbacks/callbacks.jl @@ -266,7 +266,7 @@ NVTX.@annotate function compute_diagnostics(integrator) if p.atmos.precip_model isa Microphysics0Moment (; ᶜS_ρq_tot, col_integrated_rain, col_integrated_snow) = p Fields.bycolumn(axes(Y.c)) do colidx - precipitation_tendency!(p.Yₜ, Y, p, t, colidx, p.precip_model) + precipitation_tendency!(nothing, Y, p, t, colidx, p.precip_model) end # TODO: Set the diagnostics without computing the tendency. precip_diagnostic = (; precipitation_removal = ᶜS_ρq_tot, diff --git a/src/parameterized_tendencies/microphysics/precipitation.jl b/src/parameterized_tendencies/microphysics/precipitation.jl index d9d9455334..68fd2e0ef4 100644 --- a/src/parameterized_tendencies/microphysics/precipitation.jl +++ b/src/parameterized_tendencies/microphysics/precipitation.jl @@ -105,8 +105,10 @@ function precipitation_tendency!( thermo_params = CAP.thermodynamics_params(params) cm_params = CAP.microphysics_params(params) compute_precipitation_cache!(Y, p, colidx, precip_model, turbconv_model) - @. Yₜ.c.ρq_tot[colidx] += ᶜS_ρq_tot[colidx] - @. Yₜ.c.ρ[colidx] += ᶜS_ρq_tot[colidx] + if !isnothing(Yₜ) + @. Yₜ.c.ρq_tot[colidx] += ᶜS_ρq_tot[colidx] + @. Yₜ.c.ρ[colidx] += ᶜS_ρq_tot[colidx] + end T_freeze = TD.Parameters.T_freeze(thermo_params) # update precip in cache for coupler's use @@ -131,7 +133,7 @@ function precipitation_tendency!( if :ρe_tot in propertynames(Y.c) #TODO - this is a hack right now. But it will be easier to clean up # once we drop the support for the old EDMF code - if turbconv_model isa DiagnosticEDMFX + if turbconv_model isa DiagnosticEDMFX && !isnothing(Yₜ) @. Yₜ.c.ρe_tot[colidx] += sum( p.ᶜS_q_totʲs[colidx] * @@ -145,7 +147,7 @@ function precipitation_tendency!( ᶜts[colidx], ᶜΦ[colidx], ) - else + elseif !isnothing(Yₜ) @. Yₜ.c.ρe_tot[colidx] += ᶜS_ρq_tot[colidx] * e_tot_0M_precipitation_sources_helper( thermo_params, @@ -326,33 +328,35 @@ function precipitation_advection_tendency!( # TODO: need to add horizontal advection + vertical velocity of air # TODO: use correct advection operators - @. Yₜ.c.ρq_rai[colidx] += ᶜdivᵥ( - wvec( - RB( - ρq_rai * CM1.terminal_velocity( - microphys_params, - rain_type, - velo_type, - ρ_c, - ρq_rai / ρ_c, + if !isnothing(Yₜ) + @. Yₜ.c.ρq_rai[colidx] += ᶜdivᵥ( + wvec( + RB( + ρq_rai * CM1.terminal_velocity( + microphys_params, + rain_type, + velo_type, + ρ_c, + ρq_rai / ρ_c, + ), ), ), - ), - ) + ) - @. Yₜ.c.ρq_sno[colidx] += ᶜdivᵥ( - wvec( - RB( - ρq_sno * CM1.terminal_velocity( - microphys_params, - snow_type, - velo_type, - ρ_c, - ρq_sno / ρ_c, + @. Yₜ.c.ρq_sno[colidx] += ᶜdivᵥ( + wvec( + RB( + ρq_sno * CM1.terminal_velocity( + microphys_params, + snow_type, + velo_type, + ρ_c, + ρq_sno / ρ_c, + ), ), ), - ), - ) + ) + end return nothing end @@ -373,17 +377,19 @@ function precipitation_tendency!( p.atmos.turbconv_model, ) - @. Yₜ.c.ρ[colidx] += ᶜS_ρq_tot[colidx] - @. Yₜ.c.ρq_tot[colidx] += ᶜS_ρq_tot[colidx] - @. Yₜ.c.ρq_rai[colidx] += ᶜS_ρq_rai[colidx] - @. Yₜ.c.ρq_sno[colidx] += ᶜS_ρq_sno[colidx] + if !isnothing(Yₜ) + @. Yₜ.c.ρ[colidx] += ᶜS_ρq_tot[colidx] + @. Yₜ.c.ρq_tot[colidx] += ᶜS_ρq_tot[colidx] + @. Yₜ.c.ρq_rai[colidx] += ᶜS_ρq_rai[colidx] + @. Yₜ.c.ρq_sno[colidx] += ᶜS_ρq_sno[colidx] - if :ρe_tot in propertynames(Y.c) - @. Yₜ.c.ρe_tot[colidx] += ᶜS_ρe_tot[colidx] - else - error( - "1-moment microphysics can only be coupled to ρe_tot energy variable", - ) + if :ρe_tot in propertynames(Y.c) + @. Yₜ.c.ρe_tot[colidx] += ᶜS_ρe_tot[colidx] + else + error( + "1-moment microphysics can only be coupled to ρe_tot energy variable", + ) + end end precipitation_advection_tendency!(Yₜ, Y, p, colidx, precip_model)