fix: make cyl_to_geoflux consistent with cached forward transform#252
fix: make cyl_to_geoflux consistent with cached forward transform#252krystophny merged 1 commit intomainfrom
Conversation
The cyl_to_geoflux function was using direct psi evaluation while geoflux_to_cyl uses bilinear interpolation in the (s, θ) → (R, Z) cache. This caused roundtrip inconsistency because bilinear interpolation of (R, Z) between flux surface points gives points that are not on any flux surface. Add invert_cached_surface() which uses Newton-Raphson iteration to find (s, θ) such that the cache interpolation maps back to the given (R, Z). This makes the inverse transformation mathematically consistent with the forward transformation. Also implement geoflux_from_cyl in the OOP interface to use the module's cyl_to_geoflux function.
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
User description
Summary
invert_cached_surface()which uses Newton-Raphson iteration to find (s, θ) such that the cache interpolation maps back to a given (R, Z) pointcyl_to_geofluxandcyl_to_geoflux_internalto use cache-consistent inversion when cache is builtgeoflux_from_cylin the OOP interface to use the module'scyl_to_geofluxProblem
The
cyl_to_geofluxfunction was using direct psi evaluation whilegeoflux_to_cyluses bilinear interpolation in the (s, θ) → (R, Z) cache. This caused roundtrip inconsistency because bilinear interpolation of (R, Z) between flux surface points gives points that are NOT on any flux surface (due to surface curvature).Solution
When the cache is built, the inverse transformation now uses Newton-Raphson iteration to find the exact (s, θ) that maps through the cache interpolation to the given (R, Z) point. This makes the forward and inverse transformations mathematically consistent.
Test plan
PR Type
Bug fix, Enhancement
Description
Add Newton-Raphson iteration for cache-consistent inverse transformation
Implement
invert_cached_surface()to find (s, θ) from (R, Z) coordinatesModify
cyl_to_geofluxandcyl_to_geoflux_internalto use cache inversionImplement
geoflux_from_cylin OOP interface using module functionDiagram Walkthrough
File Walkthrough
geoflux_coordinates.f90
Add cache-consistent inverse transformation with Newton-Raphsonsrc/coordinates/geoflux_coordinates.f90
invert_cached_surface()subroutine using Newton-Raphson iterationwith finite differences
cyl_to_geoflux()to use cache-consistent inversion when cacheis built
cyl_to_geoflux_internal()to use cache-consistent inversionwhen cache is built
libneo_coordinates_geoflux.f90
Implement geoflux_from_cyl OOP interface methodsrc/coordinates/libneo_coordinates_geoflux.f90
cyl_to_geofluxfromgeoflux_coordinatesmodulegeoflux_from_cyl()subroutine using the module'scyl_to_geofluxfunction