#Define the measure
ds = ufl.Measure(“ds”, subdomain_data=facet_tags, subdomain_id=5 ) #Calculate the integral
integral = dolfinx.fem.form(u_test * ufl.ds)
print(fem.assemble_scalar(integral))
Also, you need dS instead of ds because dS integrates in the interior (actually I am not 100% sure for this). Moreover, (and this is a mistake I did a lot) you need to use the custom made ds instead of ufl.ds
from dolfinx import fem, mesh
from mpi4py import MPI
import numpy as np
import ufl
import dolfinx
domain = mesh.create_unit_square(MPI.COMM_WORLD, 100, 100, mesh.CellType.triangle)
mesh=domain
V = dolfinx.fem.FunctionSpace(domain, ("Lagrange", 1))
u_test = dolfinx.fem.Function(V)
u_test.interpolate(lambda x: 1 + x[0]**2 + 2*x[1]**2)
def facet_eq(x):
return np.isclose(x[0], 0.5)
facets = dolfinx.mesh.locate_entities(mesh, mesh.topology.dim-1, facet_eq)
facet_tags = dolfinx.mesh.meshtags(mesh, mesh.topology.dim-1, facets, np.full_like(facets, 5))
#Define the measure
ds = ufl.Measure("dS", subdomain_data=facet_tags, subdomain_id=5 )
#Calculate the integral
integral = dolfinx.fem.form(u_test * ds)
print(fem.assemble_scalar(integral))
The ufl.ds was a typo, I actually didn’t use it in my code but I see I somehow messed up the MWE here. Same with the facet equation… Sorry for that.
dS is the integral measure over interior facets, these are facets that are connected to two cells. ds is for exterior facets, those only connected to one cell.