Skip to content

Add DiagonalInverseMatrix for multigrid on composed preconditioners - #5776

Draft
pbrubeck wants to merge 4 commits into
pbrubeck/linesmooth-mixed-spacefrom
pbrubeck/diagonal-inverse-matrix
Draft

pbrubeck wants to merge 4 commits into
pbrubeck/linesmooth-mixed-spacefrom
pbrubeck/diagonal-inverse-matrix

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #5775 (ASMLinesmoothPC on mixed spaces). Review only the top commit; retarget to main once #5775 merges.

Summary

Geometric multigrid can now rediscretize a preconditioner built from FormSum, Action and a new DiagonalInverseMatrix. This is the BaseForm counterpart of the Slate static-condensation path: an approximate Schur complement S = E - C D B with a diagonal or lumped D can be passed as Jp. Fieldsplit picks up its block, and multigrid coarsens it, with no PythonPC.

D = DiagonalInverseMatrix(mass, bcs=bcs, lumped=True)   # D = diag(row sums)^+
aP = a - action(div_u, action(D, grad_p))               # (p, p) block is E - C D B
solver_parameters = {
    "pc_type": "fieldsplit", "pc_fieldsplit_type": "schur",
    "pc_fieldsplit_schur_precondition": "a11",           # precondition S by the (p, p) block of aP
    "fieldsplit_1_pc_type": "mg",
    "fieldsplit_1_pc_use_amat": False,                    # use aP, not J, on every level
}

DiagonalInverseMatrix(form, bcs=(), lumped=False), D: V* → V, with arguments (Coargument(V*, 0), Coargument(V*, 1)):

operand d_i
bilinear a A_ii (point Jacobi)
bilinear a, lumped=True Σ_j A_ij over columns that are not BC nodes
linear ℓ ℓ(φ_i)

D_ii = 1/d_i, or 0 where d_i = 0 or i is a node of bcs (the pseudoinverse). So D of a one-block form is zero outside that block, and C D B never couples through BC nodes, even in a fieldsplit context whose solver BCs do not include them.

 BaseFormAssembler visitor
+  DiagonalInverseMatrix -> diagonal / row sums of the assembled operand -> zero BC nodes -> reciprocal -> diagonal AIJ
 ExtractSubBlock
+  DiagonalInverseMatrix[I, I] -> DiagonalInverseMatrix(form[I, I], bcs on I); [I, J] disjoint -> zero
 mg.ufl_utils coarsen / refine
+  Action -> Action(coarsen(left), coarsen(right))
+  DiagonalInverseMatrix -> DiagonalInverseMatrix(coarsen(form), coarsen(bcs))

Lumped row sums are a property of the matrix, so they need lumped=True. Writing them as the action of a on a function whose DoFs are all one is wrong after coarsening for H(div): injection makes the coarse DoFs about 2 or 4.

Limitations: assembly needs aij operands (MatMatMult); D can only be split into diagonal or disjoint blocks.

Related: FEniCS/ufl#578 lets replace reach the operand of a DiagonalInverseMatrix and adds C @ D @ B. This PR does not depend on it.

Evidence

New tests, on 1 and 3 processes (all fail or raise without this change):

  • test_diagonal_inverse_matrix_of_bilinear_form_inverts_diagonal, ..._of_linear_form_inverts_lumped_diagonal, test_lumped_diagonal_inverse_matrix_inverts_row_sums_without_bc_nodes, ..._is_zero_outside_block: compared with getDiagonal / A·1 computed in PETSc.
  • test_action_of_diagonal_inverse_matrix_is_approximate_schur_complement: assemble(action(C, action(D, B))) equals C · diag(A)⁻¹ · B from MatMatMult, with BCs.
  • test_split_diagonal_inverse_matrix: each split block equals createSubMatrix of the assembled D.
  • test_coarse_schur_complement_is_rediscretized[lumped=False|True]: the MG coarse operator of the Schur field equals E - C D B assembled directly on the coarse mesh. Before: coarsening raises. After: equal to 1e-12.

Mixed Darcy (RTCF × DQ0) on a MeshHierarchy, outer GMRES iterations with one V-cycle on S:

refinements 1 2 3 4 (exact LU of S)
iterations 16 20 21 21 15

The changed modules' test files (test_assemble_baseform, test_split, test_linesmoother*, multigrid test_schur_complement_gmg, test_transfer_manager, test_stokes_gmg, test_poisson_gmg_extruded, test_nested_split) pass at 1, 2 and 3 processes.

Merge Danger

Door: two-way

Blast Radius: small

New class and new dispatch entries. The only change to existing behaviour: multigrid now coarsens Action explicitly, where it used to fall back to a reconstruction that could not rebuild it.

AI tool used: Claude Code (Claude Opus 5.5).

🤖 Generated with Claude Code

DiagonalInverseMatrix(form, bcs, lumped) is the pseudoinverse of the
diagonal of a bilinear form (point Jacobi), of its row sums (lumped),
or of a linear form. It is zero on the nodes of its boundary
conditions, so that the product C D B does not couple through them. It
can be assembled, split by fieldsplit, and coarsened by multigrid, and
multigrid also coarsens Action. A preconditioner such as J - C D B is
then rediscretized on every level, for example to precondition a Schur
complement with geometric multigrid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pbrubeck pbrubeck added the LLM used An LLM was used in the production of this PR label Dec 4, 2026
@pbrubeck
pbrubeck marked this pull request as draft December 4, 2026 23:44
pbrubeck and others added 3 commits December 5, 2026 00:03
DiagonalInverseMatrix now takes and stores its form as `a`, like
MatrixBase. Its hash now includes the boundary conditions, as its
equality test does, and its repr and str use the MatrixBase format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The diagonal inverse assembled its form with separate assemblers and
options. The operand is now assembled by the post-order traversal, as
the operands of Adjoint and Action are, with the options of the
enclosing assembly. The diagonal, the row sums or the entries are then
taken from the assembled operand through PETSc, so that a matrix-free
operand gives its diagonal through ImplicitMatrixContext.getDiagonal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM used An LLM was used in the production of this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant