Skip to content

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
feature/vacuum-3d-high-orderfrom
bugfix/vacuum-close-wall-split
Open

jhalpern30 wants to merge 11 commits into
feature/vacuum-3d-high-orderfrom
bugfix/vacuum-close-wall-split

Conversation

@jhalpern30

@jhalpern30 jhalpern30 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

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:

  1. we now choose the closest point to center the quadrature on, rather than the same index of the plasma and wall (which previously led to the result only being semi-robust for conformal, non equal-arc walls).
  2. we also now account for the near-singular integrand structure (see the artifact for a good visual of the singular vs. near-singular integrand), by applying a sinh-graded Gauss-Legendre rule to resolve the integral.

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

for each observer
  if same surface
    do trapezoidal/Simpson rule
    apply singular correction
  if different surface
    do trapezoidal rule
    find nearest point
      if closer than 4 grid points
        apply near-singular correction
end

Stacked on #673 (base feature/vacuum-3d-high-order).

Release note

  • Audience: users
  • Numerical impact: wv moves 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.
  • Migration: rerun close-wall cases. A new warning fires when the plasma–wall gap is below 0.1 cell (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.

  • 3D (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 than NEAR_GAP = 4 cells skip the near correction, and plasma–wall rows interpolate at order 9.
  • 2D (Kernel2D.jl): near plasma–wall pairs are found by distance rather than by index, and integrated over a sinh-graded window of 6 cells.
  • Refactors, no change in results:
    • one 3D near-field routine with per-node Lagrange stencils, replacing the P2G matrix;
    • the 2D row is split into quadrature helpers;
    • laplace_kernel takes SVectors;
    • cross3! is replaced by StaticArrays.cross.
  • Warning: MIN_WALL_GAP_CELLS = 0.1.

Validation (base 59483ec vs aa37dd0)

  • Solov'ev, ten conformal walls from 35 cm to 0.7 mm, 3D at 40/60/80 poloidal points against 2D at M = 8192: the far-wall results match the base, and the close-wall results reach the reference floor.
  • Equal-arc walls, whose nodes are not paired with the plasma's, in 3D and 2D: ≤ 5e-4 at 80×120 down to 0.01 cell; the base is O(1).
  • W7-X, precise QA and ARIES-CS walls: 5–16 000× better at close standoff; no-wall results are bit-identical.
  • Far below 0.1 cell on coarse grids, equal-arc walls reach 1–5% error; the new warning fires there and refining fixes it (80×120 ≤ 5e-4).

Tests

  • Vacuum unit tests 438/438 (Landau, aa37dd0).
  • New: close wall: near plasma–wall pairs found by distance (2D) and close wall: 3D plasma–wall rows centred at the closest point.

Commits

  • 7ead465 REFACTOR: split the 2D kernel row into quadrature helpers
  • 06ea86b BUGFIX: 2D near pairs by distance
  • 87b6eab REFACTOR: one 3D near-field routine
  • 92c8cbe BUGFIX: 3D closest-point centre and sinh radial nodes
  • 2b39c95 PERF: NEAR_GAP skip, order-9 plasma–wall interpolation
  • 6724c6e DOCS: close-wall treatment
  • 5c5918b REFACTOR: SVector laplace_kernel
  • c44ad44 MINOR: StaticArrays cross
  • f5c1347 DOCS: comments, MIN_WALL_GAP_CELLS, far-row screen
  • aa37dd0 MINOR: plasma–wall sinh rule, RAD_DIM nodes per 2 units of the sinh variable

@jhalpern30 jhalpern30 self-assigned this Nov 18, 2026
@jhalpern30
jhalpern30 added this pull request to stack #683 November 18, 2026 16:41
@github-actions github-actions Bot added the bugfix Something was wrong and now is not label Nov 18, 2026
@jhalpern30
jhalpern30 force-pushed the bugfix/vacuum-close-wall-split branch from aa37dd0 to e43819f Compare November 18, 2026 20:13
@jhalpern30 jhalpern30 changed the title Vacuum - BUGFIX - Accurate plasma–wall rows for walls closer than one grid cell Vacuum - BUGFIX - Accurate near-singular integration for walls closer than one grid cell or with arbitrary parametrization Nov 18, 2026
@jhalpern30
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
jhalpern30 force-pushed the bugfix/vacuum-close-wall-split branch from e43819f to 3992537 Compare November 23, 2026 21:10
…-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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Something was wrong and now is not

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant