Skip to content

Commit 4340d2c

Browse files
committed
fixes
1 parent f02390a commit 4340d2c

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

src/cache/precipitation_precomputed_quantities.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function set_precipitation_velocities!(Y, p, ::NonEquilMoistModel, ::Microphysic
7171
ᶜwᵪ = get_field(p.precomputed, get_ᶜwᵪ_name_from_qᵪ_name(qᵪ_name))
7272
ᶜqᵪ = ᶜspecific_gs_tracer(Y, qᵪ_name)
7373
wᵪ = terminal_velocity_func_1M(cmc, cmp, qᵪ_name)
74-
calc_hₜ = total_energy_func(qᵪ_name)
74+
calc_hₜ = total_energy_fn(qᵪ_name)
7575
@. ᶜwᵪ = wᵪ(Y.c.ρ, clip(ᶜqᵪ))
7676
@. ᶜwₜqₜ += WVec(ᶜwᵪ * ᶜqᵪ)
7777
@. ᶜwₕhₜ += WVec(ᶜwᵪ * ᶜqᵪ * calc_hₜ(thp, ᶜts, ᶜΦ, ᶜwᵪ, ᶜu_uvw))
@@ -83,7 +83,7 @@ function set_precipitation_velocities!(Y, p,
8383
)
8484
(; ᶜΦ) = p.core
8585
(; ᶜwₜqₜ, ᶜwₕhₜ) = p.precomputed
86-
(; ᶜts⁰, ᶜtsʲs, ᶜρʲs) = p.precomputed
86+
(; ᶜts⁰, ᶜtsʲs) = p.precomputed
8787
ᶜsgsʲs = Y.c.sgsʲs
8888
ᶜρ = Y.c.ρ
8989
cmc = CAP.microphysics_cloud_params(p.params)
@@ -125,8 +125,8 @@ function set_precipitation_velocities!(Y, p,
125125
@. ᶜwᵪ = ρξw_div_ρξ_bounded(ᶜρaqwᵪ⁰ + draft_sum(ρaqwʲ_clip, ᶜsgsʲs, ᶜtsʲs), ᶜρqᵪ)
126126

127127
# implied environment mass flux: ρqᵪ⋅wᵪ (gm) - ∑ⱼ ρaʲ⋅qᵪʲ⋅wᵪʲ (drafts)
128-
ᶜρqᵪ_gm = get_field(Y.c, get_ᶜρqᵪ_name_from_qᵪ_name(qᵪ_name)) # gm
129-
ᶜρaqwᵪ⁰_implied = @. lazy(ᶜρqᵪ_gm * ᶜwᵪ) - draft_sum(ρaqwʲ, ᶜsgsʲs, ᶜtsʲs) # not clipped
128+
ᶜρqᵪ_gm = get_field(Y.c, get_ρχ_name(qᵪ_name)) # gm
129+
ᶜρaqwᵪ⁰_implied = @. lazy(ᶜρqᵪ_gm * ᶜwᵪ - draft_sum(ρaqwʲ, ᶜsgsʲs, ᶜtsʲs)) # not clipped
130130

131131
# Calculate contribution of tracer `q` to total water and energy advection
132132
ρaqwₕhₜʲ(Φ) = (ᶜsgsʲ, ᶜtsʲ) -> ρaqwʲ(ᶜsgsʲ, ᶜtsʲ) * calc_hₜ(thp, ᶜtsʲ, Φ)
@@ -154,7 +154,7 @@ function set_precipitation_velocities!(Y, p, ::NonEquilMoistModel, ::Microphysic
154154
ᶜwₙᵪ = get_field(p.precomputed, get_ᶜwₙᵪ_name_from_qᵪ_name(qᵪ_name))
155155
wᵪ_func = terminal_velocity_mass_func_2M(cm2p, cmc, cm1p, qᵪ_name)
156156
wₙᵪ_func = terminal_velocity_number_func_2M(cm2p, cmc, cm1p, qᵪ_name)
157-
calc_hₜ = total_energy_func(qᵪ_name)
157+
calc_hₜ = total_energy_fn(qᵪ_name)
158158
# Get tracer fields
159159
ᶜqᵪ = ᶜspecific_gs_tracer(Y, qᵪ_name)
160160
ρnᵪ_name = get_ρnᵪ_name_from_qᵪ_name(qᵪ_name)
@@ -300,9 +300,9 @@ function set_precipitation_velocities!(
300300

301301
# compute their contributions to energy and total water advection
302302
@. ᶜwₜqₜ = WVec(ᶜwₗ * ρq_liq + ᶜwᵢ * ρq_ice + ᶜwᵣ * ρq_rai) / ρ
303-
calc_hₗ = total_energy_func(@name(q_liq))
304-
calc_hᵢ = total_energy_func(@name(q_ice))
305-
calc_hᵣ = total_energy_func(@name(q_rai))
303+
calc_hₗ = total_energy_fn(@name(q_liq))
304+
calc_hᵢ = total_energy_fn(@name(q_ice))
305+
calc_hᵣ = total_energy_fn(@name(q_rai))
306306
@. ᶜwₕhₜ =
307307
WVec(
308308
ᶜwₗ * ρq_liq * (calc_hₗ(thp, ᶜts, ᶜΦ, ᶜwₗ, UVW(ᶜu))) +
@@ -336,24 +336,26 @@ function set_precipitation_cache!(Y, p, ::Microphysics0Moment, _)
336336
return nothing
337337
end
338338
function set_precipitation_cache!(Y, p,
339-
::Microphysics0Moment, turbconv::Union{DiagnosticEDMFX, PrognosticEDMFX},
339+
::Microphysics0Moment, turbconv_model::Union{DiagnosticEDMFX, PrognosticEDMFX},
340340
)
341341
(; ᶜΦ) = p.core
342342
(; ᶜSqₜᵖ⁰, ᶜSqₜᵖʲs) = p.precomputed
343343
(; ᶜS_ρq_tot, ᶜS_ρe_tot) = p.precomputed
344344
(; ᶜtsʲs) = p.precomputed
345345
thp = CAP.thermodynamics_params(p.params)
346346
ᶜρ = Y.c.ρ
347+
is_pedmf = turbconv_model isa PrognosticEDMFX
347348

348349
# Draft and environment area-weighted densities
349-
ᶜsgs_ρaʲs = ᶜρaʲs_list(Y, p, turbconv)
350+
ᶜsgs_ρaʲs = is_pedmf ? Y.c.sgsʲs : p.precomputed.ᶜρaʲs # used to extract env ρa
350351
## For environment we multiply by grid mean `ρ` and not by `ᶜρa⁰`, assuming `a⁰ = 1`
351-
ᶜρa⁰ = turbconv isa PrognosticEDMFX ? (@. lazy(ρa⁰(ᶜρ, Y.c.sgsʲs, turbconv))) : ᶜρ
352-
ᶜts⁰ = turbconv isa PrognosticEDMFX ? p.precomputed.ᶜts⁰ : p.precomputed.ᶜts
352+
ᶜρa⁰ = is_pedmf ? (@. lazy(ρa⁰(ᶜρ, Y.c.sgsʲs, turbconv_model))) : ᶜρ
353+
ᶜts⁰ = is_pedmf ? p.precomputed.ᶜts⁰ : p.precomputed.ᶜts
353354

354355
e_tot_src(Sqₜ, ρ, ts, Φ) = Sqₜ * ρ * e_tot_0M_precipitation_sources_helper(thp, ts, Φ)
355-
e_tot_srcʲ(Φ) = (Sqₜ, ρ, ts) -> e_tot_src(Sqₜ, ρ, ts, Φ)
356-
@. ᶜS_ρq_tot = ᶜSqₜᵖ⁰ * ᶜρa⁰ + draft_sum((S, ρ) -> S * ρ, ᶜSqₜᵖʲs, ᶜsgs_ρaʲs)
356+
e_tot_srcʲ(Φ) = (Sqₜ, sgs_ρʲ, ts) -> e_tot_src(Sqₜ, ρaʲ(sgs_ρʲ, turbconv_model), ts, Φ)
357+
Sqₜρʲ(Sqₜ, sgs_ρʲ) = Sqₜ * ρaʲ(sgs_ρʲ, turbconv_model)
358+
@. ᶜS_ρq_tot = ᶜSqₜᵖ⁰ * ᶜρa⁰ + draft_sum(Sqₜρʲ, ᶜSqₜᵖʲs, ᶜsgs_ρaʲs)
357359
ᶜS_ρe_tot⁰ = @. lazy(e_tot_src(ᶜSqₜᵖ⁰, ᶜρa⁰, ᶜts⁰, ᶜΦ))
358360
@. ᶜS_ρe_tot = ᶜS_ρe_tot⁰ + draft_sum(e_tot_srcʲ(ᶜΦ), ᶜSqₜᵖʲs, ᶜsgs_ρaʲs, ᶜtsʲs)
359361
return nothing

src/utils/variable_manipulations.jl

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ Returns:
362362
- The specific value of the quantity `χ` in the environment.
363363
"""
364364
ᶜspecific_env_value(χ_name, Y, p) =
365-
@. lazy(specific_env_value(χ_name, Y.c, p.atmos.turbconv_model))
365+
@. lazy(specific_env_value((χ_name,), Y.c, p.atmos.turbconv_model))
366366

367367
"""
368368
specific_env_value(χ_name, Yc, turbconv_model)
@@ -482,27 +482,14 @@ Returns:
482482
ρa⁰(ρ, sgsʲs, ::DiagnosticEDMFX) = env_value(ρ, ᶜρaʲ -> ᶜρaʲ, sgsʲs) # ρ - Σ ρaʲ
483483
ρa⁰(ρ, _, _) = ρ
484484

485-
"""
486-
ᶜρaʲs_list(Y, p, turbconv_model)
487-
488-
Returns the list of subdomain density containers
489-
490-
Pass each element of the list to [`ρaʲ`](@ref) to get the subdomain density.
491-
"""
492-
ᶜρaʲs_list(Y, p, ::PrognosticEDMFX) = Y.c.sgsʲs
493-
ᶜρaʲs_list(Y, p, ::DiagnosticEDMFX) = p.precomputed.ᶜρaʲs
494-
495485
"""
496486
ρaʲ(sgsʲ, turbconv_model)
497487
498488
Returns the subdomain density from the subdomain density container.
499489
500-
Use with [`ᶜρaʲs_list`](@ref), which returns the list whose elements
501-
are the first argument to this function.
502-
503490
# Examples
504491
```julia
505-
ᶜsgs_ρaʲs = ᶜρaʲs_list(Y, p, turbconv_model)
492+
ᶜsgs_ρaʲs = turbconv_model isa PrognosticEDMFX ? Y.c.sgsʲs : p.precomputed.ᶜρaʲs
506493
draft_sum = draft_sum(ρaʲ, ᶜsgs_ρaʲs)
507494
```
508495
"""

0 commit comments

Comments
 (0)