Repository navigation
Adaptive off-surface panels, field periods, run-time singular quadrature, repeated calls without allocations - #9
Merged
Merged
Conversation
…cients FitPanels starts from a 4 x 4 mesh in the grid parameters and splits each panel in half along the toroidal direction, the poloidal direction or both, until on every panel the last two Legendre coefficients along each direction of the surface coordinates, of their derivatives and of the densities are within the tolerance, relative to the largest value of each field. A panel is not split beyond 16 nodes per grid point, and the warning is printed if a panel at that limit is not resolved. The upsampling factors are chosen as before, for the finest panels. The uniform panels were chosen from the Fourier coefficients over the whole surface. For the current on the corrugated inner surface of the shell in test/bie-solvers.cpp, they gave an error of 5e-8 for a tolerance of 1e-10, without a warning; the adaptive panels warn on this grid, and reach 4e-12 with the fields upsampled 4 times. On the smooth outer surface of the shell the errors are 6e-11 (uniform: 2e-10), and on NCSX 2e-11 (uniform: 4e-11), with 1.6 to 3 times more panels than the uniform ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Legendre tails of X and its derivatives miss an area element |X_t x X_p| with branch points close to the panel, as near a sharp concave fold: on a torus with cross-section r = 0.25 (1 + 0.6 cos 6 phi), S[1] had an error of 2.4e-6 at tol 1e-10, with no warning. A panel is now also split along a direction when its area by the quadrature differs from the sum over its two halves along that direction by more than tol times the surface area; the halves are only evaluated, not kept. The error is now 3.7e-11; on NCSX the panels are unchanged. The finest panels have up to 32 nodes per grid point instead of 16, which the folds need at tol 1e-12. Adds the torus to test/boundary-integ-op, which fails with 2.4e-6 before this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lumns Upsample and Grad2D did each 2D transform with one FFTW plan on all threads, set up again on every call for Upsample. FFTW splits such a transform into teams of fewer threads, and libgomp ends the threads that a team smaller than the one before does not use and creates them again for the next larger team: 4.6 ms per change of team size on 92 threads, against 16 us for a region on all of them. On the W7-X grids on 96 threads the transforms took 5 to 19 ms, and up to hundreds of ms when the threads had to be created again. The 2D transforms are now 1D transforms of the rows, 8 at a time, and of the columns, 4 at a time (one cache line of complex values), by one thread each, from loops on all threads, or on one for fewer than 8192 points. The plans are on one thread and set up once. Only the columns that the result keeps are transformed, and Grad2D takes the derivative along the rows from the transforms of the rows alone. Upsample to the same grid is a copy, as the transforms gave X0 back exactly there. On the W7-X grids (96 threads, median of 21 calls): Resample X, dX/dt, dX/dp to 1536 x 256 10.1 ms -> 0.47 ms Resample F to 3584 x 256 18.8 ms -> 0.32 ms Grad2D of X on 3584 x 256 12.7 ms -> 0.73 ms On one thread they are 25 to 35% faster than the 2D plans. BoundaryIntegralOp with UPSAMPLE = 1 now uses the density as given instead of transforming it to the same grid and back on every evaluation, 14 to 94 ms on the W7-X quadrature grids on 96 threads. FieldPeriodBIOp::Eval takes its buffers from the scratch pool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… to the next thread made Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… bytes The Lagrange interpolation from the patch grid to the polar grid, about two thirds of the per-target setup, loads 8 values at a time from M_G2P with AVX-512. Its rows of 12 values are 96 bytes, so where M_G2P starts decides how many of these loads cross a cache line: half if it starts on a 64-byte boundary or 32 bytes past one, all if 16 or 48 bytes past one. M_G2P was a std::vector, which glibc aligns to 16 bytes only: a block this size gets its own mmap at 16 bytes past a page, and after earlier frees have raised the mmap threshold it comes from the heap at an offset that depends on all that was allocated before. So each program and each kernel class ran its setup at one of two speeds, unrelated to the code changes around it. On W7-X, one thread (time of the correction setup in the quad-grid refinement, the same with M_G2P moved to each 16-byte offset by hand): M_G2P mod 64 0 16 32 48 digits 8 17.9 s 21.0 s 17.8 s 21.0 s The tables (qx, qw, Gpou_, Ppou_, I_G2P, M_G2P, HedgehogWts_) are now sctl::Vector, and the setup takes the faster time: at digits 12, 158 s instead of 180 s in a fresh program. The results are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Lagrange weights from the patch grid to a polar point are the products of 1D weights along the two directions of the patch, a_i0 b_i1. W_G2P now holds these 2 x 12 values for each point instead of the 12 x 12 products of M_G2P: 0.18 MB instead of 3.3 MB for PATCH_DIM0 24, RAD_DIM 38, and 0.42 MB instead of 7.5 MB for 36, 57, small enough for L2. The interpolation of X and its derivatives to the polar grid takes three components at a time: the rows of the window scaled by a and summed, in vectors, then the dot with b in one vector reduction, instead of a chain of scalar additions for each component. The vectors are of the widest length up to the native one that divides the 12 values of a row (4 with AVX2 and AVX-512), so that rows are whole vectors: on AVX-512 this is faster than 8 values with a partial second vector. From the polar grid back to the patch grid, each row of the window gets a_i0 times b (x) v, the KDIM1 values v of the point, in vectors. The per-target singular-correction setup is about 2 times faster. W7-X, Laplace gradient (FieldPeriodBIOp::SetupSingular): digits 8, one thread 48.4 s -> 25.7 s digits 12, one thread 158.4 s -> 88.1 s digits 8, 96 threads 0.73 s -> 0.33 s digits 12, 96 threads 1.99 s -> 1.41 s SmallGEMM, with its own loop or with LIBXSMM, was no faster than the loop before: each product is 1 x 12 by 12 x 12, one for each point and component. The results change at the level of rounding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The panels now depend only on the surface: the Legendre tails of X and its derivatives, and the area test. Setup ignores F, which is kept for compatibility, and the callers no longer pass it. Eval no longer refits the panels for a density they do not resolve; the density only sets its own FFT upsampling before the local interpolation to the nodes. One setup thus serves every density, as in a GMRES solve. FitPanels interpolates to the nodes of each panel and of its halves and runs the tests in one pass per toroidal interval, in per-thread scratch buffers, with the grid rows extended periodically so that the inner loops need no modulo. It keeps only X at the nodes of the panels, which becomes the coordinates of the QuadElemList, with the poloidal nodes reversed if the normal points inward; BuildPanels no longer interpolates X again. The LocalUpsample FFTs run on one thread, and the buffers of FitPanels and InterpToNodes come from the scratch pool. W7-X, near targets, FitPanels (1 / 96 threads): tol 1e-4 103 ms / 33 ms -> 18 ms / 16 ms tol 1e-8 2.09 s / 98 ms -> 0.21 s / 35 ms tol 1e-12 6.21 s / 153 ms -> 0.56 s / 34 ms and the whole off-surface setup at 1e-12: 10.9 s / 305 ms -> 4.42 s / 129 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lumn transforms FourierMultiply multiplies the Fourier coefficients of a function by a factor, with the cached 1D transforms of rows and columns. SpectralInvLap, the preconditioner of InvSurfLap and GradInvSurfLap, uses it, with the lengths Lt and Lp computed once rather than at every application and no 2D FFTW plans made at every call; so does RotateToroidal, with the rotation factors precomputed. RotateToroidal agrees with the old one to 5e-16, odd grids included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…parallel The coefficients of the rows by RowsR2C and the fine rows by RowsC2R; the errors of the local interpolation of each mode cached per stencil and grid size (ModeErrors); the error loop in parallel over rows and chunks of points, without a modulo; GridLines in parallel. 2-3x faster on 1 thread, 7-13x on 96 (0.65-2.4 ms -> 0.07-0.35 ms). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The double-layer test refined to a grid and then set up a finer one, rounded to the aspect ratio of the surface, which it never tested: at digits 12 it tested 2816x256 and set up 3584x256, for the same error. Now each grid is finer by the factor that the error predicts for digits+1 digits, at most three tests, stopping when the factor is below 1.5, and the last grid tested is the one set up: at digits 12, 2816x256, eval 0.194 s -> 0.158 s on 96 threads, error 1.34e-11 -> 1.35e-11. BoundaryIntegralOp::Upsample calls SurfaceOp::Upsample. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GMRES applies SurfLap and ProjZeroMean at every iteration of InvSurfLap and GradInvSurfLap, and each new temporary of that size was new memory for the threads to fault in. SurfGrad, SurfDiv, SurfLap, SurfCurl, ProjZeroMean and the operator of InvSurfLapPrecond now take theirs from ScratchBuf, and SurfGrad reads dX and the derivatives where they are, without the copy of dX and the three transposes. On 96 threads, the inner solves of the table 7 subset: 8.4-21.5 s -> 4.1-7.0 s, page faults 560-606k -> 290-337k (7.8-8.5 s -> 3.7-4.1 s with interleaved memory, without NUMA balancing). The results are the same to rounding. Sx, the output that the operator gives RightPrecond, now holds the values left in scratch memory, so it is set to zero first, for a RightPrecond that adds to its output (the single layer of BoundaryIntegralOp::test_Precond, src/table4.cpp). It is set to zero in parallel: with SetZero, the spectral solve of GradInvSurfLap on QAS3 took 9-10% longer at 96 threads on grids of 1575x315 and 2625x525. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…emory, SmallGEMM sums over k in parts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-local static; ModeErrors: a static map The correction of each target, a product of 1 x KDIM0 Ngrid and KDIM0 Ngrid x KDIM1, was a call to BLAS dgemm, which in OpenBLAS allocates in every call: on 96 threads, a pass of W7-X 560 x 112 (<15,30>; the vacuum field and the Taylor state) went from 5.96M to 0.75M allocations with SmallGEMM, and EvalSingularCorrection from 1.82 s to 1.72 s. The static tables are now one struct built on first use as a function-local static, which C++ constructs once also when threads set up at once (the checks of InitPrecomp outside its critical sections were a race), and which is destroyed at exit before the memory manager of SCTL, constructed before it: with SCTL_MEMDEBUG, its leak check no longer reports the tables, nor the cache of ModeErrors, now a static map rather than one never freed. The size of the work buffer of Setup is the constant WorkBuffSize. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SingularCorrection::Setup builds two kernel matrices for each target from a parallel loop, and in libgomp every nested parallel region, even of one thread, allocates its team: 2 allocations for each target, and 3.8 us for each region. Inside a parallel region the matrix is now built serially, which omp_in_parallel() tells at 2.8 ns: in the pass of W7-X 560 x 112, SetupSingularCorrection 752,646 -> 6 allocations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e solvers The temporaries that the operators of the solvers make at every GMRES iteration are in scratch memory: the upsampled density of BoundaryIntegralOp, those of EvalSurfInteg and EvalSingularCorrection, the work buffers of SetupSingularCorrection, the upsampled grids of InvSurfLap and GradInvSurfLap, the right-hand sides of InvSurfLapPrecond and the integrals of ProjZeroMean. The solution of InvSurfLapPrecond's GMRES, which GMRES sizes, is kept from one call to the next on each thread with its capacity. SpectralInvLap returns a struct, and InvSurfLapPrecond takes its preconditioners by reference and gives GMRES an operator of two pointers, so that the std::functions hold their lambdas themselves rather than allocating them. SurfNormalAreaElem flips the normal in place, and BoundaryIntegralOp's setup reads the coordinates of a surface without a copy. With the solver objects of the next commit, a steady-state pass of W7-X 560 x 112 on 96 threads makes 84 allocations, all of them once per Compute (1,039 before the last four of these changes), and 8-24 page faults. SFproj and InvLapF_, the outputs given to the preconditioners outside GMRES, are set to zero first, as Sx in the operator, for preconditioners that add to their outputs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…call to the next The static Compute() sets up the boundary integral operators for each call and frees them after, so that a code that solves again and again (an optimization of the surface) allocated and page faulted their singular corrections, 13 and 28 (2 PATCH_DIM0 + 1)^2 values for each grid point, in every call. An object now holds the operators, and its Compute() sets them up for the surfaces it is given in the memory of the call before when the surfaces have no more grid points. The static Compute() is that of an object made for the one call. On 96 threads, a steady-state pass of W7-X 560 x 112 (the vacuum field and the Taylor state) with the objects kept: 118 page faults, against 13,560 with the static Compute(). The temporaries of the GMRES operators of the solvers are in scratch memory. The test compares the objects with the static Compute() over three surfaces, the second one smaller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the grid points of another The potential of a surface at the grid points of another was the trapezoidal rule only, whose error is about exp(-2 pi d / h) at a distance d for a grid spacing h. SetupSingular now finds the targets within (log(1/tol) / (2 pi) + 1) local grid spacings of a grid point of the surface and sets up OffSurfaceOp for them (with a kernel that is an SctlKernelFunction); the other targets keep the trapezoidal rule. It takes the tolerance as a last argument, 1e-10 by default, and the solvers give it 0.1 gmres_tol. For two tori 0.1 apart (0.75 toroidal grid spacings), against EvalOffSurface at 1e-12: the single layer 3.4 digits -> 13.2 and its gradient 1.8 -> 11.2. With a gap that varies around the torus, every tolerance from 1e-4 to 1e-12 is met, by 0.4 to 1 digit. On 96 threads, the first three runs of table 6: the errors the same within 0.02 digits and 13% more time; the solver tests 27% more, as in their shells all the grid points are near the other surface, where the panels have more nodes than the grid has points. The corrugated shell of bie-solvers.cpp: toroidal flux error 2.3e-3 -> 4.3e-3 on 96 x 64, from the corrugated surface, which its grid does not resolve, and 5.4e-5 -> 5.5e-5 on 288 x 192. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The operators were kept from one call of Compute() to the next, but the vectors of the solve were made again in every call: the geometry of each surface, the fields of each solution, the GMRES solutions, and temporaries made by expressions such as B_[0] * tor_flux / tor_flux_[0], by lambdas that captured vectors by value, and by std::functions whose lambdas did not fit in them. The object now keeps the vectors with their storage, the temporaries are in scratch memory, and the operators of GMRES are lambdas of one reference; also those of SurfaceOp::HodgeDecomp and OuterInnerSurfIdx. A kept GMRES solution is emptied before a solve, so that the initial guess is zero as before. On 96 threads, a steady-state pass of W7-X 560 x 112 (the vacuum field and the Taylor state): 84 -> 3 allocations, which are the output vectors B and J, made new in every pass by the benchmark, and 8 page faults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n surfaces The tutorial of the solvers shows the objects that keep their operators from one call to the next, with a new example, doc/examples/repeated-solves.cpp. The algorithms describe the near quadrature for the potential of a surface at the grid points of another, and the tutorials of the shell and of the layer potentials point to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A surface can declare NFP toroidal field periods: SetNFP(NFP) checks that NTor() is a multiple of NFP and that the coordinates are invariant under the rotation by 2 pi / NFP about the z-axis (HasSymmetry(), to 1e-10 relative to the largest coordinate by default), and NFP() returns it, 1 by default. The constructor Surface(NFP, Nt, Np, X) builds the full torus from one field period, and FieldPeriodBIOp::BuildSurface returns that surface. The predefined shapes do not declare theirs: W7X, W7X_ and Stell have 5, Quas3 and the rotating ellipses 3, LHD 5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FieldPeriodBIOp took one surface. It now takes several, with the field periods common to all (the greatest common divisor of their Surface::NFP()): the potential on a grid of one field period of each surface, the densities of the surfaces one after the other, on one field period (completed by symmetry) or on the full tori, and on the quadrature grids without resampling by operator(). Each surface gets its own quadrature grid, chosen from digits for the surface alone as before, with the patch size from the largest anisotropy of the surfaces. The kernel keeps its type, so that the potential of a surface at the targets of another uses the near quadrature of BoundaryIntegralOp, to 10^-digits. A variant, SetupSingular<UPSAMPLE,PDIM,RDIM>(Svec, ker, tol), takes the quadrature of BoundaryIntegralOp<Real,KDIM0,KDIM1,UPSAMPLE,PDIM,RDIM> instead, with the targets at the grid points of one field period, and a later setup reuses the operator and its memory. For two tori with 3 field periods 0.1 apart: the potential of the variant equals that of BoundaryIntegralOp on one field period, also with the density given on one period (2.7e-16), and with 8 digits the double layer of a constant density meets its identity to 2.7e-9 (8.6 digits). The single-surface interface is unchanged, and the field-period example gives what it gave before; its output in the tutorial was out of date. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the surfaces declare field periods (Surface::NFP()), the solvers solve on one of those common to all of them: the operators are FieldPeriodBIOp, with the quadrature of the template parameters (SetupSingular<UPSAMPLE,PATCH_DIM0, RAD_DIM>), their targets and the unknowns of GMRES on that period, and the densities completed to the full tori by the symmetry (a Cartesian vector, and the real and imaginary parts of a complex one, rotated). The geometry, the harmonic fields and the Laplace-Beltrami solves of TaylorState stay on the full tori, and the results are on the full tori as before. Without declared field periods, the results are those of before. On one of 5 field periods, the fields of the tests equal those of the solve on the full tori to 4e-13 to 1.1e-12, for one surface and for a shell. On 96 threads, W7-X 560 x 112 with the solver objects kept (the vacuum field and the Taylor state, <15,30>, GMRES tolerance 3e-4): 15.3-15.6 s -> 4.7-4.9 s for a steady-state pass, the vacuum field 1.04 s -> 0.27 s, and 19.6 GB -> 4.1 GB of peak resident memory; the fields agree to 2.5e-11 and 1.0e-11. The Taylor state gains less, as its Laplace-Beltrami solves are on the full torus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ons of BoundaryIntegralOp with it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…; VacuumField, TaylorState: the Laplace-Beltrami solves on it The operators differentiate only the metric and the components of vector fields along the tangent vectors, which repeat from one field period to the next. The orientation of the normal is taken from the grid point farthest from the z-axis. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nodes that the grid resolves; the coordinates relative to the target The Lagrange interpolation goes to 2m+1 equispaced angles on each circle of the polar grid, m = ceil(pi rho R) + 6, and the trigonometric interpolant of those gives the values at the angles of the polar grid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…emplate parameters PATCH_DIM0 and RAD_DIM The patch radius and the numbers of radial and angular nodes of the polar grid are given, or chosen from the tolerance and the anisotropy of the grid (SingularCorrection::QuadParams, GridAnisotropy). The setup of the singular quadrature moves from SurfaceOp to SingularCorrection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ature tables and the temporaries kept OffSurfaceOp fits its panels in SetupSurface() and sets up the operator for the targets in SetTargets(), only for other targets; BoundaryIntegralOp, ExtVacuumField and IntVacuumField keep their operators of EvalOffSurface(). SingularCorrection keeps the tables of its last four quadratures, FieldPeriodBIOp the operator of its test of the quadrature grids, and VacuumFieldBase the field of the unit current. The temporaries are in scratch memory, and the transforms of SurfaceOp on one thread run without a parallel region. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…egralOp's evaluation without regions of one thread Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…llel region when it would have one thread The loops run through sctl::omp_par::parallel_for: with one thread, the repeated EvalOffSurface of BoundaryIntegralOp makes no allocations, where libgomp made 32 (the teams of the regions). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The loops of SurfaceOp, SingularCorrection, the solvers, the near lists of BoundaryIntegralOp and OffSurfaceOp's panel fit run through sctl::omp_par::parallel_for and parallel_reduce, and the kernel matrices and evaluations are serial also where a region would have one thread (sctl::omp_par::one_thread). With one thread, SingularCorrection::Setup opened a region in KerWrapper::BuildMatrix twice for each target from inside its own region of one thread, which is inactive: libgomp allocated the team of each. The repeated setups and solves now make, with one thread, the allocations they make with 16 (none for the repeated SetupSingular, VacuumField::Compute and TaylorState::Compute). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ion of the sums of a group of rows Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in parallel On 96 threads, the build of the tables went from 2-13% of a first setup to 0.3-3.5%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… nvcc fixes dmalhotra/SCTL#46. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… at run time; sctl::Tensor for biest::Mat - FieldPeriodBIOp<Real, HedgehogOrder> is the public class for layer potentials, without the COORD_DIM, KDIM0 and KDIM1 parameters: SetupSingular from a tolerance and SingularQuadParams, or for the field periods of a surface; Eval and the new EvalOffSurface with the number of field periods and the source grid of each surface. BoundaryIntegralOp, the operator on full tori, is internal to boundary_integ_op.txx, with its tests and near-interaction classes. - The upsampling of the quadrature grid is chosen at run time, by SingularQuadParams::upsample_t and upsample_p or by SingularCorrection::QuadGrid() from the tolerance and the anisotropy of the grid, in place of the UPSAMPLE template parameter of BoundaryIntegralOp, VacuumField and TaylorState. SingularCorrection::Setup takes the target spacings skip_t and skip_p in place of TRG_SKIP. - biest::Mat (mat.hpp) is removed, sctl::Tensor in its place. - Explicit capture lists in place of [&]; kernels without normals are given nullptr as their normals. - VacuumField::EvalOffSurface takes tor_flux, pol_flux and a J for each surface in place of J0. - The tests, programs, tutorials and documentation for this interface. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e density as well as the surface - OffSurfaceOp::Setup and SetupSurface take an optional refine, fields on the grid of any number of components (e.g. the density, or the right-hand side of a linear system) that the panels must also resolve. They are used only to fit the panels, and are not stored. - FieldPeriodBIOp::SetupSingular (both overloads) takes an optional refine: it sets the least quadrature grid of the singular part of each surface, and the panels of the near quadrature between surfaces. - BoundaryIntegralOp::EvalOffSurface fits the panels to the density, the vacuum-field classes to B.n, sigma and J, and the solvers of bie_solvers.txx to their densities. - SingularCorrection::InterpOrder(), the order of the interpolation for a patch radius, is public. - The documentation of the singular quadrature for these fields. With panels fit to the surface alone, the off-surface evaluation of the rotating ellipse of virtual-casing reached 1.9, 3.3 and 3.6 digits for 3, 6 and 9 requested; with the density it reaches 3.7, 7.3 and 10.6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dmalhotra
force-pushed
the
adaptive-panels
branch
from
November 9, 2026 13:09
30b1aa8 to
c82ed83
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.
Adaptive quadrature panels for off-surface evaluation, field periods, singular quadrature chosen at run time, and repeated calls without heap allocations.
Changes
New features
OffSurfaceOp:FieldPeriodBIOp::SetupSingularalso chooses the quadrature grid of the singular part and the panels of the near quadrature between surfaces to resolve them.VacuumFieldandTaylorStatepass B.n, sigma and J as these fields, and the solvers ofbie_solvers.txxtheir densities.Surfacecan declare its field periods (b53b1c1).FieldPeriodBIOptakes several surfaces and a given quadrature (93eada0).VacuumFieldandTaylorStatesolve on one field period (3ddd4e5).SurfaceOpworks on one field period, with the operators in the intrinsic form, so the Laplace-Beltrami solves also run on one period (d17479f).VacuumFieldandTaylorStateobjects keep their operators and solve vectors from one call to the next (f4d4269, 84e749c).Quadrature
FieldPeriodBIOpsets up the last quadrature grid it tested, instead of an untested finer one (dccd19b).Speed
SurfaceOpupsamples, differentiates, preconditions and rotates with 1D transforms of rows and columns, instead of 2D FFTW plans (86109de, 2d2e731).OffSurfaceOp's upsampling estimate uses row transforms and runs in parallel (5987101).Memory and allocations
SingularCorrectionkeeps only the tables of its current quadrature (2d9ac71).Other
b4bfa0b, the merge of SmallGEMM one-column kernel; parallel loops through omp_par; warning and nvcc fixes SCTL#46 into SCTL master.Interface changes
FieldPeriodBIOp<Real, HedgehogOrder>is the one public layer-potential class, without theCOORD_DIM,KDIM0andKDIM1parameters.BoundaryIntegralOp, the operator on full tori, is internal toboundary_integ_op.txx(63fae2a).FieldPeriodBIOp::SetupSingulartakes a tolerance and aSingularQuadParams, or the field periods and grids of a surface, and optional fieldsrefine(c82ed83);Evaland the newEvalOffSurfacetake the number of field periods and the source grid of each surface.SingularQuadParams::upsample_tandupsample_por bySingularCorrection::QuadGrid()from the tolerance and the grid anisotropy, in place of theUPSAMPLEtemplate parameter ofBoundaryIntegralOp,VacuumFieldandTaylorState(63fae2a).SingularCorrection::Setuptakes the target spacingsskip_tandskip_pin place ofTRG_SKIP.biest::Mat(mat.hpp) is removed;sctl::Tensorin its place (63fae2a).VacuumField::EvalOffSurfacetakestor_flux,pol_fluxand aJfor each surface in place ofJ0(63fae2a).SingularQuadParams(patch radius, radial and angular nodes, or 0 to choose from the tolerance) replaces the template parametersPATCH_DIM0andRAD_DIMofBoundaryIntegralOp,FieldPeriodBIOp,VacuumFieldandTaylorState.OffSurfaceOp::SetupandSetupSurfacetake optional fieldsrefineon the grid, of any number of components (e.g. the density), that the panels must also resolve; they are used only to fit the panels, and are not stored (c82ed83).SetupSurfaceandSetTargetsset up the panels and the targets separately.SurfaceOpconstructor takesNFPand the toroidal orientation, for one field period.Surfacedeclares its field periods (SetNFP,NFP, and a constructor from one field period).VacuumFieldandTaylorStatecan be used as objects; the staticComputeremains.EvalOffSurfacetakes its targets by reference.Results
At tol 1e-12 the folded torus gets 11.4 digits, a miss of 0.6 digits, because the errors of the panels add up.
SetupSingular, the operators,EvalOffSurface(same targets),VacuumField::ComputeandTaylorState::Compute.ExtVacuumField's routines make 1-3 per call, mostly thestd::vectors they return.Tests
surface-op,boundary-integ-op,bie-solversandvacuum-field), at 12 threads on an AMD EPYC 9474F node, with the SCTL of that commit.f2e0e63(the same files asb4bfa0b): all 22 programs build without warnings; the four tests (23, 24, 26 and 8 checks) and the seven documentation examples pass at 32 threads, with output identical to SCTLa0f7eaf.🤖 Generated with Claude Code