Skip to content

ForceFreeStates - FEATURE! - Add perpendicular inertia and an ELITE-style growth-rate solve - #663

Open
d-burg wants to merge 28 commits into
developfrom
feature/growth-rate-inertia
Open

d-burg wants to merge 28 commits into
developfrom
feature/growth-rate-inertia

Conversation

@d-burg

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

Copy link
Copy Markdown
Collaborator

Release note

  • Audience: users
  • Numerical impact: against develop, 16 of 29 cases move at the integration-tolerance level and 12 are unchanged: energies ≤ 3e-6 relative, the tj_n1 plasma/vacuum split by 3.3e-6 with the total energy unchanged to 3e-10 (column-scaled plasma response solve), tj_kinetic_calculated eigenfunction norms 0.02 %, NTV torques ≤ 1.4e-7, ODE step counts within ±4, the solovev_n1 ca_left checksum (basis-dependent). The new lar_reversed_shear_growth_rate_n1 case gives γ = 2.957092e3 s⁻¹, unchanged by the review-round stop rule, which adds one probe evaluation to the root history (9 → 10 entries) (harness @ 43f91d9)
  • Migration: no input changes; existing decks and scripts run as before and their results move only as listed above. With kinetic = PerpendicularInertia(...), kinetic_factor is γ² and must now be positive.

GPEC can now compute the ideal-MHD growth rate of the least-stable free-boundary mode, the way ELITE does: PerpendicularInertia(; rho) is a kinetic source carrying the perpendicular (incompressible) plasma inertia, kinetic_factor = γ² scales it, and growth_rate(prob, Forward(); inertia) finds the γ² at which the free-boundary energy eigenvalue crosses zero. A [GrowthRate] deck section runs the same solve after the force-free-states stage, with the density taken from the equilibrium's kinetic profiles unless rho is given, and reports the peak ion diamagnetic frequency ω_*pi for the EPED1 γ > ω_*pi/2 test. Existing ideal, kinetic and resistive paths are untouched.

What this adds

  • Inertia bands. For a mode ∝ e^{γt}, δW + γ²K is stationary with K = ½∫ρ|ξ_⊥|² dV. In the energy-principle variables Ξ = ξ·∇ψ and ξ_s = (ξ×B)·e_ψ (Glasser 2016 Eqs. 8–9), ξ×B = ξ_s∇ψ + Ξu with u = χ′(∇ζ − q∇θ), so |ξ_⊥|² = |ξ×B|²/B² is algebraic in the two retained variables and K adds the Hermitian bands ⟨μ₀ρ|∇ψ|²/B²⟩ → A, ⟨μ₀ρ u·∇ψ/B²⟩ → C, ⟨μ₀ρ|u|²/B²⟩ → H of Glasser 2016 Eq. A6 (src/ForceFreeStates/Inertia.jl). They are evaluated once per problem and reused at every γ².
  • Solve path. The bands ride the existing kinetic (non-Q-factorized) F, K, G reduction with kinetic_factor = γ². With inertia the rational surfaces are regular points for γ² > 0, so singfac_min defaults to 0 for the inertial solves and the integration is a single chunk with no Frobenius crossings.
  • Root solve. growth_rate runs the ideal (γ² = 0) solve and counts the modes growing faster than γ as the interior zero crossings nzero plus one when the least-stable free-boundary energy λ_min is negative; that count cannot rise with γ² since K > 0. It brackets the count by decades (down while nothing is faster, up while something still is) and, once no interior crossing is left at the lower end, closes λ_min = 0 with an Illinois (bracketed secant) iteration. Each evaluation is one force-balance solve; the root typically needs 5–6 solves after the marginal one. Returns an IdealGrowthRateResult (γ, γ², converged, the marginal and the inertial solves, and the full (γ², λ_min, nzero) history). A crossing still present at the lower bracket end is bisected away on the count (see the count section below), a root below gamma_sq_min is reported as γ = 0, and running out of maxiter as a warning with converged = false.
  • Density from the kinetic profiles. PerpendicularInertia(equil) builds ρ(ψ_N) = μ m_p n_e from the attached kinetic profiles with the SLAYER layer's mass per electron (main ions plus the impurity at the local Z_eff), i.e. the same density InnerLayer.layer_rho uses.
  • *ω_pi. ion_diamagnetic_frequency(equil, n) gives ω_*pi(ψ_N) = n (dp_i/dΨ)/(Z_i e n_i) in the layer convention (n_i ∝ n_e, p_i = n_i T_i, Ψ the poloidal flux per radian, positive for outward-decreasing profiles); IdealGrowthRateResult.omega_star_pi is its peak over the integration domain at the lowest n (NaN without kinetic T_i), so the EPED1 criterion is gamma > omega_star_pi/2.
  • Deck surface. [GrowthRate] (keys = GrowthRateConfig fields: rho in kg/m³ with NaN meaning from the kinetic profiles, gamma_sq_init/min/max, rtol, ftol, maxiter) runs the stage after the ForceFreeStates write on the very problem that stage solved, reusing its ideal solve as the marginal one; it needs vac_flag = true, the Forward integrator and no kinetic source, and cannot share a deck with [Match] (parse-time errors). The result is main's growth_rate slot and ForceFreeStates/GrowthRate/ in gpec.h5: gamma, gamma_sq, omega_star_pi, rho on psi, and History/{gamma_sq, lambda_min, nzero}, with the section recorded under Input/. docs/src/api.md and workflow.md carry the section.
  • Exact conjugate-point count. The forward integration gains a second, exact count of the fixed-boundary modes inside the ψ interval (diagnostics.nzero_conj, with nconj_flags and maslov_defect), the Maslov index of the solution frame; it is off by default and growth_rate switches it on for its solves through an internal keyword (no deck key, public solve unchanged). Details in the count section below.
  • Tests. test/runtests_inertia.jl (core suite, 86 tests): the bands are Hermitian with A and H positive definite and linear in ρ; the metric's B² matches the equilibrium's to 1e-3; inertial solves close as :regular with no crossings; λ_min(γ²) converges to the ideal value as √γ² (the inertial-layer contribution is linear in γ, checked by a factor-of-ten ratio between γ² = 1e4 and 1e2); the crossing path (singfac_min > 0) and the single chunk agree to 1e-5; growth_rate on a stable fixture returns γ = 0 after the marginal solve alone; on a q_a = 2.9 TJ external kink it converges with nzero = 0 throughout; on the q_a = 2.9, p0 = 0.8 variant with a fixed-boundary mode inside the bracket it reaches the fastest root from gamma_sq_init = 1e8 and finds γ > 0 behind a standoff-0.05 wall with nzero > 0 in the history, reports converged = false with a warning at maxiter = 1, returns γ = 0 when the root lies below gamma_sq_min, and rejects a kinetic source and a non-positive density; ρ(ψ) from the kinetic TJ fixture matches layer_rho; ω_*pi matches a finite difference of n_e T_i and scales with n; the HDF5 group passes the repo's metadata check. test/runtests_solve_api.jl gains a "deck and API parity" case: deck and API agree on the stable TJ fixture (γ = 0) and on a q_a = 2.9 variant that is free-boundary unstable (γ = 1.35e4 s⁻¹, agreement to 1e-12, identical 8-entry histories), plus the four parse-time guards, and the same kink on the two-pass auto grid (grid_type = "auto", mpsi = 0), where deck and API agree only if the deck hands growth_rate the problem the marginal solve came from.

Verification outside the test suite

image

Cylinder limit. Uniform-current large-aspect-ratio equilibrium, zero pressure, no wall, m = 2 / n = 1 external kink, against the cylinder result (γτ_A)² = 2(m − nq_a)(nq_a − m + 1)/q_a² with τ_A = R₀√(μ₀ρ)/B₀, evaluated at the equilibrium's edge q. (a) At ε = 0.1, GPEC/cylinder runs from 0.961 near nq_a = 1 to 0.994 at 1.9, with 6–7 solves per root. (b) The deviation falls as ε²: 3.3 %, 0.74 %, 0.19 % and 0.06 % at ε = 0.2, 0.1, 0.05 and 0.025. The cross band C vanishes in this geometry, so this does not test it.

image

Root search and convergence on the TJ analytic kink (q_a = 2.9). (a) With p₀ = 0.8, λ_min(γ²) has a pole at the fixed-boundary eigenvalue (γ² ≈ 1.3e8). The number of modes faster than γ (conjugate points plus negative free-boundary eigenvalues) drops only where λ_min crosses zero: 2 → 1 at γ² ≈ 7e7, and 1 → 0 at the external kink, which growth_rate finds starting from gamma_sq_init = 1e8. At the pole one conjugate point turns into a negative eigenvalue, so the count holds at 1. A sign test on λ_min alone would stop at the pole or at the slower mode. (b) With p₀ = 0.1, γ² converges in the radial grid to 2e-7 at mpsi = 128. Poloidal resolution and the harmonic count are already at the solver's 1e-8 floor at the fixture's settings.

