Skip to content

RDCON - BUGFIX - Galerkin factorization failures: Cholesky falls back to LU, a failed LU stops - #301

Merged
matt-pharr merged 5 commits into
developfrom
pr_rdcon_galerkin_factorization
Oct 15, 2026
Merged

matt-pharr merged 5 commits into
developfrom
pr_rdcon_galerkin_factorization

Conversation

@StuartBenjamin

@StuartBenjamin StuartBenjamin commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

gal_solve (rdcon/gal.f) never checked info from zpbtrf (Cholesky, the default) or zgbtrf (LU). zpbtrf reads only the lower band and the real part of the diagonal (there is no Hermitian check; the resonant diagonal entries carry a small imaginary numerical error). When that matrix is not positive definite, zpbtrf stops partway and zpbtrs solves with the partial factor: Δ′ is garbage and nothing is printed.

Example: g147131, n = 1, tearing-physics-suite (TPS) settings (no wall, nx 64, sing_order 8, psihigh 0.999). Develop's Cholesky gives Δ′(2/1, 3/1) = 9.7e6, 7.7e7; LU gives 2.13, −14.3.

Fix

  • Cholesky fails: warn with info, switch to LU, and reassemble the full band from the element matrices (gal_assemble_mat), so LU uses the upper band and the complex diagonal, as a direct LU run does. The element matrices already carry the boundary conditions, so gal_set_boundary is not rerun. A successful Cholesky run does no extra work.
  • LU fails (singular matrix): stop with info.

This follows matt-pharr's suggestion for Julia GPEC #513.

Tests

develop 1055d1b vs this branch:

case develop this PR
g147131, TPS settings, Cholesky: Δ′ 2/1, 3/1, 4/1 9.66e6, 7.75e7, 5.56e7, no warning 2.1359, −14.334, −78.134, warning and LU fallback
same, LU 2.1296, −14.3245, −78.1207 bit-identical
DIIID_resistive_example, LU and Cholesky bit-identical

After the fallback, 2/1 differs from a direct LU run by 0.3 % (3/1 by 0.07 %). Both solve the same equations, but this matrix is indefinite and badly conditioned, so round-off is amplified. With #303 merged too, this case is positive definite and no longer falls back.

Scripts: galerkin_factorization_scripts.zip (needs g147131.02300_DIIID_KEFIT, not shipped):

PY_NC=python3 ./run_tests.sh DEV/bin/rdcon PR/bin/rdcon $GPECHOME/docs/examples g147131.02300_DIIID_KEFIT out

No dependencies; merges cleanly with #303.


🤖 Generated with Claude Code

StuartBenjamin and others added 2 commits October 12, 2026 20:19
…rf info)

gal_solve ignored info from zgbtrf/zpbtrf, so an indefinite matrix with solver='cholesky'
gave a garbage Delta' with no warning (g147131 n=1, TPS settings: 2/1 = 9.7e6). Now
program_stop with the info value. LU results unchanged (bit-identical Delta' on g147131).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Galerkin matrix is not positive definite

zpbtrf info was ignored, so solver='cholesky' on an indefinite matrix gave a garbage Delta'
(g147131 n=1, TPS settings: 2/1 = 9.7e6). Now, when zpbtrf fails, gal_solve warns, sets
solver='LU', reassembles the full band from the element matrices (gal_assemble_mat) and
solves it by LU (2/1 = 2.1359; solver='LU' gives 2.1296, it does not zero the boundary
columns). zgbtrf failure stops the run. solver='LU' runs and Cholesky runs that succeed
are bit-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@StuartBenjamin
StuartBenjamin marked this pull request as ready for review October 13, 2026 09:24

@matt-pharr matt-pharr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good very simple change, I just added a check to switch back to LU in case someone tries to run cholesky with rpec_flag=T, which incorrectly gives Delta_coil=0 presently.

@matt-pharr
matt-pharr merged commit 3e19467 into develop Oct 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants