Repository navigation
Vacuum - BUGFIX - Accurate near-singular integration for walls closer than one grid cell or with arbitrary parametrization - #682
Open
jhalpern30 wants to merge 11 commits into
Conversation
jhalpern30
force-pushed
the
bugfix/vacuum-close-wall-split
branch
from
November 18, 2026 20:13
aa37dd0 to
e43819f
Compare
jhalpern30
marked this pull request as ready for review
November 18, 2026 20:31
…nd keep the splines on the geometry No change in method. PlasmaGeometry and WallGeometry carry their periodic splines and θ-derivatives (`periodic_splines`), so the kernel no longer builds them per call; `curve_point` gives the point and tangent at any θ. The row loop splits into `simpson_nodes` + `add_regular_sum!` and `add_singular_panels!`, each called with a per-observer `kernel` closure. `lagrange_weights` (Utilities, coefficients tabulated so no division runs per call) builds the GL8 panel stencils, and the 8-point rule becomes two SVector constants. Checked: 3D outputs bit-identical; 2D Wᵛ and kernel blocks within 2e-15 relative (round-off of the tabulated stencils).
… in the 2D kernel The singular Gauss panels sat at source index j for observer j, which is the closest source point only when the wall shares the plasma's node placement. A misaligned wall (equal_arc_wall, wall files) closer than a node spacing gave O(1) errors in Wᵛ. Each row now takes one of three paths. Same surface: Simpson plus the singular panels, unchanged. Plasma–wall rows within NEAR_GAP = 4 node spacings: Simpson plus ±6 node intervals about the closest point (`closest_point`, Newton on the spline from the nearest node; `add_near_window!`), each split at it, on sinh-graded GL8–GL64 nodes (`sinh_rule`, `sinh_nodes`: Johnston & Elliott 2005, which follow a kernel peak of width ε) with the density from the 5-point Lagrange stencil. Other plasma–wall rows: the periodic trapezoidal rule, which is spectral on their smooth integrand. WallGeometry throws if the wall touches or crosses the plasma and warns when the gap is under a tenth of a grid cell, as WallGeometry3D does. The test helpers that repeated the 2π seam point (a kink the production VacuumInput never has) now exclude it. Checked: same-surface rows and all 3D outputs bit-identical; only plasma–wall rows change (Wᵛ by up to 1e-5 relative on a Solov'ev 128 close wall).
…stencils in place of the P2G matrix Prepares the close-wall fix, which needs the polar patch at an off-grid centre. The stored interpolation matrix (SingularQuadratureData: P2G, Ppou, Gpou, its cache and lock) and the polar buffers go. `near_correction!` now interpolates each polar node with its own Lagrange stencil, scatters its weight back by the same stencil, folds the patch onto the row (`fold_patch_to_row!`) and subtracts the trapezoidal sum it replaces. Per-call setup lives in `SourceQuadrature` (shared by all threads, beside the per-thread `KernelWorkspace`) and each row in `kernel_row!`. The patch pieces live in Utilities for reuse by off-surface field evaluation: `SurfacePoint`, `patch_pou`, `patch_stencil`, `interpolate_patch`, `foreach_polar_node` (radial weights hoisted out of the angle loop). Plasma–wall rows still centre the patch at the observer's index, as before. Checked: 2D bit-identical; 3D Wᵛ and kernel blocks within 3e-12 relative of the P2G path, same time (Solov'ev 40×52 close wall 0.48 s → 0.49 s).
… sinh-mapped radial nodes on plasma–wall rows Plasma–wall rows centred the singular patch at the observer's grid index on the other surface, which is the closest point only for a conformal wall on the plasma's grid, and used Gauss–Legendre radial nodes that miss the double-layer peak once the gap falls below about half a node spacing (O(1) error at 0.05 h). Plasma–wall rows now centre the patch at the closest source point (`closest_source_point!`, Gauss–Newton on the patch interpolant, `closest_point`, re-centring the patch as it moves) with radial nodes on ρ = ε sinh(μt) [Johnston & Elliott, IJNME 62 (2005) 564], which tends to the plain rule for far walls. Same-surface rows are unchanged. WallGeometry3D now warns below a tenth of a cell instead of one cell. Checked: same-surface rows and no-wall Wᵛ bit-identical; close-wall Wᵛ changes by up to 14 % (Solov'ev 32×40, 5 % standoff) and 10 % (nfp = 3 stellarator).
…polate plasma–wall rows at order 9 Plasma–wall rows more than NEAR_GAP = 4 node spacings from the source keep the trapezoidal rule alone, as in 2D (error ∝ exp(-2πd/h), ~1e-11 there). The rest interpolate at order min(INTERP_ORDER, 9), which matches 11 on those rows at 2/3 the cost. Checked: no-wall unchanged; close-wall Wᵛ within 1e-5 relative (raw plasma–wall blocks within 4e-4 of their max); Solov'ev 40×52 close wall 0.55 s → 0.51 s.
… normal
`laplace_kernel(x, y, n)` in place of nine scalars, written by component so `@fastmath` cannot reorder the sums.
SourceQuadrature stores the collocation points and normals as separate SVector{3} vectors.
…CELLS, and split the far-row screen out of the closest-point search Comments only, plus behaviour-neutral tidies: MIN_WALL_GAP_CELLS replaces the two literal 0.1 gap checks, nearest_source_node screens far plasma–wall rows before closest_source_point!, near_correction! is renamed add_near_correction!, and populate_greenfunction is derived from the source type instead of stored.
…s of the sinh variable (was 4) With RAD_DIM per 4 units, rows at gaps of 0.3–1.3 cells got a single RAD_DIM block over Δs ≈ 2–4 and under-resolved the partition-of-unity edge, the worst regime of the closest-point correction. Per 2 units (cap 8 blocks) cuts the Solov'ev conformal-wall error at s = 0.12 from 2.8e-4 to 1.3e-5 (40×60) and 2.2e-6 to 2.3e-7 (60×90), unchanged at smaller gaps, no measurable cost.
jhalpern30
force-pushed
the
bugfix/vacuum-close-wall-split
branch
from
November 23, 2026 21:10
e43819f to
3992537
Compare
…-field vacuum evaluation NEAR_SINH now takes 8 nodes per unit of the sinh variable (was per 2 units), so the close-wall kernel and the off-surface field evaluation can share one rule. Plasma–wall Wᵛ moves to the refined-rule reference to round-off (the old rule left up to 1e-10) for ≤ ~3 % solve time at allowed gaps.
This branch has not been deployed
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.
The human-written summary here:
As previous diagnosed in 2D, the vacuum calculation breaks for extremely close walls + equal arc parametrization - this PR implements some numerical method tricks from related applied math applications to enable extremely close conducting walls (at least 0.1x the grid spacing) and with arbitrary parametrization (which should help for interfacing with machine wall files).
It does this through two ways:
In addition, I did a refactor of the codebase, extracting a lot of subfunctions out to make things more clear (which is why this PR appears large). The commits are structured into cosmetic, physics changes, and optmizations for easier review. The code is optimized such that this addition costs a small fraction of runtime increase. A new addition to this is also that the plasma-wall cross surface integral uses the trapezoidal rule for a wall more than 4 grid spacings away, which is accurate because there is no peak to resolve and faster since no singular quadrature is applied. Both 2D and 3D are now clearly structured as
Stacked on #673 (base
feature/vacuum-3d-high-order).Release note
wvmoves only when a wall lies within 4 cells of the plasma. Below 0.3 cells the old values could be wrong by order one. Runs with no wall are unchanged to ≤ 3e-13.MIN_WALL_GAP_CELLS). Refine the grid when you see it.Close conducting walls now give the right vacuum response. On a Solov'ev plasma with a conformal wall at 80×120, the 3D result matches the 2D reference to ≤ 1.1e-6 down to a 0.7 mm gap (0.01 cell); the base was at 100% error there. W7-X with a wall at standoff 0.02 goes from 51% to 3e-5.
Summary
Review package with figures: https://claude.ai/artifact/FjEQx3vh2rUafMB8T25icc
When the wall is closer than about one grid cell, the double-layer kernel on a plasma–wall row is a spike of width d (the gap) around the wall node's closest point on the plasma. The base rule missed it twice. Its patch was centred on the same-index plasma node rather than on the closest point, and its Gauss–Legendre radial nodes had none inside the spike.
Kernel3D.jl): plasma–wall rows centre the polar patch at the closest source point, found by Gauss–Newton on the trigonometric surface, and map the radial nodes as ρ = ε sinh(s), ε = d / patch radius. The node count is ⌈asinh(1/ε)/2⌉ ×RAD_DIM, capped at 8×. Rows farther thanNEAR_GAP= 4 cells skip the near correction, and plasma–wall rows interpolate at order 9.Kernel2D.jl): near plasma–wall pairs are found by distance rather than by index, and integrated over a sinh-graded window of 6 cells.laplace_kerneltakesSVectors;cross3!is replaced byStaticArrays.cross.MIN_WALL_GAP_CELLS = 0.1.Validation (base 59483ec vs aa37dd0)
Tests
close wall: near plasma–wall pairs found by distance(2D) andclose wall: 3D plasma–wall rows centred at the closest point.Commits
laplace_kernelcrossMIN_WALL_GAP_CELLS, far-row screenRAD_DIMnodes per 2 units of the sinh variable