Skip to content

Consolidate rzphi geometry extraction: share flux_surface_metric between FieldReconstruction and the metric/area helpers #271

Description

@logan-nc

Summary

Two independently-developed code paths derive flux-surface geometry (|∇ψ|, Jacobian, /η-offset and their θ-derivatives) from the same rzphi bicubic, via separate implementations. They should be consolidated onto a single rzphi-geometry primitive.

Background

  • develop (src/PerturbedEquilibrium/FieldReconstruction.jl): _build_rzphi_geometry resamples the smooth rzphi primitives (, η-offset, J, and their θ-derivatives) onto a coarse ψ grid and builds cubic interpolants for the PE field-reconstruction transform (added in PerturbedEquilibrium - PERFORMANCE - Coarse-grid rzphi geometry in field reconstruction #264, 3dcde8fd).
  • feature/power-norm-eigenvalues (src/Equilibrium/FluxSurfaceMetrics.jl): flux_surface_metric is a pointwise evaluator of the same rzphi quantities returning (r, jac, |∇ψ|), shared by FFS (PowerNorm.jl) and PE (SingularCoupling.jl) after the 7dcfd5dc refactor.

These overlap conceptually: both pull , the η-offset (deta), J, and the θ-derivatives off rzphi and combine them. They are not redundant code today (different consumers, different representations — real-space |∇ψ| weight + area integral vs. mode-space reconstruction geometry), so this is a maintainability cleanup, not a performance fix. The hot per-ODE-step path is already served by coarse ψ-splines on both sides (sqrtamat_spline in FFS, _build_*_interp in PE).

Proposal

Make flux_surface_metric (in the Equilibrium module) the single source of truth for extracting smooth geometry primitives from rzphi, and have both _build_rzphi_geometry and the area/weight helpers sample it. This keeps the GPEC gpout.f metric conventions in one place and prevents the two paths from drifting.

Risk / why this is its own issue

This crosses module boundaries (Equilibrium ↔ PerturbedEquilibrium) and carries real FMA-level numerical risk: the 7dcfd5dc refactor already documented benign 1-ULP shifts (≤ 2.2e-16) in 5 PE singular-coupling quantities purely from moving the metric block across a function boundary. Any consolidation must be validated against the regression harness (diiid_n1, solovev_*) with the usual 1e-8 noise thresholds, and the ψ-derivative handling needs care — _build_rzphi_geometry deliberately differentiates the resample spline rather than resampling the bicubic ψ-derivatives (those are only C¹ and ring near axis/edge), so a shared primitive must preserve that distinction.

Out of scope for

feature/power-norm-eigenvalues (PR #225) — that branch already centralized the FFS/PE |∇ψ| duplication; this is the follow-on consolidation with develop's reconstruction geometry.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    perfSame answers, less time or memoryrefactorBehavior-preserving restructuring

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions