Skip to content

Quadrature fixes: sinh-mapped ring rules, regenerated tables, per-panel near rule, 18 digits - #15

Merged
dmalhotra merged 24 commits into
mainfrom
quad-fixes
Nov 14, 2026
Merged

dmalhotra merged 24 commits into
mainfrom
quad-fixes

Conversation

@dmalhotra

@dmalhotra dmalhotra commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Fixes to the quadrature rules of slender_element.cpp, found while computing Stokes flow past slender rods (diameter/length down to 1e-10), rerunning the tables of the CSBQ paper, and with the unit tests of #14: sinh-mapped ring rules in place of the dyadic panel rules, self-interaction tables per number of Fourier modes, a near-interaction rule that gives each panel the points for its own Bernstein ellipse, near regions that follow curved elements, ring rules built one level at a time, and the quadrature tables, regenerated by the code that precedes them. SCTL moves to release 2.1.0. In commit order:

General

  1. test_greens_identity, GeomSphere: sign of the single-layer density and element order 10 in the member test (error now 1.5e-10 at tol 1e-10); GeomSphere now makes a closed sphere.
  2. Temporaries from the scratch pool (ScratchBuf): the kernel buffer of the ring integral instead of a 10000-node stack array, which overflowed OpenMP thread stacks for the traction tensor in quad precision; and the stack arrays with a heap fallback in NearInteracHelper, SelfInteracHelper and GetFarFieldNodes.
  3. Up to 18 digits in long double and quad (DigitsDispatch replaces the four if-chains that stopped at 15). Double builds are unchanged.

Ring rules (the integrals around the cross-section)

  1. Trapezoidal rules at levels 0 and 1 (dist/r ≥ π) sized for the Fourier modes of a resolved density: N = max(Nmodes−1, ⌈digits/log10 ρ⌉) + 4 at level 0 and + 6 at level 1 (ρ = 7.28 and 4.14), instead of max(digits·2^level, Nmodes), which aliased the highest modes with kernel coefficients of order one.
  2. Training targets on a polar grid: 24 angles × 24 distances, instead of 25 points on a spiral (the distance was taken from the angle index).
  3. Table entries chosen by measured accuracy: for d digits, the rule with the fewest nodes that integrates every training target to 10^-d, among those whose weights cancel little (Σ|w| ≤ 2|Σw|).
  4. Sinh-mapped ring rules in place of the dyadic panel rules. On |θ| < h, θ = δ·sinh(t) puts the near-singularities of the kernel at height π/2 in t for every distance, so one Gauss–Legendre panel in t resolves them; one more panel resolves the Fourier modes.
    • The rules built at run time (long double, quad, and double with CSBQ_SINH_RING_QUAD, 0 by default) use them at every level past the trapezoidal ones. The dyadic panel rules they replace missed their digits (0.2 for 1 digit; 5.5e-12 at m10, level 2, 15 digits) and took 3 to 6 times more nodes (Nmodes 10, 16 digits: 432 instead of 150 at level 10, 1344 instead of 228 at level 29). Long double and quad builds no longer load ring tables they don't use.
    • Table mode uses them past the range of the tables (dist/r below 2π·2⁻²⁹), where it used the last table (error O(1) at dist/r 1e-9).
    • The rules are kept in memory down to level max(30, SigBits−10) (42 in double, 102 in quad) and built at each call beyond. A target on the loop no longer hangs the level search; it is the only case with a warning.
  5. Sinh-mapped discretization for generating the ring tables: the generalized Chebyshev rules take their nodes from the panels of the 19-digit sinh rule with twice its nodes, with one panel across θ = 0. The closest node to θ = 0 moves from 2.3e-3·δ to 3.9e-2·δ, and the outer panel has nodes in proportion to Nmodes (the 35-point dyadic panels left the training integrals of tables with many modes at 5e-9, m30, level 2, 16 digits). The dyadic panel rule is removed.
  6. All 104 ring tables regenerated, and 4 new ones for 65 Fourier modes (FourierOrder 126), in quad precision by the code of commits 4–8 (73 minutes on 6 nodes). They take 237 MB instead of 176 MB.

Self-interaction rules (the integrals along an element for targets on its own surface)

  1. CSBQ_ADAPTIVE_SELF_QUAD (0 by default) builds the self-interaction rules at run time instead of reading the tables.
  2. Elements longer than the longest table (length/radius above √2·2³⁰ ≈ 1.5e9) use the adaptive rule instead of the longest table, with a warning once per kernel (the adaptive rule is slower and, for the double layer in double precision, may lose digits); very short elements keep the shortest table, without the warning. The adaptive rule now has nodes at 0 requested digits: it had none, which gave a zero self-interaction matrix.
  3. Smaller log-singular interval in the adaptive rule: less than r/8 and at most 1/16 of the element to each side of the target (it was 2r to 4r, next to the singularities of the ring-integrated kernel at 2r). Stokes double layer at length/radius 1e6, 15 digits: about 1e-23 in quad precision instead of 2.7e-11.
  4. Reference quadrature of the tables: training integrals accurate to 2e-22 (from 1e-9 on short elements).
  5. Table entries chosen by measured accuracy, rejecting rules whose weights cancel (Σ|w| > 2|Σw|; some shipped rules had Σ|w| up to 729|Σw|).
  6. Self-interaction targets at the angles of the surface nodes, radius relative to the target's: building the self-interaction matrix in double lost digits to the drift of the target angles and the rounding of the interpolated radius, to which the on-surface double layer is sensitive. On-surface error on five rows of the paper's tables (L5, L6, S6, C4, C5): 0.17 to 0.78 digits better (C5 10.16 → 10.94 digits).
  7. Self-interaction tables per number of Fourier modes (9, 17, 33, 65), trained on densities resolved to 10^-d at their highest mode, instead of one table trained on modes 0–7. An element uses the smallest table with at least its number of modes; elements with more than 65 modes use the adaptive rule, with the same warning. In quad precision, FourierOrder 16 to 126, all four kernels: at most 0.21 digits below the requested digits (the previous tables gave 10.95 digits for 12 requested, Laplace double layer at FourierOrder 48).
  8. Tables by type of singularity: Stokes3D_FxT and Laplace3D_FxdU use the double-layer tables (ring tables, and self-interaction tables with target normals) instead of generating their own in quad precision. Laplace and Stokes keep separate tables: on Stokes kernels the Laplace tables lose 2–3 digits near the surface.
  9. The 16 self-interaction tables (special_quad_q10_m<modes>_<kernel>, replacing the 4 special_quad_q10_<kernel>), in quad precision. They take 139 MB instead of 31 MB.

