Repository navigation
Equilibrium - FEATURE - Read inverse i-files (ldp_i) such as TokaMaker save_ifile output - #511
Open
StuartBenjamin wants to merge 2 commits into
Conversation
…r save_ifile output Port of Fortran read_eq_ldp_i. eq_type = "ldp_i" (alias "ifile") reads the sequential unformatted i-file (real*8 or real*4) into an InverseRunInput. The optional trailing FF′ and p′ records feed profile_source = "derivatives" via file_profiles, as for g-files; without them the tabulated F and P are used. equilibrium_gse! now returns its residual arrays and the θ-integrated residual per surface, so the Grad-Shafranov error can be checked programmatically. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checks i-file vs g-file agreement from one TokaMaker solve, GS residual, real*4 vs real*8, the "ifile" alias, and the profile_source fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
@StuartBenjamin I am working on a code review for this, but in the mean time, this is a significant feature addition. In order to make sure everything is working well (and this should be cheap because the code is reasonably fast) I would really love to see some convergence scans showing convergence of n=1 delta W between gfiles and ifiles, or something similar you can use to convince us that this feature works properly. Furthermore, this ifile_snap thing seems important! Hopefully we can get that merged into Tokamaker soon |
StuartBenjamin
added this pull request to stack #516
October 8, 2026 22:08
This branch has not been deployed
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.
Release note
Julia GPEC can now read inverse i-files (
eq_type = "ldp_i", or"ifile"), such as OpenFUSIONToolkit TokaMaker'ssave_ifileoutput. This is a port of the Fortranread_eq_ldp_i.Regression report
regress --cases diiid_n1 --refs bugfix/efit-profiles-from-file-derivatives,feature/read_ifiles_on_bugfix: all 53 tracked quantities identical to the base branch.Changes
read_ldp_i(src/Equilibrium/ReadEquilibrium.jl):InverseRunInput, the same input the CHEASE readers build.profile_source = "derivatives"throughfile_profiles, as the g-file reader does. Without them the reader warns and uses the tabulated F and P.gpec.h5: the reader stores the sameInverseIngestas the CHEASE readers, so this works with no extra code.equilibrium_gse!now returns its residual arrays:(; xs, ys, flux_x, flux_y, source, total, error, errori). Before, it discarded them, so the Grad-Shafranov residual could not be checked from code. Its HDF5 output is unchanged.test/runtests_equil.jl, with 118 KB of data intest/test_data/TokaMaker_ifile/. That data isg65.geqdskandi33x65.ifile(real8 and real4), all from one TokaMaker solve. The test checks:"ifile"worksprofile_source, and the fallback when the records are absenteq_typelist, theprofile_sourcesection and theInverseIngestdocstring now mention i-files.Notes for reviewers
Stacked on
bugfix/efit-profiles-from-file-derivatives. This PR targets that branch, notdevelop. It usesprofile_sourceandfile_profiles, which the bugfix adds. It should merge after the bugfix, and it reachesdeveloptogether with it. The harness compares against the bugfix branch so that only this PR's changes show; a run againstdevelopmoves 44 quantities, all from the bugfix.Setup of the comparisons below. One TokaMaker reference equilibrium (DIII-D-like H-mode, q0 = 1.25, q95 = 4.49) was written both by
save_ifileand bysave_eqdsk. GPEC settings:grid_type = "ldp",psihigh = 0.995, Hamada coordinates. "GSE" isequilibrium_gse!'s local residual, normalized by the largest term.i-file and g-file give the same equilibrium. The axis agrees to the last printed digit (1e-5 m), as does psio (0.259291). q agrees to about 1e-5 at ψ = 0.1–0.95. F and P match the exact TokaMaker profiles to 1e-7–1e-6 and about 1e-5.
GS residual (stock TokaMaker DIII-D mesh, 4 cm plasma cells), mpsi = 256.
The worst-surface residual comes from TokaMaker's solution, not from the i-file.
pack_lcfs), 257 surfaces, or 1025 angles. Finer GPEC grids (larger mpsi or mtheta) make it slightly worse, not better.save_ifile's tracer tolerance is not a factor. Every point is Newton-snapped onto the exact ψ contour (ifile_snap).profile_source = "derivatives"gives no gain on these files. "values" gives an equal or smaller F′ error: for the i129x257 file, 5.2e-4 against 1.2e-3. TokaMaker now writes both formats in double precision, so the tabulated F has no rounding for the derivative route to fix. The Julia reader also uses FF′ only to rebuild F at the grid points, then takes F′ from a spline. The Fortran reader instead passes FF′/F through as the spline slopes. This reading of the cause is a hypothesis; it bears on the bugfix PR, which makes "derivatives" the default.Reproduce. The scripts ship as
read_ifiles_scripts.zip; its
README.mdhas the commands.Assignee and a named human reviewer required before merge; otherwise open as draft.