Repository navigation
Equilibrium - FEATURE - Read inverse i-files such as TokaMaker save_ifile output - #511
Conversation
|
@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 |
|
@matt-pharr here is the g-file vs i-file scan you asked for. Setup
δW, kinked profiles (values; mtheta 512)
ifile_snap. No longer needed. OFT #364's cut-cell writer puts every i-file point on the FE flux surface to ~1e-14 of the flux range, with no field-line tracing. OFT #357 (which had the snap) is closed. What changed in this PR since you looked:
Scripts and data are available if you want to rerun any of it. |
…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, using the tabulated F and P. Trailing records (TokaMaker's FF′ and p′) are ignored. 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>
…heir field-line integral The inverse solver kept the i-file's tabulated q, splined in psi, while the SFL angle nu and the metric are built from the field-line q of the interpolated geometry. Where the input surfaces are coarse near the edge (q ~ log(1-psi)) the two disagree (q up to +0.7 at psi_N 0.9985 on a uniform 129-surface file), which moves psilim and spoils Delta' (2/1: 6.39 vs 8.28 for RDCON). ldp_i/ifile now use the field-line q, as Fortran inverse_run does; LAR, CHEASE and efit_by_inversion keep their input q. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ker i-files read_ldp_i tells the optional records apart by length: FF' and p' (npsi each), then [psi_axis, psi_LCFS] (2). With the bounds, psi_N and psio are normalised to the true LCFS, so the padded last surface sits below 1; psihigh is clamped to the outermost input surface for inverse inputs (resolve_psihigh!), on the reader and rerun paths alike. Files without the record read unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…q docs
LDP_I_KINDS replaces the two hard-coded ("ldp_i", "ifile") lists, so the inverse solver does not
repeat the reader's kinds. One comment at q_from_geometry explains both q sources.
psihigh_resolved's docstring says the clamp applies to i-files and reruns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… it to the g-file's The ratio to the g-file residual held only because FastInterpolations' periodic spline is wrong on non-uniform θ grids (FastInterpolations.jl#220), which inflates the direct refit's residual. With the fix the g-file residual is 6e-6 on this data, below the i-file's 1e-4, so the ratio check would fail once the fix is released. The absolute bound stays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88f6ecc to
8635ca9
Compare
…d of ldp_i "ldp" is the initials of the format's original author, which a reader cannot guess, the reason grid_type "ldp" became "core_edge_packed". eq_type is now "ifile" only, read by read_ifile; the docstring still points to the Fortran read_eq_ldp_i it ports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
matt-pharr
left a comment
There was a problem hiding this comment.
Made necessary changes to get this merged. Thank you for the very useful contribution that will aid tokamaker + GPEC coupling efforts!
| end | ||
|
|
||
| """ | ||
| read_ldp_i(config) |
There was a problem hiding this comment.
Violates the "no people's initials as code names" rule 😡
There was a problem hiding this comment.
I recommend you amend the name. You can note in the docstring that it is Don Pearlstein's format, but it should be called something more just like read_ifile
Release note
GPEC can now read inverse i-files (
eq_type = "ifile"), such as OpenFUSIONToolkit TokaMaker'ssave_ifileoutput. This is a port of the Fortranread_eq_ldp_i.Regression report
regress --cases diiid_n1,solovev_n1 --refs 84b7e4800,15a4b7b97(develop vs this head; julia 1.12.6, pinned manifest, 8 threads): diiid_n1 53 unchanged, solovev_n1 22 unchanged. No harness case reads an i-file; the unit tests cover the reader.Full report
Notes for reviewers
GPEC had no reader for the i-file, the inverse format TokaMaker's
save_ifilewrites. An i-file stores the flux surfaces themselves, so the equilibrium does not depend on a g-file's R,Z grid.Changes
read_ifile(ReadEquilibrium.jl) builds the sameInverseRunInputandInverseIngest(forgpec.h5reruns) as the CHEASE readers. Reals may be real8 or real4 (the Fortran reader takes only real*8). F and P are the tabulated values.[ψ_axis, ψ_LCFS](save_ifile(psi_bounds=True), ALL - IMPROVEMENT - Self-describing HDF5 metadata (issue #226, PR B) #364) normalizes ψ_N to the true LCFS.resolve_psihigh!clampspsihighto the outermost file surface, for i-files and on the inverse rerun path.inverse_rundoes; the tabulated q, splined in ψ, is inaccurate where edge surfaces are coarse. Other inverse inputs keep their input q.equilibrium_gse!returns its residual arrays (HDF5 output unchanged).Results (one TokaMaker DIII-D-like H-mode solve, written by
save_ifileandsave_eqdsk;grid_type = "core_edge_packed"(then named"ldp"),psihigh = 0.995, Hamada; measured before the rebase onto develop)Tests: two testsets in
test/runtests_equil.jlon 137 KB of data from the same solve (test/test_data/TokaMaker_ifile/);runtests_equil.jl320/320. Scripts: read_ifiles_scripts.zip. The δW scan requested in review is in this comment.Dependencies: none. This PR was stacked on #506 and fed the i-file's FF′ and p′ records to its
profile_sourceoption. #506 is parked, so the PR is rebased onto develop without it; the reader skips those records untilprofile_sourcelands.🤖 Generated with Claude Code