fix(rotated-bc): warn on non-converged linear KSP#315
Open
lmoresi wants to merge 1 commit into
Open
Conversation
`ksp.solve` never raises on `KSP_DIVERGED_*`, so the two linear paths in `rotated_bc` (the default fieldsplit-Schur iterative solve at `_solve_rotated_iterative` and the opt-in direct MUMPS LU at `solve_rotated_freeslip`) both returned partial answers silently. That silence is what let the 3D rotation-nullspace bug fixed by #306 look like a working solve for as long as it did: the outer Krylov hit its `ksp_max_it` ceiling (300 in the pre-#306 code) with a residual well above tolerance, and neither the KSP nor the caller flagged it. The solution then propagated into downstream diagnostics that eventually exposed it as wrong physics rather than as a solver failure. Add a small `_warn_if_ksp_diverged` helper and call it immediately after each of the two `ksp.solve` sites. Rank-0 warning only (via `uw.mpi.pprint`), same style as the existing nonlinear-driver warning at the end of `solve_rotated_freeslip_nonlinear`. No behaviour change on the happy path; non-convergence is now loud instead of silent. test_1018_rotated_freeslip.py: 14/14 pass (2D behaviour unchanged). Underworld development team with AI support from Claude Code
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a small safety guard to the rotated free-slip linear solves so that PETSc KSP divergences (which ksp.solve() does not raise) are no longer silent, improving diagnosability of partial / non-converged rotated-frame solutions.
Changes:
- Introduces
_warn_if_ksp_diverged(ksp, kind)to emit a rank-0 warning when KSP finishes with a non-converged reason. - Calls the helper after both
ksp.solve()sites (direct LU path and iterative fieldsplit-Schur path).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+41
to
+43
| reason = int(ksp.getConvergedReason()) | ||
| if reason >= 0: | ||
| return |
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
ksp.solvenever raises onKSP_DIVERGED_*, so the two linear paths insrc/underworld3/utilities/rotated_bc.py(the default fieldsplit-Schur iterativesolve in
_solve_rotated_iterativeand the opt-in direct MUMPS LU insolve_rotated_freeslip) both returned partial answers silently.That silence is what let the 3D rotation-nullspace bug fixed by #306 look
like a working solve for as long as it did: on the 3D Zhong
SphericalShellInternalBoundarycase (test_1064setup) the outer Krylovhit its `ksp_max_it` ceiling (300 in the pre-#306 code) with a residual
around 2.7e-7 (target rtol was 1e-7) while producing rotated-frame
solutions that the caller then rotated back and returned. Diagnosed under
the /remote-control session that surfaced #306.
Change
Add a small
_warn_if_ksp_diverged(ksp, kind)helper at the top of themodule and call it immediately after each of the two `ksp.solve` sites.
Rank-0 warning only (via `uw.mpi.pprint`), same style as the existing
nonlinear-driver warning at the tail of `solve_rotated_freeslip_nonlinear`.
Impact
KSP finished on a negative converged-reason.
rank-0 warning with the reason code, iteration count, and final
residual, so a caller inspecting stdout can see it.
Tests
`tests/test_1018_rotated_freeslip.py`: 14/14 pass (13 linear + 1
nonlinear-guard, unchanged from post-#306 tip). No new tests here — the
guard fires only on divergence, and forcing a divergence in-test would
require patching in a deliberately-broken preconditioner.
Related
codebase, but this PR is scoped to `rotated_bc` only.
Underworld development team with AI support from Claude Code