@@ -296,14 +296,21 @@ end
296296# --- 0-Moment Microphysics ---
297297
298298"""
299- bulk_microphysics_tendencies(
300- ::Microphysics0Moment,
301- mp,
302- tps,
303- T,
304- q_lcl,
305- q_icl,
306- )
299+ _precip_energy(tps, T, q_lcl, q_icl)
300+
301+ Internal energy of removed condensate, weighted by the liquid fraction.
302+ Shared helper for the two 0-moment `bulk_microphysics_tendencies` methods.
303+ """
304+ @inline function _precip_energy (tps, T, q_lcl, q_icl)
305+ λ = TDI. liquid_fraction (tps, T, q_lcl, q_icl)
306+ I_liq = TDI. internal_energy_liquid (tps, T)
307+ I_ice = TDI. internal_energy_ice (tps, T)
308+ return λ * I_liq + (1 - λ) * I_ice
309+ end
310+
311+ """
312+ bulk_microphysics_tendencies(::Microphysics0Moment, mp, tps, T, q_lcl, q_icl)
313+ bulk_microphysics_tendencies(::Microphysics0Moment, mp, tps, T, q_lcl, q_icl, q_vap_sat)
307314
308315Compute 0-moment microphysics tendencies in one fused call.
309316
@@ -313,13 +320,16 @@ Returns a NamedTuple with:
313320
314321Caller adds geopotential Φ for energy tendency: `e_tot = dq_tot_dt * (e_int_precip + Φ)`
315322
323+ The first form uses the fixed condensate threshold `qc_0`;
324+ the second form uses the supersaturation threshold `S_0 * q_vap_sat`.
325+
316326# Arguments
317- - `mp`: NamedTuple with microphysics parameters:
318- - `params_0M`: Parameters0M struct (contains τ_precip, qc_0 or S_0)
327+ - `mp`: Microphysics0MParams (contains τ_precip, qc_0, S_0)
319328- `tps`: Thermodynamics parameters
320329- `T`: Temperature [K]
321330- `q_lcl`: Cloud liquid specific content [kg/kg]
322331- `q_icl`: Cloud ice specific content [kg/kg]
332+ - `q_vap_sat`: (second method only) Saturation specific humidity [kg/kg]
323333
324334# Notes
325335- Does NOT apply limiters (caller applies based on timestep)
@@ -333,22 +343,26 @@ Caller adds geopotential Φ for energy tendency: `e_tot = dq_tot_dt * (e_int_pre
333343 q_lcl,
334344 q_icl,
335345)
336- # Clamp negative specific contents to zero (robustness against numerical errors)
337346 q_lcl = UT. clamp_to_nonneg (q_lcl)
338347 q_icl = UT. clamp_to_nonneg (q_icl)
348+ dq_tot_dt = CM0. remove_precipitation (mp. precip, q_lcl, q_icl)
349+ e_int_precip = _precip_energy (tps, T, q_lcl, q_icl)
350+ return (; dq_tot_dt, e_int_precip)
351+ end
339352
340- # Unpack microphysics parameters
341- params_0M = mp. precip
342-
343- # Precipitation removal rate
344- dq_tot_dt = CM0. remove_precipitation (params_0M, q_lcl, q_icl)
345-
346- # Internal energy of removed condensate (liquid fraction weighted)
347- λ = TDI. liquid_fraction (tps, T, q_lcl, q_icl)
348- I_liq = TDI. internal_energy_liquid (tps, T)
349- I_ice = TDI. internal_energy_ice (tps, T)
350- e_int_precip = λ * I_liq + (1 - λ) * I_ice
351-
353+ @inline function bulk_microphysics_tendencies (
354+ :: Microphysics0Moment ,
355+ mp:: CMP.Microphysics0MParams ,
356+ tps,
357+ T,
358+ q_lcl,
359+ q_icl,
360+ q_vap_sat,
361+ )
362+ q_lcl = UT. clamp_to_nonneg (q_lcl)
363+ q_icl = UT. clamp_to_nonneg (q_icl)
364+ dq_tot_dt = CM0. remove_precipitation (mp. precip, q_lcl, q_icl, q_vap_sat)
365+ e_int_precip = _precip_energy (tps, T, q_lcl, q_icl)
352366 return (; dq_tot_dt, e_int_precip)
353367end
354368
0 commit comments