This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Is it possible to assemble only the diagonal part of a form?

+2 votes

I want to assemble a weighted mass matrix,

wkform = inner(rho*test, trial)*dx
M = assemble(wkform)

then extract the diagonal part of M. Since M can be large, I'd like to avoid useless computations, and assemble M in a way that makes it directly diagonal (i.e, only when test and trial are the same).
What would be a way to do that?

asked May 29, 2016 by BC FEniCS Novice (790 points)
...