Repository navigation
LIBSTELL: correct the right-edge curvature and slope of the Akima splines - #504
Merged
lazersos merged 1 commit intoOct 4, 2026
Merged
Conversation
lazersos
approved these changes
Sep 28, 2026
lazersos
left a comment
Collaborator
There was a problem hiding this comment.
Appears legitimate. Effect overall should be small.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
spline_akima.fandspline_akima_int.finLIBSTELL/Sources/Miscelextend the data by two phantom points at each end, extrapolated along the parabola through the three end knots. The left end takes the curvature of that parabola and its slope atxloc(1),and the right end forms
for the expansion
yloc(iv) + br*(x-xloc(iv)) + cr*(x-xloc(iv))**2that placesyloc(iv+1)andyloc(iv+2). Thiscrhas the wrong sign, andbris the slope of the parabola atxloc(iv-1)instead ofxloc(iv). The phantom secants therefore turn back,m(iv) = m(iv-2)andm(iv+1) = 2*m(iv-2) - m(iv-1), where at the left end they continue the trend of the data,m(0) = 2*m(1) - m(2)andm(-1) = 3*m(1) - 2*m(2). The Akima slope at the last knot comes out as(m(iv-2)+m(iv-1))/2instead of(3*m(iv-1)-m(iv-2))/2, the mirror of the slope(3*m(1)-m(2))/2at the first knot, and every other knot keeps its slope. Only the last interval changes: withh = xx(npts)-xx(npts-1), the interpolant there is off by up to4/27*|m(iv-1)-m(iv-2)|*hand its integral by|m(iv-1)-m(iv-2)|*h**2/12.Fix
Form
crandbras the mirror ofclandbl, in both files:VMEC++ forms them this way, and jonathanschilling/educational_VMEC#3 made the same correction to
crandbrin educational_VMEC. hiddenSymmetries/VMEC2000#23 makes the same change inSources/LIBSTELL_minimal, whose two files are identical to these.Test
The program below interpolates a data set and its mirror image, and samples the parabola
1 + x/2 - x**2on 11 uniformly spaced knots. Before this change the interpolant of the mirrored data, mirrored back, differs from the original by 1.8e-1 in value and 2.2e-2 in the integral, and the spline misses the parabola by 3.0e-3 in value and 1.7e-4 in the integral, all of it on the last interval; with the change all four are below 5e-16. On 48 random knot sets the fixed routines agree with the Akima profiles of VMEC++ to 6e-16, where the unfixed ones differed by up to 21% of the profile maximum.akima_check.f90Effect
profile_functions.f, in LIBSTELL and in VMEC2PIES, calls these routines for every profile of typeakima_spline,akima_spline_iorakima_spline_ip, and THRIFT (thrift_equil_p.f90,thrift_equil_j.f90) andstellopt_prof_to_vmec.f90pass their profiles to VMEC as anakima_splinepressure and anakima_spline_ipcurrent. In the Akima profiles ofBENCHMARKS/DIAGNO_TEST/input.DIIID_m20n0s128_nfp1_lasym,BENCHMARKS/DIAGNO_TEST/input.iterandBENCHMARKS/STELLOPT_TEST/RECON_TOK/input.RECON_TOKthe change is confined to the last knot interval, s > 0.989, and is at most 7.1e-4 of the profile maximum. The integral of theakima_spline_ipcurrent to s = 1 changes by 5.1e-4 ininput.iterand by 7.3e-5 ininput.RECON_TOK; VMEC divides the current profile by that value to matchCURTOR, so the current enclosed by every surface inside s = 0.989 changes by the same fraction.