Other checks: the metric's B² reproduces the equilibrium B² to 2e-5; λ_min(γ²) is monotone over six decades of γ² on the DIII-D n = 2 example; on the TJ fixture the offset λ_min(γ²) − λ_min(0) falls 6.8e-3 → 2.1e-3 → 6.6e-4 → 2.1e-4 → 6.5e-5 for γ² = 1e6 … 1e2 (√10 per decade). On the DIII-D-like example at n = 8 with ρ = 5e19 m⁻³ deuterium: γ = 5.6e4 s⁻¹, γτ_A = 0.023, 9 solves, 21 min on a laptop.

Benchmark against ELITE 5.8 (snapshot of 2026-11-15)

image

A coarse VARYPED pressure/current scan of a DIII-D pedestal equilibrium, run through ELITE 5.8 and through growth_rate on the same g-files and profile files, n = 5, 10, 15, 20, 25. Both codes are normalized the same way (γ over the peak ion diamagnetic frequency, the OMFIT gamws16 convention). GPEC is matched to ELITE's edge q for each n.

  • Stability boundary: the γ/(ω_*/2) = 1 contours of the two codes agree to within the scan's grid spacing, and the most unstable n agrees at 31 of 37 points.
  • Growth rates over the scan, median of GPEC/ELITE − 1 on the points both codes solved cleanly: n = 5: −3.9 %, n = 10: −2.5 %, n = 15: −2.0 %, n = 20: −0.9 %, n = 25: −0.8 %.
  • Reference point, converged in GPEC's resolution: GPEC − ELITE in γ is −4.8 %, −9.1 %, −7.0 %, −1.4 % and +0.2 % for n = 5 … 25 (Hamada angle, mtheta 1024; 512 at n = 5 and 25). ELITE's standard deck itself moves by ±5–10 % with its own resolution at n = 10–12, so the n = 10 gap lies inside the reference's uncertainty. At n = 20–25 the two codes agree.
  • Angle independence: in PEST coordinates with the radial grid resolved, γ is within 1.6 % of Hamada at n = 10 and n = 20.

Caveats:

  • This compares two perpendicular-inertia growth rates. It does not test the model against full ideal MHD.
  • The scan has not been rerun at the current head. It predates the column-scaled response solve (bce191e30) and the review round's root-search changes. Solves where the mode count flagged an ambiguous step, the root search did not converge or the run crashed are left out of the medians. A rerun of those points is still to do.
  • The low-n deficit (n = 5–15) is unexplained. Untested suspects: ELITE's exclusion of the core (ψ_N < 0.22), its q-rescaling compared with GPEC's, and ELITE's own resolution.
  • PEST coordinates at high n need about 5000 radial knots here, but the automatic ψ grid stops at 1024 and only warns. With the capped grid, PEST is 10–20 % off. Use Hamada for high-n growth rates; the cap is tracked separately.

The figure is a temporary diagnostic and will be replaced once the scan is rerun.

Column-scaled plasma response solve (bce191e30)

plasma_response_matrix(u) scales every frame column to unit U₁ norm before forming W = U₂ U₁⁻¹. This leaves W unchanged mathematically and is used by the free-boundary solve, the edge scan and the result assembly.

Verification on the two failing high-n inertial solves:

n γ² (1/s²) λ_min before λ_min after non-Hermiticity of W after
20 1e11 −1.44e21 +3.934471e-2 1.2e-13
25 1.1927e11 −1.42e31 +4.532821e-3 1.6e-12

Regression harness, all 28 cases, eb37c4503 (parent) against bce191e30: 20 cases identical, 8 with rows above their noise floor. No noise floor was changed.

  • Total energies: the leading eigenvalue is unchanged in every case; the full spectra move by at most 6e-9. The growth-rate case gives γ = 2.957092e3 s⁻¹ at both commits.
  • Plasma/vacuum split: tj_n1 leading-mode plasma energy 3.771920e-1 → 3.772271e-1 (0.01 %), vacuum energy by the opposite amount, largest shift over all modes 3.03 absolute; lar_reversed_shear_n1 1.5e-7 on the leading mode and 6e-4 over all modes; diiid_n1, diiid_multi_n, diiid_kinetic_multi_n, solovev_n1 and solovev_kinetic_nuzero at most 6e-9.
  • Perturbed equilibrium: diiid_n1 toroidal torque moves by 1.6e-12 absolute (1.7e-6 relative).

The split moves because the unscaled solve was already inaccurate on the standard ideal examples. Evaluating the same final frame both ways, the non-Hermiticity of W is 1.2e-4 unscaled against 5.6e-9 scaled on the TJ ideal example (cond(U₁) = 4e19), 9.0e-6 against 3.2e-7 on the reversed-shear example, and 8.2e-7 either way on Solovev. The difference between the two W matrices is off-diagonal in the eigenmode basis (TJ: diagonal 1.8e-7, off-diagonal 0.22), so eigenvalues are unaffected to first order and only eigenvector-dependent quantities move.

The Gaussian reductions themselves are rescaled in the next section. The full report below predates this commit (c2d6aff88 against develop); the three commits between it and eb37c4503 touch only the growth-rate path (root search, conjugate-point count, output) and its documentation; they were not compared against develop separately.

Column rescaling after each Gaussian reduction (a0354b860, 9b437442b)

After every Gaussian reduction the solution columns are scaled to unit norm over both blocks, and the scale is stored on the diagonal of that reduction's record so transform_u! undoes it together with the triangular part. W = U₂ U₁⁻¹ is unchanged mathematically. Without it the column norms grow without bound between reductions (5e238 at n = 25) and the high-n solves lose W.

Review. Two independent read-only reviews (numerics; downstream consumers) confirmed the reconstruction algebra, the growth-ratio bookkeeping, the truncation order, W, δW, the normalized eigenfunctions, the conjugate-point count and the Riccati path. Both found one defect, fixed in 9b437442b: the fixed-boundary zero-crossing check blends two stored steps before the reductions are undone, so a reduction between them left the two steps on different column scales and a real crossing could be rejected. The earlier step is now brought to the later step's scales, which restores the pre-rescaling behavior of that check; a unit test fails without the fix and passes with it. The same commit errors on a non-finite column norm and warns when the compounded scales fall below the floating-point range (total growth beyond ~1e308 would underflow the stored solutions nearest the axis on reconstruction).

Does the rescaling change the physics or only the rounding? The resonant lead column at an ideal crossing is picked by largest resonant amplitude, which is not scale-invariant, so the rescaling changes the lead column at every crossing. A test that forces the original lead columns back while keeping the rescaling shows that this is not what moves the numbers:

deck quantity no rescaling rescaling rescaling, original lead columns
Solovev ideal example Re et[1] 7.398220e-3 7.362676e-3 7.567382e-3
Re ep[1] −1.042151e1 −1.042157e1 −1.042127e1
DIII-D-like ideal example Re et[1] 7.979256869e-1 7.979256806e-1 7.979256876e-1

The solve is covariant under column scaling to integration tolerance, not to rounding: any rounding-level difference changes the adaptive step sequence. On the Solovev deck the plasma energy spreads 3e-5 across the three variants and the total energy is a ~1400× cancellation of plasma against vacuum energy, which turns that into −0.5 % / +2.3 %. The 0.48 % move of solovev_n1 is therefore the fixture's own tolerance-level sensitivity. The fixed-boundary count is 0 in all three variants on both decks.

Regression harness, all 28 cases, 8279da47a (parent) / a0354b860 / 9b437442b, exit code 0, no noise floor changed:

  • a0354b860 against the parent: solovev_n1 Re et[1] 7.398220e-3 → 7.362676e-3 (0.48 %), ep[1] and ev[1] by 6e-6 and 3e-6; tj_n1 toroidal torque 5.903723e-15 → 5.905384e-15 (0.03 %); tj_kinetic_calculated ‖ξ_α‖ and ‖dξ_ψ/dψ‖ by 0.013 %; NTV torques and energies in the kinetic cases ~1e-5; ODE step counts +3 on solovev_n1 and tj_n1; ca_left checksum changes (basis-dependent). Growth rate unchanged.
  • 9b437442b against a0354b860: 21 cases unchanged, 7 with rounding-level rows (energies ≤ 2e-8 relative, one ODE step fewer on solovev_n1 and tj_n1, the two tj_kinetic_calculated eigenfunction norms by 0.04 %). The fix commit multiplies each column by the stored inverse norm instead of dividing by the norm, so the applied and recorded scales agree exactly; that last-bit change is amplified by the adaptive stepper as above.

Left as they are on develop and noted for follow-up: the zero-crossing check still blends two steps that differ by the unit-triangular part of a reduction; plot_delta_prime builds its diagonal from forward-integrator coefficients, which are basis-dependent; the harness tracks no fixed-boundary count on the ideal cases.

Regression report

regress --cases <all 29> --refs b11dfb244,43f91d9d2   (develop at the merge base; branch head; landau, 1 Julia thread, 2 BLAS)
rc=1 only because develop has no [GrowthRate] section and fails the new case. Changed and failed rows only; the full report is 1200 lines.

diiid_error_field
  EFC whole-field NTV torque per kAt² [N·m]        [1 elem]      [1 elem]      1.374e-07 (0.00%)  ** CHANGED **
  EFC residual-field NTV torque per kAt² [N·m]     [1 elem]      [1 elem]      1.339e-08 (0.00%)  ** CHANGED **
  EFC residual torque against rotation [N·m/kAt²]  [9 elem]      [9 elem]      3.831e-08 (0.00%)  ** CHANGED **
  dominant-coupling singular values                [3 elem]      [3 elem]      4.364e-06 (0.00%)  ** CHANGED **

diiid_kinetic_multi_n
  total energy Re(et[1])          5.186435e-01   5.186435e-01   4.448e-08 (0.00%)  ** CHANGED **
  total energy Im(et[1])          -1.543226e-01  -1.543226e-01  3.960e-09 (0.00%)  ** CHANGED **
  total energy (all)              [82 elem]      [82 elem]      2.087e-05 (0.00%)  ** CHANGED **
  ODE steps (saved)               822            823            1.000e+00 (0.12%)  ** CHANGED **

diiid_multi_n
  total energy Re(et[1])                                        -5.750944e-01    -5.750944e-01    2.897e-09 (0.00%)  ** CHANGED **
  total energy (all)                                            [58 elem]        [58 elem]        2.883e-07 (0.00%)  ** CHANGED **
  permeability diagonal P~_ii (all n blocks)                    [58 elem]        [58 elem]        2.929e-07 (0.00%)  ** CHANGED **
  PE plasma energy (sum over n)                                 2.936508e+00     2.936508e+00     5.474e-10 (0.00%)  ** CHANGED **
  PE surface energy (sum over n)                                3.523287e+00     3.523287e+00     1.846e-09 (0.00%)  ** CHANGED **
  island half-widths per row                                    [7 elem]         [7 elem]         1.170e-07 (0.00%)  ** CHANGED **
  Chirikov parameter per row                                    [7 elem]         [7 elem]         3.239e-06 (0.00%)  ** CHANGED **
  forcing-driven Delta' per row                                 [7 elem]         [7 elem]         4.864e-08 (0.00%)  ** CHANGED **

diiid_n1
  total energy Re(et[1])                        7.979255e-01     7.979255e-01     2.898e-09 (0.00%)  ** CHANGED **
  plasma energy Re(ep[1])                       -1.377303e+00    -1.377303e+00    1.758e-09 (0.00%)  ** CHANGED **
  vacuum energy Re(ev[1])                       2.175228e+00     2.175228e+00     1.140e-09 (0.00%)  ** CHANGED **
  plasma energy (all)                           [35 elem]        [35 elem]        2.007e-06 (0.00%)  ** CHANGED **
  vacuum energy (all)                           [35 elem]        [35 elem]        3.291e-07 (0.00%)  ** CHANGED **
  total energy (all)                            [35 elem]        [35 elem]        1.934e-06 (0.00%)  ** CHANGED **
  ODE steps (saved)                             1189             1185             4.000e+00 (0.34%)  ** CHANGED **
  ODE steps (total)                             1184             1180             4.000e+00 (0.34%)  ** CHANGED **
  island half-widths                            [5 elem]         [5 elem]         7.188e-08 (0.00%)  ** CHANGED **
  Chirikov parameter                            [5 elem]         [5 elem]         1.574e-06 (0.00%)  ** CHANGED **
  dominant-coupling singular values             [3 elem]         [3 elem]         4.364e-06 (0.00%)  ** CHANGED **
  PE plasma energy                              3.321081e+00     3.321081e+00     1.036e-09 (0.00%)  ** CHANGED **
  PE surface energy                             5.521991e+00     5.521991e+00     1.292e-08 (0.00%)  ** CHANGED **
  PE toroidal torque                            9.083693e-07     9.083709e-07     1.620e-12 (0.00%)  ** CHANGED **

diiid_truncation_n1
  plasma energy Re(ep[1])                -1.377404e+00  -1.377404e+00  2.181e-08 (0.00%)  ** CHANGED **
  total energy Re(et[1])                 7.978630e-01   7.978630e-01   1.229e-08 (0.00%)  ** CHANGED **

lar_reversed_shear_growth_rate_n1
  growth rate gamma (1/s)                   FAILED     2.957092e+03         FAILED
  growth rate squared gamma^2 (1/s^2)       FAILED     8.744392e+06         FAILED
  root-find gamma^2 history                 FAILED     [10 elem]            FAILED
  root-find lambda_min history              FAILED     [10 elem]            FAILED
  root-find nzero history (integer counts)  FAILED     [10 elem]            FAILED
  total energy Re(et[1])                    FAILED     -2.263762e-02        FAILED
  # singular surfaces                       FAILED     2                    FAILED
  Runtime (s)                               FAILED     22.8s                --

lar_reversed_shear_n1
  total energy Re(et[1])                                        -2.263762e-02    -2.263762e-02    2.682e-10 (0.00%)  ** CHANGED **
  plasma energy Re(ep[1])                                       -5.912345e-02    -5.912341e-02    4.192e-08 (0.00%)  ** CHANGED **
  vacuum energy Re(ev[1])                                       3.648583e-02     3.648579e-02     4.219e-08 (0.00%)  ** CHANGED **
  plasma energy (all)                                           [31 elem]        [31 elem]        7.140e-04 (0.00%)  ** CHANGED **
  vacuum energy (all)                                           [31 elem]        [31 elem]        7.140e-04 (0.00%)  ** CHANGED **
  total energy (all)                                            [31 elem]        [31 elem]        1.280e-06 (0.00%)  ** CHANGED **

solovev_kinetic_nuzero
  vacuum energy Re(ev[1])  1.054354e+01   1.054354e+01   3.152e-07 (0.00%)  ** CHANGED **
  total energy Re(et[1])   2.316510e+00   2.316510e+00   3.476e-07 (0.00%)  ** CHANGED **
  total energy Im(et[1])   -1.555306e+00  -1.555306e+00  1.457e-07 (0.00%)  ** CHANGED **
  plasma energy Re(ep[1])  -8.227027e+00  -8.227028e+00  6.629e-07 (0.00%)  ** CHANGED **
  total energy (all)       [32 elem]      [32 elem]      6.982e-06 (0.00%)  ** CHANGED **

solovev_n1
  total energy Re(et[1])        7.361939e-03     7.361752e-03     1.873e-07 (0.00%)    ** CHANGED **
  total energy Im(et[1])        4.858849e-11     -2.636747e-10    3.123e-10 (642.67%)  ** CHANGED **
  plasma energy Re(ep[1])       -1.042158e+01    -1.042158e+01    2.892e-07 (0.00%)    ** CHANGED **
  vacuum energy Re(ev[1])       1.042894e+01     1.042894e+01     1.019e-07 (0.00%)    ** CHANGED **
  plasma energy (all)           [32 elem]        [32 elem]        4.542e-06 (0.00%)    ** CHANGED **
  vacuum energy (all)           [32 elem]        [32 elem]        1.010e-06 (0.00%)    ** CHANGED **
  total energy (all)            [32 elem]        [32 elem]        4.517e-06 (0.00%)    ** CHANGED **
  ODE steps (saved)             385              383              2.000e+00 (0.52%)    ** CHANGED **
  ODE steps (total)             383              381              2.000e+00 (0.52%)    ** CHANGED **
  ca_left (checksum)            2877e263076d...  939aa055f24a...  0.000e+00 (0.00%)    ** CHANGED **

tj_kinetic_calculated
  NTV fgar quadrature torque [N·m]   2.035601e-03   2.035591e-03   9.443e-09 (0.00%)  ** CHANGED **
  ||xi_clebsch_alpha||               3.181370e-01   3.181870e-01   5.004e-05 (0.02%)  ** CHANGED **
  total energy (all)                 [32 elem]      [32 elem]      1.532e-09 (0.00%)  ** CHANGED **
  ||Jb_theta_reg||                   5.735175e-02   5.735170e-02   4.139e-08 (0.00%)  ** CHANGED **
  ||dxi_clebsch_psi/dpsi||           1.989275e+00   1.989589e+00   3.138e-04 (0.02%)  ** CHANGED **

