Hello, I have an FEM function which I’d like to numerically integrate over the mesh it is created over. I looked around, and it seems that the assemble() function is the way to do this. My two attempts at a solution are labeled “option 1” and “option 2” in the code. For “option 1,” for some reason “assemble()” isn’t a recognized command. For “option 2,” the output is: “Form object has no attribute ‘_cpp_object’.” Here’s the minimum code to reproduce the error I’m getting:
from dolfinx import *
import ufl
from mpi4py import MPI
from basix.ufl import element, mixed_element
from dolfinx import default_scalar_type
w = 2
d = 1
msh = mesh.create_rectangle(MPI.COMM_WORLD, points=((0, 0), (w, d)), n=(10, 5))
Cg = element("Lagrange", msh.basix_cell(), 1)
Cgf = fem.functionspace(msh, Cg)
x = ufl.SpatialCoordinate(msh)
C0 = fem.Constant(msh, default_scalar_type(1))
con = fem.Function(Cgf)
con_exp = lambda x: x[0] * 2 + C0 #function I'd like to integrate
con.interpolate(con_exp)
#option 1
ans = assemble(con*ufl.dx)
#option 2
ans = fem.assemble_scalar(con*ufl.dx)
ans.assemble()