Skip to content

Equilibrium - REFACTOR - Sample the rzphi geometry primitives through one shared function - #600

Draft
logan-nc wants to merge 2 commits into
developfrom
refactor/rzphi-geometry-primitive
Draft

logan-nc wants to merge 2 commits into
developfrom
refactor/rzphi-geometry-primitive

Conversation

@logan-nc

@logan-nc logan-nc commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Release note

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

The perturbed-field reconstruction transform and the flux-surface metric helpers now sample the rzphi geometry primitives (r², η-offset, Jacobian and their θ-derivatives) through one shared Equilibrium function instead of two independent copies, so the gpout.f metric conventions cannot drift between the two paths.

Regression report

Compared develop @ 6d655c74c against this branch @ 592c67365: diiid_n1 53 unchanged, solovev_n1 22 unchanged, and diiid_error_field 10 unchanged. All numeric differences are zero; checksums are identical. Focused equilibrium, coordinate-invariant, dominant-coupling, and straight-field-line sampling tests passed.

Run on ITER SDCC through Slurm, Julia 1.12.6, CI-pinned manifest, 2 Julia threads / 1 BLAS thread per case (16 threads for diiid_error_field).

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

Regression Report: diiid_n1
===================================================================================================================
Ref 1: develop  @ 6d655c74c (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 2 threads/1 BLAS, jit build
Ref 2: refactor/rzphi-geometry-primitive  @ 592c67365 (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 2 threads/1 BLAS, jit build
-------------------------------------------------------------------------------------------------------------------
Quantity                                      develop          refactor/rzphi-geometry-primitive  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)                                   298.3s           298.8s                                        --    
||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


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

Regression Report: solovev_n1
===================================================================================================
Ref 1: develop  @ 6d655c74c (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 2 threads/1 BLAS, jit build
Ref 2: refactor/rzphi-geometry-primitive  @ 592c67365 (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 2 threads/1 BLAS, jit build
---------------------------------------------------------------------------------------------------
Quantity                      develop          refactor/rzphi-geometry-primitive  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)                   249.4s           246.3s                                        --    
===================================================================================================
Summary: 22 unchanged


================================================================
Case: diiid_error_field — DIII-D-like error-field assessment, n=1: ErrorFields stage with the NTV-limited correction couplings
================================================================

Regression Report: diiid_error_field
=================================================================================================================
Ref 1: develop  @ 6d655c74c (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 16 threads/8 BLAS, jit build
Ref 2: refactor/rzphi-geometry-primitive  @ 592c67365 (2026-10-27)
       env: julia 1.12.6, x86_64-linux-gnu, manifest 4c9d54fa (pinned), 16 threads/8 BLAS, jit build
-----------------------------------------------------------------------------------------------------------------
Quantity                                         develop       refactor/rzphi-geometry-primitive  Diff     Status
-----------------------------------------------------------------------------------------------------------------
EFC overlap per kAt                              [1 elem]      [1 elem]                           0.0e+00  OK    
EFC whole-field NTV torque per kAt² [N·m]        [1 elem]      [1 elem]                           0.0e+00  OK    
EFC residual-field NTV torque per kAt² [N·m]     [1 elem]      [1 elem]                           0.0e+00  OK    
EFC reference rotation ω_ref [rad/s]             [1 elem]      [1 elem]                           0.0e+00  OK    
EFC rotation-scan shifts [rad/s]                 [9 elem]      [9 elem]                           0.0e+00  OK    
EFC residual torque against rotation [N·m/kAt²]  [9 elem]      [9 elem]                           0.0e+00  OK    
dominant-coupling singular values                [3 elem]      [3 elem]                           0.0e+00  OK    
|delta_nominal| of coil set 1                    1.406924e-06  1.406924e-06                       0.0e+00  OK    
|Σ δ_as_designed| of the error-field coils       1.358904e-18  1.358904e-18                       0.0e+00  OK    
Monte Carlo mean |δ| of the error-field coils    4.701300e-05  4.701300e-05                       0.0e+00  OK    
Runtime (s)                                      325.2s        322.5s                                      --    
=================================================================================================================
Summary: 10 unchanged

Notes for reviewers

Closes #271.

  • Equilibrium.rzphi_primitives is the new single sampler. flux_surface_metric destructures it, and _build_rzphi_geometry in FieldReconstruction.jl fills its knot table from it. The five bicubic evaluations are the same calls in the same order, only behind one function boundary, which is why the harness is bit-clean rather than ULP-shifted.
  • ψ-derivatives are deliberately not part of the primitive. The reconstruction path keeps differentiating its ψ-resample spline (the C¹ concern raised in the issue), and that code is untouched.
  • The two other hunks in FieldReconstruction.jl (the mul! scalar spacing and the blk range) are JuliaFormatter normalizing pre-existing lines, not edits.
  • Tests run on the branch: runtests_equil.jl (324/324), runtests_coordinate_invariant.jl, runtests_dominant_coupling.jl.
  • Not a performance change, as the issue says; the hot per-step paths already use the coarse ψ-splines on both sides.
  • No review package: a small consolidation below the threshold for one.

Suggested reviewer: @ebursch (Equilibrium and PerturbedEquilibrium) or @JaeBeom1019 (Equilibrium). Opened as a draft so the maintainers can pick the reviewer.


🤖 Generated with Claude Code

https://claude.ai/code/session_0186CLfjeJeSusNTva5RMfGU

… one shared function

flux_surface_metric and the perturbed-field reconstruction geometry pulled
r², the η-offset, the Jacobian and their θ-derivatives off the rzphi bicubic
with two separate copies of the same five calls. Both now sample
rzphi_primitives, so the gpout.f conventions have one home. ψ-derivatives
stay with the resample spline in the reconstruction, as before.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186CLfjeJeSusNTva5RMfGU
@github-actions

Copy link
Copy Markdown
Contributor

This pull request is missing a reviewer.

If you are not ready to name them, mark this pull request as a draft.
docs/development/contributors.md suggests lead developers to ask.
Merging is not blocked here, but no pull request may be merged without human review.

@matt-pharr

Copy link
Copy Markdown
Collaborator

Merged develop cleanly. The shared geometry primitive and metric changes now live in Derived/FluxSurfaceMetrics.jl; the reconstruction changes retain their original intent.

This branch has not been deployed

No deployments
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.

Consolidate rzphi geometry extraction: share flux_surface_metric between FieldReconstruction and the metric/area helpers

2 participants