assembling with different submeshes: misleading error message

Issue #244 resolved
Nico Schlömer created an issue

When a form is assembled that contains functions from different meshes, e.g.,

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)

r = Expression('x[0]', domain=mesh)
V = FunctionSpace(mesh, 'CG', 1)
f = project(Constant(1.0), V)

submesh = SubMesh(mesh, subdomains, 1)

Vsub = FunctionSpace(submesh, 'CG', 1)
v = TestFunction(Vsub)
print assemble(f * v * dx)

the error message

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

is thrown. It should rather be

*** Error:   Unable to extract mesh from form.
*** Reason:  Non-matching meshes for function spaces and/or measures.
*** Where:   This error was encountered inside Form.cpp.

(Also, I'm not sure how to actually compile a RHS with a function f that lives on a supermesh.)

Comments (5)

  1. Martin Sandve Alnæs

    It should not be that message, but I'll look into improving it.

    assemble(f * v * dx) is ambiguous, since f and v don't live on the same mesh.

    Try

    assemble(f * v * dx(domain=submesh))
    assemble(f * v * dx(submesh))
    assemble(f * v * dx, mesh=submesh)
    
  2. Nico Schlömer reporter

    Thanks for the quick answer! Unfortunately, I'm getting

    ufl.log.UFLException: Label mismatch.
    

    for all three of your suggestions.

  3. Log in to comment