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

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.9120789986414
source
CloudMicrophysics.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.MassPowerLaw parameters
  • F_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].

source
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: P3Particles
  • D: maximum particle dimension [m]
source

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: The P3Particles
  • ρq_ice: The ice mass concentration [kg/m³]
  • ρn_ice: The ice number concentration [1/m³], bounded by bounded_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.

source
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 is 0

Note:

  • For n = 0, this evaluates to log(L/N₀)
  • For n = 1, this evaluates to the (unnormalized) mass-weighted mean particle size, see D_m
source
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 is 0
  • scale: The scale factor [-], default is 1.

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.

source
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 is 0
  • scale: The scale factor [-], default is 1

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₂)

source
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.

source

Ventilation

P3Scheme.ice_melt reads the ventilation integral of the size distribution from ice_ventilation_integral.

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.

Used in collision_cross_section_ice_liquid

source
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

Returns

A VolumetricCollisionRate, a function (D_ice, D_liq) -> E * K * |vᵢ - vₗ| where:

  • D_ice and D_liq are the (maximum) diameters of the ice and liquid particles
  • E is the collision efficiency
  • K is the collision cross section
  • vᵢ and vₗ 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\]

source
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

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].

source
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.AirProperties
  • tps: 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 from Tₐ to the surface temperature and freezes there [J/kg]; it is nonpositive for T_frz - Tₐ ≥ L_f / cp_l ≈ 80 K, where every collected droplet freezes
  • T_frz: freezing temperature [K]
source
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

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.

source
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 function n(D)
  • ∂ₜV: volumetric collision rate integrand function ∂ₜV(Dᵢ, D)
  • m_liq: liquid particle mass function m_liq(D)
  • ρ′_rim: local rime density function ρ′_rim(Dᵢ, D)
  • liq_bounds: integration bounds for liquid particles
  • quad: quadrature rule, a QuadratureRule

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]
source
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 function n(D)
  • v_l: liquid terminal velocity function [m/s]
  • m_liq: liquid particle mass function m_liq(D)
  • ρ′_rim: local rime density, a CollisionRimeDensity
  • v_i_at_Dᵢ: terminal velocity of the ice particle [m/s]
  • coeffs: cross-section coefficients from collision_cross_section_ice_liquid_coeffs
source
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.

source
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. from get_liquid_integrals
  • rain_integrals: inner liquid integrals for rain particles, e.g. from get_liquid_integrals
  • ice_bounds: integration bounds for ice particles, from integral_bounds
  • quad: quadrature rule, a QuadratureRule

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.

source
∫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

Returns

A tuple (QCFRZ, QCSHD, NCCOL, QRFRZ, QRSHD, NRCOL, ∫M_col, BCCOL, BRCOL), where:

  1. QCFRZ - Cloud mass collision rate due to freezing [kg/s]
  2. QCSHD - Cloud mass collision rate due to shedding [kg/s]
  3. NCCOL - Cloud number collision rate [1/s]
  4. QRFRZ - Rain mass collision rate due to freezing [kg/s]
  5. QRSHD - Rain mass collision rate due to shedding [kg/s]
  6. NRCOL - Rain number collision rate [1/s]
  7. ∫M_col - Total collision rate [kg/s]
  8. BCCOL - Cloud rime volume source [m³/m³/s]
  9. BRCOL - Rain rime volume source [m³/m³/s]
source
∫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.

source
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.

source

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)/2

with 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 integrate
  • a, b: Integration bounds. Note: if a ≥ b, or a or b is NaN, zero is returned.
  • quad: Quadrature scheme (a QuadratureRule).

Returns

Approximation to the definite integral ∫ₐᵇ f(x) dx

source
integrate(f, bnds, quad)

Integrate the function f over each subinterval of the integration bounds, bnds.

Arguments

  • f: Function to integrate
  • bnds: A tuple of bounds, (a, b, c, d, ...)
  • quad: Quadrature scheme (a QuadratureRule).

The integral is computed as the sum of the integrals over each subinterval, (a, b), (b, c), (c, d), ... — see subintervals.

source
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.

source
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

See integral_bounds for the keyword arguments and the return value.

source

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:

  1. P3Scheme.P3TableGrid gives the axes of each table group, a tuple of P3Scheme.TableAxis, with the bounds derived from the parameters and the numbers of points of P3Scheme.TABLE_POINTS.
  2. P3Scheme.table_groups gives 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 options logs and inner of the group.
  3. P3Scheme.tabulate evaluates the point function at every point of the axes of the group, on all threads for an Array, and by a broadcast where the array type places its elements for any other array type.
  4. P3Scheme.UniformTable stores the values in the float type of the parameters.
  5. P3Scheme.P3Tables holds the tables of all groups and a hash of the parameters they were built from, and with_tables returns a copy of the parameters with the tables as their integration.

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_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.

