# How can I build a mesh with holes for use in FEniCS?

This is my first time using FEniCS. I am trying to solve an elliptic PDE, fairly similar to the Laplace equation, on a rectangle with two holes in it. The holes are level sets of an energy function, so I am not completely in control over their geometry. For a first approximation I can use ellipses, but I would like to still use an extensible technique so that the potential can be varied flexibly. The tutorial mentions that mesh preprocessors are usually required to initialize problems with complex geometry, but I was unable to find an actual example of how to do this. Can anyone suggest a method for building the mesh?

• Way how to do it is: use external mesh generator (this is not naturally covered in FEniCS documentation), use meshconvert (usage covered sufficiently), import mesh in DOLFIN using Mesh(filename) constructor. – Jan Blechta May 29 '13 at 10:22

## 2 Answers

Take a look at the CSG (Constructive Solid Geometry) demos in DOLFIN. You should be able to generate a rectangle with two holes with something like

mesh = Mesh(Rectangle(...) - Ellipse(...) - Ellipse(...), resolution)

• Thanks, that will definitely help to get me off the ground. I'm not sure ellipses will be adequate overall, but it would be great to be able to get started. – Ian May 29 '13 at 13:47

If your mesh depends on solution you can do fixed-point iteration:

• compute solution,
• move mesh,
• if mesh is deformed to much, create new one and project solution on it.

If you use CSG in DOLFIN, then you can handle all three steps within DOLFIN. If using external mesh generator third step requires instructing mesh generator by DOLFIN. One way to do it is:

• prepare input for mesh generator parametrized by few floats,
• subprocess.call mesh generator, meshconvert,
• read in new mesh

Triangle can generate triangulations of domain with holes in 2D. meshconvert handles also facet and cell markers produced Triangle.

• I should have clarified that the energy function is a function only of space, not of the solution. So I only need to compute the mesh once each time I solve the problem. Also, thank you for that link; I read the name of Triangle elsewhere, but was unable to find it by searching. – Ian May 29 '13 at 14:00