Skip to content

Commit 44f1f7e

Browse files
committed
add face density method
1 parent 1ff2b0e commit 44f1f7e

File tree

6 files changed

+98
-168
lines changed

6 files changed

+98
-168
lines changed

src/prognostic_equations/advection.jl

Lines changed: 24 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
198198
advect_tke = use_prognostic_tke(turbconv_model)
199199
point_type = eltype(Fields.coordinate_field(Y.c))
200200
(; dt) = p
201-
ᶜJ = Fields.local_geometry_field(Y.c).J
201+
ᶜJ, ᶠJ = Fields.local_geometry_field(Y.c).J, Fields.local_geometry_field(Y.f).J
202+
ᶜρ, ᶠρ = Y.c.ρ, face_density(Y.c.ρ)
203+
ᶠρJ = @. lazy(ᶠρ * ᶠJ)
204+
ᶜρJ = @. lazy(ᶜρ * ᶜJ)
202205
(; ᶜf³, ᶠf¹², ᶜΦ) = p.core
203206
(; ᶜu, ᶠu³, ᶜK, ᶜts) = p.precomputed
204207
(; edmfx_mse_q_tot_upwinding) = n > 0 || advect_tke ? p.atmos.numerics : all_nothing
@@ -217,14 +220,14 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
217220
advect_tke ?
218221
(
219222
turbconv_model isa PrognosticEDMFX ?
220-
(@. lazy(ρa⁰(Y.c.ρ, Y.c.sgsʲs, turbconv_model))) : Y.c.ρ
223+
(@. lazy(ρa⁰(ᶜρ, Y.c.sgsʲs, turbconv_model))) : ᶜρ
221224
) : nothing
222225
ᶜρ⁰ = if advect_tke
223226
if n > 0
224227
(; ᶜts⁰) = p.precomputed
225228
@. lazy(TD.air_density(thermo_params, ᶜts⁰))
226229
else
227-
Y.c.ρ
230+
ᶜρ
228231
end
229232
else
230233
nothing
@@ -254,14 +257,12 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
254257
end
255258
# Without the CT12(), the right-hand side would be a CT1 or CT2 in 2D space.
256259

257-
ᶜρ = Y.c.ρ
258-
259260
# Full vertical advection of passive tracers (like liq, rai, etc) ...
260261
# If sgs_mass_flux is true, the advection term is computed from the sum of SGS fluxes
261262
if p.atmos.edmfx_model.sgs_mass_flux isa Val{false}
262263
foreach_gs_tracer(Yₜ, Y) do ᶜρχₜ, ᶜρχ, ρχ_name
263264
if !(ρχ_name in (@name(ρe_tot), @name(ρq_tot)))
264-
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
265+
ᶜχ = @. lazy(specific(ᶜρχ, ᶜρ))
265266
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜχ, FT(dt), tracer_upwinding)
266267
@. ᶜρχₜ += vtt
267268
end
@@ -283,17 +284,15 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
283284
end
284285

285286
if !(p.atmos.moisture_model isa DryModel) && energy_q_tot_upwinding != Val(:none)
286-
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
287+
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, ᶜρ))
287288
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, FT(dt), energy_q_tot_upwinding)
288289
vtt_central = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, FT(dt), Val(:none))
289290
@. Yₜ.c.ρq_tot += vtt - vtt_central
290291
end
291292

