Skip to content

Stokes refuses a solve whose pressure preconditioner cannot be factored (#1059) - #1255

Merged
lmoresi merged 5 commits into
developmentfrom
bugfix/stokes-huge-viscosity-refuses-1059
Nov 20, 2026
Merged

lmoresi merged 5 commits into
developmentfrom
bugfix/stokes-huge-viscosity-refuses-1059

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member

Fixes #1059 by refusing. The cause is found, and a fix that would make these solves work is offered below for the maintainer's decision. It changes a solver option, so it is not in this PR.

The cause

The NaN comes from the pressure block, not the velocity block:

  • Pressure swapped: setting the pressure preconditioner to Jacobi makes the 1e11 solve converge.
  • Velocity swapped: LU or Jacobi on the velocity block does not help.

The pressure block's preconditioner is GASM with ILU sub-solves, on the pressure mass matrix divided by the viscosity. PETSc's LU and ILU treat a pivot below an absolute tolerance, 2.22e-14, as zero. The largest diagonal entry of that matrix, on #1059's box (cell size 0.1), is:

viscosity largest diagonal entry solve
1e10 5.4e-13 converges
1e11 5.4e-14 pressure PC SUBPC_ERROR, SNES DIVERGED_LINEAR_SOLVE at iteration 0, u = 0
1e12 5.4e-15 the same

Once the pivots fall to the tolerance, the factorisation fails. Its failure surfaces first as the velocity sub-KSP's NaN.

With fieldsplit_pressure_sub_pc_factor_zeropivot = 0, the same solves converge at 1e11, 1e15 and 1e21. The answer scales exactly as 1/viscosity (max |v| 3.84e-14, 3.84e-18, 3.84e-24).

What this PR does

A Stokes-family solve that diverges because the pressure preconditioner could not be factored now raises a RuntimeError on every rank. Before, it returned with u = 0 and a warning. The message:

SNES_Stokes: the pressure block's preconditioner could not be factored, so the solve stopped at iteration 0 and the fields hold the initial guess. That matrix is the pressure mass matrix divided by the viscosity; its largest diagonal entry is 5.37e-15, and PETSc's factorisation treats pivots below 2.2e-14 as zero. This happens when the viscosity in the solver's frame is about 1e11 or more, as in a model in raw SI units. Give the model reference quantities (uw.get_default_model().set_reference_quantities(...), see the units-system guide), so the viscosity it solves with is of order one. (#1059)

How it decides:

For the maintainer: the option that would make these solves work

The tolerance is absolute, but this matrix scales as 1/viscosity, so the failure is set by the units the model is written in, not by the problem.

  • Option: setting fieldsplit_pressure_sub_pc_factor_zeropivot to 0 in the Stokes defaults would let raw-SI models solve.
  • Alternative: scale the pressure preconditioner matrix to order one.
  • Effect on non-dimensional models: nothing changes; their pivots are far above the tolerance.

Either would make the refusal here reachable only by a genuinely singular block. It changes a solver default, so it is not in this PR.

Test

tests/parallel/test_1059_stokes_unfactorable_pressure_pc_refused_parallel.py, tier B, in batch 3 of scripts/test.sh:

  • viscosity 1e12 and 1e21 must raise on every rank, with the remedy in the message. On development no rank raises.
  • viscosity 1e10 must still solve, at 1/1e10 of the unit-viscosity answer.

It passes at np 1, 2 and 4.

Runs. The serial files on diverged-solve reporting (#1161, #1163, the wall-clock guard, the transcript report), Stokes, nullspaces, rotated and constrained conditions, Navier-Stokes, Nitsche and units, tier C excluded:

  • 646 passed, 7 xfailed (known, all in the units files);
  • 5 skipped.

The coverage check passes.

Measured on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH).

Underworld development team with AI support from Claude Code

…ed (#1059)

The pressure block's preconditioner factors the pressure mass matrix divided
by the viscosity, and PETSc's ILU treats pivots below 2.2e-14 as zero: from a
viscosity of about 1e11 in the solver's frame the factorisation failed, the
solve stopped at iteration 0 and the fields held u = 0 with a warning. Such a
failure now raises on every rank, with the matrix's scale and the remedy
(reference quantities, so the viscosity is of order one).

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 20, 2026 04:50

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict on d48b37d: ready to merge on green from this review.

  • The refusal is the same on every rank. This holds at np 1, 2, 3 and 4, on an empty rank, and when only one rank's local block has the bad pivots.
  • The boundary is unchanged. Refusal starts between 5e10 and 5.5e10 on this mesh, on both builds. Every solve that converged on development converges on this branch, with the same answer.
  • Other diverged reasons keep their warning. We checked DIVERGED_MAX_IT, DIVERGED_LINEAR_SOLVE from a capped KSP, and DIVERGED_LINE_SEARCH.
  • The remedy works. A 1e21 Pa s model with set_reference_quantities solves on both builds.
  • 64 serial and 29 parallel Stokes solves match in iteration counts. Answers are bitwise equal, apart from np 3 round-off that development shows against itself.
  • No blocking findings. Two medium findings are about the message text and a stuck solver that development already has. Both can be follow-ups.

How it was run

Builds:

  • This branch: a fresh build of d48b37d in its own worktree. The compiled modules are dated after the build started. The new method's name is in generic_solvers.so.
  • Development: the merge base, c2f8b4f. We used an existing build whose checkout is exactly c2f8b4f, with clean sources. Its installed Python matches its source.

Probe: a small script runs the PR test's box: a unit square, cellSize=0.1, P2/P1, and a body force of sin(pi x). It solves once, or several times on the same solver. After the solve, each rank reports:

  • the SNES and KSP reasons and iteration counts;
  • its own pressure-PC failed reason;
  • its own smallest pressure-block diagonal;
  • whether it raised.

The fields were not zeroed between solves on the same solver.

Partitions: parallel runs used random and band partitions, through a shell partitioner hook on gmsh meshes. With the band layout each rank owns a horizontal strip. With the empty-band layout the last rank owns no cells.

Solve log: the solve-logging pytest plugin from our earlier reviews recorded each solve's SNES and KSP counts, reason, and solution vector, on both builds. The records were then matched solve by solve.

Every run used four cores. Every parallel run was under the MPI supervisor with a 300 s timeout. All solves here took seconds; the timeout was not reached.

The pressure preconditioner here is GASM with ILU sub-blocks, not block Jacobi. A zero pivot in a sub-block shows on the pressure PC as SUBPC_ERROR (6). That is why the PR counts SUBPC_ERROR.

Results

The key parallel question: is a local failure seen on every rank?

Viscosity is 1 below y = 0.8 and 1e12 above it, with the band partition. Only the top rank's local block has the tiny pivots.

case ranks smallest local diagonal, per rank pressure-PC failed reason, per rank raised (this branch) raised (development)
band, np 4 0, 1, 2, 3 1.2e-3, 2.1e-3, 1.9e-3, 1.2e-15 6, 6, 6, 6 4 of 4 0 of 4 (warning)
empty band, np 3, 1e12 above y = 0.6 0, 1, 2 (empty) 1.2e-3, 1.2e-15, none 6, 6, 6 3 of 3 0 of 3 (warning)
band, np 2 and 3 all — 6 on all all none
uniform 1e12, random partition, np 2, 3, 4 all — 6 on all all none
uniform 1e12, empty band, np 3 all — 6 on all 3 of 3 none

PETSc already reports the failure on every rank: development shows SUBPC_ERROR on every rank too. The PR's own MAX reduction is a second guard on top of that. The diagonal norm for the message runs only after a MIN reduction of "found the pressure block", so every rank takes it or none does. The raise comes after all the solve's collectives (the copy-back and _record_convergence_status). It is plain Python after snes.solve returns, not inside a PETSc callback.

Boundary sweep, serial, cellSize 0.1

viscosity development this branch
1e10, 2e10, 3e10, 4e10, 5e10 converged, 1 iteration converged, 1 iteration, same speed
5.5e10, 6e10, 7e10, 8e10, 9e10, 1e11, 1.5e11, 2e11, 2.5e11, 3e11, 5e11, 1e12, 1e15, 1e21 DIVERGED_LINEAR_SOLVE at iteration 0, warning, u = 0 refused on every rank

The edge matches the smallest diagonal: 1.22e-15 at 1e12 reaches 2.2e-14 at about 5.5e10. Nothing that converged on development is refused. That follows from the method's first line too: it returns at once when the converged reason is 0 or more.

Mesh dependence: at cellSize=0.03, 1e10 is refused on this branch (and diverges on development), and 1e9 solves.

Author's zero-pivot claim: with fieldsplit_pressure_sub_pc_factor_zeropivot = 0, 1e21 converges on both builds. The speed is 3.84e-24, exactly 1/viscosity times the unit answer.

Other diverged reasons, and nonlinear solves (serial)

case development this branch
viscosity 1, capped KSP (ksp_max_it=1, inner its 1) DIVERGED_LINEAR_SOLVE, warning same, warning, not raised
strain-rate viscosity, snes_max_it=2 DIVERGED_MAX_IT, warning same, warning, not raised
shear thickening, 1 + 1e18 E_II DIVERGED_LINE_SEARCH, warning same, warning, not raised
shear thickening, 1 + 1e22 E_II converged, 8 its converged, 8 its, same speed
strain-rate viscosity capped at 1e12 (1e12 at u = 0) DIVERGED_LINEAR_SOLVE at iteration 0, warning refused
strain-rate viscosity capped at 1e10 converged converged, same

Units model (the remedy the message names)

The box is lid-driven, with reference quantities of 1000 km, 5 cm/yr and 1e21 Pa s, and a viscosity of 1e21 Pa s.

case development this branch
with reference quantities, np 1 and np 2 converged, 1 iteration, lid speed 1.0 in model units same
without reference quantities, raw 1e21 DIVERGED_LINEAR_SOLVE, warning refused

The PR's test

run development this branch
np 1 2 failed, 1 passed 3 passed
np 2 2 failed, 1 passed 3 passed
np 3 — 3 passed
np 4 — 3 passed
np 3, empty band — 3 passed
np 4, band — 3 passed

scripts/test.sh runs it in the serial batch-3 list. The tests/parallel/test_*.py glob also picks it up for the MPI pass, and for the np 3 and 4 passes under --full-parallel.

Unchanged answers on standard Stokes files

Serial (test_0022 x3, test_0610, test_0786, test_0818, test_1010, test_1011, test_1013 x2, test_1014_stokes_multigrid, test_1050): 77 passed on both builds. 64 solves match in SNES and KSP counts and are bitwise equal.

file solves SNES its dev / PR KSP its dev / PR bitwise
test_0022_adjoint_operator_from_kernels 2 51 / 51 63 / 63 2
test_0022_rotated_adjoint 10 0 / 0 0 / 0 10
test_0786_stokes_jacobian_and_preconditioner_one_call_each 3 3 / 3 4 / 4 3
test_0818_stokes_nd 8 8 / 8 8 / 8 8
test_1010_stokesCart 6 6 / 6 6 / 6 6
test_1011_stokesSph 3 3 / 3 3 / 3 3
test_1013_stokes_fields_by_solver_number 15 12 / 12 24 / 24 15
test_1014_stokes_multigrid 9 9 / 9 16 / 16 9
test_1050_VEstokesCart 5 6 / 6 6 / 6 5
others (0610, 1013 nullspace, one conftest solve) 3 3 / 3 3 / 3 3

Parallel (test_0780, test_0786 rank without cells, test_1167, test_1200): same pass counts on both builds at np 2 and 3. Iteration counts match. At np 2 the answers are bitwise equal. At np 3 one test_1200 solve differs by 1.2e-14 relative. Two development runs differ from each other by the same amount, so it is run-to-run round-off.

Other solvers: the new method is called only from SNES_Stokes_SaddlePt.solve. Poisson, advection-diffusion and projection solves do not reach it, so they were not run. Stokes subclasses (VE, constrained, Navier-Stokes) reach it through super().solve, and the error propagates through their wrappers.

Findings

  1. Medium: The message gives the wrong scale for the failure. It prints the largest pressure diagonal. The failure is decided by the smallest pivot. Three cases show the problem:

    • At 1e11 it says "largest diagonal entry is 5.37e-14" and "pivots below 2.2e-14 [are] zero", which reads as a contradiction. At 5.5e10 it says 9.76e-14.
    • With a viscosity contrast, it says 0.00537. That is the band case above: viscosity 1 below, 1e12 in one band. The remedy it names cannot help there. Reference quantities rescale the whole model, and the 1e12 contrast stays.
    • "About 1e11 or more" holds only for this mesh. The edge is near 5.5e10 at cellSize=0.1, and 1e10 is already refused at cellSize=0.03. The diagonal scales with element area in 2D and volume in 3D.

    Suggestion: report the smallest absolute diagonal (getDiagonal().min(), already collective). Say the limit depends on element size and on the viscosity contrast, as well as on the reference viscosity. This is a text change and can be a follow-up.

  2. Medium: After one zero-pivot failure, the same solver stays failed. On this branch the next solve is refused with a diagnosis that is now false. This happens on development too, so the PR did not cause it. Solve at 1e12, then set the viscosity to 1 and solve again:

    • The pressure matrix is healthy: smallest diagonal 1.2e-3.
    • The pressure PC still reports SUBPC_ERROR, and the solve stops at iteration 0 with u = 0.
    • Development warns. This branch raises "could not be factored ... largest diagonal entry is 0.00537 ... set_reference_quantities".
    • Seen at np 1 and np 2. The same happens for 1 → 1e12 → 1 and for 1e12 → 1e10.
    • solve(_force_setup=True) recovers on both builds and gives the unit answer.

    A user who catches the error and fixes the viscosity on the same solver gets refused again, with advice that does not apply. Suggestion, for a follow-up issue: clear the pressure PC's state (or force the rebuild) on the solve after a factorisation failure. Or, at least, the message can say the solver must be rebuilt.

  3. Low: Any sub-PC error gets the zero-pivot text. SUBPC_ERROR is needed here, because GASM reports a sub-block's zero pivot that way. But an out-of-memory or other factor failure in the pressure block would also be described as a zero pivot. Checking the sub-PC's own reason, or wording the message less firmly, would cover that.

  4. Low: "The fields hold the initial guess" is stated whatever the iteration. If a nonlinear solve meets the bad pivot after iteration 0, the fields hold the last iterate, not the initial guess. _warn_on_diverged_solve already makes this distinction, and the message could reuse it. We could not build a case that fails mid-solve: our shear-thickening runs either converged or stopped in the line search first.

What was run and not run

Run:

  • the fine sweep from 1e10 to 1e21, serial, on both builds;
  • the uniform, band and empty-band refusal at np 2, 3 and 4, on both builds;
  • the other diverged reasons, nonlinear and repeated solves, the zero-pivot option, the finer mesh, and the units model;
  • the PR test at np 1 to 4, including band and empty band, and on development at np 1 and 2;
  • 12 serial and 4 parallel Stokes test files, with solve logs compared.

Not run:

  • the full regression suite;
  • 3D meshes;
  • Poisson, advection-diffusion and projection solvers (not on the changed path);
  • a nonlinear solve that meets the bad pivot after iteration 0 (not constructed);
  • an uncaught refusal in a script. Each rank raises its own RuntimeError, so an uncaught one prints a traceback per rank.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

From the review of the refusal. The message reported the largest pressure
diagonal, but the smallest pivot decides: it now gives both, and says
whether every entry is tiny (the viscosity's scale: reference quantities)
or a contrast spans them (which reference quantities cannot remove; the
zero-pivot option and a direct velocity solve, measured), with no fixed
viscosity threshold, which is mesh-dependent. Only a zero pivot, or a
sub-PC error with entries near the tolerance, is refused. "The initial
guess" only at iteration 0. And a PC that failed kept its failed state,
so the same solver failed again with a healthy matrix: the next solve
after a PC failure forces its setup.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Answers to the review of d48b37d are in 3f20212, with development merged in.

1. The message gives the cause and the remedy that fit.

  • Both extremes: it reports the pressure preconditioner matrix's smallest and largest |diagonal|, and the fixed "about 1e11" is gone. It says the limit depends on element size as well as viscosity.

  • Scale (every entry within 100× of the tolerance): reference quantities. On the unit box at 1e12, the diagonal runs from 1.22e-15 to 5.37e-15.

  • Contrast (viscosity 1 below y = 0.8 and 1e12 above: 1.22e-15 to 0.00537, a factor of 4.4e12): the message says reference quantities cannot remove a contrast. Measured on that box:

    • with fieldsplit_pressure_sub_pc_factor_zeropivot = 0 the pressure block factors, but the velocity multigrid then fails (NaN, reason −9);
    • with a direct velocity solve as well it converges;
    • a 1e6 contrast solves by default.

    The message says this and leaves the defaults open.

2. The same solver works once the viscosity is fixed. When the outer KSP stopped with DIVERGED_PCSETUP_FAILED, which is global, the next Stokes solve forces its setup. Test: solve at 1e12 (refused), set the viscosity to 1, and solve again on the same solver. It must converge and equal a new solver's answer. On a build without the fix it fails, as you found.

Lows:

  • Zero-pivot text: only a zero pivot (structural or numeric), or a sub-PC error whose matrix has entries within 100× of the tolerance, is refused. Any other factorisation failure keeps the diverged-solve warning.
  • Fields: they hold "the initial guess" at iteration 0, and "the last iterate" otherwise.

Tests (test_1059): new contrast and fail-then-fix cases, and the scale cases now also check that the message doesn't mention a contrast. All four changed cases fail without the fix. The file passes at np 1, 2 and 4, at np 4 with the band partition (the bad block on one rank), and at np 3 with an empty rank.

Runs: the diverged-solve files (#1161, #1163, the wall-clock guard, the transcript report) and the Stokes, nullspace, rotated, constrained, Navier-Stokes and Nitsche files, tier C excluded: 389 passed, 1 skipped. The coverage check passes.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict on 3f20212: ready to merge on green from this review.

  • All four earlier findings are fixed. We checked each one by measurement, not only by reading the code.
  • The stuck solver now recovers. After a failure, the next solve on the same solver converges to the same answer as a fresh solver, at np 1, 2 and 4. Solves that do not fail never force a setup.
  • What held at d48b37d still holds. The refusal is the same on every rank. The boundary is unchanged. Other diverged reasons keep their warning. The units remedy works. 72 serial and 33 parallel Stokes solves match development in iteration counts.
  • One new medium finding, not blocking. The scale-or-contrast choice uses an absolute bound on the largest diagonal. So a moderate contrast at a high base viscosity is called a contrast, and the message says reference quantities cannot help. They would help. This is a text fix and can be a follow-up.

Earlier findings: then and now

# finding at d48b37d at 3f20212
1 (Medium) The message printed the largest diagonal, but the smallest pivot decides. At 1e11 it read as a contradiction. For a contrast it named set_reference_quantities, which cannot help. "About 1e11" depended on the mesh. Fixed. The message gives both the smallest and the largest diagonal. For a uniform viscosity it names reference quantities; for the 1e12 band contrast it says they cannot help. "About 1e11" is gone; the message says the limit depends on element size. One edge case is left (new finding 1).
2 (Medium) After a zero-pivot failure the same solver stayed failed. _force_setup=True recovered. Fixed. After a failed PC setup, the next solve forces a setup. 1e12 → 1, 1 → 1e12 → 1 and 1e12 → 1e10 converge to the fresh-solver answer at np 1 and 2. 1e12 band → 1 converges at np 4 with the band layout. Development still stays failed in the uniform cases.
3 (Low) Any sub-PC error got the zero-pivot text. Fixed. A refusal now also needs the smallest diagonal to be within 100 times the zero-pivot tolerance. A sub-PC failure on a healthy matrix now gets the warning: we forced one with a zero-pivot tolerance of 1e3 at viscosity 1, at np 1 and 2.
4 (Low) "The fields hold the initial guess" whatever the iteration. Fixed in the code. The text says "the last iterate" when the iteration count is above 0. We still could not build a pressure-pivot failure after iteration 0 (see "Not run").

How it was run

Builds:

  • This branch: a fresh build of 3f20212 in a new worktree. All 12 compiled modules are dated after the build started. generic_solvers exposes the new _PIVOT_SUSPECT and _PETSC_ZERO_PIVOT.
  • Development: the new merge base, 6fc3fc5. We looked for an existing build whose compiled sources match it. The one checkout at 6fc3fc5 with clean sources had its installed modules built from this branch. So we built 6fc3fc5 fresh in its own worktree. All 12 of its modules are dated after that build started.
  • Every run printed underworld3.__file__, and each run used the intended build.

Probe: the same probe as in the first review: the PR test's box (unit square, cellSize=0.1, P2/P1, body force sin(pi x)). Two additions:

  • the rebuild flag, read before and after each solve;
  • the wall time of each solve.

Partitions: random, band and empty-band partitions came from the same shell partitioner hook as before.

Solve logs: the same solve-logging pytest plugin as before.

Resources: every run used four cores. Every parallel run was under the MPI supervisor with a 300 s timeout. That allows for slow healthy solves. All solves here took seconds, and no run reached the timeout.

Results

Finding 1: the message text (serial unless noted)

case outcome diagonal printed (smallest to largest) remedy named
uniform 5e10 converges, both builds — —
uniform 5.5e10 refused 2.22e-14 to 9.76e-14 reference quantities
uniform 1e11 refused 1.22e-14 to 5.37e-14 reference quantities
uniform 1e12 refused 1.22e-15 to 5.37e-15 reference quantities
uniform 1e21 refused 1.22e-24 to 5.37e-24 reference quantities
uniform 1e10, cellSize=0.03 refused (diverges on development) 1.06e-14 to 4.8e-14 reference quantities
uniform 1e9, cellSize=0.03 converges, both builds — —
band: 1 below y = 0.8, 1e12 above refused 1.22e-15 to 5.37e-3, "a factor of 4.4e+12" contrast; reference quantities cannot help; zeropivot 0 plus velocity LU
same band, cellSize=0.03 refused 1.06e-16 to 4.75e-4 contrast
same band, np 2, 3, 4 (band layout) refused on every rank as serial contrast
band contrast 1e6 converges, 1 iteration, both builds, np 1 and np 4 band — —
band contrast 1e9 converges, 2 SNES / 4 KSP iterations, both builds — —
band: 1e9 below, 1e12 above refused, np 1 and np 4 band 1.22e-15 to 5.37e-12, "a factor of 4.4e+03" contrast: "reference quantities cannot remove" (new finding 1)
band: 1 below, 1e3 above (the line above divided by 1e9) converges, 1 iteration, both builds — —

The author's zero-pivot claim: for the 1e12 band, fieldsplit_pressure_sub_pc_factor_zeropivot = 0 gets the pressure block through. The velocity solve then fails: the KSP reports a PC failure at SNES iteration 1, on both builds. That failure keeps the warning ("last iterate"). Adding fieldsplit_velocity_pc_type = lu gives convergence in 1 iteration, the same on both builds. The 1e6 contrast solves with the default options. The message's account is right.

Finding 2: the same solver after a failure

Uniform cases use the random partition in parallel. The band case uses viscosity 1e12 above y = 0.8 and the band layout. "Fresh" is the speed from a new solver at the second viscosity (0.00384 at 1; 3.84e-13 at 1e10).

sequence on one solver np this branch, second (or third) solve development
1e12 → 1 1, 2 converges, 1 iteration, speed 0.00384 = fresh stuck: SUBPC_ERROR at iteration 0, u = 0
1 → 1e12 → 1 1, 2 1e12 refused; then converges, 0.00384 = fresh stuck after the 1e12 solve
1e12 → 1e10 1, 2 converges, 3.84e-13 = fresh stuck
band 1e12 → uniform 1 1, 4 (band) converges, 0.00384 converges (the viscosity expression changed form, which already forced a rebuild)
zero-pivot tolerance 1e3, viscosity 1 → 1 1 the forced setup runs, and the user's tolerance fails again: warning both times warning both times

Same flag on every rank: the flag is set from the KSP's converged reason, which is global. At np 2, 3 and 4, every rank reported the same flag before and after each solve.

Cost:

  • The forced setup runs only on the solve after a failed PC setup. In 1 → 1 → 1 at np 1 and 2 the flag was never set, and the solve times matched development (about 0.15 s and 0.13 s for the repeat solves).
  • The first solve after a failure took 0.17 s serial and 0.22 s at np 2.
  • The solve logs below show no change in iteration counts on normal solves.

Lows 3 and 4

  • "Entries near the tolerance" means smallest <= 100 * 2.22e-14, using the global absolute minimum of the pressure PC's diagonal. It applies to all three failed reasons the code counts: structural zero pivot, numeric zero pivot and SUBPC_ERROR. If the minimum is larger, the method returns and the diverged-solve warning stands.
  • A non-zero-pivot sub-PC failure. Setting the sub-PC's zero-pivot tolerance to 1e3 at viscosity 1 makes the factorisation fail on a healthy matrix (smallest diagonal 1.2e-3). It fails with SUBPC_ERROR on every rank. It now gets the warning, not the refusal, at np 1 and 2. We could not make an out-of-memory or other non-pivot factor failure. This tolerance case is the nearest we could build.
  • Other PC failures: the velocity failure under zeropivot 0 (above) keeps the warning, with "the last iterate".
  • "Initial guess": every refusal we saw was at iteration 0 and said "the initial guess". Three runs were nonlinear (shear thickening, 1 + eta E_II, with a basic line search, eta = 1e14, 1e18 and 1e22). In those, the default Picard warm-up ran first, and the Newton solve then failed at iteration 0. The fields hold the warm-up's iterate (speed 0.00384, not 0). That iterate is the Newton solve's initial guess, so the text is defensible. With the warm-up off (picard=-1), these solves stop with DIVERGED_DTOL at iteration 1 before any pivot failure.

What held at d48b37d still holds

check this branch development
uniform 1e12, random partition, np 2, 3, 4 refused on all ranks (2/2, 3/3, 4/4) —
band 1e12, np 2, 3, 4; only the top rank's block has the tiny pivots at np 4 refused on all ranks warning
empty band np 3, 1e12 above y = 0.6, and uniform 3 of 3 —
boundary sweep 1e10, 3e10, 5e10, 5.5e10, 6e10, 1e11, 1e12, 1e21 converges up to 5e10, same speed; refused from 5.5e10 converges up to 5e10; diverges with a warning from 5.5e10
DIVERGED_MAX_IT (strain-rate viscosity, snes_max_it=2) warning, not raised same
DIVERGED_LINE_SEARCH (shear thickening 1e18) warning, not raised same
DIVERGED_LINEAR_SOLVE from a capped KSP (1e9 band, ksp_max_it=1) warning, not raised same
strain-rate viscosity capped at 1e12 converges, 4 iterations, same speed same
units model, 1e21 Pa s with reference quantities, np 1 and 2 converges, 1 iteration, lid speed 1.0 same
units model without reference quantities refused warning

At d48b37d, ksp_max_it=1 at viscosity 1 gave DIVERGED_LINEAR_SOLVE. On the new merge base it converges on both builds, so the capped-KSP case used the 1e9 band instead.

The PR's test (5 tests now):

run this branch development
np 1 5 passed 4 failed, 1 passed (the 1e10 test)
np 2 5 passed 4 failed, 1 passed
np 3, np 4 5 passed —
np 4 band, np 3 empty band 5 passed —

Standard Stokes files:

  • Serial: the same 12 files as before. 77 passed on both builds. 72 solves match in SNES and KSP counts and are bitwise equal.
  • np 2: test_0780, test_0786 rank without cells, test_1167 and test_1200. 10 passed and 2 skipped on both builds. 16 solves are bitwise equal, with the same counts.
  • np 3: the same four files. 11 passed and 1 skipped on both builds. 17 solves, with the same counts. One 3D test_1200 solve differs by 1.8e-13 relative. A second development run differs from the first by 2.2e-13 at the same solve, so this is run-to-run round-off.

The diff (1a1d537..3f20212, excluding the development merge)

  • Every branch before a collective is decided on global values. These are the SNES and KSP converged reasons, the MAX-reduced failed flag, and the MIN-reduced "found the pressure block". After that, diagonal.min() and max() are collective, so smallest and largest are the same on every rank. The early return, the scale-or-contrast branch and the iteration count are therefore the same everywhere.
  • The rebuild flag is set before any early return, so a failure that only warns also rebuilds on the next solve. That is right, since the stuck state is not specific to zero pivots. It is consumed in SNES_Stokes_SaddlePt.solve after the homotopy branch, so a homotopy march's first inner solve takes it.
  • Only Stokes solvers set or read the flag. Other solver families are unchanged, as before.

New findings

  1. Medium: A moderate contrast at a high base viscosity is called a contrast, and the message rules out the remedy that works. The code uses the reference-quantities text only when even the largest diagonal entry is within 100 times the tolerance. Otherwise it uses the contrast text. Viscosity 1e9 below y = 0.8 and 1e12 above is refused with "The entries span a factor of 4.4e+03: a viscosity contrast, which reference quantities cannot remove". The same model divided by 1e9 (1 and 1e3) solves in 1 iteration on both builds, so reference quantities would fix it. The same rule would also call a uniform high viscosity on a strongly graded mesh a contrast, since the diagonal scales with element area. We did not run that case.

    Suggestion: decide on the span, not on the largest entry. If largest / smallest is small enough that scaling the largest to order one lifts the smallest well clear of the tolerance, name reference quantities. If not, name the contrast. Or name both when the largest entry is above the bound. A 1e6 contrast solves by default, so the cut can sit well above 1e3.

  2. Low: The test file's module docstring still describes only the old behaviour. It still says "From a viscosity of about 1e11" and gives reference quantities as the remedy. The new tests cover the contrast message and the rebuild, but the docstring does not mention them.

What was run and not run

Run:

  • the message at 5.5e10, 1e11, 1e12 and 1e21; on the finer mesh; for the 1e12, 1e9 and 1e6 band contrasts; and for the 1e9 / 1e12 band;
  • the zero-pivot and velocity-LU options for the 1e12 band;
  • solves on the same solver after a failure, at np 1, 2 and 4, on both builds;
  • a forced sub-PC failure on a healthy matrix, at np 1 and 2;
  • nonlinear cases with and without the Picard warm-up;
  • the refusal at np 2, 3 and 4 with random, band and empty-band partitions;
  • the boundary sweep, the other diverged reasons and the units model, on both builds;
  • the PR test at np 1 to 4, band and empty band; development at np 1 and 2;
  • 12 serial and 4 parallel Stokes files at np 2 and 3, with solve logs compared, plus a second development run at np 3.

Not run:

  • the author's 389-test regression run. We did not know which set it is. The changed path is covered by the Stokes files above;
  • a pressure-pivot failure after iteration 0. We could not construct one: without the Picard warm-up the nonlinear cases stopped with DIVERGED_DTOL first;
  • an out-of-memory or other non-pivot factor failure;
  • uniform viscosity on a strongly graded mesh;
  • 3D meshes for the refusal itself.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

An absolute bound on the largest pressure diagonal called a 1e9-to-1e12
model a contrast reference quantities cannot remove, though divided by 1e9
it solves in one iteration: the commonest real case (raw SI, 1e19 to 1e24
Pa s) got the wrong advice. The span decides now: within 1e8, which one
rescaling brings into range (measured: a centred contrast of 1e8 solves by
default, 1e9 does not), the model is too viscous as a whole and the remedy
is reference quantities; beyond it, the contrast. The test docstring no
longer names a fixed viscosity threshold.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

At 2e3fa2d: scale or contrast is now decided by the span of the pressure block's diagonal, not by an absolute bound on its largest entry.

  • The bound, measured. On the unit box (cell size 0.1, P2/P1) with the viscosity centred on one, a contrast of 1e8 solves by default in 2 to 5 Newton iterations (diagonal span 4.4e8), and 1e9 does not. That failure is in the velocity multigrid, not a zero pivot. So _RESCALABLE_SPAN = 1e8.
    • Within the bound: one rescaling brings the model into range, and the message names reference quantities.
    • Beyond it: the contrast is the problem.
  • The case you raised. A model with viscosity 1e9 below y = 0.8 and 1e12 above (span about 4e3) now gets the reference-quantities advice. A new test checks that, and that the same model divided by 1e9 solves. A raw-SI geodynamic range of 1e19 to 1e24 Pa s is a contrast of 1e5, so it gets the scale advice too.
  • Unchanged: the uniform-1e12 case still gets the scale advice, and viscosity 1 against 1e12 still gets the contrast advice.
  • Docstring: the test's docstring no longer names a fixed threshold.
  • Runs: test_1059 passes at np 1, 2 and 4, and at np 3 with an empty rank (6 passed each).

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict on 2e3fa2d: ready to merge on green from this review.

  • Both earlier items are fixed. The scale-or-contrast choice now uses the span of the diagonal. The 1e9 / 1e12 band now gets the reference-quantities advice, and that advice works.
  • The verdict is the same on every rank. The span comes from the global minimum and maximum. Every rank raised the same message at np 2, 3 and 4, with band, random and empty-band partitions.
  • Nothing else changed. The boundary, the stuck-solver recovery and the serial Stokes solves are as before.
  • One new low finding, not blocking. The cut was measured on one coarse box. On a finer mesh, and with a different choice of reference viscosity, it moves by about a factor of ten either way. The message states its verdict more firmly than that supports.

Earlier items: then and now

# at 3f20212 at 2e3fa2d
1 (Medium) Viscosity 1e9 below y = 0.8 and 1e12 above (span 4.4e3) was called "a viscosity contrast, which reference quantities cannot remove". The same model divided by 1e9 solves in 1 iteration. Fixed. The message now reads "span a factor of 4.4e+03, which one rescaling brings into range ... Give the model reference quantities". The same model divided by 1e9 (1 below, 1e3 above) converges in 1 iteration. The new test checks both and fails on the 3f20212 build at np 1 and 2.
2 (Low) The test file's docstring still said "about 1e11". Fixed. It now says "from about 5.5e10, a limit that also depends on the element size". It also describes both remedies.

The message (serial; unit box, P2/P1, cellSize=0.1 unless noted)

"Band" means one viscosity below y = 0.8 and another above. "Rescaled" is the same model divided by a constant.

case span printed remedy named rescaled model, default options
uniform 5e10 — (converges, 1 iteration) — —
uniform 5.5e10, 1e11, 1e12, 1e21 4.4 reference quantities viscosity 1 converges
uniform 1e12, cellSize=0.03 4.5 reference quantities —
uniform 1e12, mesh graded y → y³ 1.2e3 reference quantities —
band 1 / 1e12 4.4e12 contrast —
band 1e9 / 1e12 4.4e3 reference quantities 1 / 1e3: converges, 1 iteration
band 1e9 / 1e12, cellSize=0.03 4.5e3 reference quantities 1 / 1e3: converges, 1 iteration
band 1e9 / 1e12, graded y → y³ 1.1e3 reference quantities 1 / 1e3: converges, 1 iteration
band 1e5 / 1e12 4.4e7 reference quantities 1 / 1e7: converges, 1 iteration
band 1e4 / 1e12 4.4e8 contrast 1 / 1e8: converges, 3 SNES / 5 KSP iterations (new finding 1)
band 1e3 / 1e12 4.4e9 contrast 1 / 1e9: converges, 2 SNES / 4 KSP iterations (new finding 1)
band 1e5 / 1e12, cellSize=0.03 4.5e7 reference quantities 1 / 1e7: not finished in 900 s; 3.2e-4 / 3.2e3: converges, 3 SNES iterations, 79 s (new finding 1)

Mesh dependence: the span is the viscosity contrast times the spread of the element areas. On a uniform mesh that spread is about 4.4, whether cellSize is 0.1 or 0.03. The y → y³ grading raises it to about 1.2e3. That is still five orders below the cut, so no realistic grading changes the verdict for a uniform viscosity.

The author's bound (a contrast centred on one, on the coarse box):

contrast viscosities outcome
1e7 3.2e-4 / 3.2e3 converges, 3 SNES / 6 KSP iterations
1e8 1e-4 / 1e4 converges, 5 SNES / 9 KSP iterations, 10 s
1e9 3.2e-5 / 3.2e4 diverged with a warning, not refused. The velocity sub-solve ends in NaN/Inf; the pressure PC has no failure.
1e10 1e-5 / 1e5 the same, at iteration 0

That matches the author's account: the failure is in the velocity multigrid, with no zero pivot. On the finer mesh (0.03), the 1e8 centred contrast did not finish within 300 s; the velocity multigrid was still iterating.

Runs

  • Builds:

    • This branch: a fresh build of 2e3fa2d in a new worktree. All 12 installed compiled modules are dated after the build started, and generic_solvers._RESCALABLE_SPAN is 1e8.
    • Previous head: the existing 3f20212 build, used for the "new test fails there" check.
    • Development: the existing 6fc3fc5 build.
    • Every run printed underworld3.__file__, and each run used the intended build.
  • Same verdict on every rank: the probe gathers every rank's message.

    case layout ranks that raised distinct messages remedy
    band 1e9 / 1e12 band, np 2, 3, 4 all 1 reference quantities
    band 1 / 1e12 band, np 2, 3, 4 all 1 contrast
    band 1e9 / 1e12 at y = 0.6 empty band, np 3 3 of 3 1 reference quantities
    band 1 / 1e12 at y = 0.6 empty band, np 3 3 of 3 — contrast
    uniform 1e12 empty band, np 3 3 of 3 — reference quantities
    band 1e9 / 1e12 random, np 3 (one rank owns no pressure dofs) 3 of 3 — reference quantities

    In the band layout, only the top rank holds the 1e-15 pivots, and the bottom rank's local minimum is 1e-12 or 1e-3. Every rank still gives the same verdict.

  • The PR's test (6 tests now):

    build np 1 np 2 np 3 np 4 np 4 band np 3 empty band
    2e3fa2d 6 passed 6 passed 6 passed 6 passed 6 passed 6 passed
    3f20212 5 passed, 1 failed 5 passed, 1 failed — — — —

    On 3f20212 the failing test is the new moderate-contrast test, as expected.

  • Unchanged behaviour:

    • Boundary: uniform 5e10 converges in 1 iteration; 5.5e10 is refused.
    • Stuck-solver recovery: 1e12 then 1 on the same solver: refused, then converges in 1 iteration at speed 0.00384, the fresh-solver value. We checked this at np 1 and at np 2 with a random partition.
    • Repeat solves: 1 → 1 → 1 runs at 0.15 s per repeat solve, as before.
  • Serial Stokes solve logs, same solve-logging plugin as before, development vs this branch. Both builds passed 39 tests, and every solve was bitwise equal:

    file solves SNES iterations, development / this branch KSP iterations, development / this branch
    test_0818_stokes_nd 8 8 / 8 8 / 8
    test_1010_stokesCart 6 6 / 6 6 / 6
    test_1013_stokes_fields_by_solver_number 15 12 / 12 24 / 24
    test_1050_VEstokesCart 5 6 / 6 6 / 6
  • The diff:

    • Code: one changed comparison, largest <= _RESCALABLE_SPAN * smallest, plus the new text. smallest and largest are still Vec.min() / Vec.max() on the global diagonal, which are collective. So no branch is rank-local.
    • Test: one new test, which allgathers the messages and asserts on every rank.
  • Resources: every run used four cores, while other jobs ran on the machine. Every parallel run was under the MPI supervisor with an outer timeout of 300 s. The one exception was a 900 s serial run, which timed out (see finding 1).

Logs kept by the reviewer.

New findings

  1. Low: The cut was measured on one coarse box with the range centred on one. The message states the verdict more firmly than that supports.
    • Calibration: _RESCALABLE_SPAN = 1e8 comes from contrasts centred on one, on cellSize=0.1.
    • On that box, "contrast" is given to models that rescale. At 1e4 / 1e12 and 1e3 / 1e12, the message says reference quantities "cannot remove" the contrast. Yet the same models divided by the low viscosity (1 / 1e8 and 1 / 1e9) converge by default.
    • On a finer mesh, "reference quantities" is given to a model whose obvious rescaling does not solve. On cellSize=0.03, 1e5 / 1e12 gets the reference-quantities advice (span 4.5e7). Dividing by the low viscosity (1 / 1e7) had not finished after 900 s; the velocity multigrid was still iterating. Centring the range (3.2e-4 / 3.2e3) converged in 3 iterations, but took 79 s.
    • Not blocking. Both verdicts are reasonable first advice, and the far cases (uniform; 1 / 1e12) are clear.
    • Suggestions (wording only):
      • In the contrast text, say "probably wider than one rescaling brings into range" instead of "cannot remove".
      • In the scale text, say to choose the reference viscosity near the middle of the range (the geometric mean of the low and high viscosities), not at the low end.
      • The code comment could note that the measured limit also depends on the mesh.

Not run

  • 3D meshes;
  • the slow fine-mesh cases on the development build. They are healthy solves that this change does not touch, and the solve logs show no change on healthy solves;
  • the parallel Stokes files. They were compared at np 2 and 3 at 3f20212, and this commit changes only the text chosen after a refusal;
  • the author's regression set.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 44332b4 into development Nov 20, 2026
10 checks passed
lmoresi added a commit that referenced this pull request Nov 20, 2026
The conflict in petsc_generic_snes_solvers.pyx is two methods added at the
same place: this branch's _warn_on_capped_rotated_sub_solves (#625) and
#1255's _refuse_unfactorable_pressure_preconditioner (#1059). Both are
kept, with their call sites (the rotated solve's sub_capped warning, and
the post-solve refusal with its forced setup after a PC failure).

Underworld development team with AI support from Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants