This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Integration over subdomain: Non-matching meshes for function spaces and/or measures.

+1 vote

Given a function phi on a domain (mesh) $\Omega$ and a subdomain $\Omega_1\subset\Omega$, I would like to integrate phi over $\Omega_1$. The code

assemble(phi * dx_submesh)

however yields

*** Error:   Unable to extract mesh from form.
*** Reason:  Non-matching meshes for function spaces and/or measures.

How to work-around this error?

asked Feb 13, 2014 by nschloe FEniCS User (7,120 points)

1 Answer

+1 vote
 
Best answer

The following works

from dolfin import *


class Obstacle(SubDomain):
    def inside(self, x, on_boundary):
        return (between(x[1], (0.5, 0.7)) and between(x[0], (0.2, 1.0)))

obstacle = Obstacle()

# Define mesh
mesh = RectangleMesh(0.0, 0.0, 1.0, 1.0, 100, 100)

# Initialize mesh function for interior domains
subdomains = CellFunction('size_t', mesh)
subdomains.set_all(0)
obstacle.mark(subdomains, 1)

dx = Measure('dx')[subdomains]

V = FunctionSpace(mesh, 'CG', 1)
f = project(Constant(1.1), V)

print assemble(f * dx('everywhere'))
print assemble(f * dx())
print assemble(f * dx(0))
print assemble(f * dx(1))
answered Feb 13, 2014 by nschloe FEniCS User (7,120 points)
selected Feb 13, 2014 by nschloe
...