Skip to content

Correct q sign-convention docs and enforce positive q (replaces #268) - #269

Merged
logan-nc merged 4 commits into
developfrom
sign-conventions-q-positive
Jun 12, 2026
Merged

Correct q sign-convention docs and enforce positive q (replaces #268)#269
logan-nc merged 4 commits into
developfrom
sign-conventions-q-positive

Conversation

@logan-nc

Copy link
Copy Markdown
Contributor

This PR replaces #268 (which is from a fork the maintainers cannot push to). It contains all of #268's commits plus follow-up corrections from review. Once this is open, #268 can be closed.

Background

#268 set out to correct the safety-factor q statements in the sign-conventions reference. Review surfaced a factual error in #268's own text and a related code-hardening opportunity, addressed here.

Documentation (docs/sign_conventions.rst, CLAUDE.md)

  • Corrected the inverse-equilibrium claim. Correct q and COCOS statements in sign conventions reference #268 stated inverse equilibria "keep the q profile of the input file, including its sign." In fact the main inverse path (inverse_run, equil/inverse.f) recomputes q on each surface by flux-surface integration, exactly like direct_run — the input file's q profile is read into sq_in but unused. The text now reflects this.
  • Noted the one exception: the chease4 format (inverse_chease4_run) takes q directly from the input file.
  • Removed all "negative newq0" wording — q is documented simply as always positive (this is not standard usage and shouldn't be advertised to new users).

Code — enforce positive q (equil/)

GPEC requires positive q (positive nn, positive resonant m; the mode-range and convention machinery assume q > 0). Negative q was only reachable via undocumented, unvetted paths, now closed:

  • equil.f: guard rejecting newq0 < 0 (the only knob that could force q negative), placed right after the namelist read.
  • inverse.f (inverse_chease4_run): positive-q guard IF(MINVAL(sq%fs(:,4)) <= 0) for chease4 files whose q column is itself negative.
  • direct.f, inverse.f (×2), read_eq.f: removed the now-unreachable IF(newq0==-1)newq0=-q0 sentinel and *SIGN(one,newq0) sign-flip factor. If field/q reversal is ever wanted, it should be a clearly-named flag, not a magic negative newq0.

Verification

  • Full build succeeds (gfortran); all modified fixed-format .f lines ≤72 chars.
  • DCON on the solovev inverse-path example: newq0=-1 → rejected with a clear message; newq0=0 → q0=1.900; newq0=2.0 → q0=2.000, bit-identical to before the cruft removal (the removed SIGN(one,newq0) was +1 for valid positive newq0).
  • docs/sign_conventions.rst parses under docutils (only the pre-existing Sphinx-only :doc: role message remains).
  • The chease4 guard compiles but is not runtime-tested (no chease4 input file in-repo).

🤖 Generated with Claude Code

krystophny and others added 4 commits June 10, 2026 14:24
… g-file

The sign conventions reference claimed q is read directly from the EFIT
g-file without sign manipulation. In the direct path the g-file q profile
is read but unused: direct_run rebuilds q from a field-line integration
using the sign-normalized psi map and |F|, so q is always positive for
g-file input. Verified by running DCON on a DIII-D g-file and on a copy
with all signed quantities negated: outputs (euler.bin, crit.bin, dcon.out,
netcdf) are identical except timestamps.

Also clarifies the COCOS section: sign conventions of the g-file are
normalized away on read, only the per-radian flux units are required.
Inverse equilibria keep the input q profile, including its sign.
…ip cruft

The inverse path recomputes q by flux-surface integration in inverse_run
(equil/inverse.f), like direct_run; the input q profile is unused, except
the chease4 variant which copies it. Corrects the sign-conventions
reference accordingly.

Enforces positive q: guards newq0<0 in equil_read (the only source of
negative q, previously undocumented and unvetted) and adds a positive-q
check in inverse_chease4_run for files whose q column is itself negative.
Removes the now-unreachable newq0==-1 / SIGN(one,newq0) sign-flip code from
direct.f, inverse.f, and read_eq.f.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@logan-nc logan-nc self-assigned this Jun 12, 2026
@logan-nc
logan-nc merged commit 6300c43 into develop Jun 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants