Skip to content

Commit 68ad109

Browse files
committed
rft: simplify two instances of advection_tendency!
for NonEquilibriumMoisture and Precipitation2M
1 parent 995e905 commit 68ad109

File tree

1 file changed

+33
-59
lines changed

1 file changed

+33
-59
lines changed

src/K1DModel/tendency.jl

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -251,33 +251,29 @@ end
251251
return dY
252252
end
253253
@inline function advection_tendency!(::CO.NonEquilibriumMoisture, dY, Y, aux, t)
254-
FT = eltype(Y.ρq_tot)
254+
(; q_surf) = aux
255+
(; ρw, ρw0) = aux.prescribed_velocity
256+
(; ρ) = aux.thermo_variables
257+
(; qtot_flux_correction) = aux.kid_params
255258

256259
If = CC.Operators.InterpolateC2F()
260+
extrapolate = CC.Operators.Extrapolate()
261+
bottom_bc(q) = CC.Operators.SetValue(CC.Geometry.WVector(ρw0 * q))
257262

258-
∂_qt = CC.Operators.DivergenceF2C(
259-
bottom = CC.Operators.SetValue(CC.Geometry.WVector(aux.prescribed_velocity.ρw0 * aux.q_surf)),
260-
top = CC.Operators.Extrapolate(),
261-
)
262-
∂_ql = CC.Operators.DivergenceF2C(
263-
bottom = CC.Operators.SetValue(CC.Geometry.WVector(aux.prescribed_velocity.ρw0 * FT(0.0))),
264-
top = CC.Operators.Extrapolate(),
265-
)
266-
∂_qi = CC.Operators.DivergenceF2C(
267-
bottom = CC.Operators.SetValue(CC.Geometry.WVector(aux.prescribed_velocity.ρw0 * FT(0.0))),
268-
top = CC.Operators.Extrapolate(),
269-
)
263+
∂_qt = CC.Operators.DivergenceF2C(bottom = bottom_bc(q_surf), top = extrapolate)
264+
∂_ql = CC.Operators.DivergenceF2C(bottom = bottom_bc(0), top = extrapolate)
265+
∂_qi = CC.Operators.DivergenceF2C(bottom = bottom_bc(0), top = extrapolate)
270266

271-
@. dY.ρq_tot += -∂_qt(aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ) * If(Y.ρq_tot))
272-
@. dY.ρq_liq += -∂_ql(aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ) * If(Y.ρq_liq))
273-
@. dY.ρq_ice += -∂_qi(aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ) * If(Y.ρq_ice))
267+
@. dY.ρq_tot += -∂_qt(ρw / If(ρ) * If(Y.ρq_tot))
268+
@. dY.ρq_liq += -∂_ql(ρw / If(ρ) * If(Y.ρq_liq))
269+
@. dY.ρq_ice += -∂_qi(ρw / If(ρ) * If(Y.ρq_ice))
274270

275-
fcc = CC.Operators.FluxCorrectionC2C(bottom = CC.Operators.Extrapolate(), top = CC.Operators.Extrapolate())
276-
if Bool(aux.kid_params.qtot_flux_correction)
277-
@. dY.ρq_tot += fcc(aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ), Y.ρq_tot)
271+
fcc = CC.Operators.FluxCorrectionC2C(bottom = extrapolate, top = extrapolate)
272+
if Bool(qtot_flux_correction)
273+
@. dY.ρq_tot += fcc(ρw / If(ρ), Y.ρq_tot)
278274
end
279-
@. dY.ρq_liq += fcc(aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ), Y.ρq_liq)
280-
@. dY.ρq_ice += fcc(aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ), Y.ρq_ice)
275+
@. dY.ρq_liq += fcc(ρw / If(ρ), Y.ρq_liq)
276+
@. dY.ρq_ice += fcc(ρw / If(ρ), Y.ρq_ice)
281277

282278
return dY
283279
end
@@ -346,50 +342,28 @@ end
346342
end
347343
@inline function advection_tendency!(::CO.Precipitation2M, dY, Y, aux, t)
348344
FT = eltype(Y.ρq_tot)
345+
(; ρw) = aux.prescribed_velocity
346+
(; ρ) = aux.thermo_variables
347+
(; term_vel_N_rai, term_vel_rai) = aux.velocities
349348

350349
If = CC.Operators.InterpolateC2F()
351-
= CC.Operators.DivergenceF2C(
352-
bottom = CC.Operators.Extrapolate(),
353-
top = CC.Operators.SetValue(CC.Geometry.WVector(0.0)),
354-
)
355-
∂ₐ = CC.Operators.DivergenceF2C(bottom = CC.Operators.Extrapolate(), top = CC.Operators.Extrapolate())
350+
wvec = CC.Geometry.WVector
351+
extrapolate = CC.Operators.Extrapolate()
352+
= CC.Operators.DivergenceF2C(bottom = extrapolate, top = CC.Operators.SetValue(wvec(FT(0))))
353+
∂ₐ = CC.Operators.DivergenceF2C(bottom = extrapolate, top = extrapolate)
356354

357-
@. dY.N_aer += -∂ₐ((aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ)) * If(Y.N_aer))
358-
@. dY.N_liq += -((aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ)) * If(Y.N_liq))
355+
@. dY.N_aer += -∂ₐ(ρw / If(ρ) * If(Y.N_aer))
356+
@. dY.N_liq += -(ρw / If(ρ) * If(Y.N_liq))
359357

360-
@. dY.N_rai +=
361-
-(
362-
(
363-
aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ) +
364-
CC.Geometry.WVector(If(aux.velocities.term_vel_N_rai) * FT(-1))
365-
) * If(Y.N_rai),
366-
)
367-
@. dY.ρq_rai +=
368-
-(
369-
(
370-
aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ) +
371-
CC.Geometry.WVector(If(aux.velocities.term_vel_rai) * FT(-1))
372-
) * If(Y.ρq_rai),
373-
)
358+
@. dY.N_rai += -((ρw / If(ρ) + wvec(-If(term_vel_N_rai))) * If(Y.N_rai))
359+
@. dY.ρq_rai += -((ρw / If(ρ) + wvec(-If(term_vel_rai))) * If(Y.ρq_rai))
374360

375-
fcc = CC.Operators.FluxCorrectionC2C(bottom = CC.Operators.Extrapolate(), top = CC.Operators.Extrapolate())
376-
@. dY.N_aer += fcc((aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ)), Y.N_aer)
377-
@. dY.N_liq += fcc((aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ)), Y.N_liq)
361+
fcc = CC.Operators.FluxCorrectionC2C(bottom = extrapolate, top = extrapolate)
362+
@. dY.N_aer += fcc(ρw / If(ρ), Y.N_aer)
363+
@. dY.N_liq += fcc(ρw / If(ρ), Y.N_liq)
378364

379-
@. dY.N_rai += fcc(
380-
(
381-
aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ) +
382-
CC.Geometry.WVector(If(aux.velocities.term_vel_N_rai) * FT(-1))
383-
),
384-
Y.N_rai,
385-
)
386-
@. dY.ρq_rai += fcc(
387-
(
388-
aux.prescribed_velocity.ρw / If(aux.thermo_variables.ρ) +
389-
CC.Geometry.WVector(If(aux.velocities.term_vel_rai) * FT(-1))
390-
),
391-
Y.ρq_rai,
392-
)
365+
@. dY.N_rai += fcc(ρw / If(ρ) + wvec(-If(term_vel_N_rai)), Y.N_rai)
366+
@. dY.ρq_rai += fcc(ρw / If(ρ) + wvec(-If(term_vel_rai)), Y.ρq_rai)
393367

394368
return dY
395369
end

0 commit comments

Comments
 (0)