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

assembling rhs over subdomain: Expecting a completed form with domains at this point.

+1 vote

I would like to assemble a right-hand side (a vector) over a subdomain. The code

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)
r = Expression('x[0]', domain=mesh)
# This works:
#V = FunctionSpace(mesh, 'CG', 1)
# This doesn't:
V = FunctionSpace(submesh, 'CG', 1)
v = TestFunction(V)
a = assemble(r * v * dx(1))

however yields the error

AssertionError: Expecting a completed form with domains at this point.

How to work around the issue?

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

1 Answer

+1 vote
 
Best answer

Working in next:

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)

submesh = SubMesh(mesh, subdomains, 1)
r = Expression('x[0]', domain=mesh)

Vsub = FunctionSpace(submesh, 'CG', 1)
v = TestFunction(Vsub)
a = assemble(r * v * dx(submesh))
answered Feb 15, 2014 by nschloe FEniCS User (7,120 points)

Is this feature working in the current master HEAD?

Apologies for digging out this old thread: what is the rationale behind why it would not with subdomains directly? Is it because a submesh is more general than a subdomain?

...