Add coil limits to the inverse solver#54
Merged
kpentland merged 7 commits intoFeb 12, 2026
Merged
Conversation
Collaborator
theo-brown
reviewed
Feb 11, 2026
| self.rhs_before_jtor = -freegs4e.gradshafranov.mu0 * eq.R | ||
|
|
||
| # random seed for reproducibility | ||
| self.rng = np.random.default_rng(seed=42) |
Contributor
There was a problem hiding this comment.
Please can the seed be exposed to the user as an optional input?
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.

Adds coil limits to the inverse solver and cleans up some of the delta_current calculations.
Both of these changes have been tested on a MAST-U example.
Change
delta_currentcalculationChanged the calculation of
delta_currentfromfreegsnke/freegsnke/inverse.py
Lines 409 to 410 in d8e17ed
np.linalg.solve. This ensures we get the most accurate solution and is possibly more numerically stable.There is negligible difference caused by this change for the MAST-U example.


Coil limits
Adds support for specifying coil limits. When limits are specified, a convex solver is used to solve the least-squares problem; this is because you can specify additional constraints on the convex solver, such as box constraints for the coil limits. These additional constraints have an added slack to their bound which allows the coil limits to be violated for a penalty.
The problem that is being solved is slightly different due to the coil limits and slack.
subject to
where
As can be seen, using the convex solver with no coil limits yields near-identical results to above:

When we add limits, the solution changes because the inverse solver attempts to ensure the coil currents are always within limits:

