Hi,
I had the same problem. Here is an example that might help you:
from dolfin import *
from mshr import *
from math import pi
rectangle = Rectangle(Point(-1., -1.), Point(1., 1.))
R = 0.5
origin = Point(0.,0.)
circle = Circle(origin, R, segments=32)
domain = rectangle
domain.set_subdomain(1, circle)
domain.set_subdomain(2, rectangle - circle)
mesh = generate_mesh(domain, 15)
subdomains = MeshFunction("size_t", mesh, 2, mesh.domains())
class Left(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[0] + 1.) < DOLFIN_EPS
class Right(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[0] - 1.) < DOLFIN_EPS
class Bottom(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[1] + 1.) < DOLFIN_EPS
class Top(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[1] - 1.) < DOLFIN_EPS
boundaries = FacetFunction("size_t", mesh, 0 )
Bottom().mark(boundaries, 1)
Left().mark(boundaries, 2)
Right().mark(boundaries, 2)
Top().mark(boundaries, 3)
for f in facets(mesh):
domains = []
for c in cells(f):
domains.append(subdomains[c])
domains = list(set(domains))
if len(domains) > 1:
boundaries[f] = 4
V = FunctionSpace(mesh, "CG", 1)
f = Function(V)
f.vector()[:] = 1.
dS = dS(subdomain_data=boundaries)
form4 = f*dS(4)
print form4
ans = assemble(form4)
print ans, "vs", 2*pi*R
form1 = f*dS(1)
ans = assemble(form1)
print ans, "vs", 2., "~>", "dS is non zero only in the boundaries' interface!"
ds = ds(subdomain_data=boundaries)
form1 = f*ds(1)
ans = assemble(form1)
print ans, "vs", 2.