feat(P3): Gauss-Legendre quadrature, integrand breakpoints -> GL(6) default#741
Open
haakon-e wants to merge 3 commits into
Open
feat(P3): Gauss-Legendre quadrature, integrand breakpoints -> GL(6) default#741haakon-e wants to merge 3 commits into
haakon-e wants to merge 3 commits into
Conversation
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
June 22, 2026 23:58
9c0a58a to
09ba907
Compare
Member
Author
|
This change is part of the following stack:
Change managed by git-spice. |
This was referenced Jun 23, 2026
haakon-e
force-pushed
the
he/p3-aspect-ratio-fix
branch
from
June 23, 2026 00:32
69f01fa to
abdbd39
Compare
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
June 23, 2026 00:32
09ba907 to
e4595a3
Compare
haakon-e
force-pushed
the
he/p3-aspect-ratio-fix
branch
from
June 23, 2026 21:32
abdbd39 to
7f9b793
Compare
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
June 23, 2026 21:32
e4595a3 to
2068d98
Compare
haakon-e
force-pushed
the
he/p3-aspect-ratio-fix
branch
from
June 23, 2026 22:26
7f9b793 to
3aa2995
Compare
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
June 23, 2026 22:26
2068d98 to
49695f3
Compare
haakon-e
force-pushed
the
he/p3-aspect-ratio-fix
branch
from
June 24, 2026 21:56
3aa2995 to
22a3865
Compare
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
June 24, 2026 21:56
49695f3 to
2aabe66
Compare
haakon-e
force-pushed
the
he/p3-aspect-ratio-fix
branch
from
June 25, 2026 18:01
22a3865 to
f42aeb2
Compare
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
June 25, 2026 18:01
2aabe66 to
90f0aea
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #741 +/- ##
==========================================
- Coverage 92.92% 92.81% -0.11%
==========================================
Files 56 56
Lines 2896 2952 +56
==========================================
+ Hits 2691 2740 +49
- Misses 205 212 +7
🚀 New features to boost your workflow:
|
haakon-e
force-pushed
the
he/p3-aspect-ratio-fix
branch
from
June 26, 2026 00:38
f42aeb2 to
b4b9090
Compare
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
June 26, 2026 00:38
90f0aea to
7e848a2
Compare
haakon-e
force-pushed
the
he/p3-aspect-ratio-fix
branch
from
June 26, 2026 01:22
b4b9090 to
aeb57d4
Compare
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
June 26, 2026 01:22
7e848a2 to
dfa0e14
Compare
haakon-e
force-pushed
the
he/p3-aspect-ratio-fix
branch
from
June 26, 2026 01:31
aeb57d4 to
93c9f4a
Compare
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
June 26, 2026 01:31
dfa0e14 to
0604b2c
Compare
haakon-e
force-pushed
the
he/p3-aspect-ratio-fix
branch
from
July 1, 2026 05:35
93c9f4a to
22beeec
Compare
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
3 times, most recently
from
July 3, 2026 03:53
2bd64ea to
c5474cc
Compare
haakon-e
force-pushed
the
he/rosenbrock-modes
branch
from
July 8, 2026 04:34
090fd49 to
043da95
Compare
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
2 times, most recently
from
July 9, 2026 04:16
4453b1c to
2293db0
Compare
haakon-e
commented
Jul 10, 2026
haakon-e
commented
Jul 10, 2026
haakon-e
commented
Jul 10, 2026
| # fallback values typed by the promotion of the node and the captured state | ||
| # (mixed plain/Dual under differentiation) | ||
| FT = UT.promote_typeof(Dᵢ, ΔT, Δρᵥ_sat, denom) | ||
| Tₐ ≥ T_frz && return zero(FT) # No collisional freezing above the freezing temperature |
Member
Author
There was a problem hiding this comment.
just rewriting without branches here an a few other places.
Member
There was a problem hiding this comment.
Claude is asking if ForwardDiff will propagate the non-finite rate through FT(rate) before ifelse discards it. Will Dual arithmetic with Inf work for the derivative?
haakon-e
commented
Jul 10, 2026
haakon-e
commented
Jul 10, 2026
haakon-e
commented
Jul 10, 2026
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
July 10, 2026 02:14
2293db0 to
8ef7fe6
Compare
trontrytel
reviewed
Jul 10, 2026
trontrytel
approved these changes
Jul 10, 2026
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
July 10, 2026 23:15
8ef7fe6 to
bbb3da8
Compare
haakon-e
enabled auto-merge
July 10, 2026 23:21
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
July 11, 2026 00:58
bbb3da8 to
8a2faf4
Compare
…lt order 6 Set the default P3 size-distribution quadrature to Gauss-Legendre of order 6, and place each known feature of the integrands on a quadrature subinterval boundary: the terminal-velocity regime break, the ice-liquid fall-speed crossing, the distribution-tail decay scale, and the wet-growth onset. The integrands are smooth per subinterval, so a low-order rule converges. Ice self-collection integrates the upper triangle D1 <= D2, and the collision integrals read the velocity closures and their breakpoints from the VolumetricCollisionRate. The quadrature order is a Microphysics2MParams parameter.
Add test/p3_quadrature_error_study.jl, which regenerates the accuracy table over the quadrature-consuming P3 integrals and the 2M+P3 bulk tendency. Switch the P3 and 2M integral tests to Gauss-Legendre to match the default, cross-check ice self-collection against the full-square double integral, cover the x_min = 0 mass limit, add a full-tendency benchmark, and set zero-allocation budgets for the 2M+P3 GPU kernel.
…collision cross-sections Add the quadrature_order keyword to the Microphysics2MParams docstring signature, document the error-study usage in the developer guide, list ice_self_collection and the ice-ice and ice-liquid collision cross-sections in the API @docs block so their references resolve, and update the melting and terminal-velocity plot scripts.
haakon-e
force-pushed
the
he/ice-selfcol-triangle
branch
from
July 11, 2026 03:28
dc1db96 to
355b541
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.
Set the default P3 quadrature rule to Gauss-Legendre of order 6, and place every known feature of the P3 size-distribution integrands on a quadrature subinterval boundary so that a low-order rule suffices.
Stacked on #757 (mechanical refactors and small fixes).
Each P3 size-distribution integrand has a small set of known non-smooth features: the mass-regime thresholds, the terminal-velocity regime break, the ice-liquid fall-speed crossing, the exponential decay of the distribution tail, and the wet-growth onset. Placing each feature on a subinterval boundary leaves the integrand smooth within every subinterval, where Gauss-Legendre converges geometrically. Order 6 then meets (a handwavily reasonable) target accuracy (see below).
API
P3IceParams.build_quadratureand the storedquadrature_orderfield are removed; the parameter constructors take aquadrature_order(orquad) keyword.integrateand the P3 process functions requirequad.VolumetricCollisionRatestores the ice and liquid terminal-velocity closures as fields, so the collision integrals read the velocities and their structure from the integrand itself: the crossing bounds, the closed-form rain integrals (coefficients read from the closure), and the wet-growth onset balance.velocity_breakpoints(v_term)returns the diameters where a terminal-velocity closure changes functional form.velocity_integral_boundsconsumes the closure, so the integral bounds no longer assume the Chen 2022 cutoff field.Breakpoints
velocity_integral_bounds) for the velocity-weighted integrals,ice_melt(through its ventilation factor), the outer collision integral, and ice self-collection.v_l(D) = v_i(Dᵢ): a subinterval boundary of the inner collision integrals (crossing_integral_bounds). The rain path computes the crossover diameter once per outer node and shares it across the closed-form N and M components and theB_rimquadrature. With the crossing on a boundary, the collision-efficiency family (collision sources and ice self-collection) converges with order rather than saturating at a fixed error: worst-case relative error falls from 1.2e-2 at order 6 to 5.0e-6 at order 32.3/λ): the upper bound is the(1 - p)quantile, so without this breakpoint the last subinterval spans most of thelog(1/p) ≈ 11.5decay lengths and sets the low-order error in large-mean-size states. With the breakpoint, ice self-collection in the hail-core states reaches 7.1e-5 relative error at order 12 (1.1e-2 at order 6).min()partition and the wet-growth indicator.wet_growth_onset_diameterlocates up to two balance points (the window closes again at large sizes) from a closed-form balance refined by bracketed root-finding, and places them on outer subinterval boundaries. At order 12 the shedding component reaches ~1e-7 relative error; the wet-growth-indicator component sits near 2e-4 and is nearly order-independent (2.5e-4 at order 6, 2.3e-4 at order 12), set by the onset placement rather than the node count.D₁ ≤ D₂, which places theD₁ = D₂derivative discontinuity of the relative fall speed on a boundary and halves the integrand evaluations. A test cross-checks the triangle against the full-square double integral with the ½ pair-counting factor.Accuracy and the default order
I wrote a script that let's me test the accuracy for different orders (since I suspect I'll revisit this in the future).
Over each P3 integral, the collision source vector, and the full 2M+P3 bulk tendency vector, across 17 "regime" states including hail cores. Baseline ("truth") is a GL(128) reference (converged). The
maincolumn runs the same script onmainagainstmain's own GL(128) reference (both without breakpoints). The bulk-tendency error separates into transport components (sedimentation velocities, melt) and components proportional to the collision efficiency (collision sources, ice self-collection, rime):Every bulk error above 0.45% is in a collision-efficiency component, which sets
E = 1. The package's own single-moment scheme assigns collision efficiencies from 0.1 to 1.0 for the analogous liquid-frozen and rain-frozen collisions (cloud_liquid_snow_collision_efficiency = 0.1,cloud_ice_rain_collision_efficiency = 1.0), so theE = 1choice is an upper bound uncertain to a factor of order ten. That uncertainty exceeds the ~1% quadrature error on those rates, so resolving them below ~1% adds no physical accuracy whileEis fixed. The transport components, which do not include theE = 1assumption, converge to at most 0.45% (worst-case 4.5e-3 at order 6). Order 5 reaches 2.0e-2 in the transport family and is rejected. Order 7 matchesmain's bulk p95 and is far belowmainon the worst-case bulk error; order 8 is belowmainon both. Both remain one-keyword changes (quadrature_order). Parameterizing the collision efficiency is the top follow-up, and this table should be revisited when it lands.Runtime
Then testing the runtime with these changes in Float64 on Julia 1.12.
The warm cell performs no size-distribution integrals; its sub-microsecond time differs between the two by about 0.3 µs, reproducibly across runs and negligible against the ice-path cost. The
he/p3-refactorsbase (the PR base) gives the same GL(16) baseline asmain(5011 / 4824 µs here versus 5017 / 4869 µs formainin a separate run, for the two ice cells), so the speedup is attributable to the order reduction, the closed-form rain integrals, and the triangle self-collection, net of the onset cost. The onset location costs about a quarter of the collision call (a log-spaced scan, RootSolvers Brent refinements of the closed-form balance, and two additional outer subintervals). Removing the step also removes a state-dependent discontinuity from the tendencies that the implicit solver's Jacobian must differentiate.The absolute GL(16) baseline depends on the Julia version: on Julia 1.12 the 16-node collision double integral runs at ~5000 µs, roughly 1.8× the figure a lower Julia version reports, while the GL(6) time is stable across versions. The ratio above is therefore the Julia 1.12 result (on lower versions the ratio is closer to 0.75). The measurement ran on the
climacluster.Tests:
test/p3_quadrature_error_study.jl(run_quadrature_error_study(); usage in the developer guide) regenerates the accuracy table when the quadrature machinery or the process integrands change.test/bulk_tendencies_quadrature_tests.jllocks orders 6 through 12 as a regression test against a GL(200) reference, with graupel and hail-core states in the state set.