Skip to content

ForceFreeStates - BUGFIX - Move a rational qlow start off its surface and grow the reduction store on demand - #662

Draft
d-burg wants to merge 2 commits into
developfrom
bugfix/high-n-sing-start-qlow-unorm
Draft

d-burg wants to merge 2 commits into
developfrom
bugfix/high-n-sing-start-qlow-unorm

Conversation

@d-burg

@d-burg d-burg commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Release note

  • Audience: users
  • Numerical impact: none (harness @ 2b4d088)
  • Migration: none

A qlow that is itself a rational at some n (1.5 at n = 2, 3 at n = 3, 6, 9, …) used to stop the run at the first chunk because the integration started exactly on a singular surface; the start is now moved one crossing standoff past that surface, with a warning. High-n runs (n ≳ 20 on the DIII-D-like example) overflowed the fixed-size store of Gaussian-reduction records, which left δW correct but made the reconstructed ξ profiles garbage; the store now grows on demand.

Regression report

Regression Report: diiid_n1
=====================================================================================================================
Ref 1: origin/develop  @ 324ef5665 (2026-11-07)
       env: julia 1.11.6, arm64-apple-darwin24.0.0, manifest f1e0eb38 (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: bugfix/high-n-sing-start-qlow-unorm  @ 2b4d088cb (2026-11-07)
       env: julia 1.11.6, arm64-apple-darwin24.0.0, manifest f1e0eb38 (pinned), 8 threads/8 BLAS, jit build, warm
---------------------------------------------------------------------------------------------------------------------
Quantity                                      origin/develop   bugfix/high-n-sing-start-qlow-unorm  Diff       Status
---------------------------------------------------------------------------------------------------------------------
total energy Re(et[1])                        7.979262e-01     7.979262e-01                         0.0e+00    OK    
total energy Im(et[1])                        1.122437e-06     1.122437e-06                         0.0e+00    OK    
plasma energy Re(ep[1])                       -1.377302e+00    -1.377302e+00                        0.0e+00    OK    
vacuum energy Re(ev[1])                       2.175228e+00     2.175228e+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)                             1211             1211                                 0.0e+00    OK    
ODE steps (total)                             1206             1206                                 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.842269e-01     8.842269e-01                         0.0e+00    OK    
internal inductance li2                       7.080757e-01     7.080757e-01                         0.0e+00    OK    
internal inductance li3                       7.304341e-01     7.304341e-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)                          ce38cd35fd0e...  ce38cd35fd0e...                      identical  OK    
pressure profile (checksum)                   6ab81268d66d...  6ab81268d66d...                      identical  OK    
Mercier D_I profile (checksum)                c3e460e14c0d...  c3e460e14c0d...                      identical  OK    
resistive interchange D_R profile (checksum)  a70d25e1ff98...  a70d25e1ff98...                      identical  OK    
ballooning Delta' profile (checksum)          cdebb3000867...  cdebb3000867...                      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.286404e-04     5.286404e-04                         0.0e+00    OK    
dominant-coupling singular values             [3 elem]         [3 elem]                             0.0e+00    OK    
|forcing overlap with dominant mode|          1.419632e-04     1.419632e-04                         0.0e+00    OK    
|delta_nominal| of coil set 1                 7.074907e-05     7.074907e-05                         0.0e+00    OK    
||ddelta/d(shift)|| over coil sets            1.246839e-04     1.246839e-04                         0.0e+00    OK    
||ddelta/d(tilt)|| over coil sets             4.175435e-07     4.175435e-07                         0.0e+00    OK    
PE plasma energy                              3.321081e+00     3.321081e+00                         0.0e+00    OK    
PE vacuum energy                              3.174319e+00     3.174319e+00                         0.0e+00    OK    
PE surface energy                             5.521988e+00     5.521988e+00                         0.0e+00    OK    
PE toroidal torque                            9.083768e-07     9.083768e-07                         0.0e+00    OK    
NTV torque FGAR [N·m]                         5.539324e-01     5.539324e-01                         0.0e+00    OK    
NTV kinetic energy dW FGAR [J]                8.224183e-02     8.224183e-02                         0.0e+00    OK    
Runtime (s)                                   112.8s           717.3s                                          --    
||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: origin/develop  @ 324ef5665 (2026-11-07)
       env: julia 1.11.6, arm64-apple-darwin24.0.0, manifest f1e0eb38 (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: bugfix/high-n-sing-start-qlow-unorm  @ 2b4d088cb (2026-11-07)
       env: julia 1.11.6, arm64-apple-darwin24.0.0, manifest f1e0eb38 (pinned), 8 threads/8 BLAS, jit build, warm
-----------------------------------------------------------------------------------------------------
Quantity                      origin/develop   bugfix/high-n-sing-start-qlow-unorm  Diff       Status
-----------------------------------------------------------------------------------------------------
total energy Re(et[1])        7.361643e-03     7.361643e-03                         0.0e+00    OK    
total energy Im(et[1])        2.474573e-09     2.474573e-09                         0.0e+00    OK    
plasma energy Re(ep[1])       -1.042158e+01    -1.042158e+01                        0.0e+00    OK    
vacuum energy Re(ev[1])       1.042894e+01     1.042894e+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)             381              381                                  0.0e+00    OK    
ODE steps (total)             379              379                                  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)          1f70d9bad4ed...  1f70d9bad4ed...                      identical  OK    
pressure profile (checksum)   af7dbf7be9e7...  af7dbf7be9e7...                      identical  OK    
ca_left (checksum)            23c43e08a244...  23c43e08a244...                      identical  OK    
Runtime (s)                   16.0s            37.3s                                           --    
=====================================================================================================
Summary: 22 unchanged


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

