Make the quadrature scheme the configuration choice#728
Draft
haakon-e wants to merge 4 commits into
Draft
Conversation
Member
Author
|
This change is part of the following stack: Change managed by git-spice. |
This was referenced Jun 14, 2026
haakon-e
force-pushed
the
he/rosenbrock-2m-p3
branch
from
June 14, 2026 02:45
730166f to
34dc9a0
Compare
haakon-e
force-pushed
the
he/quadrature-choice
branch
2 times, most recently
from
June 14, 2026 03:42
fac357f to
aaf6093
Compare
haakon-e
force-pushed
the
he/quadrature-choice
branch
from
June 14, 2026 04:08
aaf6093 to
603d7a2
Compare
haakon-e
force-pushed
the
he/quadrature-choice
branch
2 times, most recently
from
June 17, 2026 00:20
8024b90 to
8d49258
Compare
haakon-e
force-pushed
the
he/postsolve-diagnostics
branch
from
June 17, 2026 21:20
0122e0e to
224c902
Compare
haakon-e
changed the base branch from
he/postsolve-diagnostics
to
he/rosenbrock-modes
June 17, 2026 21:20
haakon-e
force-pushed
the
he/quadrature-choice
branch
from
June 17, 2026 21:20
8d49258 to
74d309e
Compare
haakon-e
force-pushed
the
he/rosenbrock-modes
branch
from
June 18, 2026 21:42
a4aa680 to
440ddbf
Compare
haakon-e
force-pushed
the
he/quadrature-choice
branch
2 times, most recently
from
June 18, 2026 22:41
42ceb49 to
3713bbb
Compare
haakon-e
force-pushed
the
he/rosenbrock-modes
branch
from
June 18, 2026 22:41
440ddbf to
309724f
Compare
Merged
haakon-e
force-pushed
the
he/rosenbrock-modes
branch
from
June 22, 2026 21:01
309724f to
871b731
Compare
haakon-e
force-pushed
the
he/quadrature-choice
branch
2 times, most recently
from
June 22, 2026 23:42
c26927a to
c7e9087
Compare
haakon-e
force-pushed
the
he/rosenbrock-modes
branch
from
June 22, 2026 23:43
871b731 to
205acdc
Compare
haakon-e
force-pushed
the
he/quadrature-choice
branch
from
June 22, 2026 23:55
c7e9087 to
a74dba4
Compare
haakon-e
force-pushed
the
he/ad-compat-2m-p3
branch
from
June 23, 2026 00:31
db7adcf to
04792a8
Compare
haakon-e
force-pushed
the
he/quadrature-choice
branch
from
June 23, 2026 00:31
a74dba4 to
9507c4b
Compare
haakon-e
force-pushed
the
he/ad-compat-2m-p3
branch
from
June 23, 2026 21:31
04792a8 to
26145ad
Compare
haakon-e
force-pushed
the
he/quadrature-choice
branch
from
June 23, 2026 21:31
9507c4b to
5bbf1e7
Compare
`get_state_from_prognostic` is not defined anywhere; the path was unexercised by tests.
Implicit substepping needs Jacobians of the pointwise tendencies w.r.t. the 8 prognostic species (`logλ` held fixed). - Type flexibility for mixed Dual/plain inputs: P3State, Γ_incl, the gamma_inc_inv wrapper, ice_mass_coeffs, logistic_function_integral, Chen2022_exponential_pdf, LclRaiRates, the size-distribution closures. - gamma_inc_inv: add an implicit-function-theorem Dual rule (none upstream), exact in the quantile slots; the shape slot differences the smaller of (P, Q), the larger saturating in the tails. - SB2006 autoconversion: ϕ_au ∝ τ^0.7 has a vertical tangent at τ = 0, so ∂/∂q_rai is NaN at zero rain with cloud present. Condition the enhancement below ϵ_numerics_2M_M; value at q_rai = 0 unchanged. - sgs_weight_function: Check the lower tail where atanh → -Inf makes rime-ratio partials bad in Float32. - Early returns: typing from one argument (e.g. `FT = eltype(q_tot)`) makes the return union-typed and heap-boxed for mixed-type callers. Add Utilities.promote_typeof and apply it wher relevant. Tests: per-row Jacobian-vs-FD consistency tests; AD coverage for the regularised-ratio band, the tail shape slots, and mixed arguments; sentinel_type_tests assert concrete returns per signature. Deferred: the logλ shape solve (needs ∂/∂a of forward gamma_inc) and the 1M early return cases.
The analytical solution for ρ_d has a denominator that is 0/0 as F_rim → 0. In Float32 the cancellation drives ρ_d, and therefore ρ_g, negative, which later raises a DomainError in get_D_gr. Rewrite get_ρ_d with the relative exponential functions exprel1 and exprel2 so the cancellation is removed; ρ_g then stays positive for every physical input, with no clipping. Add the derivation and an error-cancellation figure to the P3 documentation, and a Float32 stability test.
The P3 size-distribution quadrature was configured through a single
quadrature_order knob, with build_quadrature silently mapping a magic
set of orders {16, 32, 40, 64} to GaussLegendre and everything else to
ChebyshevGauss. The scheme — with its parameters, notably the order —
is now the explicit choice: pass a scheme instance,
Microphysics2MParams(FT; with_ice = true,
quadrature = Quadrature.GaussLegendre(40))
and build_quadrature only materializes it in the working float type
(GaussLegendre nodes are rebuilt in FT; ChebyshevGauss is closed-form
and passes through). The default ChebyshevGauss(100) preserves the
previous default behavior.
haakon-e
force-pushed
the
he/ad-compat-2m-p3
branch
from
June 23, 2026 22:26
26145ad to
2c7d843
Compare
haakon-e
force-pushed
the
he/quadrature-choice
branch
from
June 23, 2026 22:26
5bbf1e7 to
aaf1fff
Compare
haakon-e
force-pushed
the
he/ad-compat-2m-p3
branch
7 times, most recently
from
July 1, 2026 06:24
11eb605 to
ddd64f0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make the quadrature scheme the configuration choice
Motivation
The P3 size-distribution integrals (deposition and sublimation, melting, riming, ice-rain collection, sedimentation) were configured through a single integer quadrature_order knob. build_quadrature then mapped a magic set of orders, {16, 32, 40, 64}, to Gauss-Legendre and silently fell back to Chebyshev-Gauss for every other order. That coupling makes the knob misleading: the order selects the scheme as a side effect, so a caller who lowers the order from 40 to 36 to trade a little accuracy for speed silently switches integration rules and changes the error characteristics in a way the knob name does not suggest. The two attributes being conflated, the scheme and its order, are independent choices.
What changed
The quadrature scheme is now the explicit configuration value, passed as a scheme instance that carries its own parameters, the order among them:
build_quadrature is reduced to materializing the chosen scheme in the working float type. Chebyshev-Gauss has closed-form nodes and passes through unchanged; Gauss-Legendre is rebuilt so its stored nodes and weights adopt FT, since a Float64 rule would leak Float64 into Float32 collision integrals. This is host-side and one-shot, and the result is isbits and reused in the GPU hot loop with no per-call construction, as before.
The default is Chebyshev-Gauss at order 100, which reproduces the previous default behavior exactly (the old default order of 100 was not in the Gauss-Legendre magic set, so it already resolved to Chebyshev-Gauss). The documentation now states the scheme tradeoff directly: at matched order Gauss-Legendre is substantially more accurate on the smooth P3 integrands, roughly a factor of 20 lower error on the dominant ice-rain collision integral, while Chebyshev-Gauss remains the conservative default; the cusp-limited ice self-collection diagonal is quadrature-limited under either scheme.
Breaking change
The quadrature_order keyword argument to Microphysics2MParams and P3IceParams is removed and replaced by the quadrature keyword, which takes a scheme instance. Callers passing quadrature_order must switch to quadrature = Quadrature.ChebyshevGauss(n) or Quadrature.GaussLegendre(n). Callers relying on the implicit order-to-scheme mapping (e.g. expecting order 40 to mean Gauss-Legendre) must now name the scheme explicitly. The default behavior is unchanged.
Testing
The bulk-tendencies quadrature tests are updated to construct schemes explicitly and to cover both the pass-through (Chebyshev-Gauss) and the FT-rebuild (Gauss-Legendre) paths of build_quadrature.