source
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 point

  • hi: Coordinate of the last point

  • n: Number of points, at least two

source
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 an NTuple of coordinates to a number or an SVector
  • axes: NTuple of TableAxis
  • ArrayType: array type of the result, such as Array
source
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 of n₁ to n_N points

  • lo: Coordinate of the first point of each axis

  • hi: Coordinate of the last point of each axis

source

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:

MethodGroups
P3Distribution, in the construction of a P3Stateslope
P3Scheme.ice_terminal_velocitiesice
P3Scheme.ice_self_collectionice
P3Scheme.ice_ventilation_integral, in P3Scheme.ice_meltice
∫liquid_ice_collisions, in P3Scheme.bulk_liquid_ice_collision_sourcescloud_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

source
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.

source

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 SVector of 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 an SVector, so that the points share the expensive part of the integral. The rime density tables evaluate the points of logR in this way, and the fraction tables those of P3Scheme.number_logit.
  • The coordinates are uniform in the logarithm of a quantity that varies over orders of magnitude, logλ, logρₐ, logx̄, logR and logD.
  • The rime coordinate w = 1 - √(1 - F_rim) of P3Scheme.rime_coordinate replaces F_rim, because the particle properties change fastest near F_rim = 1.
  • P3Scheme.ice_table_key takes the primal value of logλ, so that a ForwardDiff.Dual state is differentiated through the other coordinates only, as in the quadrature.
  • P3Scheme.lookup moves a coordinate outside an axis to the nearest end of the axis.
  • The tables are in the float type of the parameters, and Adapt moves them to a device with the parameters.
  • The fingerprint of P3Tables hashes the parameters that the tables depend on, and the constructors of the parameters from a parameter dictionary check it, see P3Scheme.tables_are_current.

Adding a table

A new table group needs

  1. a family of numbers of points in P3Scheme.TABLE_POINTS, and the axes of the group in the constructor of P3TableGrid,
  2. a point function, and its entry in P3Scheme.table_groups with logs and inner,
  3. a method of the process function for P3Scheme.TabulatedP3State that reads the group with P3Scheme.lookup,
  4. the parameters of the new integrals in table_fingerprint, if the existing ones do not cover them,
  5. a test against the quadrature in test/p3_tables_tests.jl, and the errors of the new quantities in test/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.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

source

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.

source
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

source
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.

source
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.

source
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.

source

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.

source
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.

source
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

  1. the number rate per unit ice number and per unit liquid number [m³/s],
  2. the mass rate per unit ice number and per unit liquid mass [m³/s],
  3. the impact scale log κ̄, the mean of log κ over the collected mass, see impact_scale,
  4. 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

source
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

source
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.Chen2022VelType
  • particles: P3Particles
  • pdf: the size distribution of the liquid species
  • ρₐ: air density [kg/m³]
  • logx̄: log mean mass of the liquid species [log(kg)]
source
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

source
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, see collision_point
  • rime_density: the rime density table of the species, see rime_density_point
  • key: the ice coordinates of ice_table_key
  • pdf: the size distribution of the species
  • L: liquid content [kg/m³]
  • N: number concentration [1/m³]
  • ρₐ: air density [kg/m³]
  • logT: the temperature coordinate of table_log_temperature
source

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:

  1. 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 of P3Scheme.collected_point, and $D^{3/2} v^{1/2}$ from the table of P3Scheme.capacity_point.
  2. The fraction tables of P3Scheme.fraction_point and P3Scheme.capacity_fraction_point give 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, see P3Scheme.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.
  3. 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.
  4. 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.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.

source
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

source
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

source
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

source

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:

GroupPointsBuild, 16 threadsBuild, 1 thread
slope327680.01 s0.02 s
ice91238410 s109 s
cloud collisions313344014 s151 s
rain collisions304128025 s273 s
rime density7168000.9 s5.1 s
wet set27418244.3 s40 s
all, with the assembly52 s577 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

FunctionQuadratureTables
P3State, with the slope4.7 μs0.63 μs
ice_terminal_velocities4.2 μs0.09 μs
ice_self_collection183 μs0.09 μs
ice_melt4.6 μs0.42 μs
∫liquid_ice_collisions, below freezing152 μs2.4 μs
∫liquid_ice_collisions, above freezing127 μs0.26 μs
bulk_microphysics_tendencies, two-moment with P3 ice300 μs3.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.