Tests, SCTL, the near interaction and the construction of the ring rules

  1. Near-surface targets of layer-potentials at the default threshold (20× the tolerance, instead of 200× and 1000×).
  2. SCTL 2.1.0 (f097658, was 4a0fbd9): BLAS and LAPACK through SCTL's own names, GMRES's Krylov basis in scratch memory, thread teams for gemm, radix_sort and Tree, the near interactions of BoundaryIntegralOp through SmallGEMM, and Real = float builds without -Wfloat-conversion warnings.
  3. Near region along curved elements: the radius of the near region along the element is multiplied by (e^x − 1)/x, where x is the angle the centerline turns per unit s times the radius for a straight element; only the final scaling by the speed has the dimension of a length. Outside a bend, the near region of a circular arc reaches that factor farther. On 290 elements of the paper geometries (model of the far rule, smooth densities), the far rule now meets the tolerance at every sampled target outside the balls; before, 5% of the elements turning 15–60° and 24% of those turning more had targets where it missed by up to 0.56 digits. The near region grows by a median factor of 1.09, 1.36 and 1.60 for elements turning less than 15°, 15–60° and more. The matrices that interpolate from the Chebyshev nodes to the far-field nodes are cached per element order in one place, used by GetFarFieldNodes, GetFarFieldDensity and FarFieldDensityOperatorTranspose; element orders of 50 or more, which GetFarFieldDensity already could not handle, now stop with an assertion.
  4. Gauss–Legendre points of each near panel for its own Bernstein ellipse: with the points for ρ = 2.5 and the requested digits on every panel, off-surface targets near an element missed the tolerance for Stokes and close-to-touching geometries (Gauss's-law check: S4 7.55 digits for 9 requested, C4 9.27 for 12). The panel walk now uses ρ = 3, and each panel gets the points for the ellipse through the target: ρ = a + √(a² − 1), a = (d₀ + d₁)/L, at most 9, divided by 1 + 0.35·w on the outside of a bend (w the change of the unit tangent across the panel), with the error estimate brought below 10^−(digits+0.5). Together with commit 21, against the same code with the points for ρ = 2.5 and digits+2 on every panel, on the 18 problems of Tables 3–5 (medians): off-surface errors 0.79 (single layer) and 0.67 (double layer) digits smaller at the same tolerance, the on-surface errors the same within 0.01 digits, and the 1-core setup time at that code's error 13% shorter on the surface and 19% and 13% shorter off the surface; the near rule uses 0.636 of its points. A panel gets at most LegQuadOrder points, the size of the buffers. The two disabled alternatives to the walk (dyadic panels toward the element ends and toward the closest point of the centerline), which used one Gauss–Legendre rule on every panel, are removed.
  5. Test of the gradient of the Laplace single layer and the Stokes traction tensor near the surface (1e-1, 1e-3 and 1e-6 radii), and with target normals of the normal derivative and the traction, which take the double-layer tables, against long double where it is wider than double and against double at tolerance 1e-15 otherwise.
  6. Sinh-mapped ring rules built one level at a time, at first use, instead of all levels (102 in quad, 53 in long double) at the first call for a number of Fourier modes, with the packed rules and their transposed copies held together. First use of one level in quad: 0.09 s and 4 MB instead of 10.6 s and 261 MB for 10 Fourier modes, and 0.29 s and 18 MB instead of 19.0 s and 2.4 GB for 66 modes, as when generating the 65-mode self-interaction tables. The rules are bit for bit the same.

Comparison with main

Final code: single- and double-layer operators alone on the 18 problems of Tables 3–5, at the paper tolerance, against main (471d384). Digits achieved minus digits requested, difference to main (range, median):

  • Off the surface: single layer 0.10 to 2.75 digits better (median 1.54), double layer 0.59 to 3.29 better (median 1.95), on every problem. Problems below the requested digits: 2 of 18 for the single layer (main: 10) and 4 for the double layer (main: 18).
  • On the surface: double layer 0.39 to 1.90 digits better (median 0.87) on every problem. Single layer from 0.98 digits lower to 1.11 higher (median 0.25 lower; lower on 11 problems): main's single layer is more accurate than requested, and the final code still meets the requested digits wherever main does (L6 and C5 miss by the same 0.78 and 0.26 digits in both).

The paper's tables, before commits 20–22: Tables 2–6 of the paper, main against an earlier version of this branch whose near rule had the points for digits+2 on every panel and whose far-field distance was for tol/10; its other quadrature rules are bit for bit those of this one, except at 0 requested digits. AMD Genoa nodes; accuracy with 40 MPI ranks of 1 thread; times are the minimum of 2 or 3 runs.

  • Accuracy (Tables 3–5): off-surface quadrature error 0.57 to 3.72 digits better on every row except C5 (+0.01); on-surface 0.27 to 2.50 digits better on every row. Solution error within 0.15 digits on the tangle rows, and 0.31 to 0.55 digits better on C3–C5. Same GMRES iteration counts on every row.
  • Table 2 (Green's representation test): Laplace 0.09 to 2.09 digits better at every tolerance. Stokes better at 10 of the 12 tolerances; at 1e-5 (6.65 → 5.84 digits) and 1e-7 (7.64 → 7.45) it is lower but still meets the requested digits.
  • Table 6 (sedimentation of a ring): Fz agrees with main to 12.7 digits or more.
  • Time: setup 10% to 27% longer (L1 and S1, under 0.15 s: 61% to 81%). Solve on 1 core: within 1% on the tangle rows, 1% to 4% longer on the close-to-touching rows. Solve on 40 cores: 0.4% to 1.5% longer on the largest rows (L5, L6, S5, S6) and 4% to 8% longer on the close-to-touching rows; the other tangle rows (0.01 to 8.4 s) change by −11% to +18%, with run-to-run spreads of up to 46%. Table 2 setup and evaluation: 9% to 29% longer (33% and 59% at tolerance 1e-1, under 3 ms).
  • Since then, the setup time of the final code against main was not measured directly. The far-field distance for the requested tolerance instead of tol/10 takes 9% to 11% less setup time on the surface at main's error, and off the surface 9% less for the double layer and 4% more for the single layer (medians); commits 21 and 22 together take 13% to 19% less than the near rule for digits+2, at its error.

Testing

  • Each commit compiles (the three unit tests, -Wall -Wfloat-conversion, no warnings in slender_element.cpp). make check passes on the final commit (gcc 13.3) and at every commit whose tables match its code: commits 1–2 and 9–24, except 16 and 17, which stop with "Missing quadrature table" until the tables of commit 18.
  • The shipped tables are those the code builds: all 108 ring tables, rebuilt by the code of commit 16, are byte for byte the shipped ones, and so are the self-interaction tables of two length bins (length/radius 2⁻³ and 2⁻⁶) for every kernel and number of modes, rebuilt by the code of commit 17.
  • Ring tables, in quad precision against references independent of the tables on targets off the training grid (digits lost: d + log10 of the error of the d-digit rule, worst over levels 2 to 29):
    • straight ring, m10, Laplace and Stokes single and double layers, Stokes traction, Laplace gradient and normal derivative: at most 0.83 digits up to 15 digits and 0.95 at 16 (main's tables: 7.0 to 13.4 digits up to 15);
    • double layers on a curved, tapered ring (κr = 0.05, dr/ds = 0.0125), m4, m10, m20, m30 and m52: at most 0.59 digits up to 15 digits and 0.79 at 16 (main's m52 tables are off by 0.6 at level 2).
  • Sinh-mapped rules, in quad against references from refined dyadic panels on the curved, tapered ring: every kernel (Laplace and Stokes single and double layers, Stokes traction) at Nmodes 4 to 52, levels 2 to 44 and 1 to 19 digits meets its digits with at least 0.62 digits to spare; in a 50-digit model of the integrals, down to level 101 with at least 1.84 digits to spare.
  • Self-interaction tables, one straight element at length/radius 2^(j/4), j = 0..30, with densities resolved to 10^-d, against the adaptive rule at 18 digits in quad precision: at most 0.21 digits below d in quad (FourierOrder 16 to 126, d from 1 to 15). In double at d = 15: 14.1 to 14.7 digits for the single layers and 11.3 to 11.8 for the double layers. Laplace double layer against an mpmath evaluation on a straight element: 4.5e-17 to 2.6e-22 in quad precision for length/radius 0.05 to 1e4.
  • Closed loop at 1e-3 and 1e-6 radii from the surface (layer-potentials): the errors follow the tolerance down to 1e-10 (at most 3.3e-11 for Laplace and 1.1e-10 for Stokes); at tol 1e-7, Laplace 6.6e-9 and 3.0e-9 (main: 2.6e-6 and 8.6e-4).
  • Gradient, traction tensor, normal derivative and traction near the surface at tol 1e-10 (commit 23): 10.04 to 11.72 digits against long double.
  • Ring rules built one level at a time (commit 24): bit for bit the same as when built all at once, in long double and quad (hash of every rule of 10 Fourier modes, and of one level of 30 and 66 modes).
  • Ring-integral benchmark (double, 13 digits, 1 and 48 threads): same time per call as main, within ±2%.

Known limits

  • In double, the kernel's approximate reciprocal square root loses up to 1.2 digits at 3, 6, 12 and 15 digits, as on main.
  • In double, close to the loop, the rounding of the target position relative to the loop limits the accuracy whatever the rule: for the double layers, 3.5e-7 at level 30 (dist/r 6e-9) and 5e-4 at level 41 (3e-12).
  • On rings both curved and tapered, the area element √(norm_dy² + dr²) has Fourier modes beyond those the ring tables are trained on: with the tables, the Laplace and Stokes single layers, the Laplace gradient and the traction level off at 1e-10 to 4e-9 (κr = 0.05, dr/ds = 0.0125, Nmodes 4 to 52). The sinh-mapped rules don't.
  • The on-surface double layer still levels off at about 10.9 to 11.5 digits (L5, L6, S6, C4, C5 request 12 to 14): rounding inside the ring integrals, and targets at the junctions of neighboring elements. Off the surface, C5 reaches 12.1 digits for the double layer and L6 13.6, for 14 requested.
  • Long elements: with the tables (length/radius 8.4e6 to 1.3e9), at least 12.2 digits in double for 15 requested and 11.7 for 12 to 14. Beyond the tables (length/radius above 1.5e9), the adaptive rule is used, which gives 9.7 to 10.2 digits for the double layer in double (measured at length/radius 8.4e6 to 1.5e9); it has a rounding floor for the double layer, also on short elements with CSBQ_ADAPTIVE_SELF_QUAD.
  • In quad, all 102 levels of sinh-mapped rules for 10 Fourier modes take 11.4 s to build and 129 MB of memory; since commit 24 only the levels that targets reach are built.
  • On x86, the long-double reference of commit 23 makes layer-potentials take 20.5 s instead of 3.1 s without these checks (one AMD EPYC 7742 node, 8 threads; 19.9 s and 3.0 s with 128 threads), of which the checks with target normals add 0.4 s.

🤖 Generated with Claude Code

@dmalhotra
dmalhotra force-pushed the quad-fixes branch 3 times, most recently from 0e83e2f to b4e04da Compare October 30, 2026 00:54
@dmalhotra dmalhotra changed the title Quadrature fixes: ring tables, table ranges, adaptive switches, 18 digits Quadrature fixes: sinh-mapped ring rules, regenerated tables, switches, 18 digits Oct 30, 2026
@dmalhotra
dmalhotra force-pushed the quad-fixes branch 2 times, most recently from bbef644 to b9a7804 Compare November 4, 2026 17:49
dmalhotra and others added 19 commits November 4, 2026 20:41
…eometry

SlenderElemList::test_greens_identity set Fs = -dU.n, but its check
Fd/2 + Us - Ud - Uref needs +dU.n for a source outside the body (as in
test_greens_identity in utils.cpp), and half of its elements had order 8,
which has no quadrature tables, so a call generated them. Use +dU.n and
order 10: the error is now 1.5e-10 at tol 1e-10. GeomSphere passed s in
[0,1] to x = R cos(s/2), r = R sin(s/2), a cap of half-angle 0.5 rad open
at one end; use x = R cos(pi s), r = R sin(pi s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… from the scratch pool

toroidal_greens_fn_batched kept KDIM0*KDIM1*10000 values on the stack:
4.3 MB for the traction tensor (27 components) in quad precision, which
overflowed the stack of OpenMP threads. Take KDIM0*KDIM1*Nnds values from
the thread's ScratchBuf pool instead, with no heap allocation per call. A
ring integral takes the same time as before (within 2%, on 1 and 48
threads).

SelfInteracHelper and NearInteracHelper take the coordinates of the
element nodes relative to the target from the pool as well, instead of a
30-value array on the stack with a heap allocation for larger elements; so
do the other temporaries of that kind: the Lagrange interpolation weights
in NearInteracHelper (four places) and the shifted Chebyshev nodes in
SelfInteracHelper, which had 20-value arrays, and the derivatives at the
far-field nodes in GetFarFieldNodes, which had a 6000-value array.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SelfInterac and NearInterac turned tol into a number of digits of at most
15 in every build, so long-double and quad builds never used the 16-18 digit
rules of the tables (SpecialQuadRule has 19 digits, ToroidalSpecialQuadRule
20). Replace the four if-chains by DigitsDispatch (namespace detail_interac),
which goes up to the precision of Real: 15 digits for double, as before, and 18 for long double
and quad.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he Fourier modes

For dist/r >= pi the ring rules are trapezoidal, with N = max(digits*2^level,
Nmodes) nodes. Mode k of the integrand then aliases with the Fourier
coefficient of order N-k of the kernel, which for the highest modes is of
order one when Nmodes > digits*2^level. Those coefficients decay like
rho^-j, at least as fast as 7.28^-j at level 0 and 4.14^-j at level 1. For a
resolved density, whose Fourier coefficients decay from O(1) to 10^-digits at
the last mode, the error is 10^-digits for N about max(Nmodes-1,
digits/log10(rho)). Use that, with 4 more nodes at level 0 and 6 at level 1,
which the double-layer kernels need.

Against adaptive quad-precision ring integrals, with random Fourier
coefficients that decay to 10^-digits at the last mode (error relative to
the size of the terms), the rules at levels 0 and 1 meet their digits with
at least 0.5 digits to spare. For densities that are not resolved
(coefficients of order one up to the last mode), the error levels off: at
m30, 1e-6 to 1e-4 at level 0 and 3e-4 to 9e-3 at level 1, still smaller than
with the old N.

On the 18 problems of the paper's Tables 3-5, with this change removed
alone from a version of this branch whose near rule had the
Gauss-Legendre points for digits+2 and whose far-field distance was for
tol/10: with the old N, the double-layer off-surface error at the same
tolerance is 1.01 digits larger (median over the problems) and its setup
time to reach main's error 51% longer. The other setup times change by at
most 1%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…argets

BuildToroidalSpecialQuadRules fits each ring rule to targets meant to be on a
25x25 polar grid around the nearest point of the loop (25 angles, 25
distances from 0.5 to 1 times the distance of the level), but it took the
distance from the angle index: 25 distinct targets on a spiral, each angle
at one distance. The rules integrate those targets and stop improving with
the number of digits (about 44 nodes from 13 digits on, errors of 5e-5 at
dist/r 1e-8 for the Laplace double layer). Take the distance from the inner
index. Also use 24 angles, a multiple of 4, so that the targets include the
directions along the axis, where the peak of the double-layer kernel at
theta = 0 vanishes and the rest of the loop decides the integral, and the
direction toward the axis. The tables are regenerated later in this
series.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For each level and number of digits, the ring tables held the rule that
InterpQuadRule builds for a tolerance relative to the largest singular value
of all the training integrands, in L2. Close to the loop the peak at theta =
0 dominates that norm, and the rules miss their digits by far on the
integrals of single targets: from m18 on, the 12-digit rule at level 28 of
the double-layer tables is off by 4e-2.

When building a table, keep for d digits the rule with the fewest nodes that
integrates the training integrands to 10^-d, relative to the largest integral
of each target, among the rules whose weights cancel little (sum |w| <= 2
|sum w|). The targets along the axis (previous commit) matter here: without
them, small rules that cover only the peak were picked, off by up to 0.97
along the axis. In the m10 tables of the four kernels built this way, on
targets off the training grid, every entry loses at most 0.5 digits from 1
to 15 digits, and 1.0 digit at 16.

The selection uses three helpers in namespace detail_quad_tables:
QuadRuleIntegrals (the integrals of the training integrands with a rule),
QuadRuleErrors (the error of each candidate rule, relative to the largest
integral of its group of integrands, and the cancellation of its weights)
and FewestNodesQuadRule (the choice above).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ring rules come from the tables in double, for dist/r down to
2*pi*2^-29 (30 levels), and were built at run time in long double and
quad builds: dyadic panel rules, with one panel per level and 1.5*digits
Legendre nodes on each. These miss their digits for few digits (0.2 for 1
digit and 1e-2 for 3, Laplace double layer, m10) and at the first levels,
where the outer panels span several wavelengths of the higher Fourier
modes (5.5e-12 at m10, level 2, 15 digits), and they take many nodes: 432
at level 10 and 1344 at level 29 for 16 digits. Closer targets got the
rule of the last level, with a warning: in table mode the error reached
O(1) at dist/r 1e-9. A target on the loop (dist/r = 0) never ended the
loop that finds its level.

Replace the dyadic panel rules by sinh-mapped Gauss-Legendre rules: on
|theta| < h, theta = dlt*sinh(t) puts the near-singularities of the kernel
at height pi/2 in t for every distance, and one Gauss-Legendre panel in t
on [0, asinh(h/dlt)] resolves them; one more panel on h < |theta| < pi
resolves the Fourier modes. The node counts (SinhQuadRuleSize, in
namespace detail_ring_quad) are fitted to quad-precision sweeps over the
Laplace and Stokes single and double layers and the Stokes traction. The
rules built at run time use them at every level past the trapezoidal ones
(levels 0 and 1), and table mode past level 29. They are kept in memory
down to level max(30, SigBits-10) (RuleLevels): 42 in double, 102 in quad,
for targets at dist/r down to 2.9e-12 in double, 1.4e-15 in x87 long
double and 2.5e-30 in quad. Closer targets get the rule of the last level,
with a warning; in double, the rounding of the target position relative
to the loop already sets the error there (below). A target on the loop
gets the rule of the last level as well, with a warning.

CSBQ_SINH_RING_QUAD (0 by default) builds the ring rules at run time in
double builds too. They are always built at run time when Real is wider
than double (SinhRules), and the warm-up in SelfInterac now follows that:
in long-double and quad builds it loaded (or generated) ring tables that
were not used. LegendreQuadRule computes each order at its first call, up
to order 1023, instead of all orders below 50 at the first call.

The nodes of the sinh-mapped panels and the mirroring of a symmetric rule
are functions (SinhNode, MirrorRule, in namespace detail_ring_quad), and so
is the packing of a ring rule for the ring integrals (PackRingQuadRule),
which the rules from the tables use as well.

Accuracy, in quad against references from refined dyadic panels on a
curved, tapered ring (kappa*r = 0.05, dr/ds = 0.0125), levels 2 to 44:
every kernel at Nmodes 4 to 52 and 1 to 19 digits meets its digits with at
least 0.62 digits to spare; in a 50-digit model of the integrals, down to
level 101 with at least 1.84 digits to spare. In double, from level 25 on,
the rounding of the target position relative to the loop sets the error,
whatever the rule: for the double layers, 3.5e-7 at level 30 and 5.2e-4 at
level 41. With CSBQ_SINH_RING_QUAD in double, the worst error over the
kernels at 15 digits is 2.4e-15 at level 2 and 2.0e-7 at level 29.

At 16 digits and Nmodes 10, the rules have 150 nodes at level 10 and 228
at level 29. A quad build keeps 23 MB of rules for levels 0 to 29 instead
of 77 MB, and 103 MB more for levels 30 to 101 (Nmodes 10, one kernel; for
Nmodes 30, 84 MB instead of 223 MB, and 341 MB more). In double, levels 30
to 41 add 6.9 MB of rules for Nmodes 10 and 47 MB for Nmodes 52.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ables

The generalized Chebyshev rules of the ring tables take their nodes from the
discretization of the training integrands: dyadic panels with 35-point
Legendre rules. Every table entry keeps its innermost node, at 2.3e-3*dlt
from the nearest point of the loop (theta = 0). Its outer panels, a quarter
and a half of the loop, span several wavelengths of the higher Fourier
modes: the training integrals of tables with many modes are inaccurate at
the first levels (5e-9 at m30, level 2, 16 digits). Discretize instead with
the panels of the sinh-mapped rule for 19 digits and twice its nodes, since
the discretization integrates products of the integrands, but with one panel
in t on [-1, 1] across theta = 0, so that the closest node is at 3.9e-2*dlt.
The outer panel has nodes in proportion to Nmodes. The dyadic panel rule had
no other use left and is removed.

For the m10 tables of the four kernels, against tables from the dyadic
discretization: the same numbers of nodes and of negative weights. Digits
lost in quad on a straight ring, worst over levels 2 to 29, up to 16 digits
(and at 17 to 19 digits), dyadic -> sinh:
  Laplace single layer   0.45 -> 0.45  (1.32 -> 1.48)
  Laplace double layer   0.54 -> 0.95  (3.54 -> 3.95)
  Laplace gradient       0.41 -> 0.30  (2.41 -> 2.78)
  Laplace normal deriv.  0.52 -> 0.30  (2.43 -> 2.78)
  Stokes single layer    0.30 -> 0.28  (1.45 -> 1.51)
  Stokes double layer    0.86 -> 0.76  (2.56 -> 3.64)
  Stokes traction        1.04 -> 0.93  (2.73 -> 3.82)
In double, the errors of the two agree to 0.3 digits at every level, with
neither consistently smaller. The tables are generated in 85 to 258 s on
112 threads instead of 91 to 348 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
All 104 ring tables (toroidal_quad_rule_m*), built in quad precision by
the code of the previous commit: training targets on a polar grid,
entries chosen by measured accuracy and the sinh-mapped discretization.
They took 73 minutes on 6 nodes, the largest (Stokes, m52) 46 minutes on
32 threads. And the four tables for 65 Fourier modes: elements of
FourierOrder 126 (64 modes, 65 with the modal upsampling) need
toroidal_quad_rule_m65; without the file, CSBQ builds it at the first
call, which takes hours on one thread (28 minutes on 96 threads for each
Stokes kernel).

Checks in quad precision against references independent of the tables, on
targets off the training grid (digits lost: d + log10 of the error of the
d-digit rule, worst over levels 2 to 29):
- Ring tables on a straight ring at m10, for the Laplace and Stokes single
  and double layers, the Stokes traction, and the gradient and normal
  derivative of the Laplace single layer: at most 0.83 digits lost up to 15
  digits, and 0.95 at 16. Main's tables lose 7.0 to 13.4 digits up to 15.
- Double-layer ring tables on a curved, tapered ring (kappa*r = 0.05,
  dr/ds = 0.0125) at m4, m10, m20, m30 and m52: at most 0.59 digits lost up
  to 15 digits, and 0.79 at 16. Main's m52 tables are off by 0.6 at level 2.
  On this ring the single layers, the traction and the gradient level off at
  1e-10 to 4e-9: its area element has Fourier modes beyond those the tables
  are trained on.
- Layer potentials of a closed loop (lp-sweep, as in test/unit): at 1e-3
  and 1e-6 radii from the surface the errors follow the tolerance down to
  1e-10, where they are at most 3.3e-11 for Laplace and 1.1e-10 for Stokes.
  At a tolerance of 1e-7, Laplace: 6.6e-9 and 3.0e-9 (on main: 2.6e-6 and
  8.6e-4).

The tables were built with gcc 13.3 on AMD Rome nodes. Rebuilt by the code
of the self-interaction tables per number of Fourier modes later in this
series (gcc 11.5, AMD Genoa), all 108 are byte for byte these.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Building the self-interaction rules on the fly instead of reading the
tables took an edit of the default of adap_quad in SpecialQuadRule. Add a
switch for it, 0 by default, next to CSBQ_SINH_RING_QUAD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…than the tables

SpecialQuadRule has tables for length/radius from sqrt(2)*2^-7 to
sqrt(2)*2^30, and clamped the table index to that range. Longer elements got
the longest table, built for shorter elements, those up to sqrt(2)*2^31
without the warning (the index was rounded toward zero). Use the adaptive
rules for them, with a warning once per kernel. Shorter elements keep the
shortest table, now without the warning, which is not needed: along s, the ring-integrated kernel of a short
element is a log singularity plus a smooth part, as for the shortest table,
and edge elements of length/radius 4e-9 are accurate with it.

At 0 requested digits, the adaptive rule had Gauss-Legendre order 0 and
log-singular order 0: no nodes, so the self-interaction matrix was zero,
and nothing reported it. The orders are now at least 1 and 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nteraction rule

The adaptive self-interaction rule (CSBQ_ADAPTIVE_SELF_QUAD, and elements
longer than the tables) put its log-singular rule on an interval of 2r to 4r
around the target, next to the singularities of the ring-integrated kernel at
distance 2r, and missed its digits on long elements: 2.7e-11 at 15 digits and
2e-13 at 18 for the Stokes double layer at length/radius 1e6. Use 5 more
dyadic levels, and at least 4: the interval then extends less than r/8
and at most 1/16 of the element to each side of the target, and the errors
are about 1e-23 at 15 digits in quad precision.
(In long double and double, rounding errors of the double-layer kernel close
to the target dominate on short elements: 2.5e-10 at 15 digits for the
Laplace double layer at length/radius 0.05 in long double.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SpecialQuadBuildBasisMatrix integrates the training integrands of the
self-interaction tables with dyadic panels toward the target and, on the
innermost interval, a log-singular rule of order 16: exact for polynomials of
degree 7 times 1 and log s. That interval extended about
2^-(log2(L/r)+4) of the element to each side of the target: for short
elements most of it, where the degree-9 density basis is not resolved
(errors of 1e-9 at length/radius 0.05 and interior target nodes), and for
long elements r/16 to r/8 (1e-16 for the Stokes double layer at
length/radius 1e6). Use 4 more levels, and at least 8: the interval then
extends less than r/128 and at most 1/256 of the element to each side, and
the errors are 2e-22 or less.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d weight cancellation

The self-interaction rules are generalized Chebyshev rules, which interpolate
with as many nodes as integrands. 75% of the shipped rules have negative
weights, and a few have sum |w| up to 729 |sum w| (Laplace double layer, 12
digits, length/radius 3e6 to 6e6), which loses up to 2.9 digits to rounding.
When building the tables, keep for d digits the rule with the fewest nodes
that integrates the training integrands to 10^-d, relative to the largest
integral at each length, among those with sum |w| <= 2 |sum w|.

The selection uses the helpers of the ring tables (QuadRuleIntegrals,
QuadRuleErrors, FewestNodesQuadRule), with the integrands grouped by
length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s relative to the target's

The on-surface double layer stopped at about 10 digits at every
tolerance. The self-interaction matrix is well conditioned (rounded to
double, it gives 17-18 digits), but building it in double precision lost
digits in two places of SelfInteracHelper, and the double layer is
sensitive to them: an offset delta of the target from the source surface
changes it by about delta*r/z, where z, the distance of the closest node
of the rule, is about 3e-4 times the element length.
- The target angles came from repeated multiplication by exp(i dtheta),
  which drifts by up to FourierOrder roundings from the angles of the
  surface nodes. They now come from cos_theta/sin_theta, the tables
  GetGeom places the nodes with.
- The source radius at the quadrature nodes was the interpolant of the
  radius, which for a constant radius differs from the target's radius by
  roundings. It is now the target's radius plus the interpolant of the
  radius minus the target's, the way the coordinates are already
  interpolated relative to the target.

On one straight element (length/radius 0.177, FourierOrder 48, Laplace
double layer), digits of the self-interaction against quad precision:
10.32 before, 10.79 with the angles, 11.04 with both. On-surface error of
the paper's Gauss's-law check, digits before -> after (requested digits in
parentheses), measured with test hooks equivalent to this change:
  Laplace tangle  L5 10.37 -> 10.54 (13)   L6 10.19 -> 10.48 (14)
  Stokes tangle   S6 10.04 -> 10.29 (13)
  close-to-touching  C4 10.21 -> 10.94 (12)   C5 10.16 -> 10.94 (14)
The rows still miss: most of the remaining error is rounding inside the
ring integrals (computed in quad precision, the element above reaches
11.71), and targets at the junctions of neighboring elements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… trained on resolved densities

The self-interaction rules came from one table per kernel, trained on
Fourier modes 0-7 and used for elements with any number of modes. With
more modes they lost accuracy: for the Laplace double layer at
FourierOrder 48 (25 modes), the rules for 12 and 15 digits gave 10.95 and
13.48 digits (quad precision, worst over length/radius 1-181).

- Each kernel has four tables, for 9, 17, 33 and 65 Fourier modes
  (special_quad_q10_m<modes>_<kernel>, replacing special_quad_q10_<kernel>).
  An element uses the table with the fewest modes that has at least as
  many as the element. Elements with more than 65 modes use the adaptive
  rule, with the same warning as elements longer than the longest table.
  The unit tests check for the table the element uses.
- The rule for d digits is trained on densities whose coefficient of
  Fourier mode m is 10^(-d m/(M-1)), M the modes of the table: densities
  resolved to 10^-d at their highest mode. The error of a rule is the
  error for such a density with the worst signs of the coefficients,
  relative to the largest density integral at its length, instead of the
  largest error of a single mode. QuadRuleErrors takes the densities and
  their groups. The ring tables, whose densities are single integrands,
  do not change: all 108, rebuilt, are byte for byte those of the earlier
  commit.
- The rules for each d are built from the integrands weighted by these
  coefficients. So that the 19 builds stay affordable, the integrands of
  each mode are first reduced to Mintegrands_m Q^T, the rows of Q an
  orthonormal basis (Gram-Schmidt with row pivoting, to 1e-25 relative)
  of the rows of diag(sqrt(w)) Mintegrands_m.
- The closest node of a rule is at distance z = 1/(max(M-1,32)/r +
  1000/L) from the target (r the radius, L the element length) instead of
  min(0.03 r, 3e-4 L): on short elements about L/1000 instead of 3e-4 L,
  which loses fewer digits to rounding in double precision, and on long
  elements r/32 for up to 33 modes and r/64 for 65 modes. Other choices
  missed the requested digits for the Stokes double layer: in training,
  r/8 for 9 modes gave 12.54 digits for 15 requested, r/45 for 65 modes
  12.72 for 13, and L/500 on short elements 12.15 for 15; in the test
  below, the 65-mode tables built with the previous rule (r/33 on long
  elements) gave 10.50 digits for 15 requested at FourierOrder 126.

Fourier-order test: one straight element, length/radius 2^(j/4) for
j = 0..30, densities with Fourier coefficients 10^(-d k/kmax), worst over
the lengths, against the adaptive rule at 18 digits in quad precision.
- Quad precision (ring integrals at 19 digits), FourierOrder 16-126, all
  four kernels: at most 0.21 digits below the requested d at any d from 1
  to 15. At FourierOrder 16 and 32, at or above it for every d from 2 to
  15.
- Double precision, digits at d = 15, FourierOrder 16 / 32 / 64 / 126:
    Laplace single layer  14.66  14.63  14.53  14.40
    Laplace double layer  11.62  11.62  11.55  11.45
    Stokes single layer   14.50  14.41  14.23  14.12
    Stokes double layer   11.78  11.79  11.60  11.34
  With the tables of the previous rule (same training) at FourierOrder
  126: 13.19, 11.11, 11.93, 10.50.
- Mean nodes per target at d = 15: within 1% of the previous rule at
  FourierOrder 16 and 32, 2-5% more at 88 and 126.

Paper rows (Tables 3-5, error mode, 40 cores), against the tables of the
previous rule: the solution error is the same within 0.05 digits in 22
rows, higher in L4, Leta-1 and Leta-5 (by 0.14 to 0.19 digits) and lower
in Seta1 (by 0.08). The on-surface error is lower by 0.23
digits in S4 and the four Seta rows (9.47 -> 9.24, tolerance 1e-9) and
by 0.11 in C3 (8.83 -> 8.72, tolerance 1e-8), higher by 0.05 and 0.08 in
L2 and S5. The off-surface error is unchanged, and setup and solve times
agree within 3%.

Elements of length/radius 1.2e7 to 1.5e9 still miss in training with
the double-layer tables: for 13-15 requested digits, 12.33 digits at
worst with 9 and 17 modes; the 33-mode Stokes double layer misses from 5
requested digits on (11.46 for 12).

The tables are added in a later commit; without them, CSBQ builds them at
the first call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kernels without tables of their own made CSBQ generate them, in quad
precision, which is slow: Stokes3D_FxT (the traction) and Laplace3D_FxdU
look for ring tables under their own names, and with target normals for
"_dotXn" self-interaction tables, and none ship. They have the singularity
of the double layer: use the Stokes and Laplace double-layer tables, in the
ring rules, and in the self-interaction rules with target normals (on the
surface the normal derivative of the single layer is weakly singular like
the double layer, the full gradient is not). The choice is made at compile
time: QuadTableKernel gives the kernel of the ring tables, and
SelfTableKernel the kernel and target normals of the self-interaction
tables. The rest of ToroidalSpecialQuadRule and SpecialQuadRule, table
generation in quad precision included, is in the else branch, so it is not
compiled for these kernels. RequireQuadTables of the unit tests checks for
the tables CSBQ reads (RingTableFile gives the file of a ring table). On
the double-layer ring tables these kernels are as accurate as the double
layer itself. Laplace and Stokes keep separate tables: on Stokes
kernels the Laplace tables lose 2-3 digits near the surface.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 16 tables special_quad_q10_m<modes>_<kernel>, for 9, 17, 33 and 65
Fourier modes and the Laplace and Stokes single and double layers,
replacing the four special_quad_q10_<kernel>. They were built in quad
precision by the code of the previous commits; the 33- and 65-mode tables
by a run with z = 1/((M-1)/r + 1000/L), the same distance for these M, by
code that differs from this code only in that line. Rebuilt by this code,
the pieces of two length bins (length/radius 2^-3 and 2^-6) for every
kernel and number of modes are byte for byte those the tables were merged
from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t threshold

With the regenerated tables, the near-interaction at 1e-3 and 1e-6 radii
from the surface follows the accuracy tolerance like the other targets: at a
tolerance of 1e-10 the errors are at most 3.3e-11 for Laplace and 1.1e-10
for Stokes, within the default threshold of the test (ErrFactor, 20 times the
tolerance; the near-surface groups had thresholds of 200 and 1000 times).
The tolerance sweep (1e-4, 1e-6, 1e-8) now checks all targets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dmalhotra and others added 4 commits November 13, 2026 19:39
Brings in the BLAS and LAPACK calls through SCTL's own names, with the
integer width from SCTL_BLAS_INT or detected from the BLAS
(dmalhotra/SCTL#44), GMRES's Krylov basis in scratch memory and thread
teams for gemm, radix_sort and Tree (dmalhotra/SCTL#45), the near
interactions of BoundaryIntegralOp through SmallGEMM, with the parallel
loops through omp_par (dmalhotra/SCTL#46), and the constants of
BuildNearList and BoundaryIntegralOp in Real, so that Real = float builds
without -Wfloat-conversion warnings (was 4a0fbd9).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GetFarFieldNodes: the radius of the near region along the element is
multiplied by (e^x - 1)/x, where x is the angle the centerline turns per
unit s times the radius for a straight element (dist_far_gauss, in units
of s). Outside a bend, the near region of a circular arc in the thin limit
reaches that factor farther than for a straight element. The balls keep
their centers. The interpolation from the Chebyshev nodes to the far-field
Gauss-Legendre nodes, and its transpose, are cached per element order in
detail_far_field::ChebUpsample, which GetFarFieldDensity and
FarFieldDensityOperatorTranspose use as well instead of their own copies.

Checked in a model of the far rule:
- Circular arcs turning 10-180 degrees, thin limit: the balls miss 0.1-0.5%
  of the region where the far rule's error bound exceeds the tolerance,
  against 4-95% before.
- 290 elements of the paper geometries, smooth densities: the far rule
  meets the tolerance at every sampled target outside the balls. Before,
  5% of the elements turning 15-60 degrees and 24% of those turning more
  had targets outside the balls where it missed the tolerance, by up to
  0.56 digits. The volume of the near region grows by a median factor of
  1.09 for elements turning less than 15 degrees, 1.36 for 15-60 degrees
  and 1.60 for more (largest 1.25, 2.48 and 3.69).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… ellipse

With the points for rho = 2.5 and the requested digits on every panel of
the adaptive rule along the element, off-surface targets near an element
missed the requested tolerance for Stokes and for the close-to-touching
geometry: in the paper's Gauss's-law check (double layer of a unit
density, 100^3 cube grid), S4 reached 7.55 digits for 9 requested and C4
9.27 for 12.

NearInteracHelper: the rule keeps its walk, with Bernstein ellipse
parameter 3 instead of 2.5: a panel is accepted when the target's
distances to the nearest points of its two end cross-sections add up to
more than 5/3 of its length (1.45 before). Each panel then gets the
Gauss-Legendre points for its own ellipse, the one through the target:
- rho_panel = a + sqrt(a^2 - 1), a = (d0 + d1)/L, at most 9. For a long
  panel far from the target, the curvature and speed changes of the
  centerline over the panel limit rho instead.
- rho_panel is divided by 1 + 0.35 w. w is the length of the change of the
  unit tangent across the panel when the target is outside the bend, 0
  when it is inside: on the outside the singularities come closer than
  for a straight panel.
- The points bring the error estimate 64/(15 (rho^2 - 1) rho^(2n)) below
  10^-(digits + 0.5) instead of 10^-digits.
- A panel gets at most LegQuadOrder points, the count for the smallest
  rho_panel, which sizes the buffers.

The two disabled alternatives to the walk, dyadic panels toward the ends
of the element and toward the closest point of the centerline, are
removed: they used the same Gauss-Legendre rule on every panel, which the
walk no longer uses, and they were not run or tested.

Measured on the 18 problems of the paper's Tables 3-5 (medians over the
problems), together with the previous commit, against the same code with
the points for rho = 2.5 and digits+2 on every panel:
- Errors at the paper tolerance: on the surface the same to within 0.01
  digits; off the surface 0.79 (single layer) and 0.67 (double layer)
  digits smaller.
- 1-core setup time on Ice Lake at the error of that code: 13% shorter on
  the surface for both layers; off the surface 19% shorter for the single
  layer and 13% for the double layer. These times were measured with x of
  the previous commit computed from the speed of the surface point instead
  of the centerline; the errors of the two forms differ by at most 0.18
  digits on the 18 problems.
- On 36,270 sampled near targets, this rule uses 0.636 of the points of
  that code. 8 single-layer and 3 double-layer targets, of about 18,000
  each, miss the requested digits, by at most 0.24 digits.
The points for digits+2 against those for the requested digits, measured
on the 18 problems with the far-field distance for tol/10: with the points
for the requested digits, the off-surface error at the same tolerance is
0.71 (single layer) and 0.46 (double layer) digits larger, the off-surface
setup time to reach main's error 37% and 45% longer, and the on-surface
setup time 9% shorter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…test

No unit test evaluated the gradient of the Laplace single layer
(Laplace3D_FxdU) or the Stokes traction tensor (Stokes3D_FxT) near the
surface through BoundaryIntegralOp, with or without target normals; both
take the ring rules of the double layer. The layer-potentials test now
evaluates them at 1e-1, 1e-3 and 1e-6 radii from the surface of two
elements of the loop, on both sides (24 targets per distance), at
tolerance 1e-10, and with target normals the normal derivative and the
traction, with the normals of the surface at the points the targets are
offset from (OffSurfacePoints appends them on request). The reference is
the same layer potential at tolerance 1e-15 in long double where it is
wider than double (the ring rules are then built at run time, not read
from the tables), and in double otherwise. The checks use the default
threshold of the test, ErrFactor (20) times the tolerance.

Errors in digits against long double (gcc 13.3, x86-64):
                             1e-1 r  1e-3 r  1e-6 r
  Laplace gradient           11.41   11.48   10.59
  Laplace normal derivative  11.72   11.69   10.59
  Stokes traction tensor     10.95   11.12   10.25
  Stokes traction            10.71   10.95   10.04
Against quad precision the test takes 11-13 min. With long double it
takes 20.5 s instead of 3.1 s without these checks (one AMD EPYC 7742
node, 8 threads; 19.9 s and 3.0 s with 128 threads), of which the checks
with target normals add 0.4 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmalhotra dmalhotra changed the title Quadrature fixes: sinh-mapped ring rules, regenerated tables, switches, 18 digits Quadrature fixes: sinh-mapped ring rules, regenerated tables, per-panel near rule, 18 digits Nov 14, 2026
@dmalhotra
dmalhotra force-pushed the quad-fixes branch 2 times, most recently from a26be41 to 8ec2d4e Compare November 14, 2026 02:21
ToroidalSpecialQuadRule built the ring rules of every level for a number
of Fourier modes at its first call for that number. In long-double and
quad builds, and in double with CSBQ_SINH_RING_QUAD, these include the
sinh-mapped rules of all RuleLevels levels (53 in x87 long double, 102 in
quad) for 20 digit counts each, most of which no target reaches, and the
packed rules were kept together with their transposed Fourier matrices
until all were converted.

The levels below the sinh-mapped ones (the trapezoidal rules of levels 0
and 1, and in double the rules of the table file) are still built
together, at the first call that needs one of them
(BuildToroidalSpecialQuadRules). Each sinh-mapped level is built at the
first call that needs it (BuildSinhRingQuadRules, with the code that
built it before), with a ready flag for each number of modes and level.

The rules are bit for bit the same: a hash of the nodes, weights and
Fourier matrices agrees before and after, in long double and quad, for
every rule of 10 Fourier modes (every level and digit count) and for one
level of 30 and 66 modes. First call at one level (level
10, or 8 for 66 modes), Laplace double layer, one thread on AMD Rome,
time and peak memory of the process, before -> after:
  long double, 10 modes   0.14 s, 107 MB  ->  0.00 s,  4 MB
  long double, 30 modes   0.28 s, 359 MB  ->  0.01 s,  8 MB
  quad, 10 modes          10.6 s, 261 MB  ->  0.09 s,  4 MB
  quad, 30 modes          13.2 s, 837 MB  ->  0.14 s,  8 MB
  quad, 66 modes          19.0 s, 2.4 GB  ->  0.29 s, 18 MB
(66 modes: as when generating the 65-mode self-interaction tables.) All
levels in quad, 10 modes: 11.4 s either way, with a peak of 129 MB
instead of 261 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmalhotra
dmalhotra merged commit 5fd27b7 into main Nov 14, 2026
2 checks passed
@dmalhotra
dmalhotra deleted the quad-fixes branch November 14, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant