Hi All,
I’m getting very strange results when calculating integrals using assemble
over subdomains, consider the MWE:
import dolfin as fem
mesh = fem.UnitSquareMesh(100, 100)
class SubSquare(fem.SubDomain):
def __init__(self, xi, xf, yi, yf, **kwargs):
self.xi, self.xf = xi, xf
self.yi, self.yf = yi, yf
super().__init__(**kwargs)
def inside(self, x, on_boundary):
return self.xi <= x[0] <= self.xf and self.yi <= x[1] <= self.yf
cellfn = fem.MeshFunction('size_t', mesh, mesh.topology().dim())
cellfn.set_all(0)
bl = SubSquare(0.0, 0.5, 0.0, 0.5) # bottom left
br = SubSquare(0.5, 1.0, 0.0, 0.5) # bottom right
tr = SubSquare(0.5, 1.0, 0.5, 1.0) # top right
tl = SubSquare(0.0, 0.5, 0.5, 1.0) # top left
bl.mark(cellfn, 1) # bottom left
br.mark(cellfn, 2) # bottom right
tr.mark(cellfn, 3) # top right
tl.mark(cellfn, 4) # top left
V = fem.FunctionSpace(mesh, 'CG', 1)
u = fem.TrialFunction(V); v = fem.TestFunction(V)
dx = fem.Measure('dx', domain= mesh, subdomain_data= cellfn)
ds = fem.Measure('ds', domain= mesh)
a = (fem.dot(fem.grad(u), fem.grad(v)) + u*v)*dx + u*v*ds
L = v*dx
m = fem.Function(V)
fem.solve(a == L, m) # so far, everything works
# but strange results when I try to calculate some integrals, e.g.:
print(fem.assemble(m*dx)) # gives ~0.22474021790739562 (works)
# integrating over the subdomains should give roughly 1/4 the integral over
# the domain (~0.056185054476848906) due to symmetry, however:
print(fem.assemble(m*dx(1))) # gives 0.0
print(fem.assemble(m*dx(2))) # gives 0.0
print(fem.assemble(m*dx(3))) # gives 0.0
print(fem.assemble(m*dx(4))) # gives 0.0
# to make things stranger, consider
print(fem.assemble((m*1.000000000000001)*dx(1))) # gives 0.05618539993070857
print(fem.assemble((m*1.000000000000001)*dx(2))) # gives 0.056184709022991684
print(fem.assemble((m*1.000000000000001)*dx(3))) # gives 0.05618539993070186
print(fem.assemble((m*1.000000000000001)*dx(4))) # gives 0.05618470902299123
Indeed, multiplying m
by any number other than one works as expected. I find this behaviour quite strange. Anybody got an idea?