I would avoid setting up a diagonal matrix and then using it in a linear solve, since this introduces unnecessary overhead. It would be equivalent to just keep the diagonal of M_lumped
as a vector, then use PETSc’s VecPointwiseDivide
function as a linear solver. You can access it through the petsc4py
API, assuming you are using FEniCS’s default PETSc linear algebra backend. I wrote up an example of this in my answer to the following question:
See, in particular, the function lumpedProject
, which implements lumped-mass L^2 projection of some arbitrary function f
using VecPointwiseDivide
.