Skip to content

Reduce static GS boundary Green memory - #97

Merged
kpentland merged 4 commits into
mainfrom
static-gs-performance
Aug 15, 2026
Merged

Reduce static GS boundary Green memory#97
kpentland merged 4 commits into
mainfrom
static-gs-performance

Conversation

@nicamo

@nicamo nicamo commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

This reduces the memory used by the static Grad-Shafranov solver's free-boundary Green operator.

  • Build and retain Green columns only for grid points inside the limiter.
  • Store the reduced Green matrix in a contiguous two-dimensional layout.
  • Contract it directly with the limiter-contained plasma-current vector.
  • Remove the per-call outside-limiter scan and lazy fallback Green operator.
  • Add a focused regression test showing that the reduced contraction is equivalent to the full-domain contraction when plasma current is confined by the limiter.

Primary impact: memory

On the standard 65 x 129 static-solver test equilibrium:

  • boundary Green storage falls from 25.8 MB to 9.4 MB
  • this is a 64% reduction
  • the saving grows in absolute terms at higher grid resolutions because the operator scales with the number of boundary targets and source points

This should be regarded primarily as a RAM optimization.

Secondary timing impact

The reduced allocation and contraction also provide a modest speed benefit in the same test:

  • constructor median: approximately 0.274 s to 0.225 s (about 18% faster)
  • full static solve median: approximately 0.483 s to 0.443 s (about 8% faster)

These timing gains are secondary and will depend on grid resolution, limiter area, and nonlinear iteration count.

Merge dependency: no-X-point fallback

This branch should be rebased onto limiter-only-plasma-domain before merging.

The current streamlining no-X-point path can set limiter_core_mask=None. In that state, Jtor_part2 may normalize and distribute current over the computational domain, including outside the limiter. During testing, one early Newton probe produced nonzero current in 5,245 outside-limiter cells, representing approximately 397 kA in absolute current, although the converged equilibrium returned to exactly zero outside.

This PR deliberately assumes that plasma current is confined inside the limiter. Without the no-X-point fix, an exploratory state could retain outside current in the GS right-hand side while excluding it from the boundary integral. The limiter-only-plasma-domain branch resolves this at the profile level by constructing a limiter-constrained core mask when no relevant X-point is available, preserving both current confinement and profile normalization.

After rebasing, the combined implementation should include a regression test asserting that no-X-point profile evaluations return zero current outside the limiter.

Verification

  • python -m pytest -q freegsnke/tests/test_static_solver.py
  • 2 passed
  • converged equilibrium maximum flux difference from the established baseline: approximately 2.2e-9 Wb/rad, or 1.3e-8 of the flux range

@nicamo
nicamo changed the base branch from streamlining to main August 4, 2026 11:49
@kpentland
kpentland force-pushed the static-gs-performance branch from f509ae9 to 4f63987 Compare August 15, 2026 10:37
@kpentland kpentland added enhancement New feature or request ready-for-final-tests Pull request is ready to run final pre-merge tests labels Aug 15, 2026
@kpentland
kpentland merged commit 7ff7434 into main Aug 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready-for-final-tests Pull request is ready to run final pre-merge tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants