I want to set the integration rule to closed for all terms of my problem and not only the mass matrix. I have a MWE on the unit interval with P1 elements and a term f = x
from dolfinx import mesh, fem
import ufl
from mpi4py import MPI
nx = 2
domain = mesh.create_unit_interval(MPI.COMM_WORLD, nx)
V = fem.FunctionSpace(domain, ("CG", 1))
x = ufl.SpatialCoordinate( domain )
function = x[0]
v = ufl.TestFunction(V)
b = function*v*ufl.dx
linear_form = fem.form(b)
b = fem.petsc.create_vector(linear_form)
fem.petsc.assemble_vector(b, linear_form)
print( "b = \n", b.getValues(range(nx+1)) )
Exact integration gives b = [0.04166667, 0.25, 0.20833333] which is what this code outputs.
Closed integration gives b = [0.0, 0.25, 0.25]
Thanks for fixing this @dokken. I tried it out using the docker nightly build and it works for line and triangle elements. It does not work for quadrilateral elements, which is what I ultimately need. Here is a MWE with f = xy
from dolfinx import mesh, fem
import ufl
from mpi4py import MPI
N = 1
domain = mesh.create_unit_square(MPI.COMM_WORLD, N, N,
mesh.CellType.quadrilateral
)
V = fem.FunctionSpace(domain, ("CG", 1))
x = ufl.SpatialCoordinate(domain)
v = ufl.TestFunction(V)
dx = ufl.Measure("dx",
#metadata={"quadrature_rule": "vertex"}
)
b = x[0]*x[1]*v*dx
linear_form = fem.form( b )
b = fem.petsc.create_vector(linear_form)
fem.petsc.assemble_vector(b, linear_form)
print( "b = \n", b.getValues( range(b.size) ) )
Exact integration gives b = [0.02777778, 0.05555556, 0.05555556, 0.11111111] which is what this code prints. Closed integration gives b = [0.0, 0.0, 0.0, 0.25].
When I uncomment the line #metadata={"quadrature_rule": "vertex"} , I get the following error:
UnboundLocalError: local variable 'points' referenced before assignment