@@ -269,7 +269,60 @@ function edmfx_sgs_mass_flux_tendency!(
269269 )
270270 @. Yₜ. c. ρq_tot += vtt
271271 end
272- # TODO : add environment flux?
272+ end
273+
274+ # Microphysics tracers fluxes
275+ if p. atmos. moisture_model isa NonEquilMoistModel && (
276+ p. atmos. microphysics_model isa Microphysics1Moment ||
277+ p. atmos. microphysics_model isa Microphysics2Moment
278+ )
279+ microphysics_tracers = (
280+ (@name (c. ρq_liq), @name (ᶜq_liqʲs.:(1 ))),
281+ (@name (c. ρq_ice), @name (ᶜq_iceʲs.:(1 ))),
282+ (@name (c. ρq_rai), @name (ᶜq_raiʲs.:(1 ))),
283+ (@name (c. ρq_sno), @name (ᶜq_snoʲs.:(1 ))),
284+ (@name (c. ρn_liq), @name (ᶜn_liqʲs.:(1 ))),
285+ (@name (c. ρn_rai), @name (ᶜn_raiʲs.:(1 ))),
286+ )
287+ for j in 1 : n
288+ # TODO using unrolled_foreach here allocates! (breaks the flame tests
289+ # even though they use 0M microphysics)
290+ # MatrixFields.unrolled_foreach(
291+ # microphysics_tracers,
292+ # ) do (ρχ_name, χʲ_name)
293+ for (ρχ_name, χʲ_name) in microphysics_tracers
294+ MatrixFields. has_field (Y, ρχ_name) || continue
295+
296+ ᶜχʲ = MatrixFields. get_field (p. precomputed, χʲ_name)
297+ ᶜρχ = MatrixFields. get_field (Y, ρχ_name)
298+ ᶜχ = (@. lazy (specific (ᶜρχ, Y. c. ρ)))
299+
300+ @. ᶠu³_diff = ᶠu³ʲs.:($$ j) - ᶠu³
301+ # @. ᶜa_scalar =
302+ # (ᶜχʲ - ᶜχ) *
303+ # draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j))
304+ # TODO : remove this filter when mass flux is treated implicitly
305+ @. ᶜa_scalar =
306+ (ᶜχʲ - ᶜχ) * min (
307+ min (draft_area (ᶜρaʲs.:($$ j), ᶜρʲs.:($$ j)), a_max),
308+ FT (0.02 ) / max (
309+ Geometry. WVector (
310+ ᶜinterp (ᶠu³_diff),
311+ ). components. data.:1 ,
312+ eps (FT),
313+ ),
314+ )
315+ vtt = vertical_transport_precip_massflux (
316+ ᶜρʲs.:($ j),
317+ ᶠu³_diff,
318+ ᶜa_scalar,
319+ dt,
320+ edmfx_sgsflux_upwinding,
321+ )
322+ ᶜρχₜ = MatrixFields. get_field (Yₜ, ρχ_name)
323+ @. ᶜρχₜ += vtt
324+ end
325+ end
273326 end
274327 # TODO : the following adds the environment flux to the tendency
275328 # Make active and test later
0 commit comments