You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Two independently-developed code paths derive flux-surface geometry (|∇ψ|, Jacobian, r²/η-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 (r², η-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 r², 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.
Summary
Two independently-developed code paths derive flux-surface geometry (
|∇ψ|, Jacobian,r²/η-offset and their θ-derivatives) from the samerzphibicubic, via separate implementations. They should be consolidated onto a single rzphi-geometry primitive.Background
develop(src/PerturbedEquilibrium/FieldReconstruction.jl):_build_rzphi_geometryresamples the smoothrzphiprimitives (r²,η-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_metricis a pointwise evaluator of the samerzphiquantities returning(r, jac, |∇ψ|), shared by FFS (PowerNorm.jl) and PE (SingularCoupling.jl) after the7dcfd5dcrefactor.These overlap conceptually: both pull
r², theη-offset (deta),J, and the θ-derivatives offrzphiand 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_splinein FFS,_build_*_interpin PE).Proposal
Make
flux_surface_metric(in the Equilibrium module) the single source of truth for extracting smooth geometry primitives fromrzphi, and have both_build_rzphi_geometryand the area/weight helpers sample it. This keeps the GPECgpout.fmetric 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
7dcfd5dcrefactor 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_geometrydeliberately 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 withdevelop's reconstruction geometry.