tj_kinetic_multiion
  NTV total (D+T+imp+e) [N·m]  8.956205e-04  8.956328e-04  1.229e-08 (0.00%)  ** CHANGED **
  total energy Re(et[1])       4.350277e-01  4.350277e-01  3.029e-10 (0.00%)  ** CHANGED **

tj_kinetic_ntv_rates
  NTV torque fgar with supplied rates [Re, Im]  [1 elem]   [1 elem]   1.080e-08 (0.00%)  ** CHANGED **

tj_kinetic_ntv
  NTV torque fgar [Re, Im]                   [1 elem]      [1 elem]      1.515e-08 (0.00%)  ** CHANGED **
  root-area-weighted total energy Re(et[1])  4.350277e-01  4.350277e-01  3.029e-10 (0.00%)  ** CHANGED **

tj_n1
  total energy Re(et[1])        4.350277e-01     4.350277e-01     3.029e-10 (0.00%)  ** CHANGED **
  plasma energy Re(ep[1])       3.772238e-01     3.772271e-01     3.310e-06 (0.00%)  ** CHANGED **
  vacuum energy Re(ev[1])       5.780394e-02     5.780063e-02     3.310e-06 (0.01%)  ** CHANGED **
  plasma energy (all)           [32 elem]        [32 elem]        3.353e+00 (0.04%)  ** CHANGED **
  vacuum energy (all)           [32 elem]        [32 elem]        3.353e+00 (3.20%)  ** CHANGED **
  total energy (all)            [32 elem]        [32 elem]        6.808e-07 (0.00%)  ** CHANGED **
  ODE steps (saved)             291              293              2.000e+00 (0.69%)  ** CHANGED **
  ODE steps (total)             289              291              2.000e+00 (0.69%)  ** CHANGED **
  island half-width             [2 elem]         [2 elem]         2.083e-08 (0.00%)  ** CHANGED **
  Chirikov parameter            [2 elem]         [2 elem]         8.831e-08 (0.00%)  ** CHANGED **

Per-case summary:
  tj_n1: 10 changed, 15 unchanged
  diiid_truncation_n1: 2 changed, 10 unchanged
  ggj_ray_q500i: 4 unchanged
  tj_kinetic_calculated: 5 changed, 15 unchanged
  ggj_reference: 4 unchanged
  ccc_ray_q5i: 4 unchanged
  solovev_n1: 10 changed, 12 unchanged
  lar_reversed_shear_n1: 6 changed, 16 unchanged
  gal_resistive_diiid: 11 unchanged
  solovev_kinetic_nuzero: 5 changed, 9 unchanged
  diiid_slayer_n1_toroidal: 5 unchanged
  lar_reversed_shear_growth_rate_n1: 7 missing/N/A
  lar_ggj_tearing_n1: 3 unchanged
  diiid_slayer_n1_chi_perp_e: 22 unchanged
  diiid_n1_riccati_precompiled: 17 unchanged
  diiid_kinetic_multi_n: 4 changed, 4 unchanged
  solovev_multi_n: 15 unchanged
  efit_fixedbdy_separatrix: 5 unchanged
  diiid_slayer_n1_coupled: 7 unchanged
  tj_kinetic_ntv: 2 changed, 5 unchanged
  tj_kinetic_multiion: 2 changed, 4 unchanged
  gal_resistive_diiid_galinner: 11 unchanged
  diiid_slayer_n1: 22 unchanged
  diiid_n1_riccati: 17 unchanged
  diiid_multi_n: 8 changed, 11 unchanged
  tj_kinetic_ntv_rates: 1 changed, 1 unchanged
  diiid_slayer_n1_winding: 22 unchanged
  diiid_n1: 14 changed, 39 unchanged
  diiid_error_field: 4 changed, 6 unchanged

Adversarial review (two Opus agents, read-only, after the first push)

The physics reviewer re-derived the inertia bands and found them correct: the metric cofactors, B², the J weighting, the Fourier normalization and band layout, the (ξ_s, ξ_s)/(ξ_s, Ξ)/(Ξ, Ξ) placement of A/C/H, the sign of u (hence of C), the kinetic Schur reduction, and that the pencil's normalization is γ²-independent; the cylinder benchmark excludes any constant factor. Defects found and fixed in the last commit:

  • A fixed-boundary-unstable marginal (nzero > 0, λ_min ≥ 0) was reported as γ = 0, and decade bracketing on λ_min alone could step over the fastest root (λ_min has a pole at each fixed-boundary eigenvalue) and converge on a slower branch. The bracket now runs on the mode count; a fixed-boundary fastest mode errors out instead of being mislabeled.
  • On the default two-pass auto grid, main rebuilt the problem from the re-formed equilibrium, which re-forms again on a third grid: deck and API disagreed there. main now passes ffs.problem; a parity case on the auto grid covers it.
  • The inertial solves overrode singfac_min to 0, which changes the two-pass grid relative to the marginal solve. They now take every control of the marginal problem (grid identical); crossings from the kinetic surface finder can still appear far below any physical root, where only the sign of λ_min matters, and are documented.
  • maxiter exhaustion was silent (now a warning and converged = false, also in HDF5); the gamma_sq_min exit returned a never-evaluated nonzero γ with the wrong solve (now γ = 0, marginal); a kinetic source on the problem was silently replaced (now an error, API and deck); ω_*pi used the problem's lowest n (now the least-stable mode's n); missing T_e crashed the ω_*pi evaluation (now NaN, with clear errors from the constructors); the API form wrote an empty deck into Input/gpec_toml_raw (skipped without a config); the first γ² prepared the problem twice; ρ ≤ 0 or non-finite is now rejected.

Not addressed, carried as limitations: per-n ω_*pi for multi-n runs, and ω_*pi's n_i ∝ n_e assumption with Z_eff-aware μ in ρ. The fixed-boundary branch and the count are handled below.

The exact conjugate-point count

Why. The bracket of growth_rate is provably on the fastest mode only if the number of modes growing faster than the trial γ, nconj + (λ_min < 0), is exact. nconj is the number of conjugate points (fixed-boundary modes fitting inside the ψ interval). DCON's detector nzero (sign change of the smallest-magnitude eigenvalue of W⁻¹ = U₁U₂⁻¹ between stored steps) misses one whenever a stiff harmonic pins a tiny eigenvalue near zero. On the TJ fixture at qa = 2.9, p0 = 0.8 a fixed-boundary mode at γ² ≈ 1.2e8 was invisible to it, so a search from gamma_sq_init = 1e8 converged to the slower free-boundary root (6.5e7 instead of 4.9e9) and the plasma behind a standoff-0.05 wall was reported stable. nzero is kept as a diagnostic; the new count sits beside it.

What. The forward integration counts conjugate points as the Maslov index of the solution frame (Arnold 1967; Robbin & Salamon 1993). With U = [U₁; U₂] the frame of regular solutions, Ψ = (U₁ − i s U₂)(U₁ + i s U₂)⁻¹ is unitary whenever U is Lagrangian (U₁†U₂ Hermitian), has an eigenvalue −1 exactly where det U₁ = 0 (a conjugate point) and +1 where U₂ is singular (a pole of W⁻¹, harmless), and is invariant under U → U·T, so the Gaussian reductions and a column normalization leave it unchanged. At every accepted step the eigenphases of Ψ are computed, each is followed by its eigenvector (the eigenvectors are orthonormal), and a phase whose shortest arc crosses π counts one conjugate point. Result fields: diagnostics.nzero_conj, nconj_flags, maslov_defect.

How it stays exact, each item the fix for a failure seen on the fixtures:

  • Seed one accepted step into each chunk. At the axis start every column of U₁ vanishes, and after an ideal crossing the resonant column does, so those phases sit exactly at π; seeding at the chunk start counted them all (20, the number of harmonics). Counting from the first step inside the interval is Newcomb's open-interval convention.
  • Follow phases by eigenvector, not by sorted order. Matching sorted phases through a cyclic shift misattributes phases that overtake each other and produced spurious wraps.
  • Bisect a step whose phase rotates by more than π/4. Near a conjugate point the W⁻¹ eigenvalue can pass zero within one accepted step (rotations of 1.8–2.7 rad were seen), which leaves the direction of travel ambiguous; the integrator's dense output supplies the frame at intermediate points. Rescaling s instead was tried and rejected: minimizing the rotation drives s up without bound (0.26 → 1.7e4), squashing every phase toward π until a pole of W⁻¹ hops across the branch cut like a zero crossing.
  • Flag a frame that is not Lagrangian. A unitarity defect max||λ|−1| above 1e-3 means the eigenphases cannot be trusted; a flagged solve makes growth_rate warn and report converged = false. A rotation still above π/2 after bisection flags as well.
  • Column-normalize before the Cayley inverse. Between reductions the column norms span up to twenty decades, which made the inverse meaningless after the q = 2 crossing on Solovev; Ψ is invariant under the scaling, so this costs nothing.

Cost: 10–15 % of an inertial solve. Off by default; growth_rate switches it on for its solves through the internal _solve_force_balance(…; count_conjugate_points=true) (no deck key; public solve unchanged), and main turns it on for the marginal solve when a [GrowthRate] section follows.

Validation (TJ qa = 2.9, p0 = 0.8, ρ = 1e-7, n = 1; neg = negative free-boundary eigenvalues; the Morse index nconj + neg must be non-increasing and continuous across the pole):

γ² 0 1e7–5.6e7 7.5e7–1e8 1.33e8–3.16e9 4.2e9 ≥ 5.6e9
nzero (DCON) 0 0 0 0 0 0
nzero_conj 1 1 1 0 0 0
neg 1 1 0 1 1 0
Morse index 2 2 1 1 1 0

Same table with the standoff-0.05 wall (its neg differs, the index is again monotone). Flags 0 and defect ≤ 5e-10 at every γ². growth_rate from gamma_sq_init = 1e8: γ² = 4.9155e9 without the wall and 7.17449e8 with it, both converged in 11 solves; the three cases pinned as @test_broken at the previous commit now pass as @test.

A fixture no W⁻¹-based count can handle, and what it says about nzero. On the Solovev ideal fixture the frame loses the Lagrangian property after the q = 2 crossing (defect 0.2–4; the raw frame's relative non-Hermiticity stays at 1e-8 because its large columns dominate), with non-monotone phase motion even in the first chunk at tolerances 1e-7 and 1e-9. The new count flags it on 132 steps, as designed. DCON's nzero reports 6 conjugate points there (7 at 1e-9) on a fixture whose free-boundary energy has eight positive eigenvalues and none negative, hence Morse index 0: a tolerance-dependent false positive of the existing detector, not tracked by the harness. An issue is being drafted separately.

Relation to ELITE (Snyder et al. user guide, Wilson 2002, Lunniss 2016). ELITE shoots too: a finite-difference sweep in ψ, an edge matching matrix T(γ²), and a secant iteration on one of its eigenvalues from the user's gamsq guess, with no documented mode counting, γ² scan or treatment of poles, so it converges to whichever root the guess leads to. The count-based bracket here is therefore a step beyond ELITE. ELITE's inertia (Wilson 2002 Eq. 9) is the perpendicular incompressible form used here. The method and its references are written up in docs/src/stability.md and docs/development/references.md.

Notes for reviewers

  • The result type is IdealGrowthRateResult; the bare GrowthRateResult is Tearing's dispersion-root type, and the first export clashed with it (precompile warning), hence the name.
  • Not in this PR, planned as follow-ups: a Newton step from the eigenvector to cut the solve count, and an issue on the Solovev frame losing the Lagrangian property (the DCON nzero false positive above).
  • New regression case lar_reversed_shear_growth_rate_n1 (reversed-shear LAR example, uniform deuterium density 3.3e-7 kg/m³): γ = 2957 s⁻¹ after 9 solves, no nzero > 0 in the history. Its noise floors are absolute (the harness has no relative option): 1e-5 on γ and 1e-1 on γ² and the γ² history, which is the shift a 1e-10 change in λ_min near the root produces (dλ/dγ² ≈ 1.8e-9 per s⁻² there); 1e-10 on the λ_min history as elsewhere. These are new floors on a new case, not relaxed existing ones; tighten if you prefer.

🤖 Generated with Claude Code

d-burg and others added 6 commits November 7, 2026 11:18
…te solve

ELITE's inertia model in the force-balance equations: the perpendicular kinetic energy
K = ½∫ρ|ξ_⊥|² dV, with parallel inertia dropped, is algebraic in the normal displacement
Ξ = ξ·∇ψ and the in-surface variable ξ_s = (ξ×B)·e_ψ because ξ×B = ξ_s∇ψ + Ξ χ′(∇ζ − q∇θ),
so it adds Hermitian bands ⟨μ₀ρ|∇ψ|²/B²⟩, ⟨μ₀ρ u·∇ψ/B²⟩ and ⟨μ₀ρ|u|²/B²⟩ to A, C and H
(Glasser 2016 Eqs. 8-9, A6). PerpendicularInertia is a `kinetic` source with
kinetic_factor = γ² in s⁻², so the reduction runs on the kinetic (non-Q-factorized) path,
where the rational surfaces are regular for γ² > 0 and the integration is one chunk.

growth_rate brackets and Brent-solves the γ² at which the least-stable free-boundary
energy vanishes, each evaluation one solve. Prototype: constant or user-supplied ρ(ψ),
no export yet, no tests.

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

Bands Hermitian and A, H positive definite, linear in ρ; the metric B² identity the bands
rest on; the inertial solve regular with no crossings, λ_min approaching the ideal value as
√γ² (the inertial-layer term is linear in γ) and rising with γ²; the kinetic crossing
machinery and the single chunk agreeing; growth_rate returning γ = 0 on the stable fixture.
Memoize growth_rate's evaluations so Brent's endpoint re-evaluations are free.

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

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

Brent kept bisecting to its x-tolerance after |λ_min| was already 1e-11, ten extra solves per
root on the kink benchmark; an Illinois iteration stopping on |λ_min| < ftol·|λ_min(0)| or a
narrow bracket finds the same γ in 5–6 solves in total.

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

The bare GrowthRateResult is Tearing's dispersion-root type; exporting a second one from
ForceFreeStates made the top-level import ambiguous (precompile warning, import ignored).

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 feature New capability label Nov 7, 2026
d-burg and others added 8 commits November 7, 2026 18:36
… the kinetic profiles

PerpendicularInertia(equil) builds ρ(ψ_N) = μ m_p n_e from the attached kinetic profiles with the
layer's mass per electron; ion_diamagnetic_frequency gives ω_*pi(ψ_N) for a toroidal n and
growth_rate reports its peak over the domain for the EPED1 γ > ω_*pi/2 criterion. GrowthRateConfig
carries the settings of the coming [GrowthRate] deck section, and growth_rate reuses a marginal solve.

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

A [GrowthRate] section (keys = GrowthRateConfig fields; rho NaN derives the density from the kinetic
profiles) runs growth_rate after the force-free-states stage, reusing that stage's ideal solve as the
marginal one; it needs vac_flag and the Forward integrator and cannot share a deck with [Match]. The
result is the growth_rate slot of main's tuple and ForceFreeStates/GrowthRate/ in gpec.h5 (gamma,
gamma_sq, omega_star_pi, rho on psi, and the root-search History), with the inputs recorded under Input/.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…oup and a harness case

Deck-and-API parity for [GrowthRate] on the stable TJ fixture and on a q_a = 2.9 variant that is
free-boundary unstable (γ agrees to 1e-12), the three parse-time guards, the writer's metadata, and
a regression case pinning γ on the reversed-shear example with uniform deuterium density.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…and keep the inertial solves on the marginal grid

From an adversarial review of the branch. The count of modes faster than γ (interior zero crossings
plus a negative free-boundary energy) is what the decade bracket now follows, so a fixed-boundary-
unstable marginal is no longer reported as γ = 0 and the bracket cannot step over the fastest root;
a fixed-boundary fastest mode errors out. main hands growth_rate the problem its marginal solve came
from and the inertial solves keep every control of that problem, so the two-pass grid is the same.
Also: a converged flag with a warning when maxiter runs out, γ = 0 below gamma_sq_min, errors for a
kinetic source and a non-positive density, ω_*pi at the least-stable mode's n and NaN without the
profiles, no empty deck recorded from the API form, the inertia bands evaluated once.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…sing count and pin the missed-count cases

A crossing still present at the bracket's lower end is a fixed-boundary eigenvalue inside the bracket,
where the free-boundary energy has a pole. The fastest mode is free-boundary and at least as fast as any
fixed-boundary one, so growth_rate now bisects on the count until the lower end clears that eigenvalue
instead of erroring; a crossing still present at rtol means the fastest mode has no edge displacement and
the upper end is reported.

The count comes from the conjugate-point detector, which misses a crossing when a stiff harmonic holds the
smallest-magnitude eigenvalue of the inverse energy matrix near zero; on the TJ fixture at p0 = 0.8 that
hides a fixed-boundary mode at γ² ≈ 1.2e8, so a search started below it lands on a slower root or reports
stability behind a close wall. Both outcomes are pinned as test_broken and the docstring says to start
gamma_sq_init above the fastest expected growth rate.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…yley eigenphases of the solution frame

The DCON detector behind nzero follows the smallest-magnitude eigenvalue of W⁻¹ between stored steps and misses a
conjugate point whenever a stiff harmonic pins a tiny eigenvalue near zero, so growth_rate could bracket a slower mode
or report stability. The forward integration now also counts conjugate points exactly, at every accepted step, as the
eigenphases of the Cayley transform Ψ = (U₁ − i s U₂)(U₁ + i s U₂)⁻¹ that cross π (its Maslov index): Ψ is invariant
under the Gaussian reductions, has no poles, and its eigenvectors identify each phase across a step. Phases are seeded
one step into each chunk so the vanishing columns at the axis and after an ideal crossing are not counted, a step with
a fast-moving phase is bisected on the integrator's dense output, and a unitarity defect above 1e-3 (a frame that is
not Lagrangian to working precision) flags the count. growth_rate switches the count on for its solves through an
internal keyword, uses it in place of nzero, and marks a flagged result not converged; the deck path turns it on for
the marginal solve when a [GrowthRate] section follows. The three pinned cases on the TJ fixture now pass.

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

Explain in the stability page how nzero (DCON's smallest-eigenvalue test) and nzero_conj (the Maslov index of the
solution frame through its Cayley eigenphases) differ, what keeps the latter exact (seeding one step into each chunk,
eigenvector tracking, bisection of fast steps on the dense output, the unitarity-defect flag), its cost and its
validation; add Arnold 1967 and Robbin & Salamon 1993 for the Maslov index and Wilson 2002, Snyder 2002 and Lunniss
2016 for ELITE's formulation and solve procedure to the references list.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…owth-rate search

growth_rate stored the full solve of every γ² it evaluated, so memory grew by one
solve per iterate (3 GB for one n = 5 solve, 21 GB after nine; 75 GB at n = 15).
Only a bracket end can be returned, so keep the latest solve on each side of the
root and drop the rest. The iterates and the returned result are unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
…holds and correct the EPED1 factor

growth_rate applies no threshold to the ideal growth rate. State the EPED1 and EPED1.6 conventions in terms of gamma and omega_star_pi, their sources and caveats, and replace the docstring statement gamma > omega_star_pi/2 with omega_star_pi/4 (the effective frequency is half the peak).

Co-Authored-By: Claude <noreply@anthropic.com>
@logan-nc

Copy link
Copy Markdown
Collaborator

@d-burg this needs plots or an artifact containing plots please

…ith bisection

When the free-boundary energy at one bracket end dwarfs the other, the interpolated point equals the opposite end in floating point and the search stalled there, then stopped on the bracket width. The iteration now lives in _sign_change_root and takes a geometric bisection step when the interpolated point is not strictly inside the bracket or the same end has been kept three times running.

Co-Authored-By: Claude <noreply@anthropic.com>

@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 this is a good start. The algebra holds up, and the count-based bracket is the right design. I went through the diff at 98fa97b and re-derived the pieces by hand against Glasser, Phys. Plasmas 23, 072505 (2016), Wilson et al., Phys. Plasmas 9, 1277 (2002) and Snyder et al., Phys. Plasmas 16, 056118 (2009). Nothing below was run. These pieces check out:

  • the identity ξ×B = ξs∇ψ + Ξu and its sign;
  • the metric cofactors and B²;
  • the normalization, with no stray 2π;
  • the A/C/H bands acting on the true ξs through the kinetic change of variable;
  • the ξs elimination redone with A + γ²AK;
  • the cylinder formula.

The physics comes first below, because it decides how γ can be described and used. These are also the points Glasser would most likely raise against a growth rate from DCON.

Physics

  1. The number this computes is the Γ = 0 growth rate, and that is an upper bound on the ideal-MHD rate, not the rate itself.

    • DCON has already minimized δW over ξ∥. Dropping ξ∥ inertia on top of that is exactly ideal MHD with Γ = 0: δW then contains no ξ∥, and the Rayleigh quotient is maximized at ξ∥ = 0. So γ is an exact eigenvalue of a well-posed self-adjoint problem, which is good.
    • For Γ = 5/3 it is an upper bound, because δWfull ≥ δW⊥ and Kfull ≥ K⊥. The two share only the marginal point.
    • For γ ≫ cs/qR the gap is O(β). For γ ≪ cs/qR, incompressibility needs parallel return flow, and its inertia raises the effective mass by the Pfirsch–Schlüter factor. Then γ⊥/γideal → √(1+2q²) at large aspect ratio, which is √3 for a q = 1 internal kink.
    • Near marginal stability every mode is slow, so this is where the gap is largest. Wilson 2002 says this just before Eq. 9: the model is "valid at marginal stability".
    • The zero-β cylinder benchmark cannot see any of this.
    • Requested: (a) docstrings, the release note and the HDF5 long_name should say something like "growth rate with perpendicular inertia only (Γ = 0); an upper bound on the ideal-MHD growth rate". (b) Add a toroidal internal-kink known-answer test on a TJ case with q0 < 1; the code should return √3 × the Bussac rate.
    • Caveat on the factor: I have √(1+2q²) from our own derivation and from memory of Glasser–Greene–Johnson and Bussac. It should be pinned to a source before it goes in a docstring.
  2. The count in faster(h) = h.nzero + (h.lambda < 0) is the right verdict.

    • It is the Morse index of δW + γ²K with a free end point: the number of modes faster than γ equals the number of conjugate points plus the number of negative eigenvalues of WP(γ²) + WV.
    • Your own qa = 2.9, p0 = 0.8 TJ table shows why the sign of λmin alone is not enough. At γ² = 7.5e7–1e8, λmin > 0 while a mode at γ² = 4.9155e9 exists.
    • In a pedestal this is the normal case. High-n ballooning modes are nearly fixed-boundary, so their free-boundary root sits just above a pole.
    • Requested:
      • Count the negative eigenvalues instead of using (λ_min < 0), so the integer is the full index. This does not change which root the solver finds, but it matters when the count itself is the verdict. That is what an ELITE/EPED replacement would use: "is anything growing faster than ω*/2?" with no root solve.
      • State the theorem and its condition (K > 0 on (ξs, Ξ)) in docs/src/stability.md, with a citation. This is Morse / σ-stability (Goedbloed & Sakanaka, Phys. Fluids 17, 908 (1974)), not Glasser's γ = 0 theorem.
      • Add a regression test that the fixture above returns "unstable" at γ² = 9e7.
  3. The small-γ limit is non-analytic, and the √γ² test only holds at zero pressure.

    • The inertial layer at a rational surface sets cL/cS ∝ γ2μ, so WP(γ²) − WP(0) ∝ γ2μ with μ = √(−DI).
    • μ = ½ at zero β gives your linear-in-γ result. In a pedestal the exponent moves. It goes to zero as a surface approaches Mercier marginality, and for DI > 0 roots pile up at γ = 0.
    • The 8 < ratio < 12 window runs on a low-β fixture, so it confirms the exponent only where it is trivially 1.
    • Requested: fit d ln[λmin(γ²) − λmin(0)]/d ln γ on a finite-β case and compare it with 2√(−DI) from resist_eval_all! at the dominant surface.
    • The same physics means that near marginality γ ∝ (−δW)1/2μ. The layer half-width, about γτAq in |m − nq|, quickly drops below ρi.
    • So the small-γτA numbers are the most model-dependent output of the feature, including the 0.023 in the n = 8 example. It would help to write the layer widths, in metres, next to γ.
  4. ω*pi and the EPED1 threshold are off by a factor of two.

    • Snyder et al. 2009, Sec. II, gives the threshold as γ > ω*pi/2, with ω*pi taken at its half-maximum value across the edge barrier.
    • _peak_omega_star_pi returns the full maximum over [psilow, psilim], and the docstring then states gamma > omega_star_pi/2. The threshold as written is therefore twice EPED1's.
    • Because the maximum is over the whole domain, a core gradient can set it, and a psilim inside the pedestal foot can cut it off.
    • Requested: either return the profile and let the caller choose, or take the maximum over a stated pedestal window and apply the half-maximum rule explicitly. Add a test on a tanh pedestal with a steeper core gradient.
    • Separately, γ ∝ ρ−½, so uniform versus profile density can move γ/γ0 by up to about 2 in a pedestal. That deserves a switch and a note on which convention ELITE uses.
  5. For the record, though not a problem in this PR (the guard against combining with a kinetic source is right): any later kinetic growth rate needs the KineticForces resonances evaluated at ω = iγ inside the root search.

    • At γ ~ 1e4–1e5 s⁻¹, the static ω = 0 matrices are the wrong functional.
    • Once the matrices are non-Hermitian, the monotone count and the bracket no longer hold.

Code

  1. growth_rate does not set singfac_min, so the inertial solves inherit the default 1e-4.

    • The kinetic surface finder then makes a single trapezoid crossing wherever cond(F̄) > 1e8. That happens once γτA falls below roughly 1e-3 to 1e-4, near marginality.
    • The "Solve path" bullet in the description says the opposite; the adversarial-review section agrees with the code.
    • The only evidence that the crossing is accurate is one point at γ² = 1e4.
    • Requested: run the inertial solves as a single chunk, as described; or record kmsing per solve and mark the result not converged when the root used a crossing. Also compare singfac_min = 0 against the default at γτA ≈ 1e-4.
  2. nzero_conj = abs(odet.nconj) can cancel silently.

    • With a Lagrangian frame every crossing goes the same way, so a +1 and a −1 can only come from a miscounted step. Taking the absolute value hides that.
    • Requested: accumulate the up and down wraps separately and flag any solve where both are non-zero.
    • The ideal frame is the one that loses the Lagrangian property on Solovev. Consider deciding stability from an inertial single-chunk solve at gamma_sq_min and keeping the ideal count as a diagnostic.
    • It would also help to report the flag counts and maslov_defect for the DIII-D-like marginal solve.
  3. The ftol * scale stop can return converged = true with a wide bracket.

    • When the marginal λ is positive, scale is |λmin(lo)|. λmin → −∞ just above a pole, so if the bisection leaves lo near one, the first secant iterate can pass the test.
    • Requested: require the bracket to meet rtol as well, and store the final [lo, hi] on the result.
  4. CK and the non-orthogonal part of HK are untested.

    • In the cylinder they enter γ² only at O(ε²). For up-down symmetric equilibria CK has no diagonal and is purely imaginary, so a sign or conjugation error would pass every current fixture. My derivation agrees with your signs, but no test would notice if they were wrong.
    • Cheap checks:
      • the pointwise identity |∇ψ×u|² = B², i.e. integrands[1]*integrands[3] - integrands[2]^2 ≈ (jac*mu0rho)^2/b2;
      • joint positive-definiteness of [AK CK; CK† HK];
      • the same γ across jac_type = hamada / pest / boozer / equal_arc on the DIII-D-like case.
    • Truncation in m is a Ritz restriction, so γ converges from below. An under-resolved run looks more stable, which is the wrong direction for a stability tool. Please show m-convergence on that case too.
  5. Smaller items:

    • A root below gamma_sq_min comes back as γ = 0 with converged = true, so it cannot be told apart from stable. An "unstable below floor" flag would fix that.
    • Reject kinetic_factor <= 0 for PerpendicularInertia; the LU path has no definiteness check.
    • The γ² controls (1e4 / 1e9 / 1e16 s⁻²) are dimensional. In units of 1/τA² they would mean the same thing on every device.
    • The HDF5 annotation still says "at the lowest n", but the code uses the least-stable mode's n.
    • docs/src/stability.md does not yet describe the model or the solver.

Review drafted with Claude from a read of the diff and the cited papers; nothing here was run.


Generated by Claude Code

…response solve

The Euler-Lagrange frame's column magnitudes can differ by well over a hundred
decades at the edge of a high-n integration. The unscaled U2/U1 solve then loses
all accuracy when taken directly after a Gaussian reduction, giving a complex,
non-Hermitian plasma energy. Scaling each column to unit norm leaves W unchanged
and restores the solve.

Co-Authored-By: Claude <noreply@anthropic.com>
d-burg and others added 3 commits November 13, 2026 16:40
…uple

The stage result tuple gained a growth_rate entry with the [GrowthRate] deck section; the forward-run test still listed the old fields.

Co-Authored-By: Claude <noreply@anthropic.com>
…ussian reduction

The reductions only combine columns, so the column norms grew without bound (1e238 at n=25).
Each reduction now ends by scaling every column to unit norm, with the scale on the diagonal of
fixfac so transform_u! undoes it. W = U2/U1 is unchanged; ca_left/ca_right on the forward path
change with the column basis.

Co-Authored-By: Claude <noreply@anthropic.com>
…tion records consistent with the column rescaling

The fixed-boundary zero-crossing check blends two stored steps before the reductions are undone. A reduction between them now rescales the columns, so the earlier step is brought to the same scales first; without this a genuine crossing could be rejected as noise.

The rescaling errors on a non-finite solution column, skips a column whose inverse norm is not finite, and transform_u! warns when the compounded scales fall below the floating-point range.

Co-Authored-By: Claude <noreply@anthropic.com>
@logan-nc

Copy link
Copy Markdown
Collaborator

This is the missing piece for RMP studies of the pedestal. Ideal δW alone does not settle pedestal stability: the EPED test compares a growth rate with an ad hoc damping (γ > ω_*pi/2), which is why ELITE has been needed. With this PR, GPEC can do that step itself.

The chain it completes:

  1. The saturated width of an RMP-driven island at the top of the pedestal, from the modified Rutherford equation with applied-field forcing (#665: MRE with saturated-island roots and applied-field forcing).
  2. The pressure flattened across that island, and the pedestal-top pressure it removes (#677: island flattening).
  3. The bootstrap current recomputed self-consistently from the flattened profiles (#667: Redl bootstrap current), and the equilibrium re-solved with TokaMaker.
  4. This growth-rate solve for n = 1–30 on the re-solved equilibrium, which says whether the modified pedestal is peeling–ballooning stable.

Together this is a full prediction of the RMP's impact on pedestal stability, from the coil currents to the stability verdict. As far as we know, no one has done that so far.

🤖 Generated with Claude Code

@d-burg d-burg changed the title ForceFreeStates - FEATURE - Add perpendicular inertia and an ELITE-style growth-rate solve ForceFreeStates - FEATURE! - Add perpendicular inertia and an ELITE-style growth-rate solve Nov 14, 2026
@github-actions github-actions Bot added the changed-results Results move or an interface breaks - read before upgrading label Nov 14, 2026
d-burg and others added 3 commits November 16, 2026 21:06
When the refined equilibrium implies more knots than the cap allows, tightening psi_accuracy cannot help; say so and point to a smoother poloidal angle.

Co-Authored-By: Claude <noreply@anthropic.com>
… the poloidal angle

The TJ kink fixture in hamada, pest, boozer and equal_arc: the inertia cross band is 12-16 % of sqrt(|A||H|) and differs between angles, and gamma^2 agrees to 3.6e-5 (bound 1e-4).

Co-Authored-By: Claude <noreply@anthropic.com>
…endence and resolution needs

The rate is the adiabatic-index-zero eigenvalue and an upper bound for 5/3; hamada is the angle to use for high-n edge modes; cite Wilson (2002).

Co-Authored-By: Claude <noreply@anthropic.com>
d-burg and others added 5 commits November 24, 2026 17:16
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arately and flag a run with both

A Lagrangian frame wraps every conjugate point the same way, so wraps in both directions can only come from a miscounted step; abs(nconj) hid such a cancellation. The run now adds one to nconj_flags, which growth_rate already treats as not converged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… report the full mode count

The ftol stop could return converged with a wide bracket when |lambda_min| was small next to a pole; an ftol hit now triggers one probe rtol/2 across it and only a closed bracket stops. The count of faster modes is the Morse index (conjugate points plus negative free-boundary eigenvalues, Goedbloed and Sakanaka 1974), stored per evaluation. New result fields: below_floor for an unstable plasma whose root is below gamma_sq_min, and the final bracket. A root solve that placed kinetic-surface crossings is marked not converged. kinetic_factor <= 0 with PerpendicularInertia is rejected. Docstrings and the HDF5 annotation state the Gamma = 0 model and its upper-bound character.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and the full mode count

Joint positive-definiteness of [A C; C' H], the pointwise identity AH - C^2 = (J mu0 rho)^2/B^2, the bracket and floor flags, the kinetic_factor guard, and the fixture where lambda_min > 0 at gamma^2 = 9e7 while a faster mode exists. Docs describe the root search and cite Goedbloed and Sakanaka (1974).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d the angle test

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

d-burg commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

@logan-nc thanks for the careful review. Replies point by point, at 43f91d9d2 (develop merged in). Done means changed and tested; open items are collected at the end.

Harness at 43f91d9d2 against develop b11dfb244, all 29 cases: 12 unchanged, 16 moved at integration tolerance (energies ≤ 3e-6 relative, ODE step counts within ±4), and the new growth-rate case fails only on develop, which has no [GrowthRate] section. The report is in the description.

1. Γ = 0 model. (a) Done. The growth_rate docstring, the result fields, the HDF5 long_name of gamma and docs/src/stability.md now say it: perpendicular inertia only, the exact Γ = 0 eigenvalue, an upper bound on the Γ = 5/3 rate, the two agreeing only at marginality. The release note will say the same. (b) The internal-kink √3 test is open, waiting on a source for the √(1+2q²) factor, as you suggest.

2. The count. Done.

  • The count is now the full index: conjugate points plus the number of negative free-boundary eigenvalues. Both terms are stored per evaluation (history.nneg, HDF5 History/n_negative). The root found does not change.
  • The theorem and its condition (K > 0 on (ξ_s, Ξ)) are stated in the docs and the docstring, citing Goedbloed & Sakanaka, Phys. Fluids 17, 908 (1974).
  • New test on the q_a = 2.9, p₀ = 0.8 TJ fixture at γ² = 9e7: λ_min > 0 there, and the count is > 0.
  • A count-only verdict without a root solve is not exposed yet; it needs a deck surface and a parity case (open).

3. Small-γ exponent. Open. The fit against 2√(−D_I) on a finite-β case, and layer widths in metres next to γ.

*4. ω_pi.

  • The docstring and the stability page use the EPED1 half-maximum rule: unstable when gamma > omega_star_pi/4, where omega_star_pi is the full peak. A table lists the EPED1, EPED1.6 and ELITE conventions.
  • ion_diamagnetic_frequency(equil, n) returns the profile, so a caller can choose the window.
  • Open: a pedestal-window option with the tanh-pedestal test, and a note on which density convention ELITE uses. The switch itself exists: a scalar rho, or the profile from the kinetic data.

5. Agreed, for the record. The guard against combining with a kinetic source stays.

6. Kinetic crossings.

  • Done: a root solve that placed kinetic singular-surface crossings now warns and is marked not converged.
  • Open: the singfac_min = 0 versus default comparison at γτ_A ≈ 1e-4, and whether inertial solves should default to one chunk.

7. Maslov cancellation.

  • Done: upward and downward wraps are accumulated separately (nconj_up, nconj_down). A run with both nonzero adds to nconj_flags, which already marks the growth rate not converged.
  • Open: deciding stability from an inertial single-chunk solve at gamma_sq_min, and the flag and maslov_defect report for the DIII-D-like marginal solve.

8. Wide bracket. Done.

  • ftol no longer stops the iteration on its own. An ftol hit triggers one probe rtol/2 across it, and only a bracket closed to rtol counts as converged.
  • The final bracket is on the result (bracket; HDF5 gamma_sq_lower, gamma_sq_upper).
  • This changes the stop rule. On the harness case γ is unchanged (2.957092e3 s⁻¹); the root history gains one probe evaluation (9 → 10).

9. C_K and H_K.

  • Done:
    • Joint positive-definiteness of [A C; C† H] at three surfaces.
    • The pointwise identity AH − C² = (Jμ₀ρ)²/B². It holds to 4.8e-5 (the metric's Jacobian accuracy); the test bound is 2e-4.
    • The same γ across hamada, pest, boozer and equal_arc on the TJ kink fixture: within 4e-5 in γ², with the cross band at 12–16 % of √(|A||H|).
  • On the pedestal benchmark case, PEST matches Hamada to 1.6 % once its ψ grid is resolved. It needs about 8000 knots there, against the automatic grid's cap of 1024; the grid warning now says so.
  • Open:
    • The fixture is up-down symmetric, so a conjugation error in C would still pass; this needs an asymmetric case.
    • The jac_type and m-convergence checks on the DIII-D-like example. On the pedestal case, γ² rises by less than 0.1 % from delta_mhigh 8 to 32, converging from below.

10. Smaller items.

  • Done:
    • below_floor flags an unstable plasma whose root is below gamma_sq_min.
    • kinetic_factor ≤ 0 with PerpendicularInertia throws.
    • The HDF5 annotation now says "least-stable mode's n".
    • The stability page describes the model and the root search.
  • Open: γ² controls in units of 1/τ_A², an interface change I'd like a second opinion on.

Plots. The cylinder-kink benchmark and the TJ root-search/convergence figures are in the description, with the ELITE benchmark figure.

Still open on this PR

Blocking: settle before merge, because changing it afterwards would break the interface:

  • γ² controls in units of 1/τ_A², or keep s⁻²? Reviewer input wanted. — 10

Follow-up: not needed for merge; each goes to its own issue/PR after this lands:

  • Internal-kink known-answer test (factor to be pinned to a source) — 1b
  • Count-only stability verdict as a deck/API option — 2
  • Small-γ exponent vs 2√(−D_I) on a finite-β case; layer widths next to γ — 3
  • Pedestal-window option for ω_*pi with a tanh-pedestal test; ELITE's density convention — 4
  • singfac_min = 0 vs default near marginality; single chunk by default for inertial solves — 6
  • Stability verdict from an inertial single-chunk solve; flag/defect report on the DIII-D-like case — 7
  • Up-down asymmetric test for C; jac_type and m-convergence on the DIII-D-like example — 9
  • A 1.9e-8 non-Hermiticity outlier in the n = 20 pedestal solve, not yet investigated
  • The automatic ψ grid's 1024-knot cap, which under-resolves high-n runs in PEST coordinates (tracked separately; the warning now names it)
  • ELITE scan rerun at the current head; the n = 5–15 shortfall (−9 % at n = 10, inside ELITE's own ±5–10 % resolution band) is unexplained; parity at n = 20 (−1.4 %)

On this PR:

  • Figures in the description

🤖 Generated with Claude Code

@d-burg
d-burg marked this pull request as ready for review November 25, 2026 02:30
@d-burg

d-burg commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

@matt-pharr @nelsonand this is ready for review. Changes since the first review are answered point by point in the comment above; the description has the cylinder and convergence figures, the ELITE snapshot and the regression report. One decision blocks merge: whether the γ² controls should take units of 1/τ_A² (item 10). Everything else open is a follow-up.

🤖 Generated with Claude Code

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

@logan-nc @d-burg I am very concerned about the way claude hacked this in here. I have not had the time to do a full review of this yet (and I suspect it will take a while!) but as of right now it is storing these things in the kinetic matrix path, and gamma^2 in kinetic_factor, which smells like a future mess to me. If we need to make use of the kinetic integrator's ability to add arbitrary additional matrices to A,B,C,D,E,H before forming F,K,G, then this ability should be abstracted and given multiple paths, not hacked in. This also locks us into only using the forward integrator for this. In the plots for the PR, I would very much want to see some plots of the eigenfunctions, as well as the condition number of F, for a variety of growth rates.

So from me, I have yet to review the physics here properly, but I am definitely convinced this needs a major code layout and implementation overhaul to stop crossing our wires between the kinetic and new ELITE-style paths.

Some discussion needs to be had on how to revise the API call paths and the deck organization to add this capability. A good scripting/deck API:

  • Is unified, with lines in the deck corresponding directly to arguments you pass into solve() calls in scripting mode
  • Has self-describing names; i.e., this is no longer the case if we are calling this through ForceFreeStates as it is no longer solving force-balance, it is now solving for eigenmodes on the growth rate spectrum.
  • Has a single convention as to how code calls are structured, i.e. physics go in the ForceBalanceProblem() and non-physics-related numerics specific to each integrator go in the integrator, e.g. Galerkin(number of finite element cells).

Furthermore, we should consider carefully in a group discussion what code goes where for this. It is my opinion that any code that loops a different workflow should go in a different place. We have Tearing as-is, which was made to do root solves for the inner layer; now that we are calling the outer layer repeatedly also, does it not make sense to have a new module organization for this as well? I think this is especially defendable if we are planning on adding any sort of additional growth rate calculations to this. We could consider merging it with tearing into a GrowthRates module which could share certain structs and root finder related plumbing, which will be especially helpful if we ever want to solve non-self-adjoint growth rates (rotation shear can be destabilizing for low n) which causes all n=/=0 growth rates to be complex.

In summary, my thoughts are that this needs significant reworking before it is ready for develop, and I would strongly push back against the idea that this should "land now" and leave an API reworking for later (looking at you claude). From what I have seen from reviewing the PR, though, this looks really neat, and I am especially excited to dig into the new matrices and the root finder.

@matt-pharr

Copy link
Copy Markdown
Collaborator

PS I would like to know where the new matrices came from -- did claude dream them up or did they come from a reference?

@logan-nc

Copy link
Copy Markdown
Collaborator

@matt-pharr thanks for holding us accountable. I agree on all points.

It sounds like we may need regular multi person meetings on this project, as it is a huge (new module level, as you say) change. What do you think? Weekly or biweekly? Or subject of a pre holiday 2 day hackathon?

@matt-pharr

Copy link
Copy Markdown
Collaborator

@logan-nc a 2 day hackathon could be good, and I have time for weekly meetings for this. Let's correspond over slack to set this up.

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

changed-results Results move or an interface breaks - read before upgrading feature New capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants