Skip to content

ForceFreeStates.Riccati - FEATURE! - Integrate each chunk once, cross surfaces through the asymptotic series and store ξ profiles - #676

Merged
matt-pharr merged 53 commits into
developfrom
refactor/riccati-single-pass
Nov 26, 2026
Merged

matt-pharr merged 53 commits into
developfrom
refactor/riccati-single-pass

Conversation

@matt-pharr

@matt-pharr matt-pharr commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Human note, please read: the Riccati integrator integrated the entire domain in multiple passes before, IMO most likely as an artifact of layers of vibe coding. The main energy result from riccati was previously coming from a full forward pass that was happening inside of Riccati (!!!) which also took up a huge portion of the runtime as it was entirely serial. This dated back to when Riccati was first implemented in February.

This PR achieves several things, the highlights of which are:

  • Removes the superfluous solve entirely from the code and the runtime
  • Faithfully implements the STRIDE delta W calculation, just using dense propagator output to do the edge scan instead of the extra solve
  • Applies the dense propagator output to output the xi/xi' profiles
  • Implements the frobenius crossing for the forward integrator; it was already essentially built into the stride BVP half (what is done in fortran) of the integration.
  • There is no extra solve or anything fancy needed for the xi/xi' profiles; the confusion from before likely came from the way that the serial extra integrator worked.
  • Cuts over a thousand lines of dead code out of the riccati source.
  • Disables the Double64 BVP solve by default: it matched Float64 to 1e-11 up to n = 4 and was most of the run time. Still available as an opt-in, needed only beyond about 150 poloidal harmonics.

Enjoy!


Release note

  • Audience: users
  • Numerical impact: 20 of 29 harness cases move, because the crossing and the singfac_min default changed for every integrator. Energies: Forward 4e-5 or less (0.94% on lar_reversed_shear_n1, 0.50% on solovev_n1), Riccati 0.1–0.9%. Δ′ diagonal up to 0.10%, Δ_EF up to 0.27%, SLAYER growth rates up to 0.87%, resonant fields and island widths 0.01% or less (harness @ 9a2f3f7)
  • Migration: singfac_min defaults to 5e-4 (was 1e-4), and to 1e-5 for a run with a kinetic source. [Riccati] eulerlagrange_tolerance defaults to 1e-10 (was 1e-8). Remove renorm_threshold, numsteps_init and numunorms_init from [Riccati]. extended_precision_bvp defaults to false. In scripts: ffs.galerkin.solution → ffs.basis, :gal_native → :unit_edge, PlasmaResponse.odet_from_gal → unit_edge_basis. In gpec.h5: matched ξ moved from ForceFreeStates/Solutions/GalerkinIntegration/ to ForceFreeStates/Solutions/Match/.

Both ODE integrators now cross rational surfaces through the asymptotic series, so energies no longer depend on singfac_min and Forward and Riccati agree. Riccati integrates each chunk once: 0.9 s instead of 7.5 s on the DIII-D-like example at 16 threads. Against Forward it is faster from about 8 threads, level at 4, and about twice as slow on one.

Figures: https://claude.ai/artifact/QdkZdvShvLLmEJBGcMFhAS

Regression report

Base feature/analysis-plots-overhaul @ 9880101, on ITER's SDCC cluster, run at 9a2f3f750 after develop (with #650 and the larger precompile workload of #678) was merged up the stack. 29 cases: 9 unchanged, 20 changed. Every row matches the run at 8e2c8db12 on the same node type to within 0.005%. That run used a different node type of the cluster than the one at b3a2ad134, and the absolute values move with it in both branches. Energy and Δ′-diagonal differences are as before; root-found and near-tolerance quantities differ: SLAYER coupled γ 0.87% (was 0.33%), Δ_EF on diiid_n1_riccati_q1 0.27% (was 0.10%), CRF Q_peak on diiid_slayer_n1_chi_perp_e 0.28% (was 0.06%), and the NTV torque in tj_kinetic_ntv_rates now just exceeds its tolerance (1.3e-8).

Cases and every quantity that moved
Ref 1: feature/analysis-plots-overhaul @ 9880101a7   Ref 2: refactor/riccati-single-pass @ 9a2f3f750

29 cases, 9 unchanged in every tracked quantity:
  ccc_ray_q5i, efit_fixedbdy_separatrix, gal_resistive_diiid, gal_resistive_diiid_galinner, ggj_ray_q500i,
  ggj_reference, lar_ggj_tearing_n1, solovev_kinetic_nuzero, tj_kinetic_calculated

20 changed:
  diiid_error_field: 5 changed, 5 unchanged
  diiid_kinetic_multi_n: 4 changed, 4 unchanged
  diiid_multi_n: 10 changed, 9 unchanged
  diiid_n1: 24 changed, 29 unchanged
  diiid_n1_riccati: 9 changed, 8 unchanged
  diiid_n1_riccati_precompiled: 9 changed, 8 unchanged
  diiid_n1_riccati_q1: 10 changed, 7 unchanged
  diiid_slayer_n1: 13 changed, 9 unchanged
  diiid_slayer_n1_chi_perp_e: 13 changed, 9 unchanged
  diiid_slayer_n1_coupled: 5 changed, 2 unchanged
  diiid_slayer_n1_toroidal: 3 changed, 2 unchanged
  diiid_slayer_n1_winding: 13 changed, 9 unchanged
  diiid_truncation_n1: 2 changed, 10 unchanged
  lar_reversed_shear_n1: 8 changed, 14 unchanged
  solovev_multi_n: 6 changed, 9 unchanged
  solovev_n1: 9 changed, 13 unchanged
  tj_kinetic_multiion: 2 changed, 4 unchanged
  tj_kinetic_ntv: 2 changed, 5 unchanged
  tj_kinetic_ntv_rates: 1 changed, 1 unchanged
  tj_n1: 11 changed, 14 unchanged

diiid_error_field: 5 changed, 5 unchanged
Quantity                                         feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
EFC overlap per kAt                              [1 elem]                         [1 elem]                      8.776e-10 (0.00%)  ** CHANGED **
EFC whole-field NTV torque per kAt² [N·m]        [1 elem]                         [1 elem]                      3.587e-06 (0.01%)  ** CHANGED **
EFC residual-field NTV torque per kAt² [N·m]     [1 elem]                         [1 elem]                      8.441e-07 (0.04%)  ** CHANGED **
EFC residual torque against rotation [N·m/kAt²]  [9 elem]                         [9 elem]                      2.844e-06 (0.04%)  ** CHANGED **
dominant-coupling singular values                [3 elem]                         [3 elem]                      8.439e-05 (0.00%)  ** CHANGED **

diiid_kinetic_multi_n: 4 changed, 4 unchanged
Quantity                        feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
total energy Re(et[1])          5.186222e-01                     5.186223e-01                  1.633e-08 (0.00%)  ** CHANGED **
total energy Im(et[1])          -1.543126e-01                    -1.543126e-01                 6.293e-10 (0.00%)  ** CHANGED **
total energy (all)              [82 elem]                        [82 elem]                     4.833e-05 (0.00%)  ** CHANGED **
ODE steps (saved)               826                              821                           5.000e+00 (0.61%)  ** CHANGED **

diiid_multi_n: 10 changed, 9 unchanged
Quantity                                                      feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff                 Status
total energy Re(et[1])                                        -5.750944e-01                    -5.750951e-01                 6.835e-07 (0.00%)    ** CHANGED **
total energy (all)                                            [58 elem]                        [58 elem]                     9.154e-04 (0.00%)    ** CHANGED **
ODE steps (saved)                                             903                              580                           3.230e+02 (35.77%)   ** CHANGED **
permeability diagonal P~_ii (all n blocks)                    [58 elem]                        [58 elem]                     1.003e-04 (0.00%)    ** CHANGED **
PE plasma energy (sum over n)                                 2.936508e+00                     2.936508e+00                  4.708e-07 (0.00%)    ** CHANGED **
PE surface energy (sum over n)                                3.523287e+00                     3.523285e+00                  1.528e-06 (0.00%)    ** CHANGED **
PE toroidal torque sum_n -2n Im(Phi_n' Lambda_nn^-1 Phi_n)/4  2.148582e-08                     2.964295e-13                  2.149e-08 (100.00%)  ** CHANGED **
island half-widths per row                                    [7 elem]                         [7 elem]                      2.835e-06 (0.02%)    ** CHANGED **
Chirikov parameter per row                                    [7 elem]                         [7 elem]                      3.825e-05 (0.01%)    ** CHANGED **
forcing-driven Delta' per row                                 [7 elem]                         [7 elem]                      5.506e-07 (0.02%)    ** CHANGED **

diiid_n1: 24 changed, 29 unchanged
Quantity                                      feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff                 Status
total energy Re(et[1])                        7.979260e-01                     7.978958e-01                  3.021e-05 (0.00%)    ** CHANGED **
total energy Im(et[1])                        1.122432e-06                     -3.800730e-13                 1.122e-06 (100.00%)  ** CHANGED **
plasma energy Re(ep[1])                       -1.377302e+00                    -1.377361e+00                 5.904e-05 (0.00%)    ** CHANGED **
vacuum energy Re(ev[1])                       2.175228e+00                     2.175257e+00                  2.883e-05 (0.00%)    ** CHANGED **
plasma energy (all)                           [35 elem]                        [35 elem]                     1.904e-03 (0.00%)    ** CHANGED **
vacuum energy (all)                           [35 elem]                        [35 elem]                     9.694e-05 (0.00%)    ** CHANGED **
total energy (all)                            [35 elem]                        [35 elem]                     1.892e-03 (0.00%)    ** CHANGED **
ODE steps (saved)                             1149                             752                           3.970e+02 (34.55%)   ** CHANGED **
ODE steps (total)                             1144                             697                           4.470e+02 (39.07%)   ** CHANGED **
plasma volume                                 1.829472e+01                     1.829472e+01                  4.825e-12 (0.00%)    ** CHANGED **
q profile (checksum)                          961bd717d42b...                  f3efa4d67476...               0.000e+00 (0.00%)    ** CHANGED **
pressure profile (checksum)                   5a91e9a25b45...                  4c02f4e50e38...               0.000e+00 (0.00%)    ** CHANGED **
Mercier D_I profile (checksum)                6af1cf1a7c71...                  214a214e1a20...               0.000e+00 (0.00%)    ** CHANGED **
resistive interchange D_R profile (checksum)  06b6511f4350...                  551757400830...               0.000e+00 (0.00%)    ** CHANGED **
ballooning Delta' profile (checksum)          1462957def7f...                  96131c652eea...               0.000e+00 (0.00%)    ** CHANGED **
island half-widths                            [5 elem]                         [5 elem]                      1.211e-06 (0.00%)    ** CHANGED **
Chirikov parameter                            [5 elem]                         [5 elem]                      9.679e-05 (0.01%)    ** CHANGED **
dominant-coupling singular values             [3 elem]                         [3 elem]                      8.439e-05 (0.00%)    ** CHANGED **
|delta_nominal| of coil set 1                 7.074919e-05                     7.075270e-05                  3.510e-09 (0.00%)    ** CHANGED **
||ddelta/d(shift)|| over coil sets            1.246840e-04                     1.246852e-04                  1.181e-09 (0.00%)    ** CHANGED **
PE plasma energy                              3.321081e+00                     3.321089e+00                  8.030e-06 (0.00%)    ** CHANGED **
PE surface energy                             5.521988e+00                     5.522147e+00                  1.591e-04 (0.00%)    ** CHANGED **
PE toroidal torque                            9.083658e-07                     1.239009e-13                  9.084e-07 (100.00%)  ** CHANGED **
resonant area-weighted field b^r              [5 elem]                         [5 elem]                      1.798e-08 (0.00%)    ** CHANGED **

diiid_n1_riccati: 9 changed, 8 unchanged
Quantity                       feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff                  Status
delta prime (BVP diagonal)     [5 elem]                         [5 elem]                      6.821e-02 (0.00%)     ** CHANGED **
delta prime (raw side-major)   [10 elem]                        [10 elem]                     1.126e-01 (0.00%)     ** CHANGED **
edge coil response delta_coil  [10 elem]                        [10 elem]                     3.620e-04 (0.00%)     ** CHANGED **
total energy Re(et[1])         8.031976e-01                     7.978951e-01                  5.302e-03 (0.66%)     ** CHANGED **
plasma energy Re(ep[1])        -1.368533e+00                    -1.377364e+00                 8.830e-03 (0.65%)     ** CHANGED **
vacuum energy Re(ev[1])        2.171731e+00                     2.175259e+00                  3.528e-03 (0.16%)     ** CHANGED **
total energy (all)             [35 elem]                        [35 elem]                     3.741e-01 (0.00%)     ** CHANGED **
ODE steps (saved)              98                               1099                          1.001e+03 (1021.43%)  ** CHANGED **
ODE steps (total)              2665                             1044                          1.621e+03 (60.83%)    ** CHANGED **

diiid_n1_riccati_precompiled: 9 changed, 8 unchanged
Quantity                       feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff                  Status
delta prime (BVP diagonal)     [5 elem]                         [5 elem]                      6.821e-02 (0.00%)     ** CHANGED **
delta prime (raw side-major)   [10 elem]                        [10 elem]                     1.126e-01 (0.00%)     ** CHANGED **
edge coil response delta_coil  [10 elem]                        [10 elem]                     3.620e-04 (0.00%)     ** CHANGED **
total energy Re(et[1])         8.031976e-01                     7.978951e-01                  5.302e-03 (0.66%)     ** CHANGED **
plasma energy Re(ep[1])        -1.368533e+00                    -1.377364e+00                 8.830e-03 (0.65%)     ** CHANGED **
vacuum energy Re(ev[1])        2.171731e+00                     2.175259e+00                  3.528e-03 (0.16%)     ** CHANGED **
total energy (all)             [35 elem]                        [35 elem]                     3.741e-01 (0.00%)     ** CHANGED **
ODE steps (saved)              98                               1099                          1.001e+03 (1021.43%)  ** CHANGED **
ODE steps (total)              2665                             1044                          1.621e+03 (60.83%)    ** CHANGED **

diiid_n1_riccati_q1: 10 changed, 7 unchanged
Quantity                       feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff                 Status
delta prime (BVP diagonal)     [4 elem]                         [4 elem]                      3.167e-01 (0.10%)    ** CHANGED **
delta prime (raw side-major)   [8 elem]                         [8 elem]                      1.382e+00 (0.11%)    ** CHANGED **
edge coil response delta_coil  [8 elem]                         [8 elem]                      3.362e-02 (0.27%)    ** CHANGED **
total energy Re(et[1])         1.048253e+00                     1.039891e+00                  8.362e-03 (0.80%)    ** CHANGED **
plasma energy Re(ep[1])        -1.826932e+00                    -1.842507e+00                 1.558e-02 (0.85%)    ** CHANGED **
vacuum energy Re(ev[1])        2.875185e+00                     2.882399e+00                  7.214e-03 (0.25%)    ** CHANGED **
total energy (all)             [33 elem]                        [33 elem]                     1.483e-01 (0.00%)    ** CHANGED **
ODE steps (saved)              86                               871                           7.850e+02 (912.79%)  ** CHANGED **
ODE steps (total)              2118                             827                           1.291e+03 (60.95%)   ** CHANGED **
beta_n                         1.865754e+00                     1.865754e+00                  1.947e-10 (0.00%)    ** CHANGED **

diiid_slayer_n1: 13 changed, 9 unchanged
Quantity                                 feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
SLAYER r-based shear                     [6 elem]                         [6 elem]                      3.050e-07 (0.00%)  ** CHANGED **
SLAYER Lundquist S                       [6 elem]                         [6 elem]                      3.412e+00 (0.00%)  ** CHANGED **
SLAYER D_norm                            [6 elem]                         [6 elem]                      1.724e-07 (0.00%)  ** CHANGED **
SLAYER tauk                              [6 elem]                         [6 elem]                      1.446e-11 (0.00%)  ** CHANGED **
SLAYER iota_e                            [6 elem]                         [6 elem]                      9.611e-11 (0.00%)  ** CHANGED **
SLAYER Q_e                               [6 elem]                         [6 elem]                      1.524e-07 (0.00%)  ** CHANGED **
SLAYER Q_i                               [6 elem]                         [6 elem]                      2.310e-07 (0.00%)  ** CHANGED **
SLAYER toroidal critical-Δ factor D_geo  [6 elem]                         [6 elem]                      7.250e-08 (0.00%)  ** CHANGED **
SLAYER γ in 1/s [2/1,3/1,4/1]            [3 elem]                         [3 elem]                      5.005e-01 (0.11%)  ** CHANGED **
CRF b_r/B_φ crit [2/1,3/1,4/1]           [3 elem]                         [3 elem]                      9.865e-09 (0.00%)  ** CHANGED **
CRF Q_peak [2/1,3/1,4/1]                 [3 elem]                         [3 elem]                      5.600e-04 (0.06%)  ** CHANGED **
CRF Q0 [2/1,3/1,4/1]                     [3 elem]                         [3 elem]                      6.004e-07 (0.00%)  ** CHANGED **
CRF b_r crit in tesla [2/1,3/1,4/1]      [3 elem]                         [3 elem]                      1.919e-08 (0.00%)  ** CHANGED **

diiid_slayer_n1_chi_perp_e: 13 changed, 9 unchanged
Quantity                                 feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
SLAYER r-based shear                     [6 elem]                         [6 elem]                      3.050e-07 (0.00%)  ** CHANGED **
SLAYER Lundquist S                       [6 elem]                         [6 elem]                      3.412e+00 (0.00%)  ** CHANGED **
SLAYER D_norm                            [6 elem]                         [6 elem]                      1.724e-07 (0.00%)  ** CHANGED **
SLAYER tauk                              [6 elem]                         [6 elem]                      1.446e-11 (0.00%)  ** CHANGED **
SLAYER iota_e                            [6 elem]                         [6 elem]                      9.611e-11 (0.00%)  ** CHANGED **
SLAYER Q_e                               [6 elem]                         [6 elem]                      1.524e-07 (0.00%)  ** CHANGED **
SLAYER Q_i                               [6 elem]                         [6 elem]                      2.310e-07 (0.00%)  ** CHANGED **
SLAYER toroidal critical-Δ factor D_geo  [6 elem]                         [6 elem]                      7.250e-08 (0.00%)  ** CHANGED **
SLAYER γ in 1/s [2/1,3/1,4/1]            [3 elem]                         [3 elem]                      3.932e-01 (0.10%)  ** CHANGED **
CRF b_r/B_φ crit [2/1,3/1,4/1]           [3 elem]                         [3 elem]                      9.368e-09 (0.00%)  ** CHANGED **
CRF Q_peak [2/1,3/1,4/1]                 [3 elem]                         [3 elem]                      2.800e-03 (0.28%)  ** CHANGED **
CRF Q0 [2/1,3/1,4/1]                     [3 elem]                         [3 elem]                      6.004e-07 (0.00%)  ** CHANGED **
CRF b_r crit in tesla [2/1,3/1,4/1]      [3 elem]                         [3 elem]                      1.822e-08 (0.00%)  ** CHANGED **

diiid_slayer_n1_coupled: 5 changed, 2 unchanged
Quantity                     feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
SLAYER tauk                  [6 elem]                         [6 elem]                      1.446e-11 (0.00%)  ** CHANGED **
SLAYER q_shift               [6 elem]                         [6 elem]                      6.004e-07 (0.00%)  ** CHANGED **
SLAYER coupled Q_root        [1 elem]                         [1 elem]                      1.372e-04 (0.01%)  ** CHANGED **
SLAYER coupled ω             [1 elem]                         [1 elem]                      1.083e+00 (0.00%)  ** CHANGED **
SLAYER coupled γ             [1 elem]                         [1 elem]                      1.423e+00 (0.87%)  ** CHANGED **

diiid_slayer_n1_toroidal: 3 changed, 2 unchanged
Quantity                            feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
SLAYER resistive interchange D_R    [6 elem]                         [6 elem]                      5.097e-08 (0.00%)  ** CHANGED **
SLAYER critical-Δ offset D_c        [6 elem]                         [6 elem]                      8.266e-06 (0.00%)  ** CHANGED **
SLAYER γ in 1/s [2/1,3/1,4/1]       [3 elem]                         [3 elem]                      5.198e-01 (0.04%)  ** CHANGED **

diiid_slayer_n1_winding: 13 changed, 9 unchanged
Quantity                                 feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
SLAYER r-based shear                     [6 elem]                         [6 elem]                      3.050e-07 (0.00%)  ** CHANGED **
SLAYER Lundquist S                       [6 elem]                         [6 elem]                      3.412e+00 (0.00%)  ** CHANGED **
SLAYER D_norm                            [6 elem]                         [6 elem]                      1.724e-07 (0.00%)  ** CHANGED **
SLAYER tauk                              [6 elem]                         [6 elem]                      1.446e-11 (0.00%)  ** CHANGED **
SLAYER iota_e                            [6 elem]                         [6 elem]                      9.611e-11 (0.00%)  ** CHANGED **
SLAYER Q_e                               [6 elem]                         [6 elem]                      1.524e-07 (0.00%)  ** CHANGED **
SLAYER Q_i                               [6 elem]                         [6 elem]                      2.310e-07 (0.00%)  ** CHANGED **
SLAYER toroidal critical-Δ factor D_geo  [6 elem]                         [6 elem]                      7.250e-08 (0.00%)  ** CHANGED **
SLAYER γ in 1/s [2/1,3/1,4/1]            [3 elem]                         [3 elem]                      5.005e-01 (0.11%)  ** CHANGED **
CRF b_r/B_φ crit [2/1,3/1,4/1]           [3 elem]                         [3 elem]                      9.865e-09 (0.00%)  ** CHANGED **
CRF Q_peak [2/1,3/1,4/1]                 [3 elem]                         [3 elem]                      5.600e-04 (0.06%)  ** CHANGED **
CRF Q0 [2/1,3/1,4/1]                     [3 elem]                         [3 elem]                      6.004e-07 (0.00%)  ** CHANGED **
CRF b_r crit in tesla [2/1,3/1,4/1]      [3 elem]                         [3 elem]                      1.919e-08 (0.00%)  ** CHANGED **

diiid_truncation_n1: 2 changed, 10 unchanged
Quantity                               feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
plasma energy Re(ep[1])                -1.377409e+00                    -1.377468e+00                 5.904e-05 (0.00%)  ** CHANGED **
total energy Re(et[1])                 7.978611e-01                     7.978309e-01                  3.021e-05 (0.00%)  ** CHANGED **

lar_reversed_shear_n1: 8 changed, 14 unchanged
Quantity                                                      feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff                Status
total energy Re(et[1])                                        -2.263762e-02                    -2.284976e-02                 2.121e-04 (0.94%)   ** CHANGED **
plasma energy Re(ep[1])                                       -5.912344e-02                    -5.934452e-02                 2.211e-04 (0.37%)   ** CHANGED **
vacuum energy Re(ev[1])                                       3.648582e-02                     3.649476e-02                  8.942e-06 (0.02%)   ** CHANGED **
plasma energy (all)                                           [31 elem]                        [31 elem]                     2.631e-02 (0.00%)   ** CHANGED **
vacuum energy (all)                                           [31 elem]                        [31 elem]                     8.038e-04 (0.00%)   ** CHANGED **
total energy (all)                                            [31 elem]                        [31 elem]                     2.631e-02 (0.00%)   ** CHANGED **
ODE steps (saved)                                             228                              202                           2.600e+01 (11.40%)  ** CHANGED **
ODE steps (total)                                             226                              180                           4.600e+01 (20.35%)  ** CHANGED **

solovev_multi_n: 6 changed, 9 unchanged
Quantity                      feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff                 Status
total energy Re(et[1])        -2.134718e+00                    -2.137747e+00                 3.029e-03 (0.14%)    ** CHANGED **
plasma energy (all)           [70 elem]                        [70 elem]                     9.975e-03 (0.00%)    ** CHANGED **
vacuum energy (all)           [70 elem]                        [70 elem]                     3.002e-03 (0.00%)    ** CHANGED **
total energy (all)            [70 elem]                        [70 elem]                     7.461e-03 (0.00%)    ** CHANGED **
ODE steps (saved)             56                               451                           3.950e+02 (705.36%)  ** CHANGED **
ODE steps (total)             1049                             418                           6.310e+02 (60.15%)   ** CHANGED **

solovev_n1: 9 changed, 13 unchanged
Quantity                      feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff                Status
total energy Re(et[1])        7.361920e-03                     7.325353e-03                  3.657e-05 (0.50%)   ** CHANGED **
plasma energy Re(ep[1])       -1.042158e+01                    -1.042163e+01                 5.337e-05 (0.00%)   ** CHANGED **
vacuum energy Re(ev[1])       1.042894e+01                     1.042895e+01                  1.681e-05 (0.00%)   ** CHANGED **
plasma energy (all)           [32 elem]                        [32 elem]                     5.689e-05 (0.00%)   ** CHANGED **
vacuum energy (all)           [32 elem]                        [32 elem]                     1.681e-05 (0.00%)   ** CHANGED **
total energy (all)            [32 elem]                        [32 elem]                     5.503e-05 (0.00%)   ** CHANGED **
ODE steps (saved)             385                              267                           1.180e+02 (30.65%)  ** CHANGED **
ODE steps (total)             383                              245                           1.380e+02 (36.03%)  ** CHANGED **
ca_left (checksum)            b394089f28e2...                  fd2cf4408420...               0.000e+00 (0.00%)   ** CHANGED **

tj_kinetic_multiion: 2 changed, 4 unchanged
Quantity                     feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
NTV total (D+T+imp+e) [N·m]  8.956130e-04                     8.956257e-04                  1.274e-08 (0.00%)  ** CHANGED **
total energy Re(et[1])       4.350277e-01                     4.350275e-01                  1.651e-07 (0.00%)  ** CHANGED **

tj_kinetic_ntv: 2 changed, 5 unchanged
Quantity                                   feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
NTV torque fgar [Re, Im]                   [1 elem]                         [1 elem]                      1.716e-08 (0.00%)  ** CHANGED **
root-area-weighted total energy Re(et[1])  4.350277e-01                     4.350275e-01                  1.651e-07 (0.00%)  ** CHANGED **

tj_kinetic_ntv_rates: 1 changed, 1 unchanged
Quantity                                      feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff               Status
NTV torque fgar with supplied rates [Re, Im]  [1 elem]                         [1 elem]                      1.257e-08 (0.00%)  ** CHANGED **

tj_n1: 11 changed, 14 unchanged
Quantity                      feature/analysis-plots-overhaul  refactor/riccati-single-pass  Diff                Status
total energy Re(et[1])        4.350277e-01                     4.350275e-01                  1.651e-07 (0.00%)   ** CHANGED **
plasma energy Re(ep[1])       3.772108e-01                     3.772267e-01                  1.591e-05 (0.00%)   ** CHANGED **
vacuum energy Re(ev[1])       5.781690e-02                     5.780082e-02                  1.607e-05 (0.03%)   ** CHANGED **
plasma energy (all)           [32 elem]                        [32 elem]                     3.359e+00 (0.04%)   ** CHANGED **
vacuum energy (all)           [32 elem]                        [32 elem]                     3.359e+00 (3.20%)   ** CHANGED **
total energy (all)            [32 elem]                        [32 elem]                     3.196e-04 (0.00%)   ** CHANGED **
ODE steps (saved)             292                              205                           8.700e+01 (29.79%)  ** CHANGED **
ODE steps (total)             290                              183                           1.070e+02 (36.90%)  ** CHANGED **
resonant area-weighted field  [2 elem]                         [2 elem]                      5.275e-10 (0.00%)   ** CHANGED **
island half-width             [2 elem]                         [2 elem]                      5.656e-07 (0.00%)   ** CHANGED **
Chirikov parameter            [2 elem]                         [2 elem]                      2.398e-06 (0.00%)   ** CHANGED **

Notes for reviewers

What changed

  • Riccati: one solve per chunk, every output from that pass. src/ForceFreeStates/Riccati goes from 1511 to 803 lines.
  • Crossing: both integrators cross in asymptotic coefficients (Glasser & Kolemen 2018, PoP 25, 082502, Eq. 36). The shared code is Surfaces/Crossing.jl.
  • singfac_min = 5e-4 everywhere: it no longer sets an error, only where the series takes over.
  • Fill: stored solutions are filled inside the crossing distance from the series (crossing_fill_points, crossing_fill_min).
  • Riccati output: ξ profiles, and the outer solutions shared with Galerkin as ffs.basis for [Match].
  • Threading: the per-chunk loops take chunks greedily, and the edge scan's vacuum matrices and the fixed-boundary criterion run in parallel (both shared with Forward).

Free-boundary et[1], DIII-D-like Riccati example

singfac_min Riccati before Forward before Riccati now Forward now
1e-3 0.84554 0.82231 0.79789480 0.79789480
1e-4 0.80320 0.80061 0.79789463 0.79789464
1e-5 0.79847 0.79818 0.79789463 0.79789465
1e-6 0.79796 0.79792 0.79789463 0.79789474

The two integrators agree to 3e-8 on ten example decks. Riccati results are identical for 13 to 106 chunks and for 1 and 16 threads.

Known limits

  • Δ′ moves by about 0.1% with the new default, through the grid knots that follow singfac_min.
  • Two chunks per segment, or more than about 150 harmonics, lose accuracy in Float64. The run warns.
  • Solovev example: Δ′ and the outer solutions are not usable, and the run now warns, naming the surfaces. Energies are fine.
  • Multi-n: no Δ′ system, so no outer solutions.
  • Kinetic crossings still take a trapezoidal step, whose error grows as the distance cubed, so kinetic runs default to singfac_min = 1e-5.

Left for #666: plasma_response on a Riccati result, and the fixed-edge Δ′ for matching.

Issues: closes #669, closes #671, closes #481, closes #370, closes #401, closes #333, closes #253, closes #648 (by hand, since this PR is stacked). Not run from #669's list: a crossing of a Mercier-unstable surface. Supersedes the Riccati half of #668. Stacked on #658; #666 sits on top.

Tests: 58 of 60 test files pass on ITER's SDCC cluster. The other two are plot files that need CairoMakie there.

Details and caveats

Commits

  1. f17055d37 restructures the Riccati integrator.
  2. ecac988fc publishes ξ profiles from a Riccati result (first part of ForceFreeStates.Riccati - Reconstruct ξ profiles from the Δ′ BVP solution #671).
  3. 341814b43 shares the outer solutions with Galerkin (second part of ForceFreeStates.Riccati - Reconstruct ξ profiles from the Δ′ BVP solution #671).
  4. d0f04565d gives Forward the same crossing and sets singfac_min to 5e-4 (ForceFreeStates - FEATURE! - Cross ideal singular surfaces with a Frobenius-basis jump #669).
  5. 8948627bd fills the stored solutions and moves the shared crossing code into one file.
  6. 07cf80d5d is the result of a timing audit: scheduling, threading of two shared loops, and fewer copies.
  7. 8fc6c5c3e is the follow-up to review: the two new defaults, a warning where Δ′ is unresolved, a bracketed root-find in the edge scan, and tighter tests.

Timing audit (DIII-D-like Riccati example on ITER's SDCC cluster, whole integration, best of three)

before 07cf80d5d after
n = 1, 16 threads 1.21 s 0.89 s
n = 1, 8 threads 1.28 s 0.76 s
n = 1, 1 thread 2.76 s 2.71 s
n = 2, 16 threads 2.28 s 1.59 s
  • The right-hand side is 86–88% of a chunk solve, runs at BLAS speed and allocates 144 bytes per call. Keeping every solver step costs nothing measurable.
  • The default @threads schedule left the cores 65–75% busy on the chunk loop (45% at 107 harmonics); the greedy schedule keeps them above 90%.
  • Still serial at 16 threads: the asymptotic series (0.12 s) and the edge scan's eigenproblem per stored state (0.15 s). Both read a search hint shared through mats.
  • On the two-socket test node 8 threads beat 16 at 35 harmonics. The same solve run by 16 tasks at once is 65–69% slower each under OpenBLAS and 12–35% under MKL.
  • MKL makes the right-hand side 1.9 times faster on these Intel nodes, but its own threads collide with Julia's in the serial phases; the default backend is unchanged.
  • 07cf80d5d is bit-for-bit neutral with one BLAS thread and identical at 1 and 16 Julia threads. Against a run with several BLAS threads, the edge-scan energies differ by up to 7e-10 (relative) and Forward's stored criterion by up to 7e-9.
  • Memory at 35 harmonics: 80 MB of propagator steps, 40 MB of stored states, 78 MB of outer basis. At 107 harmonics these are 1.3 GB, 0.7 GB and 1.1 GB.

Riccati against Forward (integration alone, best of three, same deck and cluster; both give the same et[1] to eight digits)

Threads n = 1 n = 2 n = 4 (53 harmonics, 20 surfaces)
Riccati / Forward Riccati / Forward Riccati / Forward
1 2.77 / 1.23 s 6.19 / 3.00 s 19.1 / 6.73 s
2 1.65 / 1.10 s 3.54 / 2.58 s 11.3 / 6.16 s
4 1.05 / 1.09 s 2.29 / 2.40 s 6.96 / 5.94 s
8 0.87 / 1.13 s 1.72 / 2.26 s 5.04 / 5.82 s
16 0.90 / 1.19 s 1.82 / 2.29 s 4.64 / 5.81 s
  • Forward's integration is serial. Each Riccati chunk carries all 2N solutions of its interval where Forward carries the N regular at the axis, and restarts its step size, so on one thread it does about 2.5 times the work.

Issues this closes

Why 5e-4 (integration tolerance 1e-12)

  • The series' Euler-Lagrange residual falls going outward until the first grid knot (5e-10 at 5e-4 on the DIII-D-like q = 2 surface), then jumps by about 1e4. Series order 10 instead of 6 changes nothing.
  • Δ′ is flat from about 5e-5 out to the knot. Closer in, its q = 5 entry is off by 2e-4 at 1e-5 and flips sign at 1e-6.
  • The auto grid keeps its knots four crossing distances from each surface. On a fixed grid the solve warns when a knot falls inside one.

Why the fill matters downstream

  • The resonant-field diagnostics evaluate the solution 5e-4/(n·q′) from each surface.
  • A surface resonant at two n is crossed at the distance of its smallest n, so the larger-n row sits inside the crossing distance.
  • On diiid_multi_n those rows moved by up to 13% (resonant field) and 26% (forcing-driven jump) without the fill, and 0.01% or less with it.

Checks without a reference integrator (ten decks, a truncated run, two runs with q = 1 inside)

  • A stored column integrated from one node lands on the next to 4e-10.
  • The Δ′ solutions are continuous across chunk boundaries to 8e-11.
  • The Δ′ system reproduces the plasma response of the axis-to-edge products to 1e-12.
  • The plasma response is Hermitian to 3e-13 (9.6e-6 before).

Caveats

  • First Δ′ diagonal entry on the DIII-D-like Riccati example: 9.261159 to 9.247546. Surfaces whose knots did not move kept their Δ′ to 2e-6. On diiid_n1_riccati_q1 the change is all knots: moving them alone changes the q = 1 and q = 2 entries by 6.7e-3 and 6.1e-3, and changing the crossing distance alone by 4e-6 or less.
  • tj_n1 reports a change of 3.4 in the per-mode plasma and vacuum energies that cancels in the total (3e-4).
  • Im(et[1]) and the perturbed-equilibrium torque of ideal runs fall from 1e-6 to round-off.
  • Filled outer solutions within 1e-3 of a surface differ from Galerkin's by 1e-2 to 2e-2 in a comparison that interpolates; not yet separated from a real difference.
  • With truncate_at_dW_peak the two integrators can pick slightly different edges (0.995142 and 0.995116 on the six-surface DIII-D deck).
  • The fixed-boundary count (Riccati 0, Forward 1 on the DIII-D-like example with q₀ = 0.9) stays with ForceFreeStates - BUGFIX - Count every fixed-boundary zero crossing: inside Riccati chunks, and after a switch of the smallest eigenvalue #668.
  • ForceFreeStates - FEATURE! - Cross ideal singular surfaces with a Frobenius-basis jump #669's singfac_min scan is a test on the Solovev fixture and the table above, not a harness case.

🤖 Generated with Claude Code

…gure theme and a plots CI group

Makie becomes a weak dependency with the GPECMakieExt extension, which holds the figure theme, the label
helpers and saving with whichever backend is loaded. Analysis._draw is the entry point ported plots use; it
throws an ArgumentError naming `using CairoMakie` or `using GLMakie` when no backend is loaded. The plot tests
move to a new `plots` group whose CI job stacks a CairoMakie environment onto LOAD_PATH, so Makie stays out of
the package's own dependencies; changes under ext/ now trigger the test workflow.
…d add the control-surface, (R, Z) and island views
… list summaries only when a panel can be drawn
@jhalpern30

Copy link
Copy Markdown
Collaborator

On this PR's head, DIII-D-like n = 3 Forward (singfac_min 5e-4) reproduces the non-Hermiticity bump: max ‖W−W†‖/‖W+W†‖ of stored W is 1.55e-10 at ψ ≈ 0.2. With #520 applied it drops to 8.5e-12 at the 1e6 default and to 1.0e-13 at 1e3; the edge W and et₁ are unaffected either way (et₁ within 4e-9 of Riccati). So the bump comes from the forward reduction trigger, not from this PR.

@matt-pharr matt-pharr changed the title ForceFreeStates.Riccati - REFACTOR, FEATURE! - Overhaul Riccati integrator, removing extra serial integration, making Float64 BVP by default with Double64 opt-in, speedup ~x4, add riccati xi profile output ForceFreeStates.Riccati - FEATURE! - Integrate each chunk once, cross surfaces through the asymptotic series and store ξ profiles Nov 20, 2026
@github-actions github-actions Bot added changed-results Results move or an interface breaks - read before upgrading feature New capability labels Nov 20, 2026

@d-burg d-burg 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.

@matt-pharr I found no bugs. Logan and Jake covered the defaults, Solovev Δ′, Double64 and speed, so I looked at what they hadn't, at 8e2c8db12.

image

Checked in the code

  • Crossing vs Glasser & Kolemen 2018, Eq. 36. The nonresonant coefficients are carried across unchanged. Zeroing the resonant small coefficients of the non-pivot columns is a choice of basis within the same span, since the pivot column is the pure small solution. fill_crossings! drops the big part from every stored column. That is exact for the physical solution, because its total big coefficient is zero.
  • Chunk solves go through solve_el with the per-column abstol. Δ′ used to depend on the chunk layout through an unset abstol, and that cause is gone.
  • Test tolerances only got tighter. The three new checks at 1e-4 are a near-marginal multi-n eigenvalue and the minimal two-chunks-per-segment layout, both of which the body lists as known limits.
  • The kinetic singfac_min default reaches the auto grid as well, through ctrl.singfac_min.

Independent runs (feynman, Riccati Δ′ example plus its q₀ = 0.9 variant):

  • Threads: 1 against 8 is bit-identical.
  • Chunks: 60 against automatic agrees to 1e-9, and 20 to 1.4e-7. The body says "identical for 13 to 106 chunks"; "to about 1e-7" is closer.
  • Grid: a 3× change in psi_accuracy either way moves the Δ′ diagonal by 0.05–0.7% (1.2% on the q₀ = 0.9 deck's q = 2 entry) and et[1] by 1e-5 to 1e-4.

So the integrator's own error (crossing, chunks, threads) now sits four or more decades below the grid's. The 0.1% knot move in the release note is inside that grid band, so it isn't a concern. It does mean Δ′ is grid-limited at the 0.1–1% level on the default psi_accuracy. A line in the stability docs saying so, and that varying psi_accuracy is the convergence check, would stop people reading the 3e-8 Forward–Riccati agreement as Δ′ accuracy. Not blocking.

Related: with the fixed start now the default and the ideal torque at round-off, #464 only concerns the opt-in Frobenius start. Worth retitling or narrowing it when this lands.

@logan-nc

Copy link
Copy Markdown
Collaborator

I love that we are arguing 1e-7 and 0.1-1% errors on these automated approaches rather than 100% wildness a on manual shots in the dark.

Speaking of shots in the dark... @jhalpern30 just touched up vacuum accuracy that was spline limited. Any insights to bring back to our fundamental plasma equilibrium and profile splines that might help knock out this final 1%?

@jhalpern30

Copy link
Copy Markdown
Collaborator

Speaking of shots in the dark... @jhalpern30 just touched up vacuum accuracy that was spline limited. Any insights to bring back to our fundamental plasma equilibrium and profile splines that might help knock out this final 1%?

Honestly, could be something there. I don't know if its worth waiting holding up this PR, since I can't get to it this week. Anthropic just further tanked their weekly limits so I barely have enough left to get my normal work done on Pro. But I do have a banked usage reset I'm going to use after Thanksgiving so I can definitely look into it then. The unreliability of the splines/equilibria has actually come up a few times in semi-unrelated contexts. I remember also when implementing stellarator symmetry, the nominal Solovev boundary directly from examples was only stellarator (up-down) symmetric to like 1e-3 so I had to manually clean it up.

@matt-pharr

Copy link
Copy Markdown
Collaborator Author

@jhalpern30 any rabbit holes you go down regarding equilibria definitely also take a look at using Stuart's tokamaker I-file setup. Not sure if what you're referring to has to do with the equilibrium splining in GPEC or if it is how the equilibrium is represented outside but the I-files are far better for Delta' convergence for example

…single-pass

Conflict in src/Precompile.jl: develop's workload now loops over Riccati, Forward and Galerkin; keep that loop and drop renorm_threshold, which [Riccati] no longer accepts.
@logan-nc

Copy link
Copy Markdown
Collaborator

Sweet. Yeah, no need to hold this pr but it would be great if you could flag this on your back burner and see what transfers at some point when you have a breather

@matt-pharr
matt-pharr removed this pull request from stack #680 November 24, 2026 18:25
@matt-pharr
matt-pharr added this pull request to stack #690 November 24, 2026 18:25

@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.

This is great. Let's start closing some of these prs

@matt-pharr
matt-pharr added this pull request to the merge queue Nov 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue because a pull request earlier in the stack was removed Nov 26, 2026
@matt-pharr
matt-pharr added this pull request to the merge queue Nov 26, 2026
@matt-pharr
matt-pharr removed this pull request from the merge queue due to a manual request Nov 26, 2026
Base automatically changed from feature/analysis-plots-overhaul to develop November 26, 2026 21:28
@matt-pharr
matt-pharr merged commit 2c8f843 into develop Nov 26, 2026
23 of 24 checks passed
@matt-pharr
matt-pharr deleted the refactor/riccati-single-pass branch November 26, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment