Standalone KIM diagnostics: D_ql,e22 and integrated parallel current#137
Open
marjohma wants to merge 5 commits into
Open
Standalone KIM diagnostics: D_ql,e22 and integrated parallel current#137marjohma wants to merge 5 commits into
marjohma wants to merge 5 commits into
Conversation
Add kim_diagnostics_m with pure integrate_Ipar: complex trapezoid of 2*pi*r*jpar over the passed (layer-restricted) radial grid. First of the KIM standalone diagnostics; analytic unit tests on a non-equidistant grid cover constant and linear jpar profiles. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Port the electron (2,2) Onsager component from QL-Balance calc_transport_coeffs_ornuhl (diff_coeffs.f90) into a unit-testable KIM module kim_qldiff_m::calc_dqle22 taking plain scalars. Reuses the getIfunc/W2_arr susceptibility functions already compiled into KIM_lib via the KIM_fokkerplanck source group. Tests verify the x1 -> 0 resonant-surface limit against the closed form of Markl et al 2023 NF 63 126007 Eq. 31 for omE/nue = 0.5 and 2.0 (rel err ~1e-12). Also harden assert_close against zero real or imaginary parts of the expected value. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add compute_and_write_diagnostics to kim_diagnostics_m: after the
electromagnetic solve it evaluates D_ql,e22 at the grid point nearest
the resonant surface (local vTe, nue, om_E, B0, k_par interpolated
with the standard binsrc/plag_coeff stencil) and integrates the total
and electron-only parallel currents from EBdat.
Outputs via new IO_collection_m::write_kim_diagnostics:
- HDF5 datasets /diagnostics/{dqle22,Ipar_re,Ipar_im,Ipar_e_re,
Ipar_e_im} when hdf5_output is on
- flat file kim_diagnostics.dat (es23.15, # header) when the new
KIM_IO flag write_diagnostics_dat is on, regardless of hdf5_output;
this is the scan driver interface
Equidistant grids never call recnsplit, so the diagnostics routine
triggers the lazy resonance detection itself via the prop guard.
Integration test runs the EM solve on a coarse in-memory plasma
(QL-Balance adapter injection path) and asserts the flat file exists,
parses, has five finite values and dqle22 > 0 (1.4 s runtime).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
When |m/n| lies outside the q range, prepare_resonances leaves r_res = 0 and compute_and_write_diagnostics evaluated everything at the innermost grid point, writing plausible-looking but meaningless values that the scan driver machine-reads. Now an error is logged to stderr and no output is written; the missing kim_diagnostics.dat is the driver's failure signal. Covered by a new integration test that runs the EM solve with m/n = -4/1 against test profiles with q in [1.5, 2.5]. Also: - IO_collection: open the existing diagnostics/ HDF5 group instead of leaving h5grpid undefined when the group already exists (no cheap test; HDF5 re-entry path). - kim_diagnostics: drop the dead exact-zero kpar fallback; the A2 unit test shows the formula is well-behaved at x1 ~ 1e-6 and the collisional getIfunc branch handles x1 = 0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Gate V1 found the dqle22/|Br|^2 resonant layer can be narrower than the grid spacing (FWHM 0.034 cm vs a 0.0133 cm nearest-node offset, a 33% error for m=7), so nearest-node evaluation is not good enough for production scans. Interpolate Es, Br (new interp_local_complex, 4-point Lagrange) and the plasma parameters to r_res itself; kpar is the interpolated near-zero value, which calc_dqle22 handles since the collisional response is regular at kpar -> 0. Also write |Br(r_res)| as a 6th output (HDF5 /diagnostics/br_abs_res and a 6th flat-file column) so the scan driver gets it without digging through field profiles. Flat-file column order: dqle22, Ipar_re, Ipar_im, Ipar_e_re, Ipar_e_im, br_abs_res. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Adds standalone diagnostics to KIM so it can drive density/temperature
parameter scans of the quasilinear bifurcation criterion without
QL-Balance, sidestepping the ParameterScan profile-propagation defect
in #136.
Five focused commits:
integrate_Ipar— integrated resonant parallel current (complextrapezoid of
2π r j_∥), in a newKIM/src/diagnostics/module.calc_dqle22— quasilinear electron heat diffusion coefficientD_ql,e22, ported term-for-term from QL-Balance'sdiff_coeffs.f90(2,2) component, calling the sharedgetIfunc(no duplicated susceptibility code).
/diagnostics/{dqle22,Ipar_re,Ipar_im, Ipar_e_re,Ipar_e_im,br_abs_res}and a flatkim_diagnostics.dat,gated by a new
&KIM_IOflagwrite_diagnostics_dat(default.false.), computed once after the EM solve.error stop).r_resby interpolation (not the nearestnode) and emit
br_abs_res— needed for narrow resonant layers.Production-safety: with both diagnostics flags off,
compute_and_write_diagnosticsreturns before touching any globalstate, so existing KIM runs are byte-identical. The namelist flag is
backward-compatible (old namelists read fine).
These diagnostics were used to run a full KIM-vs-KiLCA nT scan of the
Markl 2023 (NF 63 126007) bifurcation criterion; KIM standalone
reproduces the QL-Balance+KIM pipeline at base profiles to ~2%.
Test Plan
test_kim_diagnosticspasses (analytic trapezoid onnon-equidistant grids; complex interpolation exact-on-cubic;
D_ql,e22vs the Markl 2023 Eq. 31 closed form in two collisionalityregimes; two EM-solve integration tests incl. the no-resonance skip).
ctestgreen except the pre-existingtest_rhs_balance(QL-Balance, fails identically on
main@ 225a877 — unrelated).D22 port verified term-by-term).
Related: #136 (the QL-Balance ParameterScan+KIM defect this work
routes around).
🤖 Generated with Claude Code