Repository navigation
#901: the multigrid coarse solve is redundant LU with a zero-pivot shift on every route; no SVD - #947
Conversation
…ull modes A closed free-slip wall leaves rigid rotations: one on an annulus, and three on a spherical shell with the radial normal. The Galerkin-coarsened rotated velocity block inherits them. The coarse level is then a dense SVD of the gathered matrix, whose factorisation took 64 s at np 1 and 102 s at np 4 on a 614-cell shell bottom level. test_1111 (annulus and shell, serial) and test_1112 (annulus, np 2) ask for the null-mode coarse solve, recorded as coarse_solve, and for the SVD path's answer at the measured iterations. On development both fail on the record (KeyError: 'coarse_solve'); their earlier assertions (convergence, custom FMG, the mode count) pass. Underworld development team with AI support from Claude Code
… factors with PETSc's LU When the rotated problem has verified rigid rotations, its coarse level was a dense SVD of the gathered matrix. That costs O(n^3) on every rank, and the cost rose with the rank count. The modes are known (the rotated null space), so the coarse solve now uses them. custom_mg.NullModeCoarseSolve, a python PC on the bottom level, does three things: - it restricts the modes there by least squares, (P^T P) m_c = P^T m_f; - it pins one unknown per mode, chosen by a pivoted QR of the gathered modes; - it projects the modes out of the right-hand side and the solution, and factors the pinned system with PETSc's redundant LU. A rigid rotation is a left null vector too, for any rheology, so the projection holds for Newton tangents. The choice is the bundle's new "null_modes" variant, selected by the presence of verified modes, with no user option. Both rotated routes (saddle and vector) take it. SVD stays as the fallback for modes counted but not extractable. The solve records coarse_solve in _rotated_freeslip_info. Measured: probe_coarse_depth.py in ~/+Simulations/fac_892/coarse_901. | case, np 4 | coarse solve | vel / Schur its | coarse setup + solve | wall | v_rms | |---|---|---|---|---|---| | annulus, 600 bottom cells | svd | 4 / 9 | 69.3 + 73.1 s | 144 s | 4.7831843385 | | | null modes | 4 / 9 | 0.004 + 0.023 s | 0.76 s | 4.7831843385 | | shell, 614 bottom cells, radial normal | svd | 18 / 23 | 101.6 + 105.8 s | 216 s | 1.7726841207 | | | null modes | 19 / 23 | 0.007 + 1.24 s | 7.1 s | 1.7726841152 | At 144 bottom cells: 0.016 s against 1.67 s, with identical iterations and answer. test_1111 and test_1112 pass. test_1021's gate test now expects the null-mode arm. All 227 serial tests and 18 tests/parallel tests at np 2 that touch the rotated path or _configure_pcmg pass. The rotated free-slip, solvers, fault-split multigrid and multigrid preconditioning docs describe the new coarse solve. Underworld development team with AI support from Claude Code
No glob in scripts/test.sh matched tests/test_1111_*, so check_test_coverage.py would fail the serial job and the test would never run. It joins batch 4 beside test_1110 and test_1120. All 383 files are reachable. Underworld development team with AI support from Claude Code
The rotated route sets up the velocity multigrid itself, then re-assembles the rotated coarse levels' operators to turn off inode SOR. Level 0 was in that loop, so the coarse operator's state moved and the coarse PC was set up a second time at its first application inside ksp.solve. An eager coarse solve paid its factorisation twice per solve: the dense SVD did. PETSc's redundant LU factors lazily, which hid the doubling. test_1113 puts a counting python PC, delegating to redundant LU, on the coarse level and asks for one setup per linear solve. On development's rotated path (the #902 build) it counts 2. It joins CI batch 4. Underworld development team with AI support from Claude Code
…solve The inode-SOR loop over the rotated coarse levels now starts at level 1. Level 0 is the coarse direct solve: it is not smoothed by SOR, and its direct solve factors its own gathered copy. Re-assembling its operator only moved its state, which forced a second setup at the first application. test_1113 passes: 1 setup, against 2 before. The SVD timings quoted for #901 paid the factorisation twice. The shell's "207 s" of SVD coarse work at np 4 is about 105 s with one factorisation (102 s to factor). The docs and the bundle comment now say so. The per- factorisation figures (64 s at np 1, 102 s at np 4) were one factorisation and stand. Underworld development team with AI support from Claude Code
Louis's direction: keep GAMG on the coarse level available for one case only, a coarsest mesh too large for every rank to factor a gathered copy. It is never a default and never automatic. set_custom_fmg(..., coarse_solve="gamg") asks for it, on the rotated route and on the standard (Stokes velocity block and single-field) route. custom_mg.GamgCoarseSolve, a python PC on the bottom level: - runs FGMRES to 1e-2 with GAMG on the Galerkin coarse operator, with a redundant LU and a nonzero shift at GAMG's own base; - attaches the restricted rigid-body modes as the coarse operator's near-null space: the translations and rotations, carried into the wall frame with the normal rows zeroed on the rotated saddle route, and Cartesian on the standard route; - attaches the verified rotations, where they exist, as an exact null space. The vector route and single-field solvers use GAMG's own near-null space. It is the bundle's "gamg" variant (the same python-PC key as "null_modes"). Measured in ~/+Simulations/fac_892/coarse_901/README.md (600-cell bottom levels, np 4): the answer and outer iterations are a gathered LU's, at 4-10x its coarse cost. That cost is GAMG's own 15 to 40 cycles per coarse solve; its base is at most 6% of it. test_1114 (np 2 and 4, rotated annulus and standard no-slip box) asserts: the live coarse PC is GamgCoarseSolve, the answer is the gathered LU's to 1e-8, and the iterations stay within the same solve's with the automatic coarse solve. The multigrid guide says when to use it and what it costs. Also from the review: _restrict_null_modes destroys its intermediate Vecs (they leaked at np >= 2), and the bundle docstring no longer claims every coarse variant sets the same keys. All 463 serial tests (49 files) and 40 tests/parallel tests at np 2 (15 files) that touch custom-P multigrid or the rotated path pass. Underworld development team with AI support from Claude Code
…t (Louis's ruling, A-prime) The review found that plain redundant LU, with no null-mode handling, gives the SVD's answer at its iteration counts on every fixture: - the annulus with 40 to 600 bottom cells; - the shell; - the test_1021 gate fixture; - the thin sheet; - a faulted annulus with rotated coarse levels, at np 1 and 4. The inherited rotations leave the coarse operator near-singular, not singular (lambda_min/lambda_max 2e-5 to 2e-8). Louis ruled for A-prime: - NullModeCoarseSolve, the "null_modes" bundle variant and the gate on the verified-mode count are gone. Both rotated routes use the shared coarse="redundant", and add mg_coarse_redundant_pc_factor_shift_type nonzero, which acts only on an exact zero pivot. The key is set under the velocity PC's prefix before its set-up, because PCREDUNDANT reads its LU's options at the coarse set-up and factors at the first application. It is dropped afterwards with the bundle's keys. - The GAMG coarse option, the double-setup fix and test_1113 stay. GAMG still takes the verified rotations as its exact null space. test_1111 (renamed _shifted_lu): - The annulus and the shell record the redundant coarse solve, the SVD path's answer and the measured iterations. - #306's case, a coarse level that is the fine mesh itself, checks the fixture (the restricted rotation is a null vector of the coarse operator, ||Aq|| <= 1e-10 ||A||), and that the solve gives the SVD's answer to 1e-7. With the shift disabled it fails: 5.1e-7 off. Since the double-setup fix stopped re-assembling level 0, the coarse operator keeps its inodes, and plain LU does not stop at the zero pivot there. It converges, less accurately. With the shift the answer is 7.5e-9 off. test_1112 (renamed _shifted_lu) and test_1021 assert the redundant coarse solve. The stale "svd" text is rewritten in rotated_bc, multigrid_options, test_1021, the rotated free-slip, solvers and fault-split multigrid docs, and the multigrid guide. All 464 serial tests (49 files) and 40 tests/parallel tests at np 2 (15 files) that touch custom-P multigrid or the rotated path pass. Underworld development team with AI support from Claude Code
…st-gated anchors From the adversarial review of A-prime (b704140): - The zero-pivot shift is set on the live coarse PC after the multigrid set-up (PCREDUNDANT passes it to its inner LU, which factors at the first application). There is no options key left to leak on an error path. GAMG's base keys are dropped in a finally. - test_1111, test_1112 and test_1021 read "[NONZERO]" off the live coarse KSP's view. Their docstrings now state what the forced-singular case shows. After the double-setup fix, plain LU no longer stops at that pivot: it converges 5-6e-7 off the SVD answer, inside the solver tolerance, so the shift is checked directly. - The answers and iteration counts recorded on gmsh meshes (test_1111, test_1112, test_1114) are gated on the mesh's fingerprint (global cells, volume), so a host whose gmsh triangulates differently skips them. The live shift, the coarse-solve record and the exact null-vector check hold on any host. - test_1114 asserts recorded bounds and answers instead of comparing GAMG with the automatic run, and drops a tautology. - The solver method set_custom_fmg takes coarse_solve. - Level 0 keeps the inode kernel at every np. At np 1 the LU factors the level operator itself, which lost its inodes before; at np > 1 it factors a gathered copy, which always had them. The one measured case that moves is the #906 default-normal shell at np 1 (83 -> 112 velocity iterations); the sound fixtures are unchanged. Setting the flag without re-assembly does not switch the kernel, and re-assembling brings the second setup back. The comment and test_1113 say so. - Figures corrected: - lambda_min/lambda_max is 2.0e-5 to 2.4e-8 on the annulus and 2.8e-4 on the shell; on the faulted annulus no ratio was measured; - GAMG costs 1.7x (annulus) to 4x (shell) a gathered LU at the shipped rtol 1e-2, and 10x at 1e-6; - the docs name the routes that give GAMG the rigid-body near-null space. - describe() names the GAMG coarse solve. registered_coarse_solve is private. The unused SVD bundle variant is gone. - One helper owns the velocity save and restore, writing .array; the rotation fields are built in one place. The modes are bit-identical to the .data construction, and the velocity is restored exactly, at np 1 and 2 in 2-D and 3-D. All 464 serial tests (49 files) and 40 tests/parallel tests at np 2 (15 files) that touch custom-P multigrid or the rotated path pass. test_1112 and test_1114 also pass at np 4. Underworld development team with AI support from Claude Code
#901) Louis, 2026-11-05: make everything simpler, fewer special cases, no slow SVD; on the singular case, keep the shift and have no SVD path. The advanced multigrid guide, the solvers, rotated free-slip and split-level subsystem docs now give one rule: every route factors the coarse level with the shared redundant LU and a nonzero factor shift, which acts only on a zero pivot, and a null space is fixed on the fine operator, never by the coarse solve. The rotated route's coarse solve is no longer described as a difference; that it sets the shift on the live PC is stated as an implementation detail. The SVD override example is replaced by taking the shift off, the diagnostic for a genuinely singular level, and SVD is mentioned only as something a user may set by hand. The SVD history and its timings move to the changelog. Depends on the shared bundle carrying the shift on the standard route too (multigrid_options.geometric_mg_bundle's redundant variant); on this branch the shift is set on the rotated route only. Underworld development team with AI support from Claude Code
… every route The shared bundle's redundant variant set plain LU, so only the rotated route (which sets the shift on its live coarse PC) carried the NONZERO factor shift. The bundle now sets mg_coarse_redundant_pc_factor_shift_type = nonzero; the rotated route keeps setting it on the live PC, since it deletes its keys before that PC reads them. - test_1021 reads the shift off the live coarse KSP on the native, standard custom-P and rotated routes and asserts all three carry it. - test_1014 checks the key in the standard route's default bundle. - On a nonsingular coarse level the shift changes nothing: native and standard custom-P FMG on the annulus give bitwise-identical velocity and pressure and the same iterations with and without it. - The advanced guide no longer offers taking the shift off as a test for a singular level: test_1111's singular level factored without it and converged 5e-7 off. The admission tolerance is stated as the code's relative 1e-8. Underworld development team with AI support from Claude Code
Conflicts, each resolved by keeping both sides: - scripts/test.sh: development's #907/#918/#920/#936 batch lines beside this branch's test_1111/test_1113. - custom_mg.py: the standard velocity route takes development's FAC key return and smoother set-up (#892) with this branch's coarse variant and GAMG near-null space; set_custom_fmg's docstring carries development's fac_zone (#921) and verbose (#918) text and this branch's coarse_solve. - rotated_bc.py: both rotated installs take development's level_patch_rows, _set_up_fac_smoothers and patch summary with this branch's null modes and live zero-pivot shift. Underworld development team with AI support from Claude Code
geometric_mg_bundle(coarse="svd") raised the generic "coarse must be one of
('redundant', 'gamg')". It now says the variant was removed (#901) and names the
replacement: the default coarse="redundant", redundant LU with a zero-pivot
shift. A dense SVD can still be set through the PETSc option.
- test_1021 pins the error, and checks that a script setting
fieldsplit_velocity_mg_coarse_pc_type=svd itself still gets an SVD on the
standard route's live coarse PC.
- The CHANGELOG entry says the shift now applies on the native and standard
custom-P routes too (bitwise-identical v and p on a nonsingular level), that
the svd variant is removed rather than deprecated, and that scripts setting
the PETSc option are unaffected.
Underworld development team with AI support from Claude Code
…on the error path, exact shift wording - The rotated route's live-PC writer of the zero-pivot shift (_shift_coarse_zero_pivot) goes. PCSetUp_Redundant reads the bundle's shift key inside vel_pc.setUp(), before the keys are dropped, so the bundle is the only writer on every route (round 3 probe: with the helper a no-op the rotated coarse LU still shows [NONZERO]). The "deletes its keys before the coarse PC reads them" reason is corrected wherever it was given. - A rotated set-up that raised after the multigrid set-up left its bundle and FAC keys in the global options database (11 on test_1021's fixture). Both rotated installs now drop every key under their per-solve prefix in the finally (_drop_options_under). test_1021 pins it, and fails with the sweep disabled. - The shift is described as PETSc applies it: NONZERO acts on a pivot below the zero-pivot tolerance (relative to the row's off-diagonals) and refactors with a small diagonal shift. PETSc's own default coarse LU carries INBLOCKS (PCMGSetLevels_MG, not PCSetUp_MG); development's native and standard routes kept it at np > 1 and had none at np 1. The guide, solvers.md, rotated-freeslip.md, the CHANGELOG and the docstrings say so. - The guide no longer says the coarse solve "cannot change the answer" (it is set to the solver's tolerance) and states the admission test's unassembled operator case; the CHANGELOG no longer says "never singular". - The coarse="svd" error says the PETSc-option SVD works on the standard path only; the user-svd test's docstring says what it guards (key ownership on the custom-P standard route). Underworld development team with AI support from Claude Code
…es; the bitwise identity was measured, not asserted Underworld development team with AI support from Claude Code
…d LU (#901) test_1114[standard] failed at np 2 and 4 in CI's environment on kaiju: the GAMG-coarse v_rms was 1.24e-8 and 1.53e-8 from the gathered-LU value recorded on another host, against a 1e-8 bound, at solver tolerance 1e-6. The gathered LU itself moves that much with the partition and the host (7.9e-9 at np 1 on wombat), while GAMG and LU in one run agree to 4.5e-11 or better (np 1, 2, 4). The test now solves the gathered LU on the same mesh and partition and asserts GAMG matches it to 1e-9, on any mesh. The recorded answer stays as a baseline at 1e-7, still gated on the mesh fingerprint. Underworld development team with AI support from Claude Code
…t folds it (#946) At cell size 0.5, gmsh can put all four vertices of a coarse cell on the shell's inner wall. Refinement snaps the new edge midpoints outward onto the sphere, so that cell's children fold inside out (#946). - Wombat's mesh at 0.5 had 3 folded cells and converged in 18 velocity iterations. - Kaiju's mesh, the same gmsh on Linux, ran every velocity sub-solve to the 200 cap. test_1111[shell] did not finish in an hour. - A gmsh seed that folds the same way on wombat fails with the SVD coarse solve and with the default normal too, so the coarse solve and the normal are not the cause. At 0.3 the wombat shell has no coarse cell on a wall and no folded cell. It solves in 5 velocity / 17 Schur iterations. The recorded answer there is the shifted LU's; on the old shell, LU and SVD agreed to 1e-10. A shell that refinement folded, by the signed volume in DMPlex order (the MMPDE fold guard's convention), now skips the case instead of running it. Underworld development team with AI support from Claude Code
test_1114: - The same-run GAMG-against-LU bound is 1e-8, not 1e-9. The two solves agreed to 4.5e-11 because both stop well past their tolerance. A Schur solve that stops one iteration earlier moves them 2.4e-9 apart (rotated route, tolerance 3e-6), with identical counts. - The LU run's mesh is checked against the GAMG run's by fingerprint, so a different mesh fails as that rather than as a v_rms miss. test_1111: - The fold gate uses the library's `graph._tet_cells` and `_owned_cell_mask`. A rank with no cells counts zero instead of raising, and overlap cells are not counted twice. - A watchdog: a solve that does not converge stays inside one KSPSolve, which holds the GIL, so pytest-timeout cannot stop it. faulthandler's watchdog does not need the GIL. After 10 minutes it prints every thread's stack to the real stderr and exits; the captured stderr would be lost on exit. - The shell's recorded answer is the SVD path's too. The dense SVD coarse solve, set by hand on the 0.3 shell, gave the shifted LU's v_rms and iterations, in 604 s against 17 s. Underworld development team with AI support from Claude Code
Adversarial review, round 1 (bugfix/rotated-fmg-coarse-solve at 0502a9f)Reviewed by a separate agent against Findings and what was done
Also on the branch at Louis's request: GAMG as the coarse solve, only when asked for ( |
Adversarial review, round 2 (bugfix/rotated-fmg-coarse-solve at b704140, A-prime)Reviewed by a separate agent, at np <= 4. Findings and what was done
Issue verdicts
Checked and sound
|
Adversarial review, round 3Covers 42e5565..9aa89dc: the coarse-solve docs, the shift in the shared bundle (4af4473), the merge of development (836f3e1), and the svd-removal error (9aa89dc). All runs were serial, np 1. The fixes are in af9d3c3. Findings, and what was done
Attacks that failed
Issues in this territory
Re-check of af9d3c3, serial
Parallel checks (kaiju)
Underworld development team with AI support from Claude Code |
Adversarial review, round 4: bca8434..4babb3a (test-only)Round 4 covers the two commits after round 3, both test-only:
The fixes are in e15f5fa. Findings
Attacks that failed
Issue verdicts
Underworld development team with AI support from Claude Code |
Underworld development team with AI support from Claude Code
… a missing label moves nothing (underworldcode#903) Parked work in progress: the serial tests pass, and the parallel test, the PR and the review are still to come (see the end). gmsh meshes a sphere in a parameter plane. Near a pole it can join four neighbouring wall nodes along the long diagonal, and a structured surface splits every quadrilateral the same way, so the wall creases toward the centre. On an inner or internal wall, the pocket under the crease is meshed as one cell with all four vertices on the sphere. The refinement callback then snaps the crease midpoint outward past the unlabelled midpoint of the other diagonal and folds the children. - meshing/_sphere_surface.py: `_flip_creased_sphere_edges` runs Lawson flips to the convex hull on every gmsh surface whose nodes lie on a sphere about the centre, between generate(2) and generate(3). It is called by SphericalShell, SphericalShellInternalBoundary, SegmentofSphere, CubedSphere, the segmented shell and ball, and both regional boxes. - Mesh._build_refined_hierarchy applies every refinement callback through `_apply_refinement_callback`. Of each cell the callback inverted, the vertex it moved furthest goes back where refinement placed it, until none is inverted, with a warning. Vertex flags are shared over the coordinate DM, so every copy agrees. - petsc_dm_find_labeled_points_local returns an empty array for a missing label instead of [0] (underworldcode#903). A refined ball had a NaN vertex. Tests: tests/test_0001_sphere_refinement_folds.py has 7 cases. 6 fail on development 1f87430 (creases, folded cells, no warning, NaN) and all pass here. tests/parallel/test_0001_..._parallel.py has not run yet (np 2 and 4 go to kaiju). Left to do: - Merge origin/development (underworldcode#947), and re-record test_1111's shell, whose mesh changes with the flips. - Run the 24 test files that build spherical meshes, on kaiju. - Measure the guard's cost on large meshes. - The segmented shell and ball still warn, because their Upper (and Lower) labels hold vertices off the wall: Upper reaches r 0.297 on the ball and r 0.72 on the shell. That is a labelling bug the guard now exposes. - CubedSphere(numElements=3) holds one vertex back: a crease on a patch-boundary curve, which a per-surface flip cannot reach. - TODO(BUG) markers: the internal-boundary shell's radius tolerance, and its unsnapped Internal surface. Underworld development team with AI support from Claude Code
The rotated free-slip route solved its multigrid coarse level with a dense SVD whenever the problem left rigid rotations free (#306). The SVD is O(n^3) on every rank and got slower as ranks were added: one factorisation of a 614-cell spherical-shell bottom level took 64 s at np 1 and 102 s at np 4. With LU, the whole Stokes solve takes 7 s at np 4. This replaces it with one rule on every route (Louis's ruling, 2026-11-05): redundant LU with a nonzero factor shift, and no SVD path.
Why LU is enough
The change
mg_coarse_redundant_pc_factor_shift_type = nonzero. The bundle is its only writer: the coarse LU reads it at its set-up on every route.INBLOCKS) at np > 1, which the bundle'sredundanttype keeps, and no shift at np 1, where that type replaces PETSc's shiftedPCLU. Kaiju confirmed this in CI's environment: at np 2 and 4, development's coarse LU shows[INBLOCKS]and this branch's shows[NONZERO].coarse="svd"variant is removed, not deprecated.GEOMETRIC_MG_COARSE_SOLVERSis("redundant", "gamg").geometric_mg_bundle(coarse="svd")raises aValueErrorthat names the default. It is never a silent fallback (test_1021).mg_coarse_pc_type svdthemselves are unaffected. On the standard path the user's key is respected and the live coarse PC is an SVD (test_1021). The rotated path never took apetsc_optionsoverride for its coarse solve, before or after.finally. Before, a failure after the multigrid set-up left 11 bundle and FAC keys in the global database (test_1021).set_custom_fmg(..., coarse_solve="gamg"), for a bottom level too large to gather.Measurements
Kaiju, 2026-11-01. The case is the production faulted annulus (zg95 TAf: split fault, custom-P FMG, rotated walls), 5 steps from checkpoint 20 on one node.
Record: https://claude.ai/artifact/ACJ6diJRBCGoBGvCa6aCxM
Tests
scripts/test.shruns them:Issues
_rigid_rotation_fields(numpy.zeros_likeon a unit-aware array), reached through_rigid_rotation_modes. The 2-D annulus works. From the code, this branch's_rigid_body_modes, the near-null space forcoarse_solve="gamg", calls the same function, so a 3-D units model with the GAMG coarse solve fails the same way.SphericalShelland inCubedSphere(simplex=True); the velocity multigrid can then fail outright. Found diagnosing test_1111[shell] on kaiju; the fix belongs in the meshing code, not in this branch.Four adversarial review rounds are posted as comments below: round 1 at 0502a9f, round 2 at b704140, and round 3 over 42e5565..9aa89dc, with its fixes in af9d3c3 and bca8434. test_1114's recorded-answer bound failed on kaiju at np 2 and 4; that is fixed in bbf22f7. Round 4 covers the test-only commits bbf22f7 and 4babb3a, with its fixes in e15f5fa.
Underworld development team with AI support from Claude Code