Skip to content

Commit 8809f55

Browse files
committed
feat: add face density method
1 parent 66ed40b commit 8809f55

File tree

6 files changed

+97
-173
lines changed

6 files changed

+97
-173
lines changed

src/prognostic_equations/advection.jl

Lines changed: 26 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
222222
advect_tke = use_prognostic_tke(turbconv_model)
223223
point_type = eltype(Fields.coordinate_field(Y.c))
224224
(; dt) = p
225-
ᶜJ = Fields.local_geometry_field(Y.c).J
225+
ᶜJ, ᶠJ = Fields.local_geometry_field(Y.c).J, Fields.local_geometry_field(Y.f).J
226+
ᶜρ, ᶠρ = Y.c.ρ, ᶠface_density(Y.c.ρ)
227+
ᶠρJ = @. lazy(ᶠρ * ᶠJ)
228+
ᶜρJ = @. lazy(ᶜρ * ᶜJ)
226229
(; ᶜf³, ᶠf¹², ᶜΦ) = p.core
227230
(; ᶜu, ᶠu³, ᶜK, ᶜts) = p.precomputed
228231
(; edmfx_mse_q_tot_upwinding) = n > 0 || advect_tke ? p.atmos.numerics : all_nothing
@@ -241,14 +244,14 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
241244
advect_tke ?
242245
(
243246
turbconv_model isa PrognosticEDMFX ?
244-
(@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ
247+
(@. lazy(ρa⁰(ᶜρ, Y.c.sgsʲs, turbconv_model))) : ᶜρ
245248
) : nothing
246249
ᶜρ⁰ = if advect_tke
247250
if n > 0
248251
(; ᶜts⁰) = p.precomputed
249252
@. lazy(TD.air_density(thermo_params, ᶜts⁰))
250253
else
251-
Y.c.ρ
254+
ᶜρ
252255
end
253256
else
254257
nothing
@@ -278,8 +281,6 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
278281
end
279282
# Without the CT12(), the right-hand side would be a CT1 or CT2 in 2D space.
280283

281-
ᶜρ = Y.c.ρ
282-
283284
# Full vertical advection of passive tracers (like liq, rai, etc) ...
284285
# If sgs_mass_flux is true, the advection term is computed from the sum of SGS fluxes
285286
if !(
@@ -288,7 +289,7 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
288289
)
289290
foreach_gs_tracer(Yₜ, Y) do ᶜρχₜ, ᶜρχ, ρχ_name
290291
if !(ρχ_name in (@name(ρe_tot), @name(ρq_tot)))
291-
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
292+
ᶜχ = @. lazy(specific(ᶜρχ, ᶜρ))
292293
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜχ, dt, tracer_upwinding)
293294
@. ᶜρχₜ += vtt
294295
end
@@ -310,7 +311,7 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
310311
end
311312

312313
if !(p.atmos.moisture_model isa DryModel) && energy_q_tot_upwinding != Val(:none)
313-
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
314+
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, ᶜρ))
314315
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, dt, energy_q_tot_upwinding)
315316
vtt_central = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, dt, Val(:none))
316317
@. Yₜ.c.ρq_tot += vtt - vtt_central
@@ -322,9 +323,7 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
322323

