Allow selecting a faster second-order static GS operator - #98
Merged
Conversation
kpentland
approved these changes
Aug 14, 2026
kpentland
left a comment
Collaborator
There was a problem hiding this comment.
Nice addition if users need speed!
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.
Summary
This adds a small, opt-in choice of finite-difference order for the static Grad-Shafranov solver.
gs_operator_order={2, 4}toGSstaticsolver.NKGSsolver.GSsparsesecond-order operator orGSsparse4thOrderfourth-order operator.ValueError.No stencil or numerical solver implementation is duplicated in FreeGSNKE.
Linear-solver path
Although the FreeGS4E factory is named
createVcycle, FreeGSNKE configures it with:This constructs
MGDirect, performs a sparse LU factorisation with SciPy, and uses direct back-solves. No multigrid restriction, prolongation, smoothing, or V-cycle is performed.The second-order benefit therefore comes primarily from constructing and factorising a sparser matrix.
Performance
On the standard 65 x 129 static-solver test equilibrium:
The total gain will be largest when solver objects are constructed frequently. Reusing an already-factorised solver reduces the benefit because repeated direct back-solves cost approximately the same.
Accuracy and compatibility
Second order has the expected spatial discretisation accuracy trade-off and is therefore opt-in. The default remains
gs_operator_order=4.The regression test verifies that the second-order equilibrium agrees with the established static equilibrium baseline within 0.3% of the reference flux range.
Verification
python -m pytest -q freegsnke/tests/test_static_solver.py