Skip to content

Add canonical orbit frequency APIs#489

Merged
krystophny merged 4 commits into
mainfrom
feature/canonical-orbit-frequencies
Jul 16, 2026
Merged

Add canonical orbit frequency APIs#489
krystophny merged 4 commits into
mainfrom
feature/canonical-orbit-frequencies

Conversation

@krystophny

Copy link
Copy Markdown
Member

Risk tier

  • T0: docs, comments, small build metadata
  • T1: pure refactor, no behavior change intended
  • T2: local numerical logic
  • T3: physics, output behavior, coordinate convention
  • T4: parallelism, GPU, dependency, CI, or security-sensitive build logic

Correctness contract

Intended behavior change

Add a side-effect-free Fortran API and a Python API that compute canonical bounce/transit and mean toroidal angular frequencies for trapped and passing guiding-centre orbits. Support one or multiple completed poloidal cycles, return cycle spreads and explicit status metadata, and expose interpolated tip/toroidal cut tracing through Python.

Behavior that must not change

Existing orbit tracing, classification, NetCDF output, and golden-record results are unchanged. The core frequency routine copies the caller's tracer and does no file I/O.

Coordinate / unit conventions

The source-level Fortran routine accepts SIMPLE integration coordinates. The flat/Python boundary accepts [s, theta, phi, v/v0, lambda] in public reference coordinates and performs ref_to_integ. Angles and displacements are radians, periods are seconds, and frequencies are angular frequencies in rad/s. omega_b is positive; omega_phi is signed.

Numerical invariants

Trapped periods use successive negative-to-positive parallel-velocity crossings. Passing periods use successive signed 2*pi advances of unwrapped poloidal angle. Event time and toroidal displacement are interpolated within the crossing step. Multi-cycle results report means and sample standard deviations.

Tests added

  • unit: Fortran invalid-option status and Python argument validation
  • integration: native trapped/passing, three-cycle frequency computation
  • system: Python trapped multi-cycle frequency and interpolated tip-cut APIs
  • golden record: unchanged

Golden-record impact

  • unchanged
  • changed

Failure modes considered

Invalid options, orbit loss, integrator errors, and maximum-step exhaustion return distinct statuses. Unknown orbit class remains explicit. The cut wrapper rejects unsupported cut types and non-symplectic integration.

Manual validation

Validated trapped and passing VMEC seeds through the native API; validated the Python frequency and cut interfaces against the compiled f90wrap backend.

Verification

  • make test TEST=^test_orbit_frequencies$ CONFIG=Fast VERBOSE=0
  • make test TEST=^test_simple_api$ CONFIG=Fast VERBOSE=0 (24 API cases pass)
  • Full non-regression suite: 75/76 targets pass after installing the optional plotting dependency. The remaining test_orbit_macro failure is pre-existing: it accesses pysimple._backend, which current main does not export.
  • git diff --check

@krystophny krystophny added tier/T3 physics or output behavior size/L review size up to 1000 changed lines labels Jul 14, 2026
@krystophny
krystophny marked this pull request as ready for review July 14, 2026 16:25
An orbit that reaches the outer radial boundary during
compute_canonical_frequencies ended with SYMPLECTIC_STEP_BOUNDARY,
which the status mapping lumped into FREQ_INTEGRATOR_ERROR. A particle
leaving the plasma edge is a physical loss, so it now reports
FREQ_ORBIT_LOST like the outside-domain stop; only genuinely numerical
failures remain integrator errors. This is what a default 3.5 MeV alpha
does on the circular-tokamak benchmark chart map, where the intended
case is a 5 keV deuteron.

pysimple.init() now also accepts namelist-cased parameter names such as
facE_al, matching simple.in, and python/README.md documents the
species/energy overrides needed for non-alpha frequency calculations.
@krystophny
krystophny merged commit e6d7644 into main Jul 16, 2026
7 checks passed
@krystophny
krystophny deleted the feature/canonical-orbit-frequencies branch July 16, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L review size up to 1000 changed lines tier/T3 physics or output behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant