Skip to content

Add D3D-like kinetic profiles and update example equilibrium#295

Open
d-burg wants to merge 10 commits into
developfrom
feature/diiid-kinetic-profiles
Open

Add D3D-like kinetic profiles and update example equilibrium#295
d-burg wants to merge 10 commits into
developfrom
feature/diiid-kinetic-profiles

Conversation

@d-burg

@d-burg d-burg commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Adds kinetic profiles and an NTV-torque demonstration to the DIII-D-like example, and fixes a grid setting that was producing inaccurate ideal stability results. Closes #268.

Changes

  • New kinetic profile file (TkMkr_D3Dlike_Hmode_kinetic.gpeckf): six columns
    psi_n, n_i, n_e, T_i, T_e, omega_E.
  • Replaced the example equilibrium with a new synthetic and self consistent geqdsk that uses the tokamaker DIII-D limiter and coils (toroidal field sign now negative, matching the physical DIII-D convention).
  • Added a [KineticForces] section to the example gpec.toml, which turns on the NTV-torque diagnostic. The stability solve stays ideal; NTV torque is computed as a post-PE diagnostic.
  • Added an NTV-torque regression quantity to the diiid_n1 case.

Grid fix

  • The example used mpsi = 0 (auto), which under-resolves the edge (~11 edge points) and produced a spurious, sign-flipped delta_W and unphysical edge delta-prime (order 1e4). Switched to grid_type = "ldp" with a fixed mpsi = 256. Ideal delta_W and the inner-surface delta-prime values now agree with Fortran DCON.

Test updates

  • Re-pinned the DIII-D parallel-integration regression for the corrected equilibrium and grid. et[1] and the inner-surface (q = 2, 3, 4) delta-prime are pinned tightly; the near-separatrix surfaces (q = 5, 6) are only checked for finiteness, since their values and signs are not grid-converged.

Notes

  • The diiid_n1 regression baseline shifts as expected from the equilibrium and grid changes; the new values are the correct ones.
  • Two follow-ups are out of scope here: the auto-mpsi edge under-resolution in the equilibrium grid builder, and more thorough testing of grid_type='log_asymptotic'
image image

Copilot AI review requested due to automatic review settings June 21, 2026 21:29
@d-burg d-burg added bug Something isn't working enhancement New feature or request Unit tests Issues related to unit tests labels Jun 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR updates the DIII-D-like example to use a corrected, grid-converged setup and adds “D3D-like” kinetic profiles enabling an NTV-torque diagnostic/regression.

Changes:

  • Update the example radial grid configuration (switch to grid_type="ldp" and fixed mpsi=256) to avoid edge under-resolution impacting δW/Δ′.
  • Add a kinetic profile input file and enable [KineticForces] in the example to compute NTV torque.
  • Re-pin parallel-integration and Δ′ matrix regression assertions to the corrected equilibrium/grid, and add an NTV torque regression quantity.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.

File Description
test/runtests_parallel_integration.jl Tightens/pivots regression assertions for et[1] and Δ′ matrix real parts based on the corrected grid behavior.
regression-harness/cases/diiid_n1.toml Adds an NTV torque quantity (FGAR) to the regression harness outputs.
examples/DIIID-like_ideal_example/gpec.toml Switches grid settings and enables [KineticForces] for NTV torque diagnostics.
examples/DIIID-like_ideal_example/TkMkr_D3Dlike_Hmode_kinetic.gpeckf Introduces a 6-column kinetic profile file used by the new [KineticForces] config.

Comment thread test/runtests_parallel_integration.jl Outdated
Comment on lines +308 to +312
# Parallel FM et[1] regression — pinned tightly, NOT bracketed. et[1] is grid-sensitive
# (log_asymptotic/auto-mpsi gives a spurious −0.09; ldp/mpsi=256 gives the converged
# +0.504), so a loose bracket would mask exactly that accuracy regression. Value is
# deterministic and reproducible (parallel and standard ODE paths agree to rel_diff=0).
@test isapprox(et_par, 0.504306; rtol=2e-2)
Comment thread test/runtests_parallel_integration.jl Outdated
Comment on lines +317 to +319
# No explicit parallel-vs-standard cross-path check: both paths share the equilibrium
# grid, so they agree (rel_diff=0) even on a bad grid — a cross-path check is blind to
# grid/accuracy regressions. The tight absolute pin above is the guard for those.
Comment on lines +246 to +250
[quantities.ntv_torque_fgar]
h5path = "kinetic_forces/fgar/total_torque"
type = "real_vector"
extract = "all_real"
label = "NTV torque FGAR (Re,Im) [N·m]"
@@ -0,0 +1,515 @@
psi_n n_i[m^-3] n_e[m^-3] T_i[eV] T_e[eV] omega_E[rad/s]
@logan-nc

Copy link
Copy Markdown
Collaborator

Thanks @d-burg!

Two comments before doing a full review:

  1. What's with this flat spot in omega_ExB? Looks odd/off. gradP is smooth, so it's not that. Must be something funky in the omega_toroidal profile?
image
  1. I am trying to move to the new auto-grid so it is sad it didn't work well for you... but lets not just ditch it. Did you investigate the issue? The resolution is set be a parameter psi_accuracy - try scanning that to be tighter? ldp wastes a lot of points in the core

d-burg and others added 5 commits June 22, 2026 15:40
Add read_kinetic_file (extension dispatch) and write_kinetic_h5 for a GPEC
HDF5 kinetic schema (psi, n_i, n_e, T_i, T_e, omega_E; optional omega_tor,
chi_e, chi_phi). Legacy 6-column ASCII (.gpeckf/.kin) still reads via the same
path; the NTV loader is refactored onto the dispatcher with bit-identical
results. Adds round-trip / ASCII-vs-HDF5 equivalence tests and docs;
.gitignore tracks kinetic .h5 inputs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…brium, analytic ExB, HDF5 profiles

Edge-current-matched equilibrium (q=6 retained at psihigh=0.995; fixed mpsi to
avoid edge under-resolution, see #302). Kinetic profiles carry an analytic ExB
rotation (omega_E = omega_tor - omega_dia) and synthetic transport diffusivities
chi_e/chi_phi, shipped in the new .h5 (gpec.toml points at it; .gpeckf retained
for back-compat). Relax NTV psi-quadrature tolerances as an interim mitigation
(see #303). Re-pin the parallel-integration regression (et[1], Delta-prime
diagonal) for the updated equilibrium.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
… torque

Drop leftover println/printf debug in tpsi! that flooded stdout during the
psi-quadrature (see #303).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@d-burg

d-burg commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Latest changes

  • New HDF5 kinetic-profile format. read_kinetic_file dispatches on file
    extension; write_kinetic_h5 writes it. Datasets: psi, n_i, n_e, T_i, T_e,
    omega_E, with optional chi_e (perpendicular heat diffusivity) and chi_phi
    (toroidal momentum diffusivity), used by the resistive-layer analysis.
    Legacy 6-column ASCII (.gpeckf/.kin) still reads through the same path for
    backward compatibility.

  • NTV profile loader refactored onto the new dispatcher. Verified bit-identical splines from the .h5 and the legacy .gpeckf, so NTV results are unchanged by the format switch.

  • DIII-D-like example migrated to the .h5 (n, T, omega_E plus chi_e/chi_phi from transport analysis). The .gpeckf is retained for the back-compat tests.

  • Example equilibrium updated to a more peaked j_phi profile, keeping the q=6 surface captured at psihigh=0.995.

  • Analytic ExB rotation: omega_E = omega_tor - omega_dia, with omega_tor a smooth concave profile (107*(1-psi_N)^2 + 33 + 34*psi_N^29 krad/s) and omega_dia from n,T. omega_E decreases from +100 krad/s, crosses zero near psi_N~0.9, and dips into the pedestal, with a continuous core derivative to the axis. Replaces the raw rotation column.

  • NTV torque performance: the outer psi-quadrature over-refines at the resonant rational surfaces. Interim mitigation: relaxed atol_psi/rtol_psi to 1e-2 and removed leftover per-evaluation debug prints. A proper fix (paneling the psi-integral at the rational surfaces) is tracked separately.

  • Tests and docs: added HDF5 round-trip, ASCII-vs-HDF5 equivalence, writer, and missing-field testsets; re-pinned the parallel-integration regression (et[1] and the Delta-prime diagonal) for the updated equilibrium; documented the kinetic file formats.

  • The example uses a fixed mpsi (256) rather than auto mpsi and grid_type='ldp' instead of 'log_asymptotic', which under-resolved the edge and gave spurious dW/Delta-prime (auto mpsi under-resolves the edge, giving spurious dW and Delta-prime #302). Upon resolution of auto mpsi under-resolves the edge, giving spurious dW and Delta-prime #302, log_asymptotic and auto mpsi will become the default settings once more and the regression harness will need to be re-pinned.

Related issues

image image

@logan-nc

Copy link
Copy Markdown
Collaborator

this looks very promising! I like the new rotation.

thanks for getting it together. I'll need to find time to look into the related issues, but we can get through them I'm sure. almost there!

Drop the unverified 'parallel and standard ODE paths agree to rel_diff=0'
claim from the DIIID-like testset (it only runs the parallel path); note the
cross-path agreement is verified on the Solovev testset. Addresses PR review.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@d-burg

d-burg commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

@logan-nc do we have your blessing to merge this new profile architecture, or should I run it by @matt-pharr first?

@logan-nc

Copy link
Copy Markdown
Collaborator

definitely get a second human to review it before merging plz. I probably won't get to read any gpec code until Thursday

@matt-pharr

Copy link
Copy Markdown
Collaborator

@d-burg I can review this. I want to see this so I can get profiles set up for resistive

@logan-nc

logan-nc commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

(Updated with final numbers from #313, which panels the ψ quadrature at the rational surfaces and the located kinetic resonances Ω_ℓ(x=1)=0 for the case's full ℓ ∈ −nl:nl range.)

Ran this PR's DIII-D-like example through the #303 fix branch (PR #313). Data files from this branch (geqdsk + TkMkr_D3Dlike_Hmode_kinetic.gpeckf — the .h5 reader is PR-only so the legacy file was used), code from develop vs the fix branch.

Run Code atol_psi / rtol_psi Torque (N·m) ψ evals KF stage Full n=1 pipeline
pre-mitigation (#303 report) develop 1e-3 / 1e-3 1375+ ~30 min
interim (this PR) develop 1e-2 / 1e-2 82.93 − 14.80i 345 158 s 4.0 min
same tol, atol=0 develop 0 / 1e-2 82.93 − 14.80i 345 158 s 3.1 min
#313 defaults paneled: 5 rationals + 8 kinetic resonances 0 / 1e-2 83.16 − 14.92i 210 108 s 3.3 min
#313, tight tol paneled: 5 rationals + 8 kinetic resonances 1e-9 / 1e-3 83.18 − 14.95i 450 296 s 5.3 min

Takeaways:

Evaluation clustering

  • The interim atol_psi = 1e-2 line is redundant: with |T| ≈ 83 N·m, rtol·|T| dominates and the atol=0 run is bit-identical. Once KineticForces - PERFORMANCE - Panel NTV psi quadrature at rational and kinetic-resonance surfaces with rtol-primary tolerances #313 merges, the atol_psi/rtol_psi lines here can simply be dropped — the new defaults do the right thing, and atol=0 also avoids the silent-underconvergence trap for weak applied fields (NTV ∝ δB², so a fixed N·m atol is amplitude-sensitive).
  • Rebase heads-up: this PR's [ForceFreeStates] section sets bal_flag, mer_flag, delta_mband, and thmax0, which no longer exist on develop (local_stability_flag replaces the first two; the kwargs splat errors on unknown keys) — the TOML will need those pruned when develop is merged in.

@logan-nc logan-nc requested a review from matt-pharr July 6, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request Unit tests Issues related to unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide kinetic profiles for the DIII-D-like example to enable an NTV-torque demonstration

4 participants