Adaptive quadrature
See how HPR Sim computes the area under a curve to a requested accuracy, the method behind the volume and inertia of curved parts.
In short
- What it models: a definite integral (the area under a curve) to a requested accuracy, splitting the range where the error estimate is largest. It gives the volume, center of mass and inertia of parts such as nose cones and fins.
- Sources: QUADPACK (Piessens, de Doncker-Kapenga, Überhuber and Kahaner, Springer, 1983), public domain: its 15-point rule, which carries its own error estimate, and its adaptive scheme.
- How well it is validated: analytic tests only. The rule integrates polynomials up to degree 22 exactly, and six test integrals, one infinite at an end, reach 1e-11 relative. The integrals of 22 nose cones and transitions agree with 40-digit references to 1e-12 relative (Nose cones). Not compared with another simulator or a flight.
- What it leaves out: QUADPACK’s extrapolation for singular integrands. It relies on splitting, plus changes of variable at known singularities, and reports an error when it runs out of subintervals.
Code and sources
Code: hpr_core::quadrature.
Source: [QP] R. Piessens, E. de Doncker-Kapenga, C. Überhuber and D. Kahaner, QUADPACK: A
Subroutine Package for Automatic Integration, Springer, 1983. QUADPACK is public domain. Its
routine qk15 has the rule’s nodes and weights to 33 digits.
Method
- On , the 15-point Gauss-Kronrod rule embeds the 7-point Gauss rule . is exact for polynomials of degree and for degree .
- The error estimate of a subinterval is for each component. This overestimates the error of when the integrand is smooth.
- The adaptivity is global ([QP]
QAG, §2.2 and §3.3):- Keep every subinterval with its estimates.
- While the summed error of some component exceeds the larger of and , bisect the subinterval that contributes most to the worst component.
- Stop with
QuadratureDidNotConvergeat the subinterval budget, or when a bisection point can no longer be represented. - QUADPACK’s
QAGSalso extrapolates with the -algorithm. HPR Sim does not. It relies on bisection plus variable substitutions at known singularities (Shapes).
- Vector integrands share one set of subintervals, so the moments of a solid come from the same integrand evaluations. Integrands should be scaled to order one so that one absolute tolerance suits every component.
- The relative tolerance never goes below . A NaN or infinite sample is an error
(
QuadratureNotFinite), never a silent zero.
Verification
The tests are in quadrature::tests.
- The rule is the published one:
- The Gauss nodes are roots of to 1e-15.
- Both weight sets sum to 2.
- One panel integrates exactly for (Kronrod) and (Gauss). At the next even degree it is not exact.
- A digit typo in any node or weight fails these checks.
- Convergence:
- , , , , and all reach 1e-11 relative.
- Four components converge together.
- Reversed limits change the sign.
- Failures:
- on runs out of subintervals.
- A NaN integrand is reported.