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

integrate `Constant()` function over submesh

+1 vote

How can I integrate a Constant() function over a submesh?

The following fails:

from dolfin import *

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


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()

subdomains = CellFunction('size_t', mesh)
subdomains.set_all(0)
obstacle.mark(subdomains, 1)

dx = Measure('dx')[subdomains]

submesh = SubMesh(mesh, subdomains, 1)
# Works:
assemble(Constant(1.0) * dx(mesh))
# Fails:
assemble(Constant(1.0) * dx(submesh))

Non-matching meshes for function spaces and/or measures.

asked Aug 7, 2014 by nschloe FEniCS User (7,120 points)
edited Aug 7, 2014 by nschloe

1 Answer

+1 vote
 
Best answer

The syntax has changed, see also the changelog for dolfin/ufl 1.4.0 or the following two mail to the mailing list:
http://fenicsproject.org/pipermail/fenics/2014-June/001594.html

http://fenicsproject.org/pipermail/fenics/2014-June/001595.html

The correct syntax now is:

mesh = UnitIntervalMesh(100)
assemble(Constant(2.0)*dx(domain=mesh))
answered Aug 7, 2014 by cevito FEniCS User (5,550 points)
selected Aug 7, 2014 by nschloe

How does this work for subdomains?

See the two links to the mailing list in my previous posting, use for example the following expression to integrate over subdomain 0 as defined in the cell function cell_function:

assemble(Constant(2.0)*dx(0, domain=mesh, subdomain_data=cell_function)
...