While porting my code from dolfin to dolfinx, it looks like the way to implement mass-lumping does not work anymore.
Back in dolfin one would have written:
dxL = dx(metadata={'quadrature_degree': 1, 'quadrature_scheme': 'vertex'})
In my MWE however the printed mass matrix is not diagonal as it should be, but does not even take the provided metadata into account…
MWE:
import numpy as np
from mpi4py import MPI
from dolfinx import mesh
from dolfinx.fem.petsc import assemble_matrix
from dolfinx.fem import VectorFunctionSpace, Function
domain = mesh.create_unit_square(MPI.COMM_WORLD, 8, 8, mesh.CellType.triangle)
V = VectorFunctionSpace(domain, ("Lagrange", 1), dim =2)
from dolfinx import fem
import ufl
u = ufl.TrialFunction(V)
u0 = Function(V)
v = ufl.TestFunction(V)
# Mass Lumping
dxL = ufl.dx(metadata={'quadrature_degree': 1, 'quadrature_scheme': 'vertex'})
Eqa = ufl.inner(u, v)*ufl.dx
Eqb = ufl.inner(u,v)*dxL
Xa= assemble_matrix(fem.form(Eqa))
Xb= assemble_matrix(fem.form(Eqb))
Xa.assemble()
Xb.assemble()
Xa.convert("dense")
Ca = Xa.getDenseArray()
Xb.convert("dense")
Cb = Xa.getDenseArray()
print("w/o mass lumping \n",Ca)
print("w/ mass lumping \n",Cb)
Output:
w/o mass lumping
[[0.00390625 0. 0.00065104 ... 0. 0. 0. ]
[0. 0.00390625 0. ... 0. 0. 0. ]
[0.00065104 0. 0.00130208 ... 0. 0. 0. ]
...
[0. 0. 0. ... 0.00390625 0. 0.00065104]
[0. 0. 0. ... 0. 0.00130208 0. ]
[0. 0. 0. ... 0.00065104 0. 0.00130208]]
w/ mass lumping
[[0.00390625 0. 0.00065104 ... 0. 0. 0. ]
[0. 0.00390625 0. ... 0. 0. 0. ]
[0.00065104 0. 0.00130208 ... 0. 0. 0. ]
...
[0. 0. 0. ... 0.00390625 0. 0.00065104]
[0. 0. 0. ... 0. 0.00130208 0. ]
[0. 0. 0. ... 0.00065104 0. 0.00130208]]
What am I missing?