Repository navigation
Correct the right-edge curvature and slope of the Akima splines - #23
Merged
Merged
Conversation
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.finSources/LIBSTELL_minimalextend 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. PrincetonUniversity/STELLOPT#504 makes the same change inLIBSTELL/Sources/Miscel, 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.fcalls these routines for every profile of typeakima_spline,akima_spline_iorakima_spline_ip, and none of the inputs underpython/testsuses one. In the Akima profiles of the benchmark inputs in STELLOPT the 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 anakima_spline_ipcurrent to s = 1 changes there by up to 5.1e-4; VMEC divides the current profile by that value to matchCURTOR, so the current enclosed by every surface with s < xx(npts-1) changes by the same fraction.