Skip to content

Utilities - BUGFIX! - Compute the trapped fraction from the exact pitch-angle integral - #657

Open
d-burg wants to merge 5 commits into
developfrom
bugfix/trapped-fraction-lin-liu-miller
Open

d-burg wants to merge 5 commits into
developfrom
bugfix/trapped-fraction-lin-liu-miller

Conversation

@d-burg

@d-burg d-burg commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Release note

  • Audience: users
  • Numerical impact: the trapped-particle fraction f_trap drops (by about 0.17 at mid radius in the DIII-D-like cases), so the Sauter neoclassical η, the Lundquist number S and every SLAYER growth rate move; SLAYER γ changes by up to 32 % in the harness cases. Ideal and GGJ results are unchanged. (harness @ 3f636f8)
  • Migration: Utilities.trapped_fraction(avg_B, avg_Bsq, B_min, B_max) is replaced by trapped_fraction(avg_h2, avg_sqrt, weight) (pair it with trapped_fraction_nodes()); for a quick estimate from ⟨B⟩, ⟨B²⟩, B_max and ⟨h⁻²(1 − √(1 − h)(1 + h/2))⟩ use trapped_fraction_lin_liu_miller. No input files change; regenerate any cached Sauter η tables or SLAYER results.

The trapped fraction used for neoclassical resistivity was overestimated. resist_geometry now computes it from the exact pitch-angle integral, f_t = 1 − ¾⟨h²⟩∫₀¹ λ dλ / ⟨√(1 − λh)⟩ with h = B/B_max, which is the quantity the Sauter (1999) fits are defined against.

Regression report

Run on feynman in a clean worktree at 3f636f8, with --refs e08c719cb,002db486e,3f636f84c --force --jobs 1, 8 threads; e08c719 is this branch's base on develop. The table compares that base with 3f636f8. Between 002db48 and 3f636f8 (the graded pitch-angle nodes), the SLAYER layer inputs move by about 1e-10 relative, γ, ω and Q_root are unchanged within tolerance, and CRF Q_peak moves by 0.06–0.17 %.

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

Regression Report: diiid_n1
=================================================================================================
Ref 1: e08c719cb  @ e08c719cb (2026-11-05)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: 3f636f84c  @ 3f636f84c (2026-11-16)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
-------------------------------------------------------------------------------------------------
Quantity                                      e08c719cb        3f636f84c        Diff       Status
-------------------------------------------------------------------------------------------------
total energy Re(et[1])                        7.979258e-01     7.979258e-01     0.0e+00    OK    
total energy Im(et[1])                        1.122433e-06     1.122433e-06     0.0e+00    OK    
plasma energy Re(ep[1])                       -1.377303e+00    -1.377303e+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)                             1177             1177             0.0e+00    OK    
ODE steps (total)                             1172             1172             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.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)                          b1a9e91f9145...  b1a9e91f9145...  identical  OK    
pressure profile (checksum)                   3bf10a935abe...  3bf10a935abe...  identical  OK    
Mercier D_I profile (checksum)                b72acb76916b...  b72acb76916b...  identical  OK    
resistive interchange D_R profile (checksum)  01cd20728b25...  01cd20728b25...  identical  OK    
ballooning Delta' profile (checksum)          34a4f4fac3bb...  34a4f4fac3bb...  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.286415e-04     5.286415e-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.074909e-05     7.074909e-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.521990e+00     5.521990e+00     0.0e+00    OK    
PE toroidal torque                            9.083813e-07     9.083813e-07     0.0e+00    OK    
NTV torque FGAR [N·m]                         5.539325e-01     5.539325e-01     0.0e+00    OK    
NTV kinetic energy dW FGAR [J]                8.224109e-02     8.224109e-02     0.0e+00    OK    
Runtime (s)                                   237.6s           335.0s                      --    
||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: diiid_slayer_n1 — DIII-D-like H-mode equilibrium, n=1, SLAYER tearing-mode analysis (uncoupled per-surface, AMR, validity-gated)
================================================================

Regression Report: diiid_slayer_n1
================================================================================================
Ref 1: e08c719cb  @ e08c719cb (2026-11-05)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: 3f636f84c  @ 3f636f84c (2026-11-16)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
------------------------------------------------------------------------------------------------
Quantity                                 e08c719cb  3f636f84c  Diff                Status       
------------------------------------------------------------------------------------------------
SLAYER surface indices                   [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER poloidal m                        [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER toroidal n                        [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER minor radius rs                   [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER r-based shear                     [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER Lundquist S                       [6 elem]   [6 elem]   2.017e+07 (29.73%)  ** CHANGED **
SLAYER D_norm                            [6 elem]   [6 elem]   2.924e-01 (15.95%)  ** CHANGED **
SLAYER P_perp                            [6 elem]   [6 elem]   1.345e+01 (61.69%)  ** CHANGED **
SLAYER tauk                              [6 elem]   [6 elem]   1.215e-05 (15.80%)  ** CHANGED **
SLAYER iota_e                            [6 elem]   [6 elem]   1.1e-16             OK           
SLAYER Q_e                               [6 elem]   [6 elem]   4.172e-01 (13.36%)  ** CHANGED **
SLAYER Q_i                               [6 elem]   [6 elem]   2.948e-01 (13.36%)  ** CHANGED **
SLAYER toroidal critical-Δ factor D_geo  [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER Q_root [2/1,3/1,4/1]              [3 elem]   [3 elem]   3.759e-01 (15.77%)  ** CHANGED **
SLAYER ω in rad/s [2/1,3/1,4/1]          [3 elem]   [3 elem]   2.059e+01 (0.07%)   ** CHANGED **
SLAYER γ in 1/s [2/1,3/1,4/1]            [3 elem]   [3 elem]   1.387e+02 (30.81%)  ** CHANGED **
SLAYER no_root flags [2/1,3/1,4/1]       [3 elem]   [3 elem]   0.0e+00             OK           
CRF b_r/B_φ crit [2/1,3/1,4/1]           [3 elem]   [3 elem]   2.367e-04 (17.93%)  ** CHANGED **
CRF Q_peak [2/1,3/1,4/1]                 [3 elem]   [3 elem]   1.477e-01 (14.64%)  ** CHANGED **
CRF Q0 [2/1,3/1,4/1]                     [3 elem]   [3 elem]   5.043e-01 (15.80%)  ** CHANGED **
CRF b_r crit in tesla [2/1,3/1,4/1]      [3 elem]   [3 elem]   4.604e-04 (17.93%)  ** CHANGED **
SLAYER enabled flag                      1          1          0.0e+00             OK           
Runtime (s)                              121.8s     124.2s                         --           
================================================================================================
Summary: 13 changed, 9 unchanged


================================================================
Case: diiid_slayer_n1_chi_perp_e — DIII-D-like H-mode equilibrium, n=1, SLAYER tearing-mode analysis with P_perp_model = chi_perp_e
================================================================

Regression Report: diiid_slayer_n1_chi_perp_e
================================================================================================
Ref 1: e08c719cb  @ e08c719cb (2026-11-05)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: 3f636f84c  @ 3f636f84c (2026-11-16)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
------------------------------------------------------------------------------------------------
Quantity                                 e08c719cb  3f636f84c  Diff                Status       
------------------------------------------------------------------------------------------------
SLAYER surface indices                   [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER poloidal m                        [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER toroidal n                        [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER minor radius rs                   [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER r-based shear                     [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER Lundquist S                       [6 elem]   [6 elem]   2.017e+07 (29.73%)  ** CHANGED **
SLAYER D_norm                            [6 elem]   [6 elem]   2.924e-01 (15.95%)  ** CHANGED **
SLAYER P_perp                            [6 elem]   [6 elem]   4.143e+01 (61.72%)  ** CHANGED **
SLAYER tauk                              [6 elem]   [6 elem]   1.215e-05 (15.80%)  ** CHANGED **
SLAYER iota_e                            [6 elem]   [6 elem]   1.1e-16             OK           
SLAYER Q_e                               [6 elem]   [6 elem]   4.172e-01 (13.36%)  ** CHANGED **
SLAYER Q_i                               [6 elem]   [6 elem]   2.948e-01 (13.36%)  ** CHANGED **
SLAYER toroidal critical-Δ factor D_geo  [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER Q_root [2/1,3/1,4/1]              [3 elem]   [3 elem]   3.762e-01 (15.79%)  ** CHANGED **
SLAYER ω in rad/s [2/1,3/1,4/1]          [3 elem]   [3 elem]   1.061e+01 (0.03%)   ** CHANGED **
SLAYER γ in 1/s [2/1,3/1,4/1]            [3 elem]   [3 elem]   1.227e+02 (31.88%)  ** CHANGED **
SLAYER no_root flags [2/1,3/1,4/1]       [3 elem]   [3 elem]   0.0e+00             OK           
CRF b_r/B_φ crit [2/1,3/1,4/1]           [3 elem]   [3 elem]   2.572e-04 (18.21%)  ** CHANGED **
CRF Q_peak [2/1,3/1,4/1]                 [3 elem]   [3 elem]   1.459e-01 (14.50%)  ** CHANGED **
CRF Q0 [2/1,3/1,4/1]                     [3 elem]   [3 elem]   5.043e-01 (15.80%)  ** CHANGED **
CRF b_r crit in tesla [2/1,3/1,4/1]      [3 elem]   [3 elem]   5.002e-04 (18.21%)  ** CHANGED **
SLAYER enabled flag                      1          1          0.0e+00             OK           
Runtime (s)                              73.3s      73.6s                          --           
================================================================================================
Summary: 13 changed, 9 unchanged


================================================================
Case: diiid_slayer_n1_coupled — DIII-D-like H-mode equilibrium, n=1, SLAYER coupled multi-surface determinant with kinetic-file E×B rotation (reuses the n=1 deck via overrides)
================================================================

Regression Report: diiid_slayer_n1_coupled
====================================================================================
Ref 1: e08c719cb  @ e08c719cb (2026-11-05)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: 3f636f84c  @ 3f636f84c (2026-11-16)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
------------------------------------------------------------------------------------
Quantity                     e08c719cb  3f636f84c  Diff                Status       
------------------------------------------------------------------------------------
SLAYER tauk                  [6 elem]   [6 elem]   1.215e-05 (15.80%)  ** CHANGED **
SLAYER q_shift               [6 elem]   [6 elem]   5.043e-01 (15.80%)  ** CHANGED **
SLAYER coupled Q_root        [1 elem]   [1 elem]   3.759e-01 (15.77%)  ** CHANGED **
SLAYER coupled ω             [1 elem]   [1 elem]   6.821e+00 (0.02%)   ** CHANGED **
SLAYER coupled γ             [1 elem]   [1 elem]   4.593e+01 (28.16%)  ** CHANGED **
SLAYER coupled no_root flag  [1 elem]   [1 elem]   0.0e+00             OK           
SLAYER enabled flag          1          1          0.0e+00             OK           
Runtime (s)                  68.2s      77.2s                          --           
====================================================================================
Summary: 5 changed, 2 unchanged


================================================================
Case: diiid_slayer_n1_toroidal — DIII-D-like H-mode, n=1, SLAYER with the toroidal critical-Δ offset (D_c_type = toroidal)
================================================================

Regression Report: diiid_slayer_n1_toroidal
===========================================================================================
Ref 1: e08c719cb  @ e08c719cb (2026-11-05)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: 3f636f84c  @ 3f636f84c (2026-11-16)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
-------------------------------------------------------------------------------------------
Quantity                            e08c719cb  3f636f84c  Diff                Status       
-------------------------------------------------------------------------------------------
SLAYER resistive interchange D_R    [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER critical-Δ offset D_c        [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER Q_root [2/1,3/1,4/1]         [3 elem]   [3 elem]   3.767e-01 (15.82%)  ** CHANGED **
SLAYER γ in 1/s [2/1,3/1,4/1]       [3 elem]   [3 elem]   3.917e+02 (31.05%)  ** CHANGED **
SLAYER no_root flags [2/1,3/1,4/1]  [3 elem]   [3 elem]   0.0e+00             OK           
Runtime (s)                         68.3s      82.8s                          --           
===========================================================================================
Summary: 2 changed, 3 unchanged


================================================================
Case: diiid_slayer_n1_winding — DIII-D-like H-mode equilibrium, n=1, SLAYER tearing-mode analysis with root_classification = winding
================================================================

Regression Report: diiid_slayer_n1_winding
================================================================================================
Ref 1: e08c719cb  @ e08c719cb (2026-11-05)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: 3f636f84c  @ 3f636f84c (2026-11-16)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
------------------------------------------------------------------------------------------------
Quantity                                 e08c719cb  3f636f84c  Diff                Status       
------------------------------------------------------------------------------------------------
SLAYER surface indices                   [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER poloidal m                        [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER toroidal n                        [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER minor radius rs                   [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER r-based shear                     [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER Lundquist S                       [6 elem]   [6 elem]   2.017e+07 (29.73%)  ** CHANGED **
SLAYER D_norm                            [6 elem]   [6 elem]   2.924e-01 (15.95%)  ** CHANGED **
SLAYER P_perp                            [6 elem]   [6 elem]   1.345e+01 (61.69%)  ** CHANGED **
SLAYER tauk                              [6 elem]   [6 elem]   1.215e-05 (15.80%)  ** CHANGED **
SLAYER iota_e                            [6 elem]   [6 elem]   1.1e-16             OK           
SLAYER Q_e                               [6 elem]   [6 elem]   4.172e-01 (13.36%)  ** CHANGED **
SLAYER Q_i                               [6 elem]   [6 elem]   2.948e-01 (13.36%)  ** CHANGED **
SLAYER toroidal critical-Δ factor D_geo  [6 elem]   [6 elem]   0.0e+00             OK           
SLAYER Q_root [2/1,3/1,4/1]              [3 elem]   [3 elem]   3.759e-01 (15.77%)  ** CHANGED **
SLAYER ω in rad/s [2/1,3/1,4/1]          [3 elem]   [3 elem]   2.059e+01 (0.07%)   ** CHANGED **
SLAYER γ in 1/s [2/1,3/1,4/1]            [3 elem]   [3 elem]   1.387e+02 (30.81%)  ** CHANGED **
SLAYER no_root flags [2/1,3/1,4/1]       [3 elem]   [3 elem]   0.0e+00             OK           
CRF b_r/B_φ crit [2/1,3/1,4/1]           [3 elem]   [3 elem]   2.367e-04 (17.93%)  ** CHANGED **
CRF Q_peak [2/1,3/1,4/1]                 [3 elem]   [3 elem]   1.477e-01 (14.64%)  ** CHANGED **
CRF Q0 [2/1,3/1,4/1]                     [3 elem]   [3 elem]   5.043e-01 (15.80%)  ** CHANGED **
CRF b_r crit in tesla [2/1,3/1,4/1]      [3 elem]   [3 elem]   4.604e-04 (17.93%)  ** CHANGED **
SLAYER enabled flag                      1          1          0.0e+00             OK           
Runtime (s)                              68.4s      70.6s                          --           
================================================================================================
Summary: 13 changed, 9 unchanged


================================================================
Case: lar_ggj_tearing_n1 — LAR TJ equilibrium, n=1, GGJ tearing growth rates per surface from the Galerkin Δ′ (reuses the LAR ideal-match deck via overrides)
================================================================

Regression Report: lar_ggj_tearing_n1
========================================================
Ref 1: e08c719cb  @ e08c719cb (2026-11-05)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: 3f636f84c  @ 3f636f84c (2026-11-16)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
--------------------------------------------------------
Quantity           e08c719cb  3f636f84c  Diff     Status
--------------------------------------------------------
GGJ γ in 1/s       [2 elem]   [2 elem]   0.0e+00  OK    
GGJ ω in rad/s     [2 elem]   [2 elem]   0.0e+00  OK    
GGJ no_root flags  [2 elem]   [2 elem]   0.0e+00  OK    
========================================================
Summary: 3 unchanged


================================================================
Case: gal_resistive_diiid — DIII-D-like, n=1, RDCON outer-region Galerkin Δ′ with rpec coil columns (delta_coil)
================================================================

Regression Report: gal_resistive_diiid
====================================================================
Ref 1: e08c719cb  @ e08c719cb (2026-11-05)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
Ref 2: 3f636f84c  @ 3f636f84c (2026-11-16)
       env: julia 1.11.9, x86_64-linux-gnu, manifest 6f3e1b5f (pinned), 8 threads/8 BLAS, jit build, warm
--------------------------------------------------------------------
Quantity                 e08c719cb     3f636f84c     Diff     Status
--------------------------------------------------------------------
gal # singular surfaces  4             4             0.0e+00  OK    
gal singular q values    [4 elem]      [4 elem]      0.0e+00  OK    
gal PEST3 Δ diagonal     [4 elem]      [4 elem]      0.0e+00  OK    
||gal Δ′ matrix||        2.302020e+03  2.302020e+03  0.0e+00  OK    
||gal Δ_coil block||     1.581715e+01  1.581715e+01  0.0e+00  OK    
gal D_I per surface      [4 elem]      [4 elem]      0.0e+00  OK    
gal α per surface        [4 elem]      [4 elem]      0.0e+00  OK    
||gal inner-layer Δ||    1.474579e+06  1.474579e+06  0.0e+00  OK    
||gal match cout||       3.048397e-02  3.048397e-02  0.0e+00  OK    
||gal match bpen||       1.206218e+00  1.206218e+00  0.0e+00  OK    
gal match residual       1.974897e-16  1.974897e-16  0.0e+00  OK    
Runtime (s)              19.5s         13.6s                  --    
====================================================================
Summary: 11 unchanged

Notes for reviewers

What was wrong. NeoclassicalResistivity evaluated 1 − ⟨B⟩²/⟨B²⟩ (1 − √(1 − h)(1 + h/2)) with h = B_min/B_max. That is neither the exact trapped fraction nor Lin-Liu & Miller (1995), whose upper bound uses h̄ = ⟨B⟩/B_max. The flux-surface averages themselves were correct.

What changed.

  • trapped_fraction_nodes(h_min) returns pitch-angle nodes for the λ integral, mapped through λ = 1 − x² so the √ endpoint singularity at λ = 1 is removed. The integrand varies on the scale x ~ √(1 − h_min) with h_min = B_min/B_max, so the nodes are 16-point Gauss–Legendre on the geometric panels [0, s], [s, 8s], … , 1 with s = √(1 − h_min): 16 nodes for uniform |B|, up to 112 at ε = 1e-10, and f_t within 1e-10 for 0 ≤ ε ≤ 0.9 on the model surface.
  • resist_geometry averages √(1 − λₖ h) on the same periodic-spline θ integral as the other GGJ columns, then calls trapped_fraction(⟨h²⟩, ⟨√(1 − λh)⟩, w). It tracks B_min to place the nodes.
  • trapped_fraction_lin_liu_miller is kept as the cheap approximation (0.75 f_tu + 0.25 f_tl, as in OMFIT fluxSurface.py) for cross-checks.
  • New testset on |B| = 1/(1 + ε cos θ): the exact integral against adaptive-quadrature references for ε from 1e-6 to 0.6 (atol 1e-10); node doubling leaves f_t unchanged; uniform |B| gives f_t = 0; the independent small-ε limit f_t/√ε → 1.4624249524 holds to within ε at ε = 1e-5 to 1e-7; and Lin-Liu & Miller lies within 1e-3 of the exact value for ε ≥ 0.05.

Cross-check against OMFIT (fluxSurfaces, f_t = 1 − fc, which is Lin-Liu & Miller), on 257×257 g-files:

equilibrium ψ_N OMFIT (LLM) this PR (exact)
TJ circular, p_c = 0.005 0.3 / 0.5 / 0.7 / 0.9 0.4339 / 0.4938 / 0.5399 / 0.5796 0.4342 / 0.4943 / 0.5405 / 0.5802
DIII-D-like shaped L-mode (synthetic) 0.3 / 0.5 / 0.7 / 0.9 0.5642 / 0.6337 / 0.6836 / 0.7215 0.5648 / 0.6343 / 0.6841 / 0.7219
same, at q = 2 / 3 / 4 0.657 / 0.875 / 0.962 0.6739 / 0.7175 / 0.7292 0.6745 / 0.7179 / 0.7296

Before this PR the same q = 2 / 3 / 4 surfaces gave 0.844 / 0.886 / 0.900, and the TJ q = 2 surface gave 0.656 (exact 0.492).

With the Lin-Liu & Miller form in resist_geometry the code matches OMFIT to 1e-4. The exact integral sits 3–6e-4 above it, which is the expected size of the LLM error.

ResistGeometry.f_trap feeds both the Sauter η and the SLAYER layer inputs, so S, P_⊥, τ_k and Q move together; the harness rows above show exactly that set changing and nothing upstream of it.


🤖 Generated with Claude Code

…ch-angle integral

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 06:24
@d-burg d-burg self-assigned this Nov 6, 2026
@d-burg
d-burg requested a review from matt-pharr November 6, 2026 06:24
@github-actions github-actions Bot added bugfix Something was wrong and now is not changed-results Results move or an interface breaks - read before upgrading labels Nov 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

Fixes an overestimate of the trapped-particle fraction used in neoclassical resistivity by switching to the exact pitch-angle integral definition used by the Sauter (1999) fits.

Changes:

  • Replace the old trapped-fraction estimate with an exact pitch-angle integral using Gauss–Legendre quadrature nodes (trapped_fraction_nodes + trapped_fraction).
  • Update resist_geometry to compute ⟨√(1 − λ h)⟩ consistently with existing θ-averages and remove B_min tracking.
  • Add regression tests validating the exact integral against reference values and checking the Lin-Liu & Miller approximation accuracy.
File Description
test/​runtests_slayer_params.jl Adds tests for the exact trapped-fraction integral and Lin-Liu & Miller approximation.
src/​Utilities/​Utilities.jl Updates exports to expose new trapped-fraction helpers.
src/​Utilities/​NeoclassicalResistivity.jl Introduces exact integral implementation, quadrature-node generation, and keeps Lin-Liu & Miller approximation as a helper.
src/​ForceFreeStates/​Surfaces/​ResistEval.jl Computes trapped fraction from the exact pitch-angle integral using new θ-integrand columns.

Review effort: Lite

Comment on lines +92 to +94
lambda, lambda_weight = Utilities.NeoclassicalResistivity.trapped_fraction_nodes()
ff = zeros(Float64, ntheta, 8 + length(lambda))
weight = zeros(Float64, ntheta)
all(>(0), avg_sqrt) || throw(ArgumentError("trapped_fraction: ⟨√(1 − λh)⟩ must be > 0"))
return clamp(1.0 - 0.75 * avg_h2 * sum(weight ./ avg_sqrt), 0.0, 1.0)
end

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

The physics correction is right, and I would retain it. The exact integral, normalization h = B/B_max, transformed quadrature weights, and jac/v1 flux-surface weighting are consistent. The Lin-Liu–Miller helper also matches the upper and lower bounds in Lin-Liu & Miller (1995), Eqs. (1), (4), and (7), DOI: 10.1063/1.871315.

Requesting two small revisions before merging:

  1. Qualify the quadrature accuracy and test weak trapping. The docstring at src/Utilities/NeoclassicalResistivity.jl:185 says 16 nodes give approximately 1e-9 accuracy, but this is not generally true. Using the test's model B = 1/(1 + epsilon*cos(theta)) with its uniform theta average, a numerical check of the PR implementation gives:
epsilon 16 nodes Converged result
0.05 0.3187784577 0.3187784522
0.0001 0.0146683403 0.0146236428
0.000001 0.0003978316 0.0014624244

The check used 16,384 equally spaced theta samples. For epsilon = 1e-6, 256 and 512 pitch-angle nodes give 0.00146242437809 and 0.00146242435857 respectively. The current tests start at epsilon = 0.05 and miss this limitation. Please add a weak-trapping convergence test and state the default quadrature's accuracy range. If accurate near-axis values are required, refine the quadrature there; describing the underlying integral as exact does not guarantee numerical accuracy.

  1. Fix the failing formatting check. JuliaFormatter wants the exports docstring table in NeoclassicalResistivity.jl realigned. Package tests and documentation CI otherwise pass.

All five reference values in the added test were reproduced. The posted regression report records unchanged ideal/GGJ results and substantial SLAYER changes, consistent with correcting the resistivity input. That report was reviewed rather than independently rerunning the full harness. The numerical checks above ran under Julia 1.13; a local Julia 1.11 attempt encountered a dependency incompatibility.

…e for the formatter

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BgNxCF8ZswFaPqyk7i111H

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

@d-burg — pushed one commit, then what is left.

Pushed

  • 34d8641de realigns the exports table in NeoclassicalResistivity.jl for JuliaFormatter 1.0.62 (the second item of @matt-pharr's review). Table whitespace only, so no number moves, but it is under src/ and has made the release-note stamp stale: it only needs moving to 34d8641de.

Physics

  • Checked independently: f_t = 1 − ¾⟨h²⟩∫₀¹ λ dλ/⟨√(1 − λh)⟩ with h = B/B_max; the λ = 1 − x² map and the weights w·2x(1 − x²) (they sum to ½); and the jac/v1 weighting of the new θ columns. All correct. The develop formula it replaces (h = B_min/B_max with ⟨B⟩²/⟨B²⟩) is neither Lin-Liu–Miller bound, so this is a real fix.
  • Still open: the quadrature accuracy near the axis (first item of Pharr's review, not yet answered). The integrand varies over 1 − λ ~ 2ε, i.e. x ~ √(2ε), which 16 nodes on [0, 1] stop resolving below ε ~ 1e-3. Rational surfaces rarely sit there, so SLAYER is safe today, but see the reconcile note below: a profile evaluation down to the axis would hit it. Either scale the node map with the surface (e.g. split the x interval at √(1 − h_min)), or state the validity range and leave it. The inline suggestion does the latter.

Reconcile with two other open PRs

Three branches now carry a trapped fraction:

PR What it does
this one exact integral in trapped_fraction; trapped_fraction_lin_liu_miller = ¾f_tu + ¼f_tl, exported but used only by the test
#665 (modified Rutherford equation) edits the same trapped_fraction to the Lin-Liu–Miller upper bound f_tu alone, keeping the unused B_min argument; adds sauter2002_trapped_fraction(ε, δ) for RDCON parity
#667 (Redl bootstrap current) adds circulating_fraction = 1 − (¾f_tu + ¼f_tl), the same formula as this PR's helper, on a profile that reaches the axis

Recommended order:

  1. Merge this PR first. It is the most accurate of the three.
  2. #665 drops its hunk in NeoclassicalResistivity.jl (it conflicts and is superseded) and keeps sauter2002_trapped_fraction only where RDCON parity is the point; elsewhere it reads ResistGeometry.f_trap.
  3. #667 calls trapped_fraction_lin_liu_miller instead of carrying a second copy, which also gives that helper a caller in src/. If #667 later wants the exact value on its profile, the near-axis item above becomes binding.

I will make the changes to #665 and #667 once this one is in.

Tests

  • The five reference values come from the same integral at higher order. Add one independent check: f_t → 1.46√ε as ε → 0 for this model field (Pharr's converged 1.4624e-3 at ε = 1e-6 is that limit), at whatever ε the final quadrature is claimed to reach.

No merge without approval from a human reviewer. This comment is not an approval.


Lin-Liu & Miller 1995, Phys. Plasmas **2**, 1666, Eq. (6):
Pitch-angle nodes for [`trapped_fraction`](@ref): `n`-point Gauss-Legendre in x ∈ [0, 1] with λ = 1 − x², so that
∫₀¹ λ g(λ) dλ ≈ Σₖ weight[k] g(lambda[k]). The x map removes the √ edge behavior at λ → 1; 16 nodes give f_t to ~1e-9.

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.

The 1e-9 holds only away from the axis: with the test's model field the error is 5e-9 at ε = 0.05, 4.5e-5 at ε = 1e-4 and order one at ε = 1e-6 (numbers from Pharr's review).

Suggested change
∫₀¹ λ g(λ) dλ ≈ Σₖ weight[k] g(lambda[k]). The x map removes the √ edge behavior at λ → 1; 16 nodes give f_t to ~1e-9.
∫₀¹ λ g(λ) dλ ≈ Σₖ weight[k] g(lambda[k]). The x map removes the √ edge behavior at λ → 1; 16 nodes give f_t to ~1e-8 for
inverse aspect ratio ε ≳ 0.05 and lose accuracy below ε ~ 1e-3, where the integrand varies over x ~ √(2ε).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Superseded by 3f636f84c, which grades the nodes to √(1 − B_min/B_max) instead of stating a limit. The docstring now gives the measured range (f_t within 1e-10 for 0 ≤ ε ≤ 0.9), and the test pins it, including the small-ε limit 1.4624√ε.

…B_min/B_max

A single 16-node Gauss-Legendre panel in x (λ = 1 − x²) misses the integrand's
structure at x ~ √(1 − B_min/B_max), so f_t lost accuracy below ε ~ 1e-3 (−1.1e-3
at ε = 1e-6, where f_t = 1.5e-3). trapped_fraction_nodes(h_min) now places 16
nodes on each geometric panel [0, s], [s, 8s], … , 1 with s = √(1 − h_min),
holding f_t to 1e-10 for 0 ≤ ε ≤ 0.9 on the model surface. resist_geometry
tracks B_min again to supply h_min. The test extends to ε = 1e-6 at atol 1e-10,
checks node doubling, uniform |B|, and the independent small-ε limit
f_t/√ε → 1.4624249524 from the boundary-layer integral.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@d-burg

d-burg commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

@matt-pharr @logan-nc Thanks, both. You were right about weak trapping, and 3f636f84c fixes it. That commit is rebased onto Logan's 34d8641de, which already covered the formatting.

Quadrature. I took Logan's first option. With λ = 1 − x², the integrand varies on x ~ √(1 − B_min/B_max), so trapped_fraction_nodes(h_min) now puts 16 Gauss-Legendre nodes on each geometric panel [0, s], [s, 8s], … , 1, with s = √(1 − h_min). That is 16 to 112 nodes, and resist_geometry tracks B_min again. On your model surface, f_t is within 1e-10 of an adaptive reference for 0 ≤ ε ≤ 0.9; the previous scheme reached order-one error by ε ~ 1e-6 (panel a).

image

Independent check. The boundary layer at λ → 1 gives f_t → C√ε, with C = ¾∫₀^∞ [y^(−1/2) − 1/⟨√(y + 1 + cos θ)⟩] dy = 1.4624249524 (panel b). The test checks that limit at ε = 1e-5 to 1e-7, along with the references to 1e-10 down to ε = 1e-6, node doubling, and uniform |B| giving zero.

Harness (feynman, now in the PR body): the quadrature change alone moves the SLAYER layer inputs by about 1e-10 relative, with γ and ω unchanged. Only CRF Q_peak moves visibly (0.06–0.17 %), from its peak search. Against develop, SLAYER γ still moves by 28–32 %, and the ideal and GGJ cases are unchanged.

Order. Agreed: this PR first, then #665 drops its NeoclassicalResistivity.jl hunk and #667 calls trapped_fraction_lin_liu_miller. The red api check is develop's CCC parity test from #654, not this PR.

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 changed-results Results move or an interface breaks - read before upgrading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants