### (BC problems) Warning: Found no facets matching domain for boundary condition.

188

views

1

Hello,

I am trying to add both Derichlet and Robin's BC to a 2-D rectangle defined as:

```
nx = ny = 30
mesh = RectangleMesh(Point(-2.0, -2.0), Point(2.0, 2.0), nx, ny)
V = FunctionSpace(mesh, 'P', 1)
```

```
# Define boundary condition
boundary_markers = FacetFunction('size_t', mesh)
class BoundaryX0(SubDomain):
tol = 1e-2
def inside(self, x, on_boundary):
return on_boundary and near(x[0], -2.0, 1E-2) or near(x[0], 2.0, 1E-2) or near(x[1], -2.0, 1E-2) or near(x[1], 2.0, 1E-2)
bx0 = BoundaryX0()
bx0.mark(boundary_markers, 0)
class BoundaryX1(SubDomain):
tol = 1e-2
def inside(self, x, on_boundary):
return on_boundary and near(x[0], -0.5, 1E-2) or near(x[0], 0.5, 1E-2) or near(x[1],-0.5, 1E-2) or near(x[1], 0.5, 1E-2)
bx1 = BoundaryX1()
bx1.mark(boundary_markers, 1)
boundary_conditions = {0: {'Robin': (r, s)}, 1: {'Dirichlet': u_0}}
bcs = []
for i in boundary_conditions:
if 'Dirichlet' in boundary_conditions[i]:
bc = DirichletBC(V, boundary_conditions[i]['Dirichlet'],
boundary_markers, i)
bcs.append(bc)
ds = Measure('ds', domain=mesh, subdomain_data=boundary_markers)
integrals_R = []
for i in boundary_conditions:
if 'Robin' in boundary_conditions[i]:
r, s = boundary_conditions[i]['Robin']
integrals_R.append(r*(u - s)*v*ds(i))
# Define variational problem
F = kappa*dot(grad(u), grad(v))*dx + \
sum(integrals_R) - f*v*dx
a, L = lhs(F), rhs(F)
solve(a == L, u, bcs=bc)
```

My goal is to have robin's BC on the exterior of the rectangle mesh and dirichlet on x = -0.5, 0.5 and y = -0.5, 0.5

When I run the code I get this error message:

```
Solving linear variational problem.
*** Warning: Found no facets matching domain for boundary condition.
*** Warning: Plotting backend set to 'none'. Plotting disabled.
(fenicsproject) -bash-4.1$
```

Please let me know if you can help

thanks

Community: FEniCS Project

### 3 Answers

3

Hi Terrence,

You may have to reduce the tolerance when you are finding the boundary. Your tolerance in

You may have to reduce the tolerance when you are finding the boundary. Your tolerance in

```
class BoundaryX1(SubDomain):
tol = 1E-5
def inside(self, x, on_boundary):
return on_boundary and near(x[0], -0.5) or near(x[0], 0.5) or near(x[1],-0.5) or near(x[1], 0.5)
```

is too tight. You could try 1e-3 or lower and check.

3

Hi Terrance,

This should work, try it out

This should work, try it out

```
class BoundaryX0(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and near(x[0], -2.0, 1E-3) or near(x[0], 2.0, 1E-3) or near(x[1], -2.0,1E-3) or near(x[1], 2.0,1E-3)
```

No still the same answer.

written
4 months ago by
Terrence

Is there something wrong with my definition of ds maybe:

```
ds = Measure('ds', domain=mesh, subdomain_data=boundary_markers)
```

written
4 months ago by
Terrence

1

Hi Terrance,

```
class BoundaryX1(SubDomain):
tol = 1e-2
def inside(self, x, on_boundary):
return on_boundary and near(x[0], -0.5, 1E-2) or near(x[0], 0.5, 1E-2) or near(x[1],-0.5, 1E-2) or near(x[1], 0.5, 1E-2)
```

does not lie on the boundary. The first boundary condition is correct.

written
4 months ago by
Kaushik Vijaykumar

Thank you so much It worked!!! I assume to have another Dirichlet BC on the interior I would have to change the "inside" statement to something else?

written
4 months ago by
Terrence

0

Please login to add an answer/comment or follow this question.

Thank you so much for your comment. I tried reducing my tolerances to tol = 1E-3 and then all the way to tol = 1 with no avail. I am still getting the same error.