Skip to content

Equilibrium - REFACTOR - Arrange the Equilibrium module by pipeline stage - #551

Merged
matt-pharr merged 6 commits into
developfrom
refactor/equilibrium-file-split
Oct 27, 2026
Merged

matt-pharr merged 6 commits into
developfrom
refactor/equilibrium-file-split

Conversation

@matt-pharr

@matt-pharr matt-pharr commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Release note

  • Audience: developers
  • Numerical impact: none (harness @ f5e1f94)
  • Migration: none

src/Equilibrium/ is arranged by pipeline stage. Equilibrium.jl holds the module docstring, imports, constants, includes and exports. Config.jl, PlasmaEquilibrium.jl and Construction.jl hold the configs, the result type and how it is formed. Sources/ has one file per input format, the ingest types and Analytic/. Grid/ holds the ψ grids, Axisymmetric/ the 2D solvers, Grad-Shafranov residual and separatrix finding, and Derived/ the quantities computed from a formed equilibrium. Its docstring states which folder new code belongs in.

Regression report

Compared against develop @ e0324a91d, with this branch @ f5e1f9459: every tracked quantity is bit-identical (81 rows at 0.0e+00, 9 identical checksums).

================================================================
Case: solovev_n1 — Solovev analytical equilibrium, n=1, ideal stability
================================================================

Regression Report: solovev_n1
=================================================================================================
Ref 1: develop  @ e0324a91d (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 2 threads/1 BLAS, jit build
Ref 2: refactor/equilibrium-file-split  @ f5e1f9459 (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 2 threads/1 BLAS, jit build
-------------------------------------------------------------------------------------------------
Quantity                      develop          refactor/equilibrium-file-split  Diff       Status
-------------------------------------------------------------------------------------------------
total energy Re(et[1])        1.090560e-02     1.090560e-02                     0.0e+00    OK
total energy Im(et[1])        1.309258e-10     1.309258e-10                     0.0e+00    OK
plasma energy Re(ep[1])       -1.041640e+01    -1.041640e+01                    0.0e+00    OK
vacuum energy Re(ev[1])       1.042730e+01     1.042730e+01                     0.0e+00    OK
vacuum matrix min eigenvalue  2.170703e+00     2.170703e+00                     0.0e+00    OK
plasma energy (all)           [32 elem]        [32 elem]                        0.0e+00    OK
vacuum energy (all)           [32 elem]        [32 elem]                        0.0e+00    OK
total energy (all)            [32 elem]        [32 elem]                        0.0e+00    OK
ODE steps (saved)             287              287                              0.0e+00    OK
ODE steps (total)             285              285                              0.0e+00    OK
q0                            1.900006e+00     1.900006e+00                     0.0e+00    OK
q95                           3.147422e+00     3.147422e+00                     0.0e+00    OK
beta_t                        4.621027e-02     4.621027e-02                     0.0e+00    OK
beta_n                        3.217775e+00     3.217775e+00                     0.0e+00    OK
# singular surfaces           2                2                                0.0e+00    OK
singular psi locations        [2 elem]         [2 elem]                         0.0e+00    OK
singular q values             [2 elem]         [2 elem]                         0.0e+00    OK
mpert                         32               32                               0.0e+00    OK
npert                         1                1                                0.0e+00    OK
q profile (checksum)          2340b888d410...  2340b888d410...                  identical  OK
pressure profile (checksum)   108b947087e6...  108b947087e6...                  identical  OK
ca_left (checksum)            21c2d085d11b...  21c2d085d11b...                  identical  OK
Runtime (s)                   232.3s           194.4s                                      --
=================================================================================================
Summary: 22 unchanged


================================================================
Case: solovev_multi_n — Solovev analytical equilibrium, multi-n, ideal stability
================================================================

Regression Report: solovev_multi_n
=================================================================================================
Ref 1: develop  @ e0324a91d (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 2 threads/1 BLAS, jit build
Ref 2: refactor/equilibrium-file-split  @ f5e1f9459 (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 2 threads/1 BLAS, jit build
-------------------------------------------------------------------------------------------------
Quantity                      develop          refactor/equilibrium-file-split  Diff       Status
-------------------------------------------------------------------------------------------------
total energy Re(et[1])        -2.134718e+00    -2.134718e+00                    0.0e+00    OK
total energy Im(et[1])        1.943387e-10     1.943387e-10                     0.0e+00    OK
vacuum matrix min eigenvalue  1.730832e+00     1.730832e+00                     0.0e+00    OK
plasma energy (all)           [70 elem]        [70 elem]                        0.0e+00    OK
vacuum energy (all)           [70 elem]        [70 elem]                        0.0e+00    OK
total energy (all)            [70 elem]        [70 elem]                        0.0e+00    OK
ODE steps (saved)             56               56                               0.0e+00    OK
ODE steps (total)             1044             1044                             0.0e+00    OK
q0                            1.900006e+00     1.900006e+00                     0.0e+00    OK
q95                           3.147422e+00     3.147422e+00                     0.0e+00    OK
# singular surfaces           3                3                                0.0e+00    OK
singular psi locations        [3 elem]         [3 elem]                         0.0e+00    OK
mpert                         35               35                               0.0e+00    OK
npert                         2                2                                0.0e+00    OK
q profile (checksum)          2340b888d410...  2340b888d410...                  identical  OK
Runtime (s)                   191.6s           189.8s                                      --
=================================================================================================
Summary: 15 unchanged


================================================================
Case: diiid_n1 — DIII-D-like equilibrium, n=1, ideal + perturbed equilibrium
================================================================

Regression Report: diiid_n1
=================================================================================================================
Ref 1: develop  @ e0324a91d (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 2 threads/1 BLAS, jit build
Ref 2: refactor/equilibrium-file-split  @ f5e1f9459 (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 2 threads/1 BLAS, jit build
-----------------------------------------------------------------------------------------------------------------
Quantity                                      develop          refactor/equilibrium-file-split  Diff       Status
-----------------------------------------------------------------------------------------------------------------
total energy Re(et[1])                        8.006122e-01     8.006122e-01                     0.0e+00    OK
total energy Im(et[1])                        7.924888e-05     7.924888e-05                     0.0e+00    OK
plasma energy Re(ep[1])                       -1.372261e+00    -1.372261e+00                    0.0e+00    OK
vacuum energy Re(ev[1])                       2.172874e+00     2.172874e+00                     0.0e+00    OK
vacuum matrix min eigenvalue                  1.873975e-01     1.873975e-01                     0.0e+00    OK
plasma energy (all)                           [35 elem]        [35 elem]                        0.0e+00    OK
vacuum energy (all)                           [35 elem]        [35 elem]                        0.0e+00    OK
total energy (all)                            [35 elem]        [35 elem]                        0.0e+00    OK
ODE steps (saved)                             792              792                              0.0e+00    OK
ODE steps (total)                             787              787                              0.0e+00    OK
q0                                            1.204212e+00     1.204212e+00                     0.0e+00    OK
q95                                           4.781723e+00     4.781723e+00                     0.0e+00    OK
beta_t                                        1.327024e-02     1.327024e-02                     0.0e+00    OK
beta_n                                        1.372511e+00     1.372511e+00                     0.0e+00    OK
internal inductance li1                       8.842268e-01     8.842268e-01                     0.0e+00    OK
internal inductance li2                       7.080757e-01     7.080757e-01                     0.0e+00    OK
internal inductance li3                       7.304340e-01     7.304340e-01                     0.0e+00    OK
poloidal beta betap1                          6.680739e-01     6.680739e-01                     0.0e+00    OK
poloidal beta betap2                          5.349836e-01     5.349836e-01                     0.0e+00    OK
poloidal beta betap3                          5.518764e-01     5.518764e-01                     0.0e+00    OK
# singular surfaces                           5                5                                0.0e+00    OK
singular psi locations                        [5 elem]         [5 elem]                         0.0e+00    OK
singular q values                             [5 elem]         [5 elem]                         0.0e+00    OK
current beta betaj                            4.236480e-01     4.236480e-01                     0.0e+00    OK
plasma volume                                 1.829472e+01     1.829472e+01                     0.0e+00    OK
plasma current                                1.152130e+00     1.152130e+00                     0.0e+00    OK
mpert                                         35               35                               0.0e+00    OK
npert                                         1                1                                0.0e+00    OK
toroidal field bt0                            2.006573e+00     2.006573e+00                     0.0e+00    OK
wall field bwall                              3.880145e-01     3.880145e-01                     0.0e+00    OK
aspect ratio                                  2.845746e+00     2.845746e+00                     0.0e+00    OK
elongation kappa                              1.708322e+00     1.708322e+00                     0.0e+00    OK
q profile (checksum)                          6da947d0754e...  6da947d0754e...                  identical  OK
pressure profile (checksum)                   c9c6ca4072ca...  c9c6ca4072ca...                  identical  OK
Mercier D_I profile (checksum)                26babbe22505...  26babbe22505...                  identical  OK
resistive interchange D_R profile (checksum)  c46830151a0b...  c46830151a0b...                  identical  OK
ballooning Delta' profile (checksum)          c27c6779804a...  c27c6779804a...                  identical  OK
island half-widths                            [5 elem]         [5 elem]                         0.0e+00    OK
Chirikov parameter                            [5 elem]         [5 elem]                         0.0e+00    OK
||resonant area-weighted field||              5.288461e-04     5.288461e-04                     0.0e+00    OK
dominant-coupling singular values             [3 elem]         [3 elem]                         0.0e+00    OK
|forcing overlap with dominant mode|          1.411548e-04     1.411548e-04                     0.0e+00    OK
|delta_nominal| of coil set 1                 7.034622e-05     7.034622e-05                     0.0e+00    OK
||ddelta/d(shift)|| over coil sets            1.245446e-04     1.245446e-04                     0.0e+00    OK
||ddelta/d(tilt)|| over coil sets             4.177337e-07     4.177337e-07                     0.0e+00    OK
PE plasma energy                              3.320466e+00     3.320466e+00                     0.0e+00    OK
PE vacuum energy                              3.174319e+00     3.174319e+00                     0.0e+00    OK
PE surface energy                             5.508585e+00     5.508585e+00                     0.0e+00    OK
PE toroidal torque                            1.119355e-04     1.119355e-04                     0.0e+00    OK
NTV torque FGAR [N·m]                         5.480580e-01     5.480580e-01                     0.0e+00    OK
NTV kinetic energy dW FGAR [J]                8.163220e-02     8.163220e-02                     0.0e+00    OK
Runtime (s)                                   226.9s           225.7s                                      --
||forcing b~|| (root-area-weighted)           4.683171e-04     4.683171e-04                     0.0e+00    OK
resonant area-weighted field b^r              [5 elem]         [5 elem]                         0.0e+00    OK
=================================================================================================================
Summary: 53 unchanged

Notes for reviewers

  • Pure move, no code changes, plus one docs commit: the Equilibrium module docstring in Equilibrium.jl now says where code goes, so new code lands in the right folder. Otherwise only file locations and include order change; develop (including Equilibrium - FEATURE! - Store the analytic config on PlasmaEquilibrium and re-form every source from it #548) is merged in. A script compared the non-blank lines of the whole module before and after: none were added or removed apart from include lines and two header comments that this PR had itself added earlier.

  • Layout:

    src/Equilibrium/
      Equilibrium.jl        module: imports, constants, includes, exports
      Config.jl             EquilibriumConfig, EquilibriumParameters
      PlasmaEquilibrium.jl  the result type + ProfileSplines, GeometryProfileSplines, KineticProfileSplines
      Construction.jl       run_input dispatch, PlasmaEquilibrium(config, source), the constructors, reform
      Sources/              Ingest.jl, GFile.jl, Chease.jl, IFile.jl, IMAS.jl
        Analytic/           Analytic.jl (AnalyticEquilibriumConfig, ANALYTIC_EQ), Solovev.jl, LargeAspectRatio.jl, TJAnalytic.jl
      Grid/                 PsiGrid.jl, GridRefinement.jl
      Axisymmetric/         Direct.jl, DirectArcLength.jl, DirectByInversion.jl, Inverse.jl, SolveTolerances.jl,
                            GradShafranovResidual.jl, Separatrix.jl
      Derived/              GlobalParameters.jl, FluxSurfaceMetrics.jl, GeometryProfiles.jl, CoordinateInvariant.jl
      KineticProfiles.jl    unchanged
    
  • Where the pieces came from:

    • EquilibriumTypes.jl was split into Config.jl, Sources/Ingest.jl, the analytic files and PlasmaEquilibrium.jl.
    • ReadEquilibrium.jl was split into one file per format, with build_*_from_ingest going to Ingest.jl.
    • AnalyticEquilibrium.jl was split into the three model files, each now holding its config and its solver.
    • The first-pass ψ grid builders moved from DirectEquilibrium.jl to Grid/PsiGrid.jl.
    • The other files were moved whole with git mv.
  • Include order:

    • ANALYTIC_EQ is built when its file loads, so it needs the model solvers, and the model configs subtype AnalyticEquilibriumConfig. So Sources/Analytic/Analytic.jl defines the abstract type, then includes the three model files, then builds the registry. These are the only nested includes.
    • KineticProfileSplines sits in PlasmaEquilibrium.jl because GridRefinement.jl's method signatures need it at load time.
  • Text-only edits outside the move:

    • test/runtests_equil.jl reads the direct solver's source as text, so its path now points to Axisymmetric/Direct.jl.
    • File paths are updated in docs/src/conventions.md, the header of Separatrix.jl, a comment in TJAnalytic.jl, and the Key-files list in docs/development/architecture.md.
  • Reading the diff: git diff --color-moved or GitHub's moved-line view shows the blocks as moved.

  • Where things moved (for open PRs that edit these files):

    Old file New location
    EquilibriumTypes.jl Config.jl (EquilibriumConfig, EquilibriumParameters, symbolize_keys), Sources/Ingest.jl (ingest and run-input types), Sources/Analytic/Analytic.jl (AnalyticEquilibriumConfig), the analytic model files (their configs), PlasmaEquilibrium.jl (spline containers and the result type)
    ReadEquilibrium.jl Sources/GFile.jl, Sources/Chease.jl, Sources/IFile.jl, Sources/IMAS.jl; build_*_from_ingest in Sources/Ingest.jl
    AnalyticEquilibrium.jl Sources/Analytic/Solovev.jl, LargeAspectRatio.jl, TJAnalytic.jl
    Equilibrium.jl (body) Construction.jl (run_input, constructors, reform), Sources/Analytic/Analytic.jl (ANALYTIC_EQ), Axisymmetric/Separatrix.jl, Derived/GlobalParameters.jl, Axisymmetric/GradShafranovResidual.jl
    DirectEquilibrium.jl Axisymmetric/Direct.jl; make_optimal_psi_grid and _build_psi_grid in Grid/PsiGrid.jl
    DirectEquilibriumArcLength.jl, DirectEquilibriumByInversion.jl, InverseEquilibrium.jl, SolveTolerances.jl Axisymmetric/DirectArcLength.jl, DirectByInversion.jl, Inverse.jl, SolveTolerances.jl
    SeparatrixQLaw.jl Axisymmetric/Separatrix.jl
    GridRefinement.jl Grid/GridRefinement.jl
    FluxSurfaceMetrics.jl, GeometryProfiles.jl, CoordinateInvariant.jl Derived/
    KineticProfiles.jl unchanged

    Whole-file moves follow automatically when an open PR merges develop. Edits to the split files (EquilibriumTypes.jl, ReadEquilibrium.jl, AnalyticEquilibrium.jl, the Equilibrium.jl body, the ψ grid builders) need porting by hand to the new location.

🤖 Generated with Claude Code

… Equilibrium.jl into their own files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matt-pharr matt-pharr self-assigned this Oct 21, 2026
@github-actions github-actions Bot added the refactor Behavior-preserving restructuring label Oct 21, 2026
@matt-pharr
matt-pharr added this pull request to stack #566 October 23, 2026 10:22
@matt-pharr matt-pharr changed the title Equilibrium - REFACTOR - Move construction and post-processing out of Equilibrium.jl into their own files Equilibrium - REFACTOR - Arrange the Equilibrium module by pipeline stage Oct 23, 2026
@matt-pharr matt-pharr added this to the GPEC v2.0.0 milestone Oct 26, 2026
Base automatically changed from refactor/equilibrium-source to develop October 26, 2026 22:14

@logan-nc logan-nc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked mechanically rather than by reading 5,500 lines: after whitespace normalisation, every removed line reappears as an added line except 30, and every added line was present before except 51; all 81 are include(...) paths, the # File.jl headers, and path references in the two docs pages and test/runtests_equil.jl. So this is a pure move, and the relative includes in Sources/Analytic/Analytic.jl resolve to files that exist on the branch. Two notes: #548 (its base) merged today, so this needs a retarget and rebase onto develop; and #581 also edits Equilibrium.jl and EquilibriumTypes.jl, which this PR moves to Config.jl/PlasmaEquilibrium.jl, so whichever of the two lands second pays the conflict.

@matt-pharr

Copy link
Copy Markdown
Collaborator Author

@logan-nc I am going to take your comment as an approval here. I will make sure that all PRs open that edit equilibrium are rebased correctly onto this when it goes in. I cc'ed @jhalpern30 as a reviewer as well on this so he can see how I am reorganizing things. I have one more PR that is still unopened that will edit the Equilibrium submodule a liottle bit, so @jhalpern30 feel free to leave comments here and I can address them in that PR. But I am going to merge this now to avoid a huge dependency chain today so we can keep things rolling for 2.0.0 work.

matt-pharr and others added 2 commits October 27, 2026 11:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…docstring

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matt-pharr
matt-pharr marked this pull request as ready for review October 27, 2026 10:21
@matt-pharr
matt-pharr merged commit 6d655c7 into develop Oct 27, 2026
10 of 11 checks passed
@matt-pharr
matt-pharr deleted the refactor/equilibrium-file-split branch October 27, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Behavior-preserving restructuring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants