Skip to content

EQUIL - BUG FIX - Fix kappa calculation in separatrix finder#208

Merged
logan-nc merged 2 commits into
refac/fast_interp_v0.4from
fix/kappa
Apr 2, 2026
Merged

EQUIL - BUG FIX - Fix kappa calculation in separatrix finder#208
logan-nc merged 2 commits into
refac/fast_interp_v0.4from
fix/kappa

Conversation

@mgyoo86
Copy link
Copy Markdown
Collaborator

@mgyoo86 mgyoo86 commented Apr 1, 2026

Summary

equilibrium_separatrix_find! used unbounded Newton to find separatrix geometry. Without bracket constraints, Newton frequently diverged — θ escaped to values like ±1e2 or larger. Due to sin/cos periodicity, the diverged θ still returned plausible values, but which extremum it landed on depended on spline coefficients and grid resolution. When both sides landed on the same extremum, kappa ≈ 0 or kappa < 0.

Fix

Replace all Newton calls in equilibrium_separatrix_find! with bracketed Brent:

  • zsep (top/bottom Z extrema): Brent on dZ/dθ = 0, θ ∈ [0.5, 1.0] (bottom) / [0.0, 0.5] (top). Removes z_deriv2 entirely.
  • rsep (outboard/inboard midplane R): Brent on θ + η(θ) - η₀ = 0, θ ∈ [-0.25, 0.25] (outboard) / [0.25, 0.75] (inboard). Removes derivative-based Newton step.

Adds regression tests for kappa and separatrix geometry with Solovev equilibria (e=1.6, e=1.0).

Performance (zsep loop, @btime)

Newton (old) Brent (new)
iside=1 (bottom) 3.1 μs, 11 allocs (5.2 KiB) 1.0 μs, 5 allocs (80 B)
iside=2 (top) 2.9 μs, 11 allocs (5.2 KiB) 1.8 μs, 5 allocs (80 B)

No d²Z/dθ² computation and fewer iterations within the bracket.

mgyoo86 added 2 commits March 31, 2026 17:18
…paratrix finder

The zsep loop in equilibrium_separatrix_find! used unbounded Newton
iteration to find dZ/dθ = 0 extrema. Newton diverged when d²Z/dθ²
passed through zero (inflection point), sending θ to values like ±1e9.
Due to sin/cos periodicity the diverged θ still produced plausible Z
values, silently returning wrong extrema depending on floating-point
luck. This caused kappa ≈ 0 or kappa < 0 for some equilibria.

Fix: use bracketed Brent method on dZ/dθ with θ ∈ [0.5,1.0] (bottom)
and θ ∈ [0.0,0.5] (top). This eliminates d²Z/dθ² entirely, is 4x
faster, and guarantees convergence to the correct extremum.

Adds regression tests for kappa with Solovev equilibria (e=1.6, e=1.0).
…force tests

Convert the rsep loop (outboard/inboard midplane finding) from unbounded
Newton to bracketed Brent for consistency with the zsep fix. Remove
unused mtheta and vector variables that were only needed for Newton
initial guesses.

Add rsep value-level checks (amean ≈ 0.33, rmean ≈ 1.0) and circular
cross-section rext symmetry test (rext[1] ≈ rext[2]).
@mgyoo86 mgyoo86 requested review from jhalpern30 and logan-nc April 1, 2026 00:53
@logan-nc logan-nc added the bug Something isn't working label Apr 2, 2026
@logan-nc logan-nc self-assigned this Apr 2, 2026
@logan-nc
Copy link
Copy Markdown
Collaborator

logan-nc commented Apr 2, 2026

Thanks!!

@logan-nc logan-nc merged commit b1a66ab into refac/fast_interp_v0.4 Apr 2, 2026
3 checks passed
@logan-nc logan-nc deleted the fix/kappa branch April 2, 2026 13:08
logan-nc added a commit that referenced this pull request Apr 2, 2026
Incorporates:
- PR #207: FastInterpolations v0.4 API (Series() wrappers, ZeroCurvBC, remove explicit defaults)
- PR #208: Separatrix finder Brent method fix
- PR #198: Analysis module improvements (plot_eigenvalues, plot_delta_prime, plot_ffs_summary)
- AdaptiveArrayPools v0.3.5, FastInterpolations v0.4.7

Conflict resolved in src/Analysis/ForceFreeStates.jl: retained our
plot_edge_stability_scan alongside develop's new plot_eigenvalues,
plot_delta_prime, and plot_ffs_summary functions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants