# FEniCS: how to specify boundary conditions on a circle inside 2D mesh

I would like to numerically find a mutual capacitance of two stripes of metal on the opposites sides of a cylinder. The problem is obviously a 2D Laplace equation. I would like to find the potential outside the cylinder as well. Therefore I have something like this:

mesh = UnitCircleMesh(50)
V = FunctionSpace(mesh, 'Lagrange', 1)

u_L = Constant(-1)
def left_boundary(x, on_boundary):
r = math.sqrt(x * x + x * x)
return near(r, 0.7) and x < 0 and between(x, (-0.5, 0.5))

u_R = Constant(1)
def right_boundary(x, on_boundary):
r = math.sqrt(x * x + x * x)
return near(r, 0.7) and x > 0 and between(x, (-0.5, 0.5))

leftPlate = DirichletBC(V, u_L, left_boundary)
rightPlate = DirichletBC(V, u_R, right_boundary)
bcs = [leftPlate, rightPlate]

u = TrialFunction(V)
v = TestFunction(V)

u = Function(V)
solve(a == Constant(0) * v * dx, u, bcs)


When I run it, I receive *** Warning: Found no facets matching domain for boundary condition.. And the found solution is 0. What is wrong?

• Are you trying to hit boundary facets or facets on radius 0.7 (in unit circle)? – Jan Blechta May 24 '13 at 21:35
• Are you trying to hit exterior or interior (on radius 0.7) boundary? If the latter is your intent consider wheter there are facets with their vertices and midpoint on radius cca 0.7 forming connected interior boundary. If yes, you probably need to increase tolerance by near(r, 0.7, tol) as target facets would be rough approximation to circle. – Jan Blechta May 24 '13 at 21:43
• Also fit your mesh = UnitCircleMesh(n) where $n = \frac{2}{0.7} m$ both $n$, $m$ being natural. – Jan Blechta May 24 '13 at 21:54
• I want to calculate the potential both in the exterior and the interior of the cylinder. – facetus May 24 '13 at 22:38
• Then increase tolerance of near function very much and tweak n so that mesh hits better radius 0.7 as suggested above. – Jan Blechta May 24 '13 at 22:44

As the error message suggest the DirichletBC does not hit any mesh entities with corresponding dofs. You need to examine your subdomains. One way to debug these are to apply the DirichletBC to a Function and plot the result:

def left_boundary(x, on_boundary):
r = math.sqrt(x * x + x * x)
return r < 0.5

leftPlate = DirichletBC(V, u_L, left_boundary)
u = Function(V)
u.vector()[:] = 0
leftPlate.apply(u.vector())
plot(u, interactive=True)


This will plot a nice hat. Now you can start tweak your left_boundary function until you reach the result you want.

• Thanks! I'll try this. What is a subdomain (excuse me for a silly question)? – facetus May 24 '13 at 22:41
• @noxmetus: SubDomain is DOLFIN class for definition of some subdomain of your spatial domain, see fenicsproject.org/documentation/dolfin/1.2.0/python/…. Function left_boundary(x, on_boundary) is convenience way of defining subdomains without actually subclassing SubDomain. Notice that left_boundary has same interface as SubDomain.inside(). – Jan Blechta May 25 '13 at 0:05
• Note that you can plot boundary conditions directly without creating a Function first: plot(leftPlate) – Anders Logg May 26 '13 at 21:55