Skip to content

Surface quadrature: duplicate-free SquaredFlux and midpoint half-period grid - #127

Merged
rogeriojorge merged 8 commits into
mainfrom
fix/surface-quadrature-half-period
Oct 19, 2026
Merged

rogeriojorge merged 8 commits into
mainfrom
fix/surface-quadrature-half-period

Conversation

@rogeriojorge

@rogeriojorge rogeriojorge commented Oct 5, 2026 •

Copy link
Copy Markdown
Member
  • SquaredFlux (all three definitions) averaged with jnp.mean over the raw grid, so with close=True the duplicated theta = 2 pi column (and phi end row) were counted twice: ~10% error on the test surface. It now uses _surface_mean.
  • range_torus='half period', close=False sampled phi in [0, pi/nfp) at the left endpoints: first-order quadrature for area/volume/flux/cross-section. The grid is now shifted by half a step (the simsopt convention), a midpoint rule that is spectrally accurate for stellarator-symmetric integrands.
  • _surface_mean is a module function; surfaces without close/range_torus (VMEX's HighOrderSurfaceSamples, an open one-period grid) get the plain mean. VMEX's test_high_order_surface_composes_with_essos_objective passes against this branch.

Measured on a shaped nfp=3 surface (ntheta=64) with a toroidal + poloidal field, relative error vs a 256-point reference for nphi = 2, 4, 8, 16, 32 on the half-period grid:

volume area quadratic flux
main 2.3e-1 ... 1.3e-2 1.3e-1 ... 7.4e-3 5.4e-2 ... 3.3e-3
this PR <1e-15 7e-5, 2e-7, 2e-12, 1e-15 7e-3, 4e-5, 6e-10, 6e-16

SIMSOPT 1.11.1 gives the same numbers as this PR (same midpoint rule), so this brings ESSOS in line rather than ahead.

Tests: the ('half period', False) case in the grid-independence test, test_squared_flux_does_not_count_duplicated_end_points, and test_half_period_integrals_converge_spectrally (analytic volume 2 pi^2 R0 a b of a shifted-ellipse torus at nphi = 3, 5, 9; main fails it).

Note: points of a half-period open grid no longer include phi = 0.

@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
essos/surfaces.py 76.89% <100.00%> (+2.77%) ⬆️

@rogeriojorge
rogeriojorge changed the base branch from fix/surface-volume-area to main October 16, 2026 20:01
@rogeriojorge
rogeriojorge merged commit 0018dda into main Oct 19, 2026
5 checks passed
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