Skip to content

Add permanent-magnet field-line examples and correct rotational-transform counting - #32

Open
joshuabourassa wants to merge 51 commits into
mainfrom
pm
Open

joshuabourassa wants to merge 51 commits into
mainfrom
pm

Conversation

@joshuabourassa

@joshuabourassa joshuabourassa commented May 19, 2026 •

Copy link
Copy Markdown

Adds permanent-magnet field and optimization examples, with MUSE and rotating-ellipse inputs for reproducing the experiments.

Follow-up validation

  • Both v3 rotational-transform entry points use the same Poincaré calculation. Crossings are counted at full turns of the unwrapped toroidal angle. Signed toroidal winding keeps the estimate consistent when the trace is reversed.
  • On synthetic traces with prescribed iota of −0.33 and +0.20, the calculation found 12 crossings in each traversal direction. The maximum absolute iota error was 2.2e-8. Six tests cover signs, the branch cut, starts on the section and a trace that reverses to zero net winding. The estimate assumes less than π of toroidal phase advance between saved samples and less than π of poloidal phase advance between section samples.
  • Lossless compression reduces muse_opt_inputs_64x64.npz from 8,835,264 to 6,311,880 bytes, a saving of 2,523,384 bytes (28.56%). The path, seven NumPy members and their uncompressed bytes are preserved. The native FOCUS input paths are preserved, including the attributed Zot80 fixture from SIMSOPT.

@rogeriojorge

Copy link
Copy Markdown
Member

This looks good. Let's put this as a priority once PR #29 is merged (hopefully within the next few weeks), with the help of @Agastyarathee and Tejas.

Joshua Bourassa and others added 16 commits June 7, 2026 19:35
…os-native coil loading, volume-penalty, works with Djins field.py
…hing changes in the form of two new scripts for testing
…les, added examples for comparisons against essos and simsopt (G Matrix compute times and B),Fixed ESSOS_ROOT path depth in every moved script
# Conflicts:
#	examples/plot_PM_results.py
#	examples/pm_opt.py
… set for a GPU must change "cuda" to "auto" for CPU
@rogeriojorge

Copy link
Copy Markdown
Member

Hi Joshua, thanks for all the permanent-magnet work here. I'd like to get it into ESSOS, but in its current form the PR can't be reviewed or merged: it adds about 191k lines in 43 files, most of it data (the zot80 and nfp4/nfp8 .focus grids are 53k, 27k and 99k lines) plus around 25 example and plotting scripts. It is also 85 commits behind main, and main has since gained an InterpolatedField, while #153 adds a PointDipoleField with the dipole moments as optimization dofs. Part of DipoleField here overlaps with both.

Could you close this one and resubmit as a few small PRs, each with a test and based on current main? A structure that would work well:

  1. Dipole field. One field class in essos/fields.py (B, gradient, symmetries over nfp and stellarator symmetry), built on or merged with PointDipoleField from PointDipoleField: point dipoles with the moments as dofs #153 rather than a second class. Test: compare B against the analytic dipole formula and against SIMSOPT's DipoleField on a few points. No DipoleField_old.
  2. FAMUS/FOCUS reader. read_famus_dipoles in essos/util.py or the coils I/O, tested on a small grid of ~10 magnets committed under tests/. Large grids should not go in the repo; attach them to a release or generate them with a short script.
  3. Optimization. The B·n loss and the regularization term in essos/losses.py / optimization.py, with one example, examples/optimize_permanent_magnets.py, that runs in a few minutes on a small grid (MUSE is a good case) and ends with one plot.
  4. Benchmarks, if you want them. One script comparing time and B·n with SIMSOPT, replacing the three sweep scripts.

The iota, Poincaré and plotting scripts can mostly reuse existing ESSOS examples, so I'd leave them out at first. Happy to review each piece as it comes in.

@rogeriojorge rogeriojorge changed the title Pm updates Add permanent-magnet field-line examples and correct rotational-transform counting Nov 18, 2026
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.

2 participants