292293
if isnothing(ᶠf¹²)
293294
# shallow atmosphere
294-
@. Yₜ.c.uₕ -=
295-
ᶜinterp(ᶠω¹² × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) / (Y.c.ρ * ᶜJ) +
296-
(ᶜf³ + ᶜω³) × CT12(ᶜu)
295+
@. Yₜ.c.uₕ -= ᶜinterp(ᶠω¹² × (ᶠρJ * ᶠu³)) / ᶜρJ + (ᶜf³ + ᶜω³) × CT12(ᶜu)
297296
@. Yₜ.f.u₃ -= ᶠω¹² × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
298297
for j in 1:n
299298
@. Yₜ.f.sgsʲs.:($$j).u₃ -=
@@ -302,9 +301,7 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
302301
end
303302
else
304303
# deep atmosphere
305-
@. Yₜ.c.uₕ -=
306-
ᶜinterp((ᶠf¹² + ᶠω¹²) × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) /
307-
(Y.c.ρ * ᶜJ) + (ᶜf³ + ᶜω³) × CT12(ᶜu)
304+
@. Yₜ.c.uₕ -= ᶜinterp((ᶠf¹² + ᶠω¹²) × (ᶠρJ * ᶠu³)) / ᶜρJ + (ᶜf³ + ᶜω³) × CT12(ᶜu)
308305
@. Yₜ.f.u₃ -= (ᶠf¹² + ᶠω¹²) × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
309306
for j in 1:n
310307
@. Yₜ.f.sgsʲs.:($$j).u₃ -=
@@ -349,11 +346,7 @@ Modifies EDMF updraft fields in `Yₜ.c.sgsʲs` and `Yₜ.f.sgsʲs`.
349346
"""
350347
edmfx_sgs_vertical_advection_tendency!(Yₜ, Y, p, t, turbconv_model) = nothing
351348

352-
function edmfx_sgs_vertical_advection_tendency!(
353-
Yₜ,
354-
Y,
355-
p,
356-
t,
349+
function edmfx_sgs_vertical_advection_tendency!(Yₜ, Y, p, t,
357350
turbconv_model::PrognosticEDMFX,
358351
)
359352
(; params) = p
@@ -395,26 +388,21 @@ function edmfx_sgs_vertical_advection_tendency!(
395388
end
396389

397390
for j in 1:n
398-
ᶜa = (@. lazy(draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j))))
391+
ᶜρʲ = ᶜρʲs.:($j)
392+
ᶜa = (@. lazy(draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲ)))
399393

400394
# Flux form vertical advection of area farction with the grid mean velocity
401395
vtt =
402-
vertical_transport(ᶜρʲs.:($j), ᶠu³ʲs.:($j), ᶜa, dt, edmfx_mse_q_tot_upwinding)
396+
vertical_transport(ᶜρʲ, ᶠu³ʲs.:($j), ᶜa, dt, edmfx_mse_q_tot_upwinding)
403397
@. Yₜ.c.sgsʲs.:($$j).ρa += vtt
404398

405399
# Advective form advection of mse and q_tot with the grid mean velocity
406400
# Note: This allocates because the function is too long
407-
va = vertical_advection(
408-
ᶠu³ʲs.:($j),
409-
Y.c.sgsʲs.:($j).mse,
410-
edmfx_mse_q_tot_upwinding,
411-
)
401+
va = vertical_advection(ᶠu³ʲs.:($j), Y.c.sgsʲs.:($j).mse, edmfx_mse_q_tot_upwinding)
412402
@. Yₜ.c.sgsʲs.:($$j).mse += va
413403

414404
va = vertical_advection(
415-
ᶠu³ʲs.:($j),
416-
Y.c.sgsʲs.:($j).q_tot,
417-
edmfx_mse_q_tot_upwinding,
405+
ᶠu³ʲs.:($j), Y.c.sgsʲs.:($j).q_tot, edmfx_mse_q_tot_upwinding
418406
)
419407
@. Yₜ.c.sgsʲs.:($$j).q_tot += va
420408

@@ -433,15 +421,8 @@ function edmfx_sgs_vertical_advection_tendency!(
433421
ᶜ∂ρ∂t_sed = p.scratch.ᶜtemp_scalar_3
434422
@. ᶜ∂ρ∂t_sed = 0
435423

436-
ᶜinv_ρ̂ = (@. lazy(
437-
specific(
438-
FT(1),
439-
Y.c.sgsʲs.:($$j).ρa,
440-
FT(0),
441-
ᶜρʲs.:($$j),
442-
turbconv_model,
443-
),
444-
))
424+
ᶜinv_ρ̂ =
425+
@. lazy(specific(FT(1), Y.c.sgsʲs.:($$j).ρa, FT(0), ᶜρʲ, turbconv_model))
445426

446427
# Sedimentation
447428
# TODO - lazify ᶜwₗʲs computation. No need to cache it.
@@ -462,21 +443,11 @@ function edmfx_sgs_vertical_advection_tendency!(
462443
ᶜwʲ = MatrixFields.get_field(p.precomputed, wʲ_name)
463444

464445
# Advective form advection of tracers with updraft velocity
465-
va = vertical_advection(
466-
ᶠu³ʲs.:($j),
467-
ᶜqʲ,
468-
edmfx_tracer_upwinding,
469-
)
446+
va = vertical_advection(ᶠu³ʲs.:($j), ᶜqʲ, edmfx_tracer_upwinding)
470447
@. ᶜqʲₜ += va
471448

472449
# Flux form sedimentation of tracers
473-
vtt = updraft_sedimentation(
474-
ᶜρʲs.:($j),
475-
ᶜwʲ,
476-
ᶜa,
477-
ᶜqʲ,
478-
ᶠJ,
479-
)
450+
vtt = updraft_sedimentation(ᶜρʲs.:($j), ᶜwʲ, ᶜa, ᶜqʲ, ᶠJ)
480451
@. ᶜqʲₜ += ᶜinv_ρ̂ * vtt
481452
@. Yₜ.c.sgsʲs.:($$j).q_tot += ᶜinv_ρ̂ * vtt
482453
@. ᶜ∂ρ∂t_sed += vtt
@@ -493,15 +464,8 @@ function edmfx_sgs_vertical_advection_tendency!(
493464
else
494465
error("Unsupported moisture tracer variable")
495466
end
496-
vtt = updraft_sedimentation(
497-
ᶜρʲs.:($j),
498-
ᶜwʲ,
499-
ᶜa,
500-
ᶜqʲ .* ᶜmse_li,
501-
ᶠJ,
502-
)
503-
@. Yₜ.c.sgsʲs.:($$j).mse +=
504-
ᶜinv_ρ̂ * vtt
467+
vtt = updraft_sedimentation(ᶜρʲ, ᶜwʲ, ᶜa, ᶜqʲ .* ᶜmse_li, ᶠJ)
468+
@. Yₜ.c.sgsʲs.:($$j).mse += ᶜinv_ρ̂ * vtt
505469
end
506470

507471
# Contribution of density variation due to sedimentation
@@ -542,21 +506,11 @@ function edmfx_sgs_vertical_advection_tendency!(
542506
ᶜwʲ = MatrixFields.get_field(p.precomputed, wʲ_name)
543507

544508
# Advective form advection of tracers with updraft velocity
545-
va = vertical_transport(
546-
ᶠu³ʲs.:($j),
547-
ᶜχʲ,
548-
edmfx_tracer_upwinding,
549-
)
509+
va = vertical_transport(ᶠu³ʲs.:($j), ᶜχʲ, edmfx_tracer_upwinding)
550510
@. ᶜχʲₜ += va
551511

552512
# Flux form sedimentation of tracers
553-
vtt = updraft_sedimentation(
554-
ᶜρʲs.:($j),
555-
ᶜwʲ,
556-
ᶜa,
557-
ᶜχʲ,
558-
ᶠJ,
559-
)
513+
vtt = updraft_sedimentation(ᶜρʲ, ᶜwʲ, ᶜa, ᶜχʲ, ᶠJ)
560514
@. ᶜχʲₜ += ᶜinv_ρ̂ * vtt
561515

562516
# Contribution of density variation due to sedimentation

src/prognostic_equations/implicit/implicit_tendency.jl

Lines changed: 44 additions & 80 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,26 @@ 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.ρ
106+
ᶠρ = face_density(ᶜρ)
114107
(; ᶠgradᵥ_ᶜΦ) = p.core
115108
(; ᶠu³, ᶜp, ᶜts) = p.precomputed
116109
thermo_params = CAP.thermodynamics_params(params)
117110
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-
)
111+
e_tot = @. lazy(specific(Y.c.ρe_tot, ᶜρ))
112+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, e_tot))
125113

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

128116
# Central vertical advection of active tracers (e_tot and q_tot)
129-
vtt = vertical_transport(Y.c.ρ, ᶠu³, ᶜh_tot, dt, Val(:none))
117+
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜh_tot, dt, Val(:none))
130118
@. Yₜ.c.ρe_tot += vtt
131119
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))
120+
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, ᶜρ))
121+
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, dt, Val(:none))
134122
@. Yₜ.c.ρq_tot += vtt
135123
end
136124

@@ -140,63 +128,41 @@ function implicit_vertical_advection_tendency!(Yₜ, Y, p, t)
140128
# using downward biasing and free outflow bottom boundary condition
141129
if moisture_model isa NonEquilMoistModel
142130
(; ᶜ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-
)
131+
q_liq = @. lazy(specific(Y.c.ρq_liq, ᶜρ))
132+
q_ice = @. lazy(specific(Y.c.ρq_ice, ᶜρ))
133+
@. Yₜ.c.ρq_liq -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwₗ) * q_liq))
134+
@. Yₜ.c.ρq_ice -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwᵢ) * q_ice))
153135
end
154136
if microphysics_model isa Microphysics1Moment
155137
(; ᶜ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-
)
138+
q_rai = @. lazy(specific(Y.c.ρq_rai, ᶜρ))
139+
q_sno = @. lazy(specific(Y.c.ρq_sno, ᶜρ))
140+
@. Yₜ.c.ρq_rai -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwᵣ) * q_rai))
141+
@. Yₜ.c.ρq_sno -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwₛ) * q_sno))
166142
end
167143
if microphysics_model isa Microphysics2Moment
168144
(; ᶜ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-
)
145+
n_liq = @. lazy(specific(Y.c.ρn_liq, ᶜρ))
146+
n_rai = @. lazy(specific(Y.c.ρn_rai, ᶜρ))
147+
q_rai = @. lazy(specific(Y.c.ρq_rai, ᶜρ))
148+
q_sno = @. lazy(specific(Y.c.ρq_sno, ᶜρ))
149+
@. Yₜ.c.ρn_liq -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwₙₗ) * n_liq))
150+
@. Yₜ.c.ρn_rai -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwₙᵣ) * n_rai))
151+
@. Yₜ.c.ρq_rai -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwᵣ) * q_rai))
152+
@. Yₜ.c.ρq_sno -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwₛ) * q_sno))
189153
end
190154
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)
155+
(; ᶜwnᵢ, ᶜwᵢ) = p.precomputed
156+
ᶜρ = Y.c.ρ
157+
ᶠρ = face_density(ᶜρ)
195158

196159
# 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, ρ)))
160+
n_ice = @. lazy(specific(Y.c.ρn_ice, ᶜρ))
161+
q_rim = @. lazy(specific(Y.c.ρq_rim, ᶜρ))
162+
b_rim = @. lazy(specific(Y.c.ρb_rim, ᶜρ))
163+
@. Yₜ.c.ρn_ice -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwnᵢ) * n_ice))
164+
@. Yₜ.c.ρq_rim -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwᵢ) * q_rim))
165+
@. Yₜ.c.ρb_rim -= ᶜprecipdivᵥ(ᶠρ * ᶠright_bias(-WVec(ᶜwᵢ) * b_rim))
200166
end
201167

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

213178
if rayleigh_sponge isa RayleighSponge
214179
ᶠz = Fields.coordinate_field(Y.f).z
@@ -217,8 +182,7 @@ function implicit_vertical_advection_tendency!(Yₜ, Y, p, t)
217182
@. Yₜ.f.u₃ -= β_rayleigh_w(rs, ᶠz, zmax) * Y.f.u₃
218183
if turbconv_model isa PrognosticEDMFX
219184
for j in 1:n
220-
@. Yₜ.f.sgsʲs.:($$j).u₃ -=
221-
β_rayleigh_w(rs, ᶠz, zmax) * Y.f.sgsʲs.:($$j).u₃
185+
@. Yₜ.f.sgsʲs.:($$j).u₃ -= β_rayleigh_w(rs, ᶠz, zmax) * Y.f.sgsʲs.:($$j).u₃
222186
end
223187
end
224188
end

0 commit comments

Comments
 (0)