Regression Report: solovev_multi_n
=====================================================================================================
Ref 1: origin/develop  @ 324ef5665 (2026-11-07)
       env: julia 1.11.6, arm64-apple-darwin24.0.0, manifest f1e0eb38 (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: bugfix/high-n-sing-start-qlow-unorm  @ 2b4d088cb (2026-11-07)
       env: julia 1.11.6, arm64-apple-darwin24.0.0, manifest f1e0eb38 (pinned), 8 threads/8 BLAS, jit build, warm
-----------------------------------------------------------------------------------------------------
Quantity                      origin/develop   bugfix/high-n-sing-start-qlow-unorm  Diff       Status
-----------------------------------------------------------------------------------------------------
total energy Re(et[1])        -2.134718e+00    -2.134718e+00                        0.0e+00    OK    
total energy Im(et[1])        1.050131e-10     1.050131e-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)             1038             1038                                 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)          1f70d9bad4ed...  1f70d9bad4ed...                      identical  OK    
Runtime (s)                   60.8s            70.9s                                           --    
=====================================================================================================
Summary: 15 unchanged


================================================================
Case: lar_reversed_shear_n1 — Large-aspect-ratio reversed-shear equilibrium (hollow current), n=1, ideal stability
================================================================

Regression Report: lar_reversed_shear_n1
=====================================================================================================================================
Ref 1: origin/develop  @ 324ef5665 (2026-11-07)
       env: julia 1.11.6, arm64-apple-darwin24.0.0, manifest f1e0eb38 (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: bugfix/high-n-sing-start-qlow-unorm  @ 2b4d088cb (2026-11-07)
       env: julia 1.11.6, arm64-apple-darwin24.0.0, manifest f1e0eb38 (pinned), 8 threads/8 BLAS, jit build, warm
-------------------------------------------------------------------------------------------------------------------------------------
Quantity                                                      origin/develop   bugfix/high-n-sing-start-qlow-unorm  Diff       Status
-------------------------------------------------------------------------------------------------------------------------------------
total energy Re(et[1])                                        -2.263762e-02    -2.263762e-02                        0.0e+00    OK    
total energy Im(et[1])                                        2.135928e-15     2.135928e-15                         0.0e+00    OK    
plasma energy Re(ep[1])                                       -5.912341e-02    -5.912341e-02                        0.0e+00    OK    
vacuum energy Re(ev[1])                                       3.648579e-02     3.648579e-02                         0.0e+00    OK    
vacuum matrix min eigenvalue                                  3.488391e-02     3.488391e-02                         0.0e+00    OK    
plasma energy (all)                                           [31 elem]        [31 elem]                            0.0e+00    OK    
vacuum energy (all)                                           [31 elem]        [31 elem]                            0.0e+00    OK    
total energy (all)                                            [31 elem]        [31 elem]                            0.0e+00    OK    
ODE steps (saved)                                             229              229                                  0.0e+00    OK    
ODE steps (total)                                             227              227                                  0.0e+00    OK    
q0                                                            2.397229e+00     2.397229e+00                         0.0e+00    OK    
q95                                                           2.687221e+00     2.687221e+00                         0.0e+00    OK    
beta_t                                                        3.331679e-04     3.331679e-04                         0.0e+00    OK    
beta_n                                                        1.898177e-01     1.898177e-01                         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    
singular dq/dpsi (opposite signs on the two q = 2 crossings)  [2 elem]         [2 elem]                             0.0e+00    OK    
mpert                                                         31               31                                   0.0e+00    OK    
npert                                                         1                1                                    0.0e+00    OK    
q profile (checksum)                                          39d1db7ce55d...  39d1db7ce55d...                      identical  OK    
pressure profile (checksum)                                   0996d4ffdc7a...  0996d4ffdc7a...                      identical  OK    
Runtime (s)                                                   4.3s             153.5s                                          --    
=====================================================================================================================================
Summary: 22 unchanged


================================================================
Case: tj_n1 — TJ-analytic equilibrium, n=1, no wall, ideal stability + perturbed equilibrium
================================================================

Regression Report: tj_n1
=====================================================================================================
Ref 1: origin/develop  @ 324ef5665 (2026-11-07)
       env: julia 1.11.6, arm64-apple-darwin24.0.0, manifest f1e0eb38 (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: bugfix/high-n-sing-start-qlow-unorm  @ 2b4d088cb (2026-11-07)
       env: julia 1.11.6, arm64-apple-darwin24.0.0, manifest f1e0eb38 (pinned), 8 threads/8 BLAS, jit build, warm
-----------------------------------------------------------------------------------------------------
Quantity                      origin/develop   bugfix/high-n-sing-start-qlow-unorm  Diff       Status
-----------------------------------------------------------------------------------------------------
total energy Re(et[1])        4.350277e-01     4.350277e-01                         0.0e+00    OK    
total energy Im(et[1])        -1.001802e-14    -1.001802e-14                        0.0e+00    OK    
plasma energy Re(ep[1])       3.772270e-01     3.772270e-01                         0.0e+00    OK    
vacuum energy Re(ev[1])       5.780072e-02     5.780072e-02                         0.0e+00    OK    
vacuum matrix min eigenvalue  3.082359e-02     3.082359e-02                         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)             295              295                                  0.0e+00    OK    
ODE steps (total)             293              293                                  0.0e+00    OK    
q0                            1.599966e+00     1.599966e+00                         0.0e+00    OK    
q95                           2.980037e+00     2.980037e+00                         0.0e+00    OK    
beta_t                        6.656722e-04     6.656722e-04                         0.0e+00    OK    
beta_n                        4.156626e-01     4.156626e-01                         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)          c1ce6c39d2ce...  c1ce6c39d2ce...                      identical  OK    
resonant area-weighted field  [2 elem]         [2 elem]                             0.0e+00    OK    
pressure profile (checksum)   2d937bf30331...  2d937bf30331...                      identical  OK    
island half-width             [2 elem]         [2 elem]                             0.0e+00    OK    
Chirikov parameter            [2 elem]         [2 elem]                             0.0e+00    OK    
toroidal torque [N·m]         6.396822e-14     6.396822e-14                         0.0e+00    OK    
Runtime (s)                   10.6s            166.2s                                          --    
=====================================================================================================
Summary: 25 unchanged

