@@ -49,17 +49,23 @@ function ᶜremaining_tendency_ρ(ᶜY, ᶠY, p, t)
4949
5050 if ! (p. atmos. moisture_model isa DryModel)
5151 ᶜwₜqₜ = compute_ᶜwₜqₜ (ᶜY, ᶠY, p, t)
52- ∑tendencies = lazy . (∑tendencies .- water_adv (ᶜρ, ᶜJ, ᶠJ, ᶜwₜqₜ))
52+ ∑tendencies = sub_tend (∑tendencies, water_adv (ᶜρ, ᶜJ, ᶠJ, ᶜwₜqₜ))
5353 end
5454 return (;ρ= ∑tendencies)
5555end
56+
57+ add_tend (∑tends, t) = lazy .(∑tends .+ t)
58+ add_tend (∑tends, :: NullBroadcasted ) = ∑tends
59+ sub_tend (∑tends, :: NullBroadcasted ) = ∑tends
60+ sub_tend (∑tends, t) = lazy .(∑tends .- t)
61+
5662function ᶜremaining_tendency_uₕ (ᶜY, ᶠY, p, t)
5763 :uₕ in propertynames (ᶜY) || return ()
5864 ∑tendencies = zero (eltype (ᶜY. uₕ))
5965 (; viscous_sponge, rayleigh_sponge) = p. atmos
6066 ᶜuₕ = ᶜY. uₕ
61- ∑tendencies = lazy . (∑tendencies .+ viscous_sponge_tendency_uₕ (ᶜuₕ, viscous_sponge))
62- ∑tendencies = lazy . (∑tendencies .+ rayleigh_sponge_tendency_uₕ (ᶜuₕ, rayleigh_sponge))
67+ ∑tendencies = add_tend (∑tendencies, viscous_sponge_tendency_uₕ (ᶜuₕ, viscous_sponge))
68+ ∑tendencies = add_tend (∑tendencies, rayleigh_sponge_tendency_uₕ (ᶜuₕ, rayleigh_sponge))
6369
6470 return (;uₕ= ∑tendencies)
6571end
@@ -82,19 +88,19 @@ function ᶜremaining_tendency_ρe_tot(ᶜY, ᶠY, p, t)
8288
8389 if ! (p. atmos. moisture_model isa DryModel)
8490 ᶜwₕhₜ = compute_ᶜwₕhₜ (ᶜY, ᶠY, p, t)
85- ∑tendencies = lazy . (∑tendencies .- water_adv (ᶜρ, ᶜJ, ᶠJ, ᶜwₕhₜ))
91+ ∑tendencies = sub_tend (∑tendencies, water_adv (ᶜρ, ᶜJ, ᶠJ, ᶜwₕhₜ))
8692 end
8793 if energy_upwinding != Val (:none )
8894 (; dt) = p
8995 ᶠu³ = compute_ᶠu³ (ᶜY, ᶠY)
9096 vtt = vertical_transport (ᶜρ, ᶠu³, ᶜh_tot, float (dt), energy_upwinding)
91- ∑tendencies = lazy . (∑tendencies .+ vtt)
97+ ∑tendencies = add_tend (∑tendencies, vtt)
9298 vtt_central = vertical_transport (ᶜρ, ᶠu³, ᶜh_tot, float (dt), Val (:none ))
9399 # need to improve NullBroadcast support for this.
94- ∑tendencies = lazy . (∑tendencies .+ ( - 1 ) .* vtt_central)
100+ ∑tendencies = sub_tend (∑tendencies, vtt_central)
95101 end
96102
97- ∑tendencies = lazy . (∑tendencies .+ viscous_sponge_tendency_ρe_tot (ᶜρ, ᶜh_tot, viscous_sponge))
103+ ∑tendencies = add_tend (∑tendencies, viscous_sponge_tendency_ρe_tot (ᶜρ, ᶜh_tot, viscous_sponge))
98104 return (;ρe_tot= ∑tendencies)
99105end
100106function ᶜremaining_tendency_ρq_tot (ᶜY, ᶠY, p, t)
@@ -108,7 +114,7 @@ function ᶜremaining_tendency_ρq_tot(ᶜY, ᶠY, p, t)
108114 cmc = CAP. microphysics_cloud_params (p. params)
109115 cmp = CAP. microphysics_1m_params (p. params)
110116 thp = CAP. thermodynamics_params (p. params)
111- ∑tendencies = lazy . (∑tendencies .- water_adv (ᶜρ, ᶜJ, ᶠJ, ᶜwₜqₜ))
117+ ∑tendencies = sub_tend (∑tendencies, water_adv (ᶜρ, ᶜJ, ᶠJ, ᶜwₜqₜ))
112118 end
113119 (; tracer_upwinding) = p. atmos. numerics
114120 if ! (p. atmos. moisture_model isa DryModel) && tracer_upwinding != Val (:none )
@@ -118,7 +124,8 @@ function ᶜremaining_tendency_ρq_tot(ᶜY, ᶠY, p, t)
118124 ᶠu³ = compute_ᶠu³ (ᶜY, ᶠY)
119125 vtt = vertical_transport (ᶜρ, ᶠu³, ᶜq_tot, float (dt), tracer_upwinding)
120126 vtt_central = vertical_transport (ᶜρ, ᶠu³, ᶜq_tot, float (dt), Val (:none ))
121- ∑tendencies = lazy .(∑tendencies .+ vtt .- vtt_central)
127+ ∑tendencies = add_tend (∑tendencies, vtt)
128+ ∑tendencies = sub_tend (∑tendencies, vtt_central)
122129 end
123130
124131 return (;ρq_tot= ∑tendencies)
@@ -161,7 +168,7 @@ function ᶠremaining_tendency_u₃(ᶜY, ᶠY, p, t)
161168 ᶜuₕ = ᶜY. uₕ
162169 ᶠuₕ³ = compute_ᶠuₕ³ (ᶜuₕ, ᶜρ)
163170 ᶠu₃ = compute_ᶠu₃_with_bcs (ᶠY. u₃, ᶠuₕ³)
164- ∑tendencies = lazy . (∑tendencies .+ viscous_sponge_tendency_u₃ (ᶠu₃, viscous_sponge))
171+ ∑tendencies = add_tend (∑tendencies, viscous_sponge_tendency_u₃ (ᶠu₃, viscous_sponge))
165172 return (;u₃= ∑tendencies)
166173end
167174function ᶠremaining_tendency_sgsʲs (ᶜY, ᶠY, p, t)
0 commit comments