323324
if isnothing(ᶠf¹²)
324325
# shallow atmosphere
325-
@. Yₜ.c.uₕ -=
326-
ᶜinterp(ᶠω¹² × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) / (Y.c.ρ * ᶜJ) +
327-
(ᶜf³ + ᶜω³) × CT12(ᶜu)
326+
@. Yₜ.c.uₕ -= ᶜinterp(ᶠω¹² × (ᶠρJ * ᶠu³)) / ᶜρJ + (ᶜf³ + ᶜω³) × CT12(ᶜu)
328327
@. Yₜ.f.u₃ -= ᶠω¹² × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
329328
for j in 1:n
330329
@. Yₜ.f.sgsʲs.:($$j).u₃ -=
@@ -333,9 +332,7 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
333332
end
334333
else
335334
# deep atmosphere
336-
@. Yₜ.c.uₕ -=
337-
ᶜinterp((ᶠf¹² + ᶠω¹²) × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) /
338-
(Y.c.ρ * ᶜJ) + (ᶜf³ + ᶜω³) × CT12(ᶜu)
335+
@. Yₜ.c.uₕ -= ᶜinterp((ᶠf¹² + ᶠω¹²) × (ᶠρJ * ᶠu³)) / ᶜρJ + (ᶜf³ + ᶜω³) × CT12(ᶜu)
339336
@. Yₜ.f.u₃ -= (ᶠf¹² + ᶠω¹²) × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
340337
for j in 1:n
341338
@. Yₜ.f.sgsʲs.:($$j).u₃ -=
@@ -380,11 +377,7 @@ Modifies EDMF updraft fields in `Yₜ.c.sgsʲs` and `Yₜ.f.sgsʲs`.
380377
"""
381378
edmfx_sgs_vertical_advection_tendency!(Yₜ, Y, p, t, turbconv_model) = nothing
382379

383-
function edmfx_sgs_vertical_advection_tendency!(
384-
Yₜ,
385-
Y,
386-
p,
387-
t,
380+
function edmfx_sgs_vertical_advection_tendency!(Yₜ, Y, p, t,
388381
turbconv_model::PrognosticEDMFX,
389382
)
390383
(; params) = p
@@ -426,27 +419,21 @@ function edmfx_sgs_vertical_advection_tendency!(
426419
end
427420

428421
for j in 1:n
429-
ᶜa = (@. lazy(draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j))))
422+
ᶜρʲ = ᶜρʲs.:($j)
423+
ᶜa = (@. lazy(draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲ)))
424+
ᶠu³ʲ = ᶠu³ʲs.:($j)
425+
ᶜsgsʲ = Y.c.sgsʲs.:($j)
430426

431427
# Flux form vertical advection of area farction with the grid mean velocity
432-
vtt =
433-
vertical_transport(ᶜρʲs.:($j), ᶠu³ʲs.:($j), ᶜa, dt, edmfx_mse_q_tot_upwinding)
428+
vtt = vertical_transport(ᶜρʲ, ᶠu³ʲ, ᶜa, dt, edmfx_mse_q_tot_upwinding)
434429
@. Yₜ.c.sgsʲs.:($$j).ρa += vtt
435430

436431
# Advective form advection of mse and q_tot with the grid mean velocity
437432
# Note: This allocates because the function is too long
438-
va = vertical_advection(
439-
ᶠu³ʲs.:($j),
440-
Y.c.sgsʲs.:($j).mse,
441-
edmfx_mse_q_tot_upwinding,
442-
)
433+
va = vertical_advection(ᶠu³ʲ, ᶜsgsʲ.mse, edmfx_mse_q_tot_upwinding)
443434
@. Yₜ.c.sgsʲs.:($$j).mse += va
444435

445-
va = vertical_advection(
446-
ᶠu³ʲs.:($j),
447-
Y.c.sgsʲs.:($j).q_tot,
448-
edmfx_mse_q_tot_upwinding,
449-
)
436+
va = vertical_advection(ᶠu³ʲ, ᶜsgsʲ.q_tot, edmfx_mse_q_tot_upwinding)
450437
@. Yₜ.c.sgsʲs.:($$j).q_tot += va
451438

452439
if p.atmos.moisture_model isa NonEquilMoistModel && (
@@ -464,15 +451,8 @@ function edmfx_sgs_vertical_advection_tendency!(
464451
ᶜ∂ρ∂t_sed = p.scratch.ᶜtemp_scalar_3
465452
@. ᶜ∂ρ∂t_sed = 0
466453

467-
ᶜinv_ρ̂ = (@. lazy(
468-
specific(
469-
FT(1),
470-
Y.c.sgsʲs.:($$j).ρa,
471-
FT(0),
472-
ᶜρʲs.:($$j),
473-
turbconv_model,
474-
),
475-
))
454+
ᶜinv_ρ̂ =
455+
@. lazy(specific(FT(1), Y.c.sgsʲs.:($$j).ρa, FT(0), ᶜρʲ, turbconv_model))
476456

477457
# Sedimentation
478458
# TODO - lazify ᶜwₗʲs computation. No need to cache it.
@@ -493,21 +473,11 @@ function edmfx_sgs_vertical_advection_tendency!(
493473
ᶜwʲ = MatrixFields.get_field(p.precomputed, wʲ_name)
494474

495475
# Advective form advection of tracers with updraft velocity
496-
va = vertical_advection(
497-
ᶠu³ʲs.:($j),
498-
ᶜqʲ,
499-
edmfx_tracer_upwinding,
500-
)
476+
va = vertical_advection(ᶠu³ʲs.:($j), ᶜqʲ, edmfx_tracer_upwinding)
501477
@. ᶜqʲₜ += va
502478

503479
# Flux form sedimentation of tracers
504-
vtt = updraft_sedimentation(
505-
ᶜρʲs.:($j),
506-
ᶜwʲ,
507-
ᶜa,
508-
ᶜqʲ,
509-
ᶠJ,
510-
)
480+
vtt = updraft_sedimentation(ᶜρʲs.:($j), ᶜwʲ, ᶜa, ᶜqʲ, ᶠJ)
511481
@. ᶜqʲₜ += ᶜinv_ρ̂ * vtt
512482
@. Yₜ.c.sgsʲs.:($$j).q_tot += ᶜinv_ρ̂ * vtt
513483
@. ᶜ∂ρ∂t_sed += vtt
@@ -524,15 +494,8 @@ function edmfx_sgs_vertical_advection_tendency!(
524494
else
525495
error("Unsupported moisture tracer variable")
526496
end
527-
vtt = updraft_sedimentation(
528-
ᶜρʲs.:($j),
529-
ᶜwʲ,
530-
ᶜa,
531-
ᶜqʲ .* ᶜmse_li,
532-
ᶠJ,
533-
)
534-
@. Yₜ.c.sgsʲs.:($$j).mse +=
535-
ᶜinv_ρ̂ * vtt
497+
vtt = updraft_sedimentation(ᶜρʲ, ᶜwʲ, ᶜa, ᶜqʲ .* ᶜmse_li, ᶠJ)
498+
@. Yₜ.c.sgsʲs.:($$j).mse += ᶜinv_ρ̂ * vtt
536499
end
537500

538501
# Contribution of density variation due to sedimentation
@@ -573,21 +536,11 @@ function edmfx_sgs_vertical_advection_tendency!(
573536
ᶜwʲ = MatrixFields.get_field(p.precomputed, wʲ_name)
574537

575538
# Advective form advection of tracers with updraft velocity
576-
va = vertical_transport(
577-
ᶠu³ʲs.:($j),
578-
ᶜχʲ,
579-
edmfx_tracer_upwinding,
580-
)
539+
va = vertical_transport(ᶠu³ʲs.:($j), ᶜχʲ, edmfx_tracer_upwinding)
581540
@. ᶜχʲₜ += va
582541

583542
# Flux form sedimentation of tracers
584-
vtt = updraft_sedimentation(
585-
ᶜρʲs.:($j),
586-
ᶜwʲ,
587-
ᶜa,
588-
ᶜχʲ,
589-
ᶠJ,
590-
)
543+
vtt = updraft_sedimentation(ᶜρʲ, ᶜwʲ, ᶜa, ᶜχʲ, ᶠJ)
591544
@. ᶜχʲₜ += ᶜinv_ρ̂ * vtt
592545

593546
# Contribution of density variation due to sedimentation

src/prognostic_equations/implicit/implicit_tendency.jl

Lines changed: 42 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,22 @@ end
7373
# the implicit tendency function. Since dt >= dtγ, we can safely use dt for now.
7474

7575
function vertical_transport(ᶜρ, ᶠu³, ᶜχ, dt, ::Val{:none})
76-
ᶜJ = Fields.local_geometry_field(axes(ᶜρ)).J
77-
ᶠJ = Fields.local_geometry_field(axes(ᶠu³)).J
78-
return @. lazy(-(ᶜadvdivᵥ(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ * ᶠu³ * ᶠinterp(ᶜχ))))
76+
ᶠρ = ᶠface_density(ᶜρ)
77+
return @. lazy(-(ᶜadvdivᵥ(ᶠρ * ᶠu³ * ᶠinterp(ᶜχ))))
7978
end
8079
function vertical_transport(ᶜρ, ᶠu³, ᶜχ, dt, ::Val{:first_order})
81-
ᶜJ = Fields.local_geometry_field(axes(ᶜρ)).J
82-
ᶠJ = Fields.local_geometry_field(axes(ᶠu³)).J
83-
return @. lazy(-(ᶜadvdivᵥ(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ * ᶠupwind1(ᶠu³, ᶜχ))))
80+
ᶠρ = ᶠface_density(ᶜρ)
81+
return @. lazy(-(ᶜadvdivᵥ(ᶠρ * ᶠupwind1(ᶠu³, ᶜχ))))
8482
end
8583
@static if pkgversion(ClimaCore) v"0.14.22"
8684
function vertical_transport(ᶜρ, ᶠu³, ᶜχ, dt, ::Val{:vanleer_limiter})
87-
ᶜJ = Fields.local_geometry_field(axes(ᶜρ)).J
88-
ᶠJ = Fields.local_geometry_field(axes(ᶠu³)).J
89-
return @. lazy(
90-
-(ᶜadvdivᵥ(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ * ᶠlin_vanleer(ᶠu³, ᶜχ, dt))),
91-
)
85+
ᶠρ = ᶠface_density(ᶜρ)
86+
return @. lazy(-(ᶜadvdivᵥ(ᶠρ * ᶠlin_vanleer(ᶠu³, ᶜχ, dt))))
9287
end
9388
end
9489
function vertical_transport(ᶜρ, ᶠu³, ᶜχ, dt, ::Val{:third_order})
95-
ᶜJ = Fields.local_geometry_field(axes(ᶜρ)).J
96-
ᶠJ = Fields.local_geometry_field(axes(ᶠu³)).J
97-
return @. lazy(-(ᶜadvdivᵥ(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ * ᶠupwind3(ᶠu³, ᶜχ))))
90+
ᶠρ = ᶠface_density(ᶜρ)
91+
return @. lazy(-(ᶜadvdivᵥ(ᶠρ * ᶠupwind3(ᶠu³, ᶜχ))))
9892
end
9993

10094
vertical_advection(ᶠu³, ᶜχ, ::Val{:none}) =
@@ -105,32 +99,25 @@ vertical_advection(ᶠu³, ᶜχ, ::Val{:third_order}) =
10599
@. lazy(-(ᶜadvdivᵥ(ᶠupwind3(ᶠu³, ᶜχ)) - ᶜχ * ᶜadvdivᵥ(ᶠu³)))
106100

107101
function implicit_vertical_advection_tendency!(Yₜ, Y, p, t)
108-
(; moisture_model, turbconv_model, rayleigh_sponge, microphysics_model) =
109-
p.atmos
102+
(; moisture_model, turbconv_model, rayleigh_sponge, microphysics_model) = p.atmos
110103
(; params, dt) = p
111104
n = n_mass_flux_subdomains(turbconv_model)
112-
ᶜJ = Fields.local_geometry_field(axes(Y.c)).J
113-
ᶠJ = Fields.local_geometry_field(axes(Y.f)).J
105+
ᶜρ, ᶠρ = Y.c.ρ, ᶠface_density(Y.c.ρ)
114106
(; ᶠgradᵥ_ᶜΦ) = p.core
115-
(; ᶠu³, ᶜp, ᶜts) = p.precomputed
107+
(; ᶠu³, ᶜts) = p.precomputed
116108
thermo_params = CAP.thermodynamics_params(params)
117109
cp_d = CAP.cp_d(params)
118-
ᶜh_tot = @. lazy(
119-
TD.total_specific_enthalpy(
120-
thermo_params,
121-
ᶜts,
122-
specific(Y.c.ρe_tot, Y.c.ρ),
123-
),
124-
)
110+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, ᶜρ))
111+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
125112

126-
@. Yₜ.c.ρ -= ᶜdivᵥ(ᶠinterp(Y.c.ρ * ᶜJ) / ᶠJ * ᶠu³)
113+
@. Yₜ.c.ρ -= ᶜdivᵥ(ᶠρ * ᶠu³)
127114

128115
# Central vertical advection of active tracers (e_tot and q_tot)
129-
vtt = vertical_transport(Y.c.ρ, ᶠu³, ᶜh_tot, dt, Val(:none))
116+
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜh_tot, dt, Val(:none))
130117
@. Yₜ.c.ρe_tot += vtt
131118
if !(moisture_model isa DryModel)
132-
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
133-
vtt = vertical_transport(Y.c.ρ, ᶠu³, ᶜq_tot, dt, Val(:none))
119+
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, ᶜρ))
120+
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, dt, Val(:none))
134121
@. Yₜ.c.ρq_tot += vtt
135122
end
136123

@@ -140,63 +127,39 @@ function implicit_vertical_advection_tendency!(Yₜ, Y, p, t)
140127
# using downward biasing and free outflow bottom boundary condition
141128
if moisture_model isa NonEquilMoistModel
142129
(; ᶜwₗ, ᶜwᵢ) = p.precomputed
143-
@. Yₜ.c.ρq_liq -= ᶜprecipdivᵥ(
144-
ᶠinterp(Y.c.ρ * ᶜJ) / ᶠJ * ᶠright_bias(
145-
Geometry.WVector(-(ᶜwₗ)) * specific(Y.c.ρq_liq, Y.c.ρ),
146-
),
147-
)
148-
@. Yₜ.c.ρq_ice -= ᶜprecipdivᵥ(
149-
ᶠinterp(Y.c.ρ * ᶜJ) / ᶠJ * ᶠright_bias(
150-
Geometry.WVector(-(ᶜwᵢ)) * specific(Y.c.ρq_ice, Y.c.ρ),
151-
),
152-
)
130+
q_liq = @. lazy(specific(Y.c.ρq_liq, ᶜρ))
131+
q_ice = @. lazy(specific(Y.c.ρq_ice, ᶜρ))
132+
@. Yₜ.c.ρq_liq -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwₗ) * q_liq))
133+
@. Yₜ.c.ρq_ice -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwᵢ) * q_ice))
153134
end
154135
if microphysics_model isa Microphysics1Moment
155136
(; ᶜwᵣ, ᶜwₛ) = p.precomputed
156-
@. Yₜ.c.ρq_rai -= ᶜprecipdivᵥ(
157-
ᶠinterp(Y.c.ρ * ᶜJ) / ᶠJ * ᶠright_bias(
158-
Geometry.WVector(-(ᶜwᵣ)) * specific(Y.c.ρq_rai, Y.c.ρ),
159-
),
160-
)
161-
@. Yₜ.c.ρq_sno -= ᶜprecipdivᵥ(
162-
ᶠinterp(Y.c.ρ * ᶜJ) / ᶠJ * ᶠright_bias(
163-
Geometry.WVector(-(ᶜwₛ)) * specific(Y.c.ρq_sno, Y.c.ρ),
164-
),
165-
)
137+
q_rai = @. lazy(specific(Y.c.ρq_rai, ᶜρ))
138+
q_sno = @. lazy(specific(Y.c.ρq_sno, ᶜρ))
139+
@. Yₜ.c.ρq_rai -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwᵣ) * q_rai))
140+
@. Yₜ.c.ρq_sno -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwₛ) * q_sno))
166141
end
167142
if microphysics_model isa Microphysics2Moment
168143
(; ᶜwₙₗ, ᶜwₙᵣ, ᶜwᵣ, ᶜwₛ) = p.precomputed
169-
@. Yₜ.c.ρn_liq -= ᶜprecipdivᵥ(
170-
ᶠinterp(Y.c.ρ * ᶜJ) / ᶠJ * ᶠright_bias(
171-
Geometry.WVector(-(ᶜwₙₗ)) * specific(Y.c.ρn_liq, Y.c.ρ),
172-
),
173-
)
174-
@. Yₜ.c.ρn_rai -= ᶜprecipdivᵥ(
175-
ᶠinterp(Y.c.ρ * ᶜJ) / ᶠJ * ᶠright_bias(
176-
Geometry.WVector(-(ᶜwₙᵣ)) * specific(Y.c.ρn_rai, Y.c.ρ),
177-
),
178-
)
179-
@. Yₜ.c.ρq_rai -= ᶜprecipdivᵥ(
180-
ᶠinterp(Y.c.ρ * ᶜJ) / ᶠJ * ᶠright_bias(
181-
Geometry.WVector(-(ᶜwᵣ)) * specific(Y.c.ρq_rai, Y.c.ρ),
182-
),
183-
)
184-
@. Yₜ.c.ρq_sno -= ᶜprecipdivᵥ(
185-
ᶠinterp(Y.c.ρ * ᶜJ) / ᶠJ * ᶠright_bias(
186-
Geometry.WVector(-(ᶜwₛ)) * specific(Y.c.ρq_sno, Y.c.ρ),
187-
),
188-
)
144+
n_liq = @. lazy(specific(Y.c.ρn_liq, ᶜρ))
145+
n_rai = @. lazy(specific(Y.c.ρn_rai, ᶜρ))
146+
q_rai = @. lazy(specific(Y.c.ρq_rai, ᶜρ))
147+
q_sno = @. lazy(specific(Y.c.ρq_sno, ᶜρ))
148+
@. Yₜ.c.ρn_liq -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwₙₗ) * n_liq))
149+
@. Yₜ.c.ρn_rai -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwₙᵣ) * n_rai))
150+
@. Yₜ.c.ρq_rai -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwᵣ) * q_rai))
151+
@. Yₜ.c.ρq_sno -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwₛ) * q_sno))
189152
end
190153
if microphysics_model isa Microphysics2MomentP3
191-
(; ρ, ρn_ice, ρq_rim, ρb_rim) = Y.c
192-
ᶜwnᵢ = @. lazy(Geometry.WVector(p.precomputed.ᶜwnᵢ))
193-
ᶜwᵢ = @. lazy(Geometry.WVector(p.precomputed.ᶜwᵢ))
194-
ᶠρ = @. lazy(ᶠinterp(ρ * ᶜJ) / ᶠJ)
154+
(; ᶜwnᵢ, ᶜwᵢ) = p.precomputed
195155

196156
# Note: `ρq_ice` is handled above, in `moisture_model isa NonEquilMoistModel`
197-
@. Yₜ.c.ρn_ice -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(- ᶜwnᵢ * specific(ρn_ice, ρ)))
198-
@. Yₜ.c.ρq_rim -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(- ᶜwᵢ * specific(ρq_rim, ρ)))
199-
@. Yₜ.c.ρb_rim -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(- ᶜwᵢ * specific(ρb_rim, ρ)))
157+
n_ice = @. lazy(specific(Y.c.ρn_ice, ᶜρ))
158+
q_rim = @. lazy(specific(Y.c.ρq_rim, ᶜρ))
159+
b_rim = @. lazy(specific(Y.c.ρb_rim, ᶜρ))
160+
@. Yₜ.c.ρn_ice -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwnᵢ) * n_ice))
161+
@. Yₜ.c.ρq_rim -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwᵢ) * q_rim))
162+
@. Yₜ.c.ρb_rim -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwᵢ) * b_rim))
200163
end
201164

202165
# TODO - decide if this needs to be explicit or implicit
@@ -207,8 +170,7 @@ function implicit_vertical_advection_tendency!(Yₜ, Y, p, t)
207170
ᶜθ_v = @. lazy(theta_v(thermo_params, ᶜts))
208171
ᶜθ_vr = @. lazy(theta_vr(thermo_params, ᶜts))
209172
ᶜΠ = @. lazy(dry_exner_function(thermo_params, ᶜts))
210-
@. Yₜ.f.u₃ -= ᶠgradᵥ_ᶜΦ - ᶠgradᵥ(ᶜΦ_r) +
211-
cp_d * (ᶠinterp(ᶜθ_v - ᶜθ_vr)) * ᶠgradᵥ(ᶜΠ)
173+
@. Yₜ.f.u₃ -= ᶠgradᵥ_ᶜΦ - ᶠgradᵥ(ᶜΦ_r) + cp_d * (ᶠinterp(ᶜθ_v - ᶜθ_vr)) * ᶠgradᵥ(ᶜΠ)
212174

213175
if rayleigh_sponge isa RayleighSponge
214176
ᶠz = Fields.coordinate_field(Y.f).z
@@ -217,8 +179,7 @@ function implicit_vertical_advection_tendency!(Yₜ, Y, p, t)
217179
@. Yₜ.f.u₃ -= β_rayleigh_w(rs, ᶠz, zmax) * Y.f.u₃
218180
if turbconv_model isa PrognosticEDMFX
219181
for j in 1:n
220-
@. Yₜ.f.sgsʲs.:($$j).u₃ -=
221-
β_rayleigh_w(rs, ᶠz, zmax) * Y.f.sgsʲs.:($$j).u₃
182+
@. Yₜ.f.sgsʲs.:($$j).u₃ -= β_rayleigh_w(rs, ᶠz, zmax) * Y.f.sgsʲs.:($$j).u₃
222183
end
223184
end
224185
end

0 commit comments

Comments
 (0)