Skip to content

Commit e91b55b

Browse files
committed
refactor(diffusion): route EDMFX updraft vertical diffusion through shared helpers
Replace the zero-flux divergence operators in edmfx_vertical_diffusion_tendency! with the shared ᶜdiffusive_flux_divergenceᵥ for the updraft mse, q_tot, and SGS tracer fluxes, keeping the trailing division by the updraft density.
1 parent 6cb0756 commit e91b55b

1 file changed

Lines changed: 8 additions & 21 deletions

File tree

src/prognostic_equations/mass_flux_closures.jl

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,7 @@ function edmfx_vertical_diffusion_tendency!(
174174
if p.atmos.edmfx_model.vertical_diffusion isa Val{true}
175175
(; params) = p
176176
(; ᶜρʲs) = p.precomputed
177-
FT = eltype(p.params)
178177
n = n_mass_flux_subdomains(turbconv_model)
179-
ᶜdivᵥ_mse = Operators.DivergenceF2C(
180-
top = Operators.SetValue(C3(0)),
181-
bottom = Operators.SetValue(C3(0)),
182-
)
183-
ᶜdivᵥ_q_tot = Operators.DivergenceF2C(
184-
top = Operators.SetValue(C3(0)),
185-
bottom = Operators.SetValue(C3(0)),
186-
)
187178

188179
(; ᶜK_h) =
189180
ᶜeddy_diffusivities!(Y, p; ᶜmixing_length_field = p.scratch.ᶜtemp_scalar)
@@ -194,19 +185,16 @@ function edmfx_vertical_diffusion_tendency!(
194185
ᶜq_totʲ = Y.c.sgsʲs.:($j).q_tot
195186
# Note: For this and other diffusive tendencies, we should use ρaʲ instead of ρʲ,
196187
# but it causes stability issues when ρaʲ is small
197-
@. Yₜ.c.sgsʲs.:($$j).mse -=
198-
ᶜdivᵥ_mse(-(ᶠinterp(ᶜρʲ) * ᶠinterp(ᶜK_h) * ᶠgradᵥ(ᶜmseʲ))) / ᶜρʲ
199-
@. Yₜ.c.sgsʲs.:($$j).q_tot -=
200-
ᶜdivᵥ_q_tot(-(ᶠinterp(ᶜρʲ) * ᶠinterp(ᶜK_h) * ᶠgradᵥ(ᶜq_totʲ))) / ᶜρʲ
188+
ᶠcoef = @. lazy(ᶠinterp(ᶜρʲ) * ᶠinterp(ᶜK_h))
189+
ᶜ∇ᵥρD∇mseʲ = ᶜdiffusive_flux_divergenceᵥ(ᶠcoef, ᶜmseʲ)
190+
@. Yₜ.c.sgsʲs.:($$j).mse -= ᶜ∇ᵥρD∇mseʲ / ᶜρʲ
191+
ᶜ∇ᵥρD∇q_totʲ = ᶜdiffusive_flux_divergenceᵥ(ᶠcoef, ᶜq_totʲ)
192+
@. Yₜ.c.sgsʲs.:($$j).q_tot -= ᶜ∇ᵥρD∇q_totʲ / ᶜρʲ
201193
end
202194

203195
if !isempty(sgs_tracer_names(Y))
204196
α_vert_diff_microphysics = CAP.α_vert_diff_tracer(params)
205197
ᶜρʲ = ᶜρʲs.:(1)
206-
ᶜdivᵥ_q = Operators.DivergenceF2C(
207-
top = Operators.SetValue(C3(FT(0))),
208-
bottom = Operators.SetValue(C3(FT(0))),
209-
)
210198
# Sedimenting microphysics species are diffused with
211199
# α_vert_diff_tracer * K_h, passive tracers with the unscaled K_h,
212200
# matching the grid-mean tracer diffusion and the implicit
@@ -218,10 +206,9 @@ function edmfx_vertical_diffusion_tendency!(
218206
one(α_vert_diff_microphysics)
219207
ᶜχʲ = MatrixFields.get_field(Y.c.sgsʲs.:(1), χ_name)
220208
ᶜχʲₜ = MatrixFields.get_field(Yₜ.c.sgsʲs.:(1), χ_name)
221-
@. ᶜχʲₜ -=
222-
ᶜdivᵥ_q(
223-
-(ᶠinterp(ᶜρʲ) * ᶠinterp(ᶜK_h) * α * ᶠgradᵥ(ᶜχʲ)),
224-
) / ᶜρʲ
209+
ᶠcoef = @. lazy(ᶠinterp(ᶜρʲ) * ᶠinterp(ᶜK_h) * α)
210+
ᶜ∇ᵥρD∇χʲ = ᶜdiffusive_flux_divergenceᵥ(ᶠcoef, ᶜχʲ)
211+
@. ᶜχʲₜ -= ᶜ∇ᵥρD∇χʲ / ᶜρʲ
225212
end
226213
end
227214
end

0 commit comments

Comments
 (0)