P3 internals
This page is a reference for the building blocks of the P3 functions on the API page, grouped by what they compute. Their names, arguments, and behavior can change without notice, so models should call the API functions instead.
Mass relation
P3Scheme.P3Particles evaluates these relations once at construction, from the rime mass fraction and the rime density. The graupel density follows from the density of the unrimed part, and the size thresholds of the mass regimes follow from the densities. The aspect ratio of a particle uses the material density of its regime.
CloudMicrophysics.P3Scheme.get_ρ_d — Function
get_ρ_d(mass, F_rim, ρ_rim)Return the density of the unrimed portion of the particle [kg/m³].
The result is the exact solution as a function of the rime mass fraction F_rim, the mass power law parameters mass, and the rime density ρ_rim.
For the derivation of the numerically stable form used here, see the (P3 scheme documentation).
Arguments
mass:CMP.MassPowerLawparametersF_rim: rime mass fractionρ_rim: rime density
Returns
ρ_d: density of the unrimed portion of the particle [kg/m³]
Examples
julia> import CloudMicrophysics.Parameters as CMP,
ClimaParams as CP,
CloudMicrophysics.P3Scheme as P3
julia> FT = Float64;
julia> mass = CMP.MassPowerLaw(CP.create_toml_dict(FT));
julia> F_rim, ρ_rim = FT(0.5), FT(916.7);
julia> ρ_d = P3.get_ρ_d(mass, F_rim, ρ_rim)
488.9120789986414CloudMicrophysics.P3Scheme.get_ρ_g — Function
get_ρ_g(mass, F_rim, ρ_rim)Return the density of total (deposition + rime) ice mass for graupel [kg/m³].
Arguments
mass:CMP.MassPowerLawparametersF_rim: rime mass fraction (L_rim / L_ice) [-]ρ_rim: rime density (L_rim / B_rim) [kg/m³]
Returns
ρ_g: density of total (deposition + rime) ice mass for graupel [kg/m³]
Notes:
The density of the unrimed portion of the particle is get_ρ_d. See Eq. 16 in [29].
CloudMicrophysics.P3Scheme.get_D_th — Function
get_D_th(mass, ρ_i)Return the critical size separating spherical and nonspherical ice [m].
See Eq. 8 in [29].
Arguments
mass:CMP.MassPowerLawρ_i: density of solid ice [kg/m³]
CloudMicrophysics.P3Scheme.get_D_gr — Function
get_D_gr(mass, ρ_g)Return the size of equal mass for graupel and unrimed ice [m].
See Eq. 15 in [29].
Arguments
mass:CMP.MassPowerLawρ_g: graupel density [kg/m³]
CloudMicrophysics.P3Scheme.get_D_cr — Function
get_D_cr(mass, F_rim, ρ_g)Return the size of equal mass for graupel and partially rimed ice [m].
See Eq. 14 in [29].
Arguments
mass:CMP.MassPowerLawF_rim: rime mass fraction [-]ρ_g: graupel density [kg/m³]
CloudMicrophysics.P3Scheme.ϕ_material_density — Function
ϕ_material_density(particles, D)Return the material density of the solid of an ice particle at diameter D [kg/m³].
It is used in the aspect-ratio closure ϕᵢ. This is ρ_i in every mass regime except graupel (D_gr ≤ D < D_cr), where it is the graupel density ρ_g.
This is the density of the actual solid material, not the size-dependent effective density mᵢ / (π D³ / 6) returned by ice_density; see the P3 documentation for the distinction.
Arguments
particles:P3ParticlesD: maximum particle dimension [m]
Slope solve
P3Scheme.P3Distribution solves for the slope with get_distribution_logλ. The solve matches log(L/N) from logLdivN, built from the mass moments of logmass_gamma_moment and the gamma moments of loggamma_moment, to the ratio of the ice mass and the bounded number. The shape parameter follows from the slope with get_μ, and the intercept from the number with get_logN₀. logN′ice evaluates the log of the number concentration at a diameter.
CloudMicrophysics.P3Scheme.get_distribution_logλ — Function
get_distribution_logλ(particles, ρq_ice, ρn_ice)Solve for logλ, the log of the slope parameter of the P3 size distribution.
The solve uses the ice mass ρq_ice, the bounded ice number ρn_ice, and the mass relation of the P3Particles particles.
The assumed distribution is of the form
\[N′(D) = N₀ D^μ e^{-λD}\]
where N′(D) is the number concentration at diameter D and μ is the shape parameter. The shape parameter is parameterized, e.g. CMP.SlopePowerLaw or CMP.SlopeConstant.
This algorithm solves for logλ = log(λ) given ρq_ice and ρn_ice by solving the equations:
\[\begin{align*} \log(L) &= \log ∫_0^∞ m(D) N′(D)\ \mathrm{d}D, \\ \log(N) &= \log ∫_0^∞ N′(D)\ \mathrm{d}D, \\ \end{align*}\]
where m(D) is the mass of a particle at diameter D (see ice_mass). The procedure is described in detail in the P3 docs.
The solve uses the primal (as opposed to ForwardDiff.Dual) values of its arguments and returns a primal value, so logλ is constant under differentiation with respect to the state.
Arguments
particles: TheP3Particlesρq_ice: The ice mass concentration [kg/m³]ρn_ice: The ice number concentration [1/m³], bounded bybounded_ice_number
The search bounds are logλ_bounds. Without ice mass, the result is the upper bound, the smallest particles. With mass but without number, it is the lower bound, the largest particles.
CloudMicrophysics.P3Scheme.logLdivN — Function
logLdivN(particles, logλ)Compute log(L/N) given the particles and logλ.
Arguments
particles:P3Particleslogλ: The log of the slope parameter [log(1/m)]
CloudMicrophysics.P3Scheme.logmass_gamma_moment — Function
logmass_gamma_moment(particles, μ, logλ; n = 0)Compute log(∫_0^∞ Dⁿ m(D) N′(D) dD) given the particles, μ, and logλ.
This is the log of the n-th moment of the mass-weighted PSD.
Arguments
particles:P3Particlesμ: The shape parameter [-]logλ: The log of the slope parameter [log(1/m)]
Keyword arguments
n: The order of the moment, default is0
Note:
- For
n = 0, this evaluates tolog(L/N₀) - For
n = 1, this evaluates to the (unnormalized) mass-weighted mean particle size, seeD_m
CloudMicrophysics.P3Scheme.loggamma_moment — Function
loggamma_moment(μ, logλ; [k = 0], [scale = 1])Compute log(scale ⋅ ∫_0^∞ G(D) D^k dD).
G(D) ≡ D^μ e^{-λD} is the (unnormalized) gamma kernel, k is an arbitrary exponent, and scale is a scale factor.
Arguments
μ: The PSD shape parameter [-]logλ: The log of the PSD slope parameter [log(1/m)]
Keyword arguments
k: An arbitrary exponent [-], default is0scale: The scale factor [-], default is1.
The implementation follows the same logic as loggamma_inc_moment, but with D₁ = 0 and D₂ = ∞, which implies q_D₁ = 1 and q_D₂ = 0.
CloudMicrophysics.P3Scheme.loggamma_inc_moment — Function
loggamma_inc_moment(D₁, D₂, μ, logλ, [k = 0], [scale = 1])Compute log(Iᵏ) where Iᵏ is the following integral:
``I^k = ∫_{D₁}^{D₂} G(D) D^k dD``$G(D) ≡ D^μ e^{-λD}$ is the (unnormalized) gamma kernel, and k is an arbitrary exponent.
If scale is provided, log(scale ⋅ Iᵏ) is returned.
With appropriate scaling, we can compute useful quantities like:
- the
k-th moment of the ice PSD, $M^k = N₀ I^k$ - combined power law and moment weighted integrals, $∫_{D₁}^{D₂} (aD^b) D^n K(D) dD ≡ a I^(b + n)$
Arguments
D₁: The minimum diameter [m]D₂: The maximum diameter [m]μ: The PSD shape parameter [-]logλ: The log of the PSD slope parameter [log(1/m)]k: An arbitrary exponent [-], default is0scale: The scale factor [-], default is1
Extended help
Implementation details
We can write ∫_D₁^D₂ G(D) D^k dD, where G(D) = D^μ e^{-λD} as: ∫_D₁^∞ G(D) D^k dD - ∫_D₂^∞ G(D) D^k dD with the transformation x = λD, and z = μ+k+1, each term can be written as: ∫_{Dᵢ}^∞ G(D) D^k dD = ∫_{λDᵢ}^∞ x^z e^{-x} dx / λ^z = Γ(z, λDᵢ) / λ^z where Γ(z, λDᵢ) = q ⋅ Γ(z) and q is the incomplete gamma function ratio given by (_, q) = UT.gamma_inc(z, x). This means that the integral ∫_{Dᵢ}^∞ G(D) D^k dD is computed as: Γ(z) ⋅ q / λ^z The full integral from D₁ to D₂ is then: Γ(z) ⋅ (q_D₁ - q_D₂) / λ^z In log-space, this is: - z log(λ) + logΓ(z) + log(q_D₁ - q_D₂)
CloudMicrophysics.P3Scheme.get_μ — Function
get_μ(slope, logλ)Compute the shape parameter μ.
Arguments
slope:CMP.SlopeLawlogλ: The log of the slope parameter [log(1/m)]
CloudMicrophysics.P3Scheme.get_logN₀ — Function
get_logN₀(N_ice, μ, logλ)Compute log(N₀) given N_ice, μ, and logλ.
The intercept follows from
N = N₀ ∫ G(D) dD
log N₀ = log N - log(∫G(D) dD)
= log(N) - log( ∫D^μ e^{-λD} dD )
= log(N) - log(M⁰)Arguments
N_ice: The number concentration [1/m³]μ: The shape parameter [-]logλ: The log of the slope parameter [log(1/m)]
Without ice number, log(N₀) = -Inf, with zero derivatives.
CloudMicrophysics.P3Scheme.logN′ice — Function
logN′ice(dist)Return a callable that computes log(N′(D)) for the P3Distribution dist.
N′(D) is the ice particle number concentration at diameter D.
Arguments
dist:P3Distribution
CloudMicrophysics.P3Scheme.logλ_bounds — Function
logλ_bounds(params)Return the smallest and largest logλ [log(1/m)] of the slope solve.
The smallest is 2, and the largest is the slope at which the mean particle mass equals the mass of a newly nucleated crystal.
Arguments
params:CMP.ParametersP3
Ventilation
P3Scheme.ice_melt reads the ventilation integral of the size distribution from ice_ventilation_integral.
CloudMicrophysics.P3Scheme.ice_ventilation_integral — Function
ice_ventilation_integral(velocity_params, aps, state, ρₐ)Return the ventilation integral ∫ D F_v(D) N′(D) dD of the ice size distribution [m⁻²], with the ventilation factor F_v of CO.ventilation_factor.
Arguments
velocity_params:CMP.Chen2022VelTypeaps:CMP.AirPropertiesstate:P3Stateρₐ: air density [kg/m³]
Liquid-ice collisions
P3Scheme.bulk_liquid_ice_collision_sources builds the collision kernel, the local rime density, and the maximum freezing rate for the ice particles of the state. For each ice diameter, get_liquid_integrals integrates the kernel over the liquid size distribution, split at the diameter at which a drop falls as fast as the ice particle. ∫liquid_ice_collisions integrates the result over the ice size distribution, split at the wet-growth onset diameters, and partitions the collected mass between freezing and shedding.
CloudMicrophysics.P3Scheme.collision_cross_section_ice_liquid_coeffs — Function
collision_cross_section_ice_liquid_coeffs(rᵢ)
collision_cross_section_ice_liquid_coeffs(particles, Dᵢ)Return the monomial coefficients (k₀, k₁, k₂) of the ice-liquid collision cross-section.
The cross-section is a polynomial in the liquid diameter Dₗ,
\[σ(Dᵢ, Dₗ) = π (rᵢ + Dₗ/2)² = k₀ + k₁ Dₗ + k₂ Dₗ²,\]
with k₀ = π rᵢ², k₁ = π rᵢ, k₂ = π/4, where the ice effective radius is rᵢ = √(ice_area(particles, Dᵢ)/π); see ice_area.
CloudMicrophysics.P3Scheme.collision_cross_section_ice_liquid — Function
collision_cross_section_ice_liquid(particles, Dᵢ, Dₗ)Return the ice-liquid collision cross-section [m²], π (rᵢ(Dᵢ) + Dₗ/2)².
It is evaluated by Horner from the shared collision_cross_section_ice_liquid_coeffs.
CloudMicrophysics.P3Scheme.volumetric_collision_rate_integrand — Function
volumetric_collision_rate_integrand(velocity_params, particles, ρₐ)Return a function that computes the volumetric collision rate integrand for ice-liquid collisions [m³/s].
The returned function takes ice and liquid particle diameters as arguments.
Arguments
velocity_params: velocity parameterization, e.g.CMP.Chen2022VelTypeparticles:P3Particlesρₐ: air density [kg/m³]
Returns
A VolumetricCollisionRate, a function (D_ice, D_liq) -> E * K * |vᵢ - vₗ| where:
D_iceandD_liqare the (maximum) diameters of the ice and liquid particlesEis the collision efficiencyKis the collision cross sectionvᵢandvₗare the terminal velocities of ice and liquid particles
Note that E, K, vᵢ and vₗ are all, in general, functions of D_ice and D_liq.
This function is a component of integrals like
\[∫ ∫ E * K * |vᵢ - vₗ| * N'_i * N'_l dD_i dD_l\]
CloudMicrophysics.P3Scheme.VolumetricCollisionRate — Type
VolumetricCollisionRate(particles, v_i, v_l)The volumetric collision rate (D_ice, D_liq) -> E * K * |vᵢ - vₗ| [m³/s] of ice-liquid collisions.
See volumetric_collision_rate_integrand.
Fields
particles:P3Particlesv_i,v_l: ice and liquid terminal velocity functions [m/s]
CloudMicrophysics.P3Scheme.compute_max_freeze_rate — Function
compute_max_freeze_rate(aps, tps, velocity_params, particles, ρₐ, Tₐ)Return a function max_freeze_rate(Dᵢ) of the maximum possible freezing rate [kg/s].
The rate is that of an ice particle of diameter Dᵢ [m]. It evaluates to 0 if T ≥ T_freeze.
Arguments
aps:CMP.AirPropertiestps:TDP.ThermodynamicsParametersvelocity_params: velocity parameterization, e.g.CMP.Chen2022VelTypeparticles:P3Particlesρₐ: air density [kg/m³]Tₐ: air temperature [K]
This rate represents the thermodynamic upper limit to collisional freezing, which occurs when the heat transfer from the ice particle to the environment is balanced by the latent heat of fusion.
From Eq (A7) in Musil (1970), [37].
CloudMicrophysics.P3Scheme.max_freeze_rate_scalars — Function
max_freeze_rate_scalars(aps, tps, ρₐ, Tₐ)Return the factors of the maximum freezing rate of compute_max_freeze_rate that do not depend on the particle.
The maximum freezing rate of an ice particle of diameter Dᵢ is 2π Dᵢ F_v(Dᵢ) heat / denom below the freezing temperature T_frz if denom > 0, and unbounded if denom ≤ 0.
Arguments
aps:CMP.AirPropertiestps:TDP.ThermodynamicsParametersρₐ: air density [kg/m³]Tₐ: air temperature [K]
Returns
A NamedTuple (; heat, denom, T_frz), where:
heat: heat flux from the particle surface per unit capacity, by conduction and by vapor diffusion [W/m]denom: heat to remove per unit mass of collected liquid, which warms fromTₐto the surface temperature and freezes there [J/kg]; it is nonpositive forT_frz - Tₐ ≥ L_f / cp_l ≈ 80 K, where every collected droplet freezesT_frz: freezing temperature [K]
CloudMicrophysics.P3Scheme.compute_local_rime_density — Function
compute_local_rime_density(velocity_params, particles, ρₐ, T)Return a function ρ′_rim(Dᵢ, Dₗ) that computes the local rime density [kg/m³].
The arguments are the ice particle diameter Dᵢ [m] and the liquid particle diameter Dₗ [m].
Arguments
velocity_params: velocity parameterization, e.g.CMP.Chen2022VelTypeparticles:P3Particlesρₐ: air density [kg/m³]T: temperature [K]
Returns
A function that computes the local rime density [kg/m³] using the equation:
\[ρ'_{rim} = a + b R_i + c R_i^2\]
where
\[R_i = -\frac{ 10^6 ⋅ D_{liq} ⋅ |v_{liq} - v_{ice}| }{ 2 T_{sfc} }\]
and $T_{sfc} < 0$ is the sub-zero surface temperature [°C], $D_{liq}$ is the liquid particle diameter [m], $v_{liq/ice}$ is the particle terminal velocity [m/s]. With the $10^6$ factor converting $D_{liq}$ from [m] to [μm], the units of $R_i$ are [μm m s⁻¹ °C⁻¹]. The units of $ρ'_{rim}$ are [kg/m³].
We assume for simplicity that $T_{sfc}$ equals $T$, the ambient air temperature. For real graupel, $T_{sfc}$ is slightly higher than $T$ due to latent heat release of freezing liquid particles onto the ice particle. Morrison & Milbrandt (2013) found little sensitivity to "realistic" increases in $T_{sfc}$.
See also LocalRimeDensity.
Extended help
Implementation follows Cober and List (1993), Eq. 16 and 17. See also the P3 fortran code, microphy_p3.f90, Line 3315-3323, which extends the range of the calculation to $R_i ≤ 12$, the upper limit of which then equals the solid bulk ice density, $ρ_ice = 916.7 kg/m^3$. At and above $T_{sfc} = 0$, the local rime density is $ρ_ice$.
Note that Morrison & Milbrandt (2015) [29] only uses this parameterization for collisions with cloud droplets. For rain drops, they use a value near the solid bulk ice density, $ρ^* = 900 kg/m^3$. We do not consider this distinction, and use this parameterization for all liquid particles.
CloudMicrophysics.P3Scheme.CollisionRimeDensity — Type
CollisionRimeDensity(ρ_rim_local, T°C, v_i, v_l)Local rime density ρ′_rim(Dᵢ, Dₗ) [kg/m³] of a collision, returned by compute_local_rime_density.
Fields
ρ_rim_local:CMP.LocalRimeDensityT°C: temperature [°C]v_i,v_l: ice and liquid terminal velocity functions [m/s]
CloudMicrophysics.P3Scheme.rime_density_at — Function
rime_density_at(ρ′, Δv, Dₗ)Return the local rime density [kg/m³] of a collision at the fall-speed difference Δv.
Arguments
ρ′:CollisionRimeDensityΔv: fall-speed difference|vᵢ - vₗ|[m/s]Dₗ: drop diameter [m]
CloudMicrophysics.P3Scheme.get_liquid_integrals — Function
get_liquid_integrals(n, ∂ₜV, m_liq, ρ′_rim, liq_bounds, quad)Return a function liquid_integrals(Dᵢ) of the liquid particle integrals at ice diameter Dᵢ.
For a VolumetricCollisionRate and a CollisionRimeDensity, the integrals are split at the fall-speed crossing, see crossing_integral_bounds.
Arguments
n: liquid particle size distribution functionn(D)∂ₜV: volumetric collision rate integrand function∂ₜV(Dᵢ, D)m_liq: liquid particle mass functionm_liq(D)ρ′_rim: local rime density functionρ′_rim(Dᵢ, D)liq_bounds: integration bounds for liquid particlesquad: quadrature rule, aQuadratureRule
Notes
The function liquid_integrals(Dᵢ) returns a tuple (∂ₜN_col, ∂ₜM_col, ∂ₜB_col) of collision rates at Dᵢ, where:
∂ₜN_col: number collision rate [1/s]∂ₜM_col: mass collision rate [kg/s]∂ₜB_col: rime volume collision rate [m³/s]
CloudMicrophysics.P3Scheme.liquid_collision_integrand — Function
liquid_collision_integrand(n, v_l, m_liq, ρ′_rim, v_i_at_Dᵢ, coeffs)Return the integrand D -> (∂ₜN, ∂ₜM, ∂ₜB) of get_liquid_integrals at one ice diameter.
Arguments
n: liquid particle size distribution functionn(D)v_l: liquid terminal velocity function [m/s]m_liq: liquid particle mass functionm_liq(D)ρ′_rim: local rime density, aCollisionRimeDensityv_i_at_Dᵢ: terminal velocity of the ice particle [m/s]coeffs: cross-section coefficients fromcollision_cross_section_ice_liquid_coeffs
CloudMicrophysics.P3Scheme.crossover_diameter — Function
crossover_diameter(v_target, v_l, D_min, D_max)Find the diameter D in [D_min, D_max] where v_l(D) = v_target
CloudMicrophysics.P3Scheme.crossing_integral_bounds — Function
crossing_integral_bounds((D_min, D_max), v_l, v_i_at_Dᵢ)Return the liquid integration bounds (D_min, D*, D_max) split at the fall-speed crossing D*.
At D* a drop falls as fast as the ice particle, v_l(D*) = v_i_at_Dᵢ, and |v_i_at_Dᵢ - v_l(D)| is not smooth.
CloudMicrophysics.P3Scheme.∫liquid_ice_collisions — Function
∫liquid_ice_collisions(
n_i, ∂ₜM_max, cloud_integrals, rain_integrals, ice_bounds, quad,
)Computes the bulk collision rate integrands between ice and liquid particles.
Arguments
n_i: ice particle size distribution function n_i(D)∂ₜM_max: maximum freezing rate function ∂ₜM_max(Dᵢ)cloud_integrals: inner liquid integrals for cloud particles, e.g. fromget_liquid_integralsrain_integrals: inner liquid integrals for rain particles, e.g. fromget_liquid_integralsice_bounds: integration bounds for ice particles, fromintegral_boundsquad: quadrature rule, aQuadratureRule
Returns
A 9-element vector of integrated rates, (QCFRZ, QCSHD, NCCOL, QRFRZ, QRSHD, NRCOL, ∫M_col, BCCOL, BRCOL); see the method below for the definition of each entry.
∫liquid_ice_collisions(
psd_c, psd_r, aps, tps, vel, m_liq, state,
L_c, N_c, L_r, N_r, ρₐ, T,
)Compute key liquid-ice collision rates and quantities. Used by bulk_liquid_ice_collision_sources.
Arguments
psd_c:CMP.CloudParticlePDF_SB2006psd_r:CMP.RainParticlePDF_SB2006aps:CMP.AirPropertiestps:TDP.ThermodynamicsParametersvel: velocity parameterization, e.g.CMP.Chen2022VelTypem_liq: liquid particle mass functionm_liq(D)state:P3StateL_c: cloud liquid water content [kg/m³]N_c: cloud liquid water number concentration [1/m³]L_r: rain water content [kg/m³]N_r: rain number concentration [1/m³]ρₐ: air density [kg/m³]T: temperature [K]
Returns
A tuple (QCFRZ, QCSHD, NCCOL, QRFRZ, QRSHD, NRCOL, ∫M_col, BCCOL, BRCOL), where:
QCFRZ- Cloud mass collision rate due to freezing [kg/s]QCSHD- Cloud mass collision rate due to shedding [kg/s]NCCOL- Cloud number collision rate [1/s]QRFRZ- Rain mass collision rate due to freezing [kg/s]QRSHD- Rain mass collision rate due to shedding [kg/s]NRCOL- Rain number collision rate [1/s]∫M_col- Total collision rate [kg/s]BCCOL- Cloud rime volume source [m³/m³/s]BRCOL- Rain rime volume source [m³/m³/s]
∫liquid_ice_collisions(
psd_c, psd_r, aps, tps, vel, m_liq, state::TabulatedP3State,
L_c, N_c, L_r, N_r, ρₐ, T,
)Return the liquid-ice collision rates of ∫liquid_ice_collisions from the tables, as an SVector in the same order.
The collected rates come from tabulated_collection, and the freeze and shed partition from tabulated_wet_set. Above the freezing temperature every collected particle sheds, and below T_freeze - L_f / cp_l every one freezes.
CloudMicrophysics.P3Scheme.wet_growth_onset_diameters — Function
wet_growth_onset_diameters(cloud_integrals, rain_integrals, ∂ₜM_max, D_lo, D_hi)Return the two ice diameters in [D_lo, D_hi] at which the collected liquid mass rate equals ∂ₜM_max.
The collected rate is the sum of the mass rates of cloud_integrals and rain_integrals, see get_liquid_integrals. The crossings are found by CloudMicrophysics.Utilities.find_zeros on a log-spaced grid, and an absent crossing is returned as D_lo.
CloudMicrophysics.P3Scheme.liquid_ice_collision_quantile — Function
liquid_ice_collision_quantile(FT)Return the quantile p of the size distributions at which the liquid-ice collision integrals are cut.
The integrals extend from the quantile p to the quantile 1 - p of the ice, cloud and rain size distributions, see integral_bounds.
CloudMicrophysics.P3Scheme.r_eff_ice — Function
r_eff_ice(particles, D)Return the effective radius √(A/π) [m] of an ice particle of diameter D, with projected area A.
See ice_area.
Quadrature
The P3 integrals split the integration range at the regime thresholds and at the kinks of the integrand, and sum a quadrature over each subinterval.
CloudMicrophysics.Quadrature.integrate — Function
integrate(f, a, b, quad)Approximate the definite integral ∫ₐᵇ f(x) dx using the quadrature rule quad.
Mathematical Background
The integral is transformed to the standard interval [-1, 1]:
y = (2x - (a+b)) / (b-a) → x = (b-a)y/2 + (a+b)/2with Jacobian dx/dy = (b-a)/2, so that
∫ₐᵇ f(x) dx = (b-a)/2 ∫₋₁¹ f(x(y)) dy
≈ (b-a)/2 ∑ᵢ f(xᵢ) · inv_weight_fun(quad, yᵢ) · weight(quad, i)where yᵢ = node(quad, i), xᵢ = (b-a)yᵢ/2 + (a+b)/2, and the inv_weight_fun/weight factors are rule-specific (see ChebyshevGauss and GaussLegendre).
Arguments
f: Function to integratea,b: Integration bounds. Note: ifa ≥ b, oraorbisNaN, zero is returned.quad: Quadrature scheme (aQuadratureRule).
Returns
Approximation to the definite integral ∫ₐᵇ f(x) dx
integrate(f, bnds, quad)Integrate the function f over each subinterval of the integration bounds, bnds.
Arguments
f: Function to integratebnds: A tuple of bounds,(a, b, c, d, ...)quad: Quadrature scheme (aQuadratureRule).
The integral is computed as the sum of the integrals over each subinterval, (a, b), (b, c), (c, d), ... — see subintervals.
CloudMicrophysics.Quadrature.subintervals — Function
subintervals(bnds::NTuple)Pair adjacent elements of a flat boundary tuple into the consecutive subintervals they delimit:
subintervals((a, b, c, d)) ≡ ((a, b), (b, c), (c, d))Base.front and Base.tail are zero-cost on fixed-length tuples, so the helper compiles to a direct tuple construction with no runtime dispatch.
CloudMicrophysics.P3Scheme.velocity_integral_bounds — Function
velocity_integral_bounds(particles, dist, v_term; p, moment_order = 0)Compute the integration bounds for a velocity-weighted P3 integral.
This function returns the same integration bounds as integral_bounds, but with additional breakpoints that a terminal-velocity closure v_term may introduce, see velocity_breakpoints.
Arguments
particles:P3Particlesdist:P3Distributionv_term: terminal-velocity closure, seeice_particle_terminal_velocity
See integral_bounds for the keyword arguments and the return value.
CloudMicrophysics.P3Scheme.insert_breakpoints — Function
insert_breakpoints(bnds, Ds)Return the integration bounds bnds with the diameters Ds inserted, in ascending order.
Each diameter in Ds must lie in [first(bnds), last(bnds)].
CloudMicrophysics.P3Scheme.velocity_breakpoints — Function
velocity_breakpoints(v_term)Return the diameters where the terminal-velocity closure v_term changes functional form.
Integrals with v_term in the integrand place these on subinterval boundaries, see velocity_integral_bounds.
Lookup tables
The quantities in the tables and their use are described in Lookup tables. This section describes how the tables are built and read, the conventions that every table follows, and the steps to add a table.
Building the tables
P3Scheme.with_tables builds the tables in five steps:
P3Scheme.P3TableGridgives the axes of each table group, a tuple ofP3Scheme.TableAxis, with the bounds derived from the parameters and the numbers of points ofP3Scheme.TABLE_POINTS.P3Scheme.table_groupsgives the point function of each group, which maps the coordinates of one grid point to the values of the group there by quadrature, and the storage optionslogsandinnerof the group.P3Scheme.tabulateevaluates the point function at every point of the axes of the group, on all threads for anArray, and by a broadcast where the array type places its elements for any other array type.P3Scheme.UniformTablestores the values in the float type of the parameters.P3Scheme.P3Tablesholds the tables of all groups and a hash of the parameters they were built from, andwith_tablesreturns a copy of the parameters with the tables as theirintegration.
Each group is stored before the next one is evaluated, so the build holds the values of one group at a time.
CloudMicrophysics.P3Scheme.TABLE_POINTS — Constant
TABLE_POINTSThe default numbers of points of the axes of the P3TableGrid, for each family of table groups.
CloudMicrophysics.P3Scheme.table_groups — Function
table_groups(ice_params, grid, generator)Return the point function and the storage of each table group, a NamedTuple with the keys of grid.groups.
Each entry is a NamedTuple (; point, logs, inner) of the point function, which maps the coordinates of a grid point to the values of the group there by quadrature with the rule generator, and the keyword arguments logs and inner of UniformTable.
CloudMicrophysics.P3Scheme.TableAxis — Type
TableAxis{FT}A uniform axis of n points from lo to hi, with coordinates of the float type FT.
Construction
TableAxis(lo, hi, n)with FT the float type that lo and hi promote to.
Fields
lo: Coordinate of the first pointhi: Coordinate of the last pointn: Number of points, at least two
CloudMicrophysics.P3Scheme.grid_point — Function
grid_point(axes, I)Return the coordinates of the point with the CartesianIndex I of the grid spanned by the TableAxis objects in axes, a tuple in the float types of the axes.
CloudMicrophysics.P3Scheme.tabulate — Function
tabulate(f, axes, ArrayType = Array)Return the array of the values of the point function f at the points of the grid spanned by axes.
The element at the index I is f at the coordinates grid_point(axes, I), and the array has one dimension per TableAxis of axes. For an Array, the points are evaluated by tasks on all threads, in chunks that are scheduled dynamically. For any other array type, the values are filled by a broadcast over the indices into ArrayType{T}(undef, dims), so the points are evaluated where the array type places them.
Arguments
f: point function, which maps anNTupleof coordinates to a number or anSVectoraxes:NTupleofTableAxisArrayType: array type of the result, such asArray
CloudMicrophysics.P3Scheme.UniformTable — Type
UniformTable{FT, N, K, A}A function of N coordinates with K components, stored on a grid that is uniform along each axis.
lookup reads all components at once by multilinear interpolation.
Construction
UniformTable(values, axes, FT; logs = nothing, inner = false)stores the array values of a point function at the points of the grid spanned by the N TableAxis objects in axes (see tabulate) as FT, in an array of the type of values. Each element of values is a number or an SVector of K components. logs is an NTuple of Bool, whether each component is stored as its logarithm, all false by default. With inner = true, values spans the axes after the first, and each element holds the values at the points of the first axis, so the table has one component. The construction throws a DomainError for a value that is not finite or a log component that is not positive.
Fields
data: Stored values, of size(K, n₁, …, n_N)for axes ofn₁ton_Npointslo: Coordinate of the first point of each axishi: Coordinate of the last point of each axis
CloudMicrophysics.P3Scheme.integral_logλ_bounds — Function
integral_logλ_bounds(params)Return the smallest and largest logλ [log(1/m)] of a size distribution with a mean particle mass within the limits of bounded_ice_number.
The largest is that of logλ_bounds, and the smallest is the slope of unrimed ice of the mean mass ice_mean_particle_mass_max.
CloudMicrophysics.P3Scheme.liquid_mass_bounds — Function
liquid_mass_bounds(pdf)Return the smallest and largest mean particle mass [kg] of a liquid size distribution the tables support.
For CMP.CloudParticlePDF_SB2006, these are the mass limits of the distribution. The slope of CMP.RainParticlePDF_SB2006_limited lies within its limits λ_min and λ_max, so its mean mass π ρw / λ³ lies within the bounds. Any other distribution throws an ArgumentError.
Reading the tables
A P3Scheme.TabulatedP3State is a P3Scheme.P3State whose integration is a P3Tables. The process functions have a method for this type with the signature of the quadrature method, so the callers do not change. Each method computes the coordinates of the state, reads the values with P3Scheme.lookup, and multiplies them by the ice number and by the liquid number or mass of the state:
| Method | Groups |
|---|---|
P3Distribution, in the construction of a P3State | slope |
P3Scheme.ice_terminal_velocities | ice |
P3Scheme.ice_self_collection | ice |
P3Scheme.ice_ventilation_integral, in P3Scheme.ice_melt | ice |
∫liquid_ice_collisions, in P3Scheme.bulk_liquid_ice_collision_sources | cloud_collision, rain_collision, cloud_rime_density, rain_rime_density, and below freezing the wet-set groups |
P3Scheme.ice_table_key gives the coordinates (logλ, w, ρ_rim, logρₐ) of a state, which all groups on the ice axes share.
CloudMicrophysics.P3Scheme.lookup — Function
lookup(t, x...)Return the SVector of the components of the table t at the coordinates x by multilinear interpolation.
A coordinate outside the grid is moved to the nearest edge, and NaN to the first point (see uniform_index). A coordinate with partials, such as a ForwardDiff.Dual, gives the derivative of the interpolation along its axis.
Arguments
t:UniformTablex: one coordinate per axis of the table
CloudMicrophysics.P3Scheme.interpolate — Function
interpolate(t, cells)Return the SVector of the components of the UniformTable t interpolated multilinearly in the cells cells, one axis_cell per axis.
CloudMicrophysics.P3Scheme.axis_cell — Function
axis_cell(t, d, x)Return the cell of the coordinate x on the axis d of the UniformTable t, see uniform_index.
CloudMicrophysics.P3Scheme.uniform_index — Function
uniform_index(x, lo, hi, n)Return the index i of the lower point of the cell of a uniform axis that holds x, and the fraction of the cell below x.
The axis has n points from lo to hi. A coordinate outside the axis, including ±Inf, is moved to the nearest end, and NaN to the first point. The index follows from the primal value of x (see primal_value), and the fraction has the type of x.
CloudMicrophysics.P3Scheme.primal_value — Function
primal_value(x)Return the value of x with the partials of every nesting level of ForwardDiff.Dual dropped.
Conventions
- A point function takes a tuple of the coordinates of one point, in the order of the axes of its group, and returns a number or an
SVectorof components. - The values are per unit ice number, and per unit liquid number or mass, so that a table depends only on the shapes of the size distributions.
- A component that scales as a power of the coordinates is stored as its logarithm, with
logs, so that the interpolation is accurate and the value stays positive. - With
inner = true, the point function evaluates every point of the first axis at once and returns their values as anSVector, so that the points share the expensive part of the integral. The rime density tables evaluate the points oflogRin this way, and the fraction tables those ofP3Scheme.number_logit. - The coordinates are uniform in the logarithm of a quantity that varies over orders of magnitude,
logλ,logρₐ,logx̄,logRandlogD. - The rime coordinate
w = 1 - √(1 - F_rim)ofP3Scheme.rime_coordinatereplacesF_rim, because the particle properties change fastest nearF_rim = 1. P3Scheme.ice_table_keytakes the primal value oflogλ, so that aForwardDiff.Dualstate is differentiated through the other coordinates only, as in the quadrature.P3Scheme.lookupmoves a coordinate outside an axis to the nearest end of the axis.- The tables are in the float type of the parameters, and
Adaptmoves them to a device with the parameters. - The fingerprint of
P3Tableshashes the parameters that the tables depend on, and the constructors of the parameters from a parameter dictionary check it, seeP3Scheme.tables_are_current.
CloudMicrophysics.P3Scheme.rime_coordinate — Function
rime_coordinate(F_rim)Return the rime coordinate w = 1 - √(1 - F_rim) of the tables.
The coordinate spreads the rime mass fractions near one, where the ice properties change fastest with F_rim. Its inverse is rime_mass_fraction_at.
CloudMicrophysics.P3Scheme.rime_mass_fraction_at — Function
rime_mass_fraction_at(w)Return the rime mass fraction F_rim = w (2 - w) at the rime coordinate w, below one.
It inverts rime_coordinate, and returns the largest float below one at w = 1.
Adding a table
A new table group needs
- a family of numbers of points in
P3Scheme.TABLE_POINTS, and the axes of the group in the constructor ofP3TableGrid, - a point function, and its entry in
P3Scheme.table_groupswithlogsandinner, - a method of the process function for
P3Scheme.TabulatedP3Statethat reads the group withP3Scheme.lookup, - the parameters of the new integrals in
table_fingerprint, if the existing ones do not cover them, - a test against the quadrature in
test/p3_tables_tests.jl, and the errors of the new quantities intest/p3_tables_accuracy.jl.
test/p3_tables_accuracy.jl also measures the errors of a proposed grid, which helps to choose the numbers of points.
Inverse slope table
The tables use the slope $λ$ as their coordinate, rather than the mean particle mass $\bar{x} = L/N$. The shape parameter $μ$ changes steeply in a narrow range of the mean mass, so a table on the mean mass would need many points there. The left panel shows the slope table at the rime density 400 kg/m³: the mean mass decreases monotonically with the slope, so the table has an inverse. The right panel shows the shape parameter against the mean mass, and the range where its slope against $\log \bar{x}$ exceeds half of its largest value, in gray.
include("plots/P3SlopeTable.jl")P3Scheme.slope_point evaluates P3Scheme.logLdivN on uniform logλ points. P3Scheme.tabulated_distribution_logλ interpolates the table bilinearly in the rime coordinate and the rime density, finds the segment of logλ that holds the target by a bisection with a fixed number of steps, inverts the target linearly on it, and refines the result with one Newton step on the closed form.
CloudMicrophysics.P3Scheme.slope_point — Function
slope_point(params, (logλ, w, ρ_rim))Return the log mean particle mass logLdivN at the slope logλ, the rime coordinate w and the rime density ρ_rim, the value of the inverse slope table.
tabulated_distribution_logλ inverts the table along logλ.
CloudMicrophysics.P3Scheme.tabulated_distribution_logλ — Function
tabulated_distribution_logλ(table, particles, ρq_ice, ρn_ice)Return logλ, the log of the slope parameter of the P3 size distribution, from the inverse slope table.
The result solves the equation of get_distribution_logλ, with the same values without ice mass or number, and is a primal value.
Arguments
table: theslopetable of aP3Tables, the values ofslope_pointon(logλ, w, ρ_rim)particles:P3Particlesρq_ice: ice mass concentration [kg/m³]ρn_ice: ice number concentration [1/m³], bounded bybounded_ice_number
Ice tables
P3Scheme.ice_point evaluates the ventilation moment M_v, the self-collection rate and the mean fall speeds per unit number, on logλ, the rime coordinate, the rime density and the log air density. P3Scheme.node_self_collection evaluates the self-collection rate with the node values of each subinterval evaluated once. P3Scheme.table_state gives the state of unit number at a grid point, and P3Scheme.tabulated_ice_integrals reads the table.
CloudMicrophysics.P3Scheme.ice_point — Function
ice_point(params, vel, generator, (logλ, w, ρ_rim, logρₐ))Return the integrals of the ice table at a point, per unit number, or per unit number squared for the self-collection rate.
The value is an SVector of the ventilation moment M_v of ventilation_moment [m² s^(-1/2)], the self-collection rate of node_self_collection [m³/s], and the number- and mass-weighted velocities of ice_terminal_velocities [m/s], for the state of table_state and the rule generator. The table stores their logarithms.
CloudMicrophysics.P3Scheme.ventilation_moment — Function
ventilation_moment(vel, state, ρₐ)Return the ventilation moment M_v = ∫ D^(3/2) v(D)^(1/2) N′(D) dD [m⁻¹ s^(-1/2)] by quadrature.
With the coefficients (a, b) of CO.ventilation_coefficients, the ventilation integral of ice_ventilation_integral is a M_1 + b M_v, with the first moment M_1 = ∫ D N′(D) dD.
CloudMicrophysics.P3Scheme.node_self_collection — Function
node_self_collection(vel, generator, state, ρₐ)Return the self-collection rate of ice_self_collection per unit number squared, with the node values of each subinterval evaluated once.
For a GaussLegendre rule, the quadrature is that of ice_self_collection, with the values at the nodes of the subintervals after the one of the outer diameter reused.
Arguments
vel:CMP.Chen2022VelTypegenerator:QuadratureRulestate:P3Stateof unit ice numberρₐ: air density [kg/m³]
CloudMicrophysics.P3Scheme.table_state — Function
table_state(params, generator, logλ, w, ρ_rim)Return the P3State of unit ice number with the slope logλ [log(1/m)], the rime coordinate w and the rime density ρ_rim [kg/m³], integrated with the rule generator.
CloudMicrophysics.P3Scheme.ice_table_key — Function
ice_table_key(state, ρₐ)Return the coordinates (logλ, w, ρ_rim, logρₐ) of state in the ice tables.
logλ is a primal value, as for the quadrature, and the other coordinates keep their partials.
CloudMicrophysics.P3Scheme.tabulated_ice_integrals — Function
tabulated_ice_integrals(tables, state, ρₐ)Return the NamedTuple (; M_v, self_collection, v_n, v_m) of the ice integral table of tables at the coordinates of state, see ice_point.
The integrals are per unit number, or per unit number squared for self_collection.
Liquid-ice tables
P3Scheme.collision_point evaluates the collected number and mass of cloud or rain per unit ice number and per unit liquid number or mass, on the four ice axes and the liquid mean mass, without the freeze and shed partition. A liquid size distribution is its number times a shape that depends only on its mean mass, see P3Scheme.liquid_table_scales, so the collected rates per unit liquid number or mass depend on the liquid only through logx̄. The local rime density depends on the temperature through the ratio Rᵢ of the impact scale to the temperature, so P3Scheme.rime_density_point evaluates the mean rime density on the log of that ratio at the mean impact scale log κ̄ of the collected mass. P3Scheme.tabulated_collection reads the tables for a state, at logR = log κ̄ - log|T - T_freeze|.
CloudMicrophysics.P3Scheme.collision_point — Function
collision_point(params, vel, pdf, generator, (logλ, w, ρ_rim, logρₐ, logx̄))Return the collected rates of one liquid species at a point of its collision table, without the freeze and shed partition.
The value is an SVector of the first three elements of collection_integrals: the collected number rate per unit ice number and per unit liquid number [m³/s], the collected mass rate per unit ice number and per unit liquid mass [m³/s], and the impact scale log κ̄. The table stores the logarithms of the two rates. Per unit liquid number, the liquid size distribution depends only on its mean mass, see liquid_table_scales.
CloudMicrophysics.P3Scheme.rime_density_point — Function
rime_density_point(params, vel, pdf, generator, logR, (logλ, w, ρ_rim, logρₐ, logx̄))Return the mean local rime density [kg/m³] of the mass of one liquid species that the ice collects, at each point of logR.
A point of logR stands for the temperature T = -exp(log κ̄ - logR) [°C] at the impact scale log κ̄ of collection_integrals.
CloudMicrophysics.P3Scheme.collection_integrals — Function
collection_integrals(params, vel, pdf, generator, logλ, w, ρ_rim, logρₐ, logx̄, T°Cs)Return the collected rates of one liquid species by the ice of table_state, without the freeze and shed partition.
The result is an SVector of
- the number rate per unit ice number and per unit liquid number [m³/s],
- the mass rate per unit ice number and per unit liquid mass [m³/s],
- the impact scale
log κ̄, the mean oflog κover the collected mass, seeimpact_scale, - the rime volume rate per unit ice number and per unit liquid mass at each temperature of
T°Cs[m⁶/(kg s)].
The integrals are those of ∫liquid_ice_collisions with the rule generator, with the rates of one ice particle of particle_collection.
Arguments
params:CMP.ParametersP3vel:CMP.Chen2022VelTypepdf: the size distribution of the liquid speciesgenerator:QuadratureRulelogλ,w,ρ_rim: the ice state, seetable_statelogρₐ: log air density [log(kg/m³)]logx̄: log mean mass of the liquid species [log(kg)], seeliquid_table_scalesT°Cs:Tupleof temperatures [°C]
CloudMicrophysics.P3Scheme.particle_collection — Function
particle_collection(params, particles, liquid, T°Cs, generator)Return the function of the ice diameter Dᵢ [m] that gives the rates at which one ice particle collects one liquid species.
The rates are an SVector of the collected number rate [1/s], the collected mass rate [kg/s], the collected mass rate times log κ (see impact_scale) [kg/s], and the rime volume rate at each temperature of T°Cs [m³/s], each integrated over the liquid size distribution with the rule generator, split at the fall-speed crossing (see crossing_integral_bounds).
Arguments
params:CMP.ParametersP3particles:P3Particlesliquid: the parts of the integrals oftable_liquidT°Cs:Tupleof temperatures [°C]generator:QuadratureRule
CloudMicrophysics.P3Scheme.impact_scale — Function
impact_scale(D, Δv)Return the product κ = r Δv of the radius r = D / 2 [μm] of a drop of diameter D [m] and its impact speed Δv [m/s], see rime_density_at.
CloudMicrophysics.P3Scheme.table_liquid — Function
table_liquid(vel, particles, pdf, ρₐ, logx̄)Return the parts of the liquid-ice collision integrals with one liquid species of mean mass exp(logx̄).
The result is a NamedTuple with the ice and liquid terminal velocities v_i and v_l, the liquid size distribution n_l, its integration bounds bounds_l, the liquid particle mass m_liq, and the mass and number of the distribution, see liquid_table_scales.
Arguments
vel:CMP.Chen2022VelTypeparticles:P3Particlespdf: the size distribution of the liquid speciesρₐ: air density [kg/m³]logx̄: log mean mass of the liquid species [log(kg)]
CloudMicrophysics.P3Scheme.liquid_table_scales — Function
liquid_table_scales(pdf, L, N, ρₐ)Return the scales of the liquid-ice collision tables for a liquid species of content L and number N.
A liquid size distribution is its number times a shape that depends only on its mean mass. The result is a NamedTuple with
present: whether the distribution is nonzero, from primal values,logx̄: the log of its mean mass [log(kg)], the table coordinate,mass: its mass [kg/m³], which scales the mass rates,number: its number [1/m³], which scales the number rates.
For the limited rain distribution, these are the values of the distribution with its clamped intercept and slope.
Arguments
pdf:CMP.CloudParticlePDF_SB2006orCMP.RainParticlePDF_SB2006_limitedL: liquid content [kg/m³]N: number concentration [1/m³]ρₐ: air density [kg/m³]
CloudMicrophysics.P3Scheme.table_log_temperature — Function
table_log_temperature(T, T_freeze)Return log|T - T_freeze| [log(°C)] of the temperature T [K], at least the log of floatmin.
The rime density tables are read at logR = log κ̄ - log|T - T_freeze|, see tabulated_collection.
CloudMicrophysics.P3Scheme.tabulated_collection — Function
tabulated_collection(collision, rime_density, key, pdf, L, N, ρₐ, logT)Return the collected rates of one liquid species per unit ice number from its liquid-ice tables, without the partition.
The result is a NamedTuple with the mass rate M [kg/s], the number rate N [1/s], the mean local rime density ρ′ [kg/m³], and the mass and logx̄ of liquid_table_scales.
Arguments
collision: the collision table of the species, seecollision_pointrime_density: the rime density table of the species, seerime_density_pointkey: the ice coordinates ofice_table_keypdf: the size distribution of the speciesL: liquid content [kg/m³]N: number concentration [1/m³]ρₐ: air density [kg/m³]logT: the temperature coordinate oftable_log_temperature
Wet-set tables
An ice particle of diameter $D$ collects the liquid mass $u(D) = L_c\, \hat{u}_c(D) + L_r\, \hat{u}_r(D)$ per unit time, with $\hat{u}_l$ the collected mass per unit liquid mass, and it freezes at most
\[m(D) = c_1 D + c_2 D^{3/2} v(D)^{1/2},\]
the maximum freezing rate $∂_t\mathcal{M}_\text{max}$ of Collisions with liquid droplets. The coefficients $c_1$ and $c_2$ hold the temperature, the air properties and the ventilation coefficients, see P3Scheme.max_freeze_rate_scalars. The particles with $u > m$ form the wet set $W$, which freezes $∫_W m N' \mathrm{d}D$ and sheds $∫_W (u - m) N' \mathrm{d}D$, and the other particles freeze all they collect.
P3Scheme.tabulated_wet_set evaluates this partition in four steps:
- A scan of 25 points uniform in $\log D$, between the bounds of the collision integrals from the table of
P3Scheme.collision_bounds_point, locates the ends of $W$ as the zeros of $\log(u / m)$. $\hat{u}_l$ comes from the per-particle tables ofP3Scheme.collected_point, and $D^{3/2} v^{1/2}$ from the table ofP3Scheme.capacity_point. - The fraction tables of
P3Scheme.fraction_pointandP3Scheme.capacity_fraction_pointgive the fractions of $∫ \hat{u}_l N' \mathrm{d}D$ and of $M_v = ∫ D^{3/2} v^{1/2} N' \mathrm{d}D$ below each end of $W$, on the number logit of the end, seeP3Scheme.number_logit. The fraction of the first moment $∫ D N' \mathrm{d}D$ has a closed form in the incomplete gamma function. The frozen mass is the mass collected outside $W$ plus $c_1 ∫_W D N' \mathrm{d}D + c_2 ∫_W D^{3/2} v^{1/2} N' \mathrm{d}D$, and the shed mass the mass collected on $W$ less the frozen mass on $W$. The smaller of the frozen and the shed mass is computed, and the larger is the collected mass less the smaller, which keeps the relative precision of the smaller. - The trapezoid rule on the scan points, with the frozen fraction $\min(m / u, 1)$ at each point, divides the smaller mass between cloud and rain.
- The rime volume of each species is its frozen mass over its mean local rime density. The trapezoid rule gives the ratio of the mean inverse rime density of the frozen mass to that of the collected mass, with the local rime density of each point at the mean impact scale of the mass that a particle collects there, and this ratio scales the rime density table.
CloudMicrophysics.P3Scheme.collision_bounds_point — Function
collision_bounds_point((μ,))Return the SVector of the logs of the bounds of the scaled diameter ξ = D λ of the collision integrals at the shape parameter μ, see collision_logξ_lo.
CloudMicrophysics.P3Scheme.collected_point — Function
collected_point(params, vel, pdf, generator, (logD, w, ρ_rim, logρₐ, logx̄))Return the mass of one liquid species that one ice particle of diameter exp(logD) collects per unit liquid mass [m³/s], and the impact scale log κ̄ of that mass.
The rates are those of particle_collection, and log κ̄ is the mean of log κ over the collected mass, see impact_scale. The table stores the log of the mass rate.
CloudMicrophysics.P3Scheme.capacity_point — Function
capacity_point(params, vel, (logD, w, ρ_rim, logρₐ))Return D^(3/2) v(D)^(1/2) [m² s^(-1/2)] of one ice particle of diameter D = exp(logD), the integrand of the ventilation moment of ventilation_moment.
CloudMicrophysics.P3Scheme.fraction_point — Function
fraction_point(params, vel, pdf, generator, logits, (logλ, w, ρ_rim, logρₐ, logx̄))Return the SVector of the logits of the fractions of the mass of one liquid species that the ice below the diameters of the number logits logits collects.
The fractions are those of cumulative_logits of the mass rate of one particle of particle_collection, for the state of table_state.
CloudMicrophysics.P3Scheme.capacity_fraction_point — Function
capacity_fraction_point(params, vel, generator, logits, (logλ, w, ρ_rim, logρₐ))Return the SVector of the logits of the fractions of the ventilation moment M_v below the diameters of the number logits logits.
The fractions are those of cumulative_logits of the integrand of capacity_point, for the state of table_state.
CloudMicrophysics.P3Scheme.cumulative_logits — Function
cumulative_logits(k, particles, dist, v_i, logits, generator)Return the SVector of the logits of the fractions of ∫ k(D) N′(D) dD below the diameters at the number logits logits, see number_logit.
The integral extends between the diameters of the first and last of logits. Both terms of each logit log(F) - log(1 - F) are at least max(1e-30 total, floatmin), so the first and last logits are those of the fractions 0 and 1 at this floor.
Arguments
k: function of the ice diameterD[m]particles:P3Particlesdist:P3Distributionv_i: ice terminal velocity, seeice_particle_terminal_velocitylogits:NTupleof increasing number logitsgenerator:QuadratureRule
CloudMicrophysics.P3Scheme.number_logit — Function
number_logit(μ, ξ)Return the logit log(P) - log(1 - P) of the number fraction P = P(μ + 1, ξ) of the ice below the scaled diameter ξ = D λ, see UT.gamma_inc.
Arguments
μ: shape parameter [-]ξ: scaled diameter [-]
CloudMicrophysics.P3Scheme.logistic_fractions — Function
logistic_fractions(z)Return the fraction F = 1 / (1 + exp(-z)) of the logit z limited to ±50, and 1 - F.
CloudMicrophysics.P3Scheme.wet_set_scan_intervals — Constant
wet_set_scan_intervalsThe number of intervals of the scan of tabulated_wet_set.
CloudMicrophysics.P3Scheme.tabulated_wet_set — Function
tabulated_wet_set(tables, state, key, cloud, rain, coeffs, logT)Return the freeze and shed partition of the liquid-ice collisions per unit ice number from the wet-set tables.
The result is a NamedTuple with the frozen mass cloud_frozen, rain_frozen, the shed mass cloud_shed, rain_shed, and the rime volume of the frozen mass cloud_rime, rain_rime, of cloud and rain, all per unit ice number, see Wet-set tables.
Arguments
tables:P3Tablesstate:P3Statekey: the ice coordinates ofice_table_keycloud,rain: the collected rates oftabulated_collectioncoeffs: the coefficients(c₁, c₂)of the maximum freezing ratec₁ D + c₂ D^(3/2) v(D)^(1/2)of one particlelogT: the temperature coordinate oftable_log_temperature
CloudMicrophysics.P3Scheme.collision_diameter_bounds — Function
collision_diameter_bounds(params, (logλ_lo, logλ_hi); n = 257)Return the bounds of the ice diameters of the liquid-ice collisions over the slopes from logλ_lo to logλ_hi.
The collision integrals extend between the quantiles of liquid_ice_collision_quantile of the size distribution, see integral_bounds. The result is a NamedTuple of the bounds of the log diameter logD_bounds [log(m)] and of the shape parameter μ_bounds over n uniform values of logλ. A constant shape parameter gives the bounds (μ, μ + 1).
Arguments
params:CMP.ParametersP3(logλ_lo, logλ_hi): bounds oflogλ[log(1/m)]
CloudMicrophysics.P3Scheme.collision_logξ_lo — Function
collision_logξ_lo(μ)
collision_logξ_hi(μ)Return the log of the lower or upper bound of the scaled diameter ξ = D λ of the liquid-ice collisions.
The bounds are the quantiles p and 1 - p of the gamma distribution of shape μ + 1, with p from liquid_ice_collision_quantile, as in integral_bounds.
Cost of the tables
The build is dominated by the liquid-ice collision tables, a double integral at each of 6.2 million points, and by the ice tables, whose self-collection integral is a double integral at each of 0.9 million points:
| Group | Points | Build, 16 threads | Build, 1 thread |
|---|---|---|---|
| slope | 32768 | 0.01 s | 0.02 s |
| ice | 912384 | 10 s | 109 s |
| cloud collisions | 3133440 | 14 s | 151 s |
| rain collisions | 3041280 | 25 s | 273 s |
| rime density | 716800 | 0.9 s | 5.1 s |
| wet set | 2741824 | 4.3 s | 40 s |
| all, with the assembly | 52 s | 577 s |
These are times in Float64, measured in November 2026 on an Apple M4 Max with 12 performance and 4 efficiency cores; in Float32 the build takes 70 s on 16 threads and 515 s on one. On one thread of the same machine, the rates take
| Function | Quadrature | Tables |
|---|---|---|
P3State, with the slope | 4.7 μs | 0.63 μs |
ice_terminal_velocities | 4.2 μs | 0.09 μs |
ice_self_collection | 183 μs | 0.09 μs |
ice_melt | 4.6 μs | 0.42 μs |
∫liquid_ice_collisions, below freezing | 152 μs | 2.4 μs |
∫liquid_ice_collisions, above freezing | 127 μs | 0.26 μs |
bulk_microphysics_tendencies, two-moment with P3 ice | 300 μs | 3.6 μs |
These are Float32 times with the state built, except for P3State and bulk_microphysics_tendencies. The time of bulk_microphysics_tendencies is the mean over 400 random states from 235 K to 280 K.