Skip to content

KineticForces: single METHOD_REGISTRY for NTV method flags, docs, and dispatch - #284

Merged
logan-nc merged 3 commits into
developfrom
refactor/kinetic-method-registry
Jun 15, 2026
Merged

KineticForces: single METHOD_REGISTRY for NTV method flags, docs, and dispatch#284
logan-nc merged 3 commits into
developfrom
refactor/kinetic-method-registry

Conversation

@logan-nc

Copy link
Copy Markdown
Collaborator

Closes#248.

Problem

src/KineticForces/ enumerated the same 18 NTV methods, in the same order, in three (really four) position-coupled places that had to be hand-kept in lockstep:

  1. KineticForcesInternal.methods (names) + .docs (doc strings) vectors
  2. The flags = [...] array in Compute.jl, indexed flags[m] against intr.methods[m]/intr.docs[m]
  3. The hardcoded elseif method in ["fgar", …, "prmm"] dispatch list in Torque.jl

The positional coupling in (2) was the real hazard: a single transposed or omitted entry silently paired the wrong boolean/doc with the wrong method and would produce wrong-but-plausible NTV output. The old guard test only checked length == 18, which would pass even with two flags swapped.

Change

A single const METHOD_REGISTRY in KineticForcesStructs.jl of (name, flag, kind, doc) NamedTuples is now the one place the methods are enumerated:

  • Compute.jl iterates the registry and reads each flag via getfield(ctrl, entry.flag) — the flags array and methods/docs vectors are gone.
  • Torque.jl routes on the kind tag (:gar/:fcgl/:rlar/:clar) via a new method_kind helper, replacing the hardcoded membership list and else error(...).
  • The 18 *_flag struct fields on KineticForcesControl stay — the TOML kwargs splat (KineticForcesControl(; (Symbol(k) => v …)...)) and direct ctrl.fgar_flag accesses require them.

The length-guard test is replaced with a structural test asserting every registry flag is a real KineticForcesControl field with a recognized kind and round-trips through method_kind — no fixed count, so adding a method needs no magic-number edit.

Drift surfaces drop from 3+ to 1.

Verification

  • Unit tests: 190/190 pass (runtests_kinetic.jl), including the new METHOD_REGISTRY testset.
  • Regression harness (solovev_kinetic_calculated, local vs develop): 15/15 quantities identical (0.0e+00 / OK). The case exercises the NTV dispatch (nonzero kinetic Im(et[1])), confirming the refactor is numerically inert.

🤖 Generated with Claude Code

logan-ncand others added 2 commits June 14, 2026 07:41
…s, docs, and dispatch
Closes#248. Replaces three position-coupled enumerations of the 18 NTV methods
(KineticForcesInternal.methods/.docs vectors, the Compute.jl flags array, and the
Torque.jl dispatch membership list) with a single const METHOD_REGISTRY of
(name, flag, kind, doc) NamedTuples. Compute.jl iterates the registry and reads each
flag via getfield; Torque.jl routes on the kind tag via method_kind. The 18 *_flag
struct fields stay (the TOML kwargs splat and direct ctrl.*_flag accesses need them).
The length-guard test is replaced with a structural test asserting every registry
flag is a real KineticForcesControl field with a valid dispatch kind — no fixed count,
so adding a method needs no magic-number edit.
Verified: 190/190 kinetic unit tests pass; regression harness solovev_kinetic_calculated
local vs develop is 15/15 identical (numerically inert).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@logan-nclogan-nc self-assigned this Jun 14, 2026
@logan-nclogan-nc added refactor Behavior-preserving restructuring auto-merge labels Jun 14, 2026
@github-actions
github-actionsBot enabled auto-merge June 14, 2026 12:05
@logan-nc
logan-nc disabled auto-merge June 15, 2026 00:59
@logan-nc
logan-nc merged commit bb3c503 into developJun 15, 2026
3 checks passed
@logan-nc
logan-nc deleted the refactor/kinetic-method-registry branch June 15, 2026 00:59
@logan-nclogan-nc mentioned this pull request Jun 21, 2026
logan-nc added a commit that referenced this pull request Sep 4, 2026
The bounce-point spline samples 1-(lmda/bo)*B(theta), which is periodic on the
closed poloidal interval, but was fitted with non-periodic endpoint conditions
while the adjacent equilibrium B spline (tspl) was already periodic. The
resulting fit is only C0 at the theta=0/1 seam, so it can manufacture false
near-seam extrema and bounce-root pairs. On a synthetic shaped field the seam
derivative mismatch drops ~5x (1.4e-4 -> 2.6e-5) when the fit is made periodic.
Fixed at both construction sites (the tpsi! quadrature path and the
_setup_surface_state kinetic-matrix path). Renamed B_extrap -> B_vpar and
_vpar_from_extrap -> _vpar_from_spline, since after this change the old names
describe a fit that no longer exists.
Julia analog of Fortran GPEC PR #284, which fixed the same spline_fit(vspl,
"extrap") -> "periodic" defect in pentrc/torque.F90 after it produced
non-finite omega_b/omega_D and an LSODE failure on an ITER case.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactorBehavior-preserving restructuring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KineticForces — single registry for method flags, docs, and names

1 participant

@logan-nc