Skip to content

EQUIL - BUG FIX - Integrate equilibrium 0D flux integrals out to the boundary - #292

Merged
github-actions[bot] merged 3 commits into
developfrom
bugfix/equil-0d-inductance-integration
Jun 20, 2026
Merged

EQUIL - BUG FIX - Integrate equilibrium 0D flux integrals out to the boundary#292
github-actions[bot] merged 3 commits into
developfrom
bugfix/equil-0d-inductance-integration

Conversation

@logan-nc

@logan-nclogan-nc commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Bug

The 0D flux-surface integrals behind betat, betap*, betaj, li1/2/3, and volume integrated only up to the last grid point (psihigh) and dropped the edge slice out to the plasma boundary ψ=1 that Fortran equil_out_global includes. On the Fortran-matched DIII-D grid (psihigh=0.993) this made volume/li2/li3 ~1.5–1.8% low and betat/betan ~1.5% high.

Fix (minimal)

Replace the four trapezoidal sums with the native FastInterpolations cubic integral (already used elsewhere in this file) plus Fortran's linear edge slice to ψ=1 — a small local fsi closure, no new module-level machinery:

dpsi_b =1.0- xs[end]
functionfsi(y)
s =cubic_interp(xs, y; extrap=ExtendExtrap())
return FastInterpolations.integrate(s, xs[1], xs[end]) + (y[end] +deriv1(s)(xs[end]) * dpsi_b /2) * dpsi_b
end

Verified against the Fortran DIII-D KEFIT dcon.out (matched hamada/ldp grid, psilow=1e-4, psihigh=0.993, mpsi=128, mtheta=256): volume 0.02%, betat 0.015%, li1 0.09%, li2/li3 ~0.5%, betan 0.34%. All remaining residual is a separate, pre-existing ~0.3% crnt edge-geometry difference (every leftover is a crnt/bwall-dependent quantity), out of scope.

Regression

Tracks the previously-untracked 0D params (li1/2/3, betap1/2/3, betaj, volume, crnt, bt0, bwall, aratio, kappa) in diiid_n1. regress --cases diiid_n1 --refs develop,local: 10 changed, 36 unchanged — only the flux-integration params move (≤0.12% on the shipped example, whose psihigh=0.9995 shrinks the edge slice); all energies, q/pressure checksums, singular surfaces, Δ', and PE outputs are bit-identical.

Also

Adds a short "Minimal-change discipline" note to CLAUDE.md (reuse native ops/existing utilities before writing new ones; size the change to the problem; no throwaway benchmark/agent-memory artifacts for minor fixes).

🤖 Generated with Claude Code

@logan-nc
logan-ncforce-pushed the bugfix/equil-0d-inductance-integration branch from 36b8cda to ebe92a2CompareJune 20, 2026 17:28
@logan-nclogan-nc changed the title EQUIL - BUG FIX - Match Fortran flux-surface integration for 0D parameters (betan, li, volume)EQUIL - BUG FIX - Integrate equilibrium 0D flux integrals out to the boundaryJun 20, 2026
@logan-nc
logan-ncforce-pushed the bugfix/equil-0d-inductance-integration branch from ebe92a2 to f899c68CompareJune 20, 2026 17:42
@logan-nclogan-nc self-assigned this Jun 20, 2026
@logan-nclogan-nc added the bug Something isn't working label Jun 20, 2026
…boundary
The 0D flux-surface integrals (betat, betap*, betaj, li1/2/3, volume) stopped at the
last grid point (psihigh) and dropped the edge slice out to the plasma boundary psi=1.
On the Fortran-matched DIII-D grid (psihigh=0.993) this made volume/li2/li3 ~1.5-1.8%
low and betat/betan ~1.5% high vs Fortran equil_out_global.
Switch the four trapezoidal sums to the native FastInterpolations cubic integral over
[psilow, 1]; ExtendExtrap carries the integral past psihigh to the boundary, matching
what Fortran adds. After the fix, the matched-grid run agrees with dcon.out to <=0.5%
(volume 0.05%, betat 0.01%, li1 0.12%); the remaining residual is a separate
pre-existing ~0.3% crnt edge-geometry difference.
Track the previously-untracked 0D params (li1/2/3, betap1/2/3, betaj, volume, crnt,
bt0, bwall, aratio, kappa) in the diiid_n1 regression case. Harness: only the
flux-integration params move (<=0.12% on the shipped example, psihigh=0.9995); all
energies, q/pressure checksums, singular surfaces, and PE outputs bit-identical.
Add a "Minimal-change discipline" note to CLAUDE.md (reuse native ops/existing
utilities, size the change to the problem, no throwaway artifacts for minor fixes).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@logan-nc
logan-ncforce-pushed the bugfix/equil-0d-inductance-integration branch from f899c68 to a378e2cCompareJune 20, 2026 18:13
@logan-nc

Copy link
Copy Markdown
CollaboratorAuthor

@parkjk who found funny li values? I was only able to see ~1% differences with fortran and here I fix them to be <1%. I don't see any way the minor differences would have made "crazy" li unless the psilow or psihigh was 0.5 or something unusual like that. If your group is still or is ever finding odd results - be sure to post an issue so we can fix them!

@github-actions
github-actionsBot merged commit 006ae37 into developJun 20, 2026
4 checks passed
@github-actions
github-actionsBot deleted the bugfix/equil-0d-inductance-integration branch June 20, 2026 18:38
@jmlmir369

jmlmir369 commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

@logan-nc
I was the one who previously observed the odd li3 values. Upon checking, it seems the issue was due to my using an older version of GPEC. When I pulled the develop branch for ballooning on April 23, the li3 calculation was indeed incorrect, but it has since been resolved in the main branch. Thank you for benchmarking this

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@logan-nc@jmlmir369