Using the MINI element (P1 Lagrange enriched with a bubble) for the (Navier-)Stokes equations in DOLFINx 0.11.0, with petsc4py 3.25.4 on macOS. Want to use gamg or hypre as a multigrid preconditioner. The PETSc docs for PCGAMG say you must indicate the number of degrees of freedom per grid point, so I checked and found the submatrix (0,0) of the nested PETSc.Mat has blocksize 1. A minimal example comparing a plain P2 vector element vs enrichedelement([P1, bubble]) shows the difference via problem.A.getBlockSize(). Is this user error, a misunderstanding, or an actual issue — and does the block size actually matter for gamg?
Incorrect PETSc.Mat block size when using enriched_element (MINI element)
youre not doing anything wrong here. the block size comes from the dofmap (check V.dofmap.bs), which dolfinx derives from the basix element. a plain vector lagrange element is built as a blocked element, so bs = gdim and you get a baij matrix. enriched_element builds a generic combined element that doesnt advertise any block structure, basix just reports block size 1, so the dofmap and the matrix end up unblocked. known limitation, not a bug in your code.
and yes, it does matter for gamg. that dofs per grid point bit from the petsc docs is exactly this: gamg reads the matrix block size during setup. with bs = 1 it treats every dof as scalar, which usually still converges but the multigrid hierarchy is less effective on the velocity block.
pragmatic workaround: every node in the mini velocity space genuinely carries gdim dofs (vertices from the p1 part, cell interiors from the bubble), so you can just tell petsc yourself, e.g. problem.A.setBlockSize(gdim) before the solve. same idea for the (0,0) block in your nested matrix.
Source: https://fenicsproject.discourse.group/t/incorrect-petsc-mat-block-size-when-using-enriched-element/19805