Preserve geometry at pitch crossings - #165
Conversation
|
Spatial campaign 18573023 completed at 1,920/3,840/7,680 steps on the pinned PR head. All three component runs exited zero with no adaptive recoveries; topology stayed fixed and the maximum qflux relative error was 3.48e-14. The two harmonic-response components were (-13.6163181,-70.1506689), (-13.6152840,-70.1478445), and (-13.6134972,-70.1396413). Successive relative changes were (7.59e-5,4.03e-5) and (1.31e-4,1.17e-4): both are below 1e-3, but the final change grows rather than contracts, so this does not pass the spatial convergence gate. The submission also omitted the local-projection and join-end trace flags. It therefore did not record the constant-distribution closure or global Lorentz correction at each resolution and is retained only as a rejected diagnostic. Campaign 18573042 repeats 3,840/7,680 and extends to 15,360 steps with both traces enabled. The incomplete pitch campaign was cancelled and replaced by diagnostic-complete campaign 18573043 at 30/60/120/240 bands. Collision physics, source, coordinates, units, boundary conditions, ABI, and serialized layout remain unchanged. No pointwise current or physical profile is accepted pending both corrected gates. |
rearrange_phideps received only the padded extent iend = ub_mag + 2*modify_br and forwarded ubound(phi_divide,1) as the physical scan bound, while every caller allocates phi_divide(1:ub_mag). With right boundary-layer modification active the crossing scan ingested the duplicated padding nodes, the strict-monotonicity guard then rejected every crossing, and a padding-region rejection wrote the refinement flag past the actual phi_divide extent, silently losing the ierr = 3 gate and leaving delt_pos/delt_neg/fact_* uninitialized. Pass the physical ub_mag explicitly, size the phi_divide dummy by it, scan only 0:ub_mag on both sides of the field minimum, and clamp the legacy sub-interval split writes to the physical extent. Behavior with modify_br = 0 is unchanged (ub_mag == iend there). Add a modify_br = 1 regression test covering benign and crossing-like padding values plus an in-range rejection flag.
Bounds/gate defect fixed in 6aec6fcDefect
The pinned HELCORE campaigns (18573042/18573043) ran the axisymmetric Fix
With VerificationNew behavioral test Test fails on this PR's previous head 0345e33 (call adapted to the old Test passes after the fix, along with the existing crossing tests: ctest: 43/44 pass; the single failure is the pre-existing NEO-2-PAR keeps its own separate |
There was a problem hiding this comment.
Review verdict: Approve
Review of PR #165: Crossing Geometry Alignment and phi_divide Bounds Fix
Summary: This PR fixes an out-of-bounds bug in phi_divide (declared dimension(1:iend) but allocated 1:ub_mag), replacing the old nearest-neighbor crossing alignment with 6-point Lagrange interpolation and bisection root-finding. The core fix changes phi_divide's declaration to dimension(1:ub_mag) matching its allocation, and adds max(1, ib+1) / min(ie, ub_mag) clamping on all writes. Two new test files exercise the alignment and padding regression paths. The changes are well-structured and the new module phi_crossing_alignment_mod cleanly separates the interpolation logic.
Findings:
-
minor
NEO-2-QL/ripple_solver_ArnoldiOrder2_test.f90:~5410— Debug file I/O (open(111, file='phi_placement_problem.dat'...) remains inalign_phi_crossing_geometry, writing to disk on every crossing. This is pre-existing (carried from oldfix_phiplacement_problem`), not a regression, but it should eventually be guarded behind a debug flag or removed for production builds. -
minor
NEO-2-QL/ripple_solver_axi_test.f90:~3409—rearrange_phideps_oldis still present in the file but no longer called (dead code). Consider removing in a follow-up cleanup. -
minor
NEO-2-QL/ripple_solver_axi_test.f90:~773—unused_dbcovar_mflis allocated, zeroed, passed torearrange_phidepsasdbcovar_s_hat_dphi_mfl, and deallocated without being used. This is harmless but suggests thebcovar_columnpath is intended for future use; a comment would help. -
minor
NEO-2-QL/phi_crossing_alignment_mod.f90:~65—stencil_leftcomputation usescrossing_stencil_size/2(integer division, 6/2=3), which is correct for Fortran integer division. The+1ensures the bracket node is centered in the stencil. No issue, noting for clarity.
Verdict: Approve — The core OOB fix is correct (declaration now matches allocation, all writes are bounds-clamped). The new alignment method is sound, well-tested, and the claim_crossing_target double-assignment guard is a good defensive measure. The nder change from 0→1 correctly enables derivative computation. No blockers or major issues found. The minor items are pre-existing or cosmetic.
There was a problem hiding this comment.
Review verdict: Request changes
Review of PR #165: Phi crossing geometry alignment refactor
Summary: This PR refactors phi-crossing geometry handling in the QL test variants. A new phi_crossing_alignment_mod introduces bracketed root-finding (bracketed_phi_crossing), crossing-target claiming (claim_crossing_target), and status codes. rearrange_phideps gains a ub_mag parameter so phi_divide is allocated to the physical extent (1:ub_mag), with writes clamped via max(1,ib+1):min(ie,ub_mag) to protect padding nodes. align_phi_crossing_geometry replaces fix_phiplacement_problem, scanning only the physical grid for crossings and rejecting non-simple roots. Two new test programs are added.
Findings:
-
[major]
TEST/test_crossing_geometry_padding.f90:122— Unbalanced parentheses inallocatestatements. Line 122 hasallocate (dbcovar(0:iend), delt_pos(0:iend), delt_neg(0:iend))with an extra), which is a compile error. This newly added test file cannot build as written. Fix: Remove the extra closing paren on each affectedallocatestatement. -
[major]
TEST/test_phi_crossing_alignment.f90:54-56— Incorrect parenthesization in test assertions makes them vacuously true. Line 54 computesabs(sum(weights*bhat_profile(...))) * eta_root - 1.0instead ofabs(sum(...)*eta_root - 1.0). Theabs()closes before*eta_root, so the test checks|sum| * eta - 1rather than|sum*eta - 1|. It passes even with wrong weights. Fix: Move the closing paren ofabs()to encompass*eta_root - 1.0_real64. -
[minor]
NEO-2-QL/ripple_solver_ArnoldiOrder2_test.f90:~5370—align_phi_crossing_geometryopens and writes to'phi_placement_problem.dat'on every crossing during integration. This debug file I/O in the hot path is inherited from the oldfix_phiplacement_problemand should be removed or guarded by a debug flag. -
[minor]
NEO-2-QL/phi_crossing_alignment_mod.f90:~100— The strict monotonicity checkany(phi(ibeg+1:iend) <= phi(ibeg:iend-1))has no tolerance. Tiny floating-point noise in real MHD equilibria could cause spuriouscrossing_non_simplerejections. Consider a relative tolerance on the phi differences.
Verdict: Request changes — The test files contain syntax errors (unbalanced parentheses) and logic errors (vacuous assertions) that would cause compile failures or silently pass with incorrect values. These must be fixed before the PR can be merged.
Problem
PR 164 makes the discrete constant-distribution null exact, but its crossing
repair changes only
bhat_mflat a grid point. The coordinate, metric, drift,and derivative arrays remain sampled at the old point. This creates an
internally inconsistent geometry that moves with spatial resolution.
Change
1 - eta B(phi) = 0in the existing six-point Lagrange representation.pitch bands, array bounds, ABI, or serialized propagator layout.
B,h_phi,dlogB/ds,bcovar_s_hat, andgeodcufrom oneunchanged stencil. Recompute
dlogB/dphiandd(bcovar_s_hat)/dphifromthe same polynomial.
arrays and nonuniform cell factors are built after alignment.
one cell crosses more than one pitch band, the field is not monotone away
from its minimum, or two crossings require the same node.
The magnetic-field representation, CGS units, pitch measure, mirror and
periodic endpoint conventions, node order, and solver storage layout are
unchanged. This PR changes where existing field data are sampled; it does not
change the collision operator or introduce a new source.
This PR is stacked on #164 and should remain unmerged until the pinned spatial
and pitch campaigns pass.
Verification
Test fails on the base branch
With the new behavioral test applied before the implementation:
Test passes after fix
The format warning is limited to the two pre-existing legacy solver files;
the module and behavioral test are formatted.