integration over subdomain broken

Issue #240 invalid
Nico Schlömer created an issue

When using the new dx(...) integration, integrating over a subdomain is no longer working.

MWE:

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)
# This works:
# r = Expression('x[0]', domain=mesh)
# This fails:
r = Expression('x[0]', domain=submesh)
a = assemble(r * dx(1))

Error message:

*** 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.

Comments (4)

  1. Jan Blechta

    This never worked. You are integrating on non-matching domain. See #85 and #88. You need to to do

    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)
    
    subdomains_sub = CellFunction('size_t', submesh)
    obstacle.mark(subdomains_sub, 1)
    
    dx_sub = Measure('dx')[subdomains_sub]
    
    r = Expression('x[0]', domain=submesh)
    a = assemble(r * dx_sub(1))
    
  2. Log in to comment