# Imposing Dirichlet bc on the boundary of a hole embedded in a continuum body

**URL:** <https://fenicsproject.discourse.group/t/imposing-dirichlet-bc-on-the-boundary-of-a-hole-embedded-in-a-continuum-body/6215>\
**Category:** mesh\
**Created:** [July 10, 2021, 5:41pm UTC](https://fenicsproject.discourse.group/t/imposing-dirichlet-bc-on-the-boundary-of-a-hole-embedded-in-a-continuum-body/6215 "2021-07-10T17:41:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RicCav](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/riccav/32/2780_2.png) [@RicCav](https://fenicsproject.discourse.group/u/RicCav)\
**Post date:** [July 10, 2021, 5:41pm UTC](https://fenicsproject.discourse.group/t/imposing-dirichlet-bc-on-the-boundary-of-a-hole-embedded-in-a-continuum-body/6215/1 "2021-07-10T17:41:48Z")

</div>

Hello,  
I am solving an elasticity problem in which the domain is a rectangle (150x120) with two circular voids (radius = 4) (shaped like a videotape). I would like to apply Dirichlet BC on the boundary of the voids and to apply other Dirichlet BC on the right boundary of the rectangle. When I run my code I get the error:  
\*\*\* Warning: Found no facets matching domain for boundary condition.  
I checked the similar question asked here:[https://fenicsproject.discourse.group/t/dirichlet-bcs-on-an-annulus/1711](https://fenicsproject.discourse.group/t/dirichlet-bcs-on-an-annulus/1711)  
but I was hoping for a new answer since 2 years have passed. I understand the problem is probably with the BC on the voids.  
So, the way I wrote it is:

```
# Boundary conditions
right= CompiledSubDomain("near(x[0], 150.0) && x[1] < 120.0 && x[1] >= 0.0 && on_boundary")

tondo_top = CompiledSubDomain("(x[0]-25.00)*(x[0]-25.00)+(x[1]-87.50)*(x[1]-87.50)-16.00 < 0.001 && (x[0]-25.00)*(x[0]-25.00)+(x[1]-87.50)*(x[1]-87.50)-16.00 > -0.001 && x[1]-87.50 >= 0.0 && on_boundary")
tondo_bot = CompiledSubDomain("(x[0]-25.00)*(x[0]-25.00)+(x[1]-32.50)*(x[1]-32.50)-16.00 < 0.001 && (x[0]-25.00)*(x[0]-25.00)+(x[1]-32.50)*(x[1]-32.50)-16.00 > -0.001 && x[1]-32.50 >= 0.0 && on_boundary")

load_top = Expression("t", t = 0.0, degree=1)
load_bot = Expression("t", t = 0.0, degree=1)

bc_tondo_top= DirichletBC(W.sub(1), load_top, tondo_top)
bc_tondo_bot= DirichletBC(W.sub(1), load_bot, tondo_bot)
bcright= DirichletBC(W, Constant((0.0,0.0)), right) 

bc_u = [bc_tondo_top, bc_tondo_bot, bcright]
boundaries = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
boundaries.set_all(0)
tondo_top.mark(boundaries,1)
ds = Measure("ds")(subdomain_data=boundaries)
n = FacetNormal(mesh)

```

The reason I am defining “n” is because at the end of the code I ask for the dot product of a tensor and “n” (this is not necessary).  
Can anyone help?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [July 10, 2021, 6:19pm UTC](https://fenicsproject.discourse.group/t/imposing-dirichlet-bc-on-the-boundary-of-a-hole-embedded-in-a-continuum-body/6215/2 "2021-07-10T18:19:45Z")

</div>

As you have not supplied your mesh file, it is not very easy to help you. Please not that if you create your mesh with an external mesh creator (say GMSH) you can mark your boundaries in the creation step and import them, as covered in:

> [@Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio](https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/172):
>
> Your msh file does not contain any physical markers (i.e Physical Line/Volume/Surface), thus you cannot read in cell\_data. I would suggest using the following code for reading meshes (from [Accessing and marking imported boundaries - #8 by dokken](https://fenicsproject.discourse.group/t/accessing-and-marking-imported-boundaries/5753/8)). Note that here I have defined a physical surface and physical curve. import meshio msh = meshio.read("cylinder.msh") def create\_mesh(mesh, cell\_type, prune\_z=False): cells = mesh.get\_cells\_type(cell\_type) cell\_data = mesh.get\_cell\_data("g…

---

<div class="post-metadata">

**Author:** ![RicCav](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/riccav/32/2780_2.png) [@RicCav](https://fenicsproject.discourse.group/u/RicCav)\
**Post date:** [July 11, 2021, 4:08pm UTC](https://fenicsproject.discourse.group/t/imposing-dirichlet-bc-on-the-boundary-of-a-hole-embedded-in-a-continuum-body/6215/3 "2021-07-11T16:08:28Z")

</div>

I changed the lines:

```
tondo_top = CompiledSubDomain("(x[0]-25.00)*(x[0]-25.00)+(x[1]-87.50)*(x[1]-87.50)-16.00 < 0.001 && (x[0]-25.00)*(x[0]-25.00)+(x[1]-87.50)*(x[1]-87.50)-16.00 > -0.001 && x[1]-87.50 >= 0.0 && on_boundary")
tondo_bot = CompiledSubDomain("(x[0]-25.00)*(x[0]-25.00)+(x[1]-32.50)*(x[1]-32.50)-16.00 < 0.001 && (x[0]-25.00)*(x[0]-25.00)+(x[1]-32.50)*(x[1]-32.50)-16.00 > -0.001 && x[1]-32.50 >= 0.0 && on_boundary")

```

with the following:

```
def tondo_top(x, on_boundary):
return abs((x[0]-25.00)**2+(x[1]-87.50)**2 - 16.00) >= 1E-6 and on_boundary

def tondo_bot(x, on_boundary):
return abs((x[0]-25.00)**2+(x[1]-87.50)**2 - 16.00) >= 1E-6 and on_boundary

```

and the error disappeared. Unfortunately, now I cannot assign any label to boundaries and get an error for “n”. I tried to fix it as **dokken** suggested by generating the mesh on freefem (.mesh file) and labeling there the various boundaries.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [July 11, 2021, 5:40pm UTC](https://fenicsproject.discourse.group/t/imposing-dirichlet-bc-on-the-boundary-of-a-hole-embedded-in-a-continuum-body/6215/4 "2021-07-11T17:40:38Z")

</div>

As you are not staying what error you are obtaining, and you do not provide a minimal code example reproducing the error, I cannot provide you much more help.