Notes for reviewers

  • Found while scoping an ELITE-type high-n peeling–ballooning scan. On the DIII-D-like example at n = 2 the ξ profiles with numunorms_init = 3 are now bitwise identical to those with 100 (the store grows 3 → 6 → 12 → 24 → 48); on develop they differed by a relative 4e49.
  • The move applies to every integrator, Galerkin included, since sing_min! sets the common psilow. Examples and harness decks use qlow = 1.02 or the default, so nothing in the harness moves.
  • Not covered: a kinetic run whose kinetic singular surface (found later, from det F̄) coincides with the start; ising_start treats such a surface as still to be crossed. Improbable, left as is.
  • grow_reduction_store! also fixes a latent bug: the old warn-and-drop branch kept writing the overflow reduction into the last record.

🤖 Generated with Claude Code

d-burg and others added 2 commits November 7, 2026 11:04
… and grow the reduction store on demand

A qlow that is itself a rational at some n (1.5 at n=2, 3 at n=3,6,9) put the
integration start exactly on a singular surface, where the chunker stopped with an
error. sing_min! now moves the start one crossing standoff singfac_min/|n q'| past
any surface it lands on, with a warning.

The Gaussian-reduction records (fixfac, index, fixstep, sing_flag, zeroed_idx) were
fixed at numunorms_init; high-n runs reduce at every rational and every
renorm_threshold trigger, overflowed the store at n ≳ 20, and lost the records
transform_u! needs, so δW stayed right while the ξ profiles came back as garbage.
The store now doubles on demand.

Unit tests for both; verified on the DIII-D-like example at n=2 (ξ profiles
bitwise identical between numunorms_init=3 and 100).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…e growth

Skip the move when singfac_min = 0 (no standoff, no crossings) or q' = 0 at the surface
(infinite standoff), error instead of moving past psilim, and grow a zero-capacity
reduction store to one record. Tests for each.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@d-burg d-burg self-assigned this Nov 7, 2026
@github-actions github-actions Bot added the bugfix Something was wrong and now is not label Nov 7, 2026

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

bugfix Something was wrong and now is not

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant