# ToElementMesh of Region with Hole

When I try to mesh the following region it fails. Why? Is there a workaround?

Needs["NDSolveFEM"];
Len = 1;  (*length *)
ht = 0.125; (* height *)
wd = 0.5; (* width *)
hwd = 0.25; (* hole width *)
reg = RegionDifference[Cuboid[{0, -wd/2, 0}, {Len, wd/2, ht}],
Cuboid[{Len/2 - hwd/2, -hwd/2, 0}, {Len/2 + hwd/2, hwd/2, ht}]];
Region[reg]


mesh = ToElementMesh[reg];


DiscretizeGraphics::rnimpl: The function DiscretizeGraphics is not implemented for Tetrahedron[<<1>>].

Version 11.3 for Windows.

• Mar 13, 2019 at 18:05

## 2 Answers

I don't know why on earth a Tetrahedron-wrapped list of 3D-simplices is returned by RegionDifference, but this helps to circumvent it:

R1 = BoundaryDiscretizeRegion[
Cuboid[{0, -wd/2, 0}, {Len, wd/2, ht}],
MaxCellMeasure -> ∞
];
R2 = BoundaryDiscretizeRegion[
Cuboid[{Len/2 - hwd/2, -hwd/2, 0}, {Len/2 + hwd/2, hwd/2, ht}],
MaxCellMeasure -> ∞
];
reg = RegionDifference[R1, R2];
mesh = ToElementMesh[reg]


ElementMesh[{{0., 1.}, {-0.25, 0.25}, {0., 0.125}}, {TetrahedronElement["<" 13557 ">"]}]

• This does the job. Thanks.
– Hugh
Mar 14, 2019 at 17:34
• Hugh, you're welcome. Mar 14, 2019 at 18:15

May I suggest using MeshTools package? It offers more flexibility and alternative solutions for generating meshes on simple geometries.

Needs["NDSolveFEM"];
Len = 1;(*length*)
ht = 0.125;(*height*)
wd = 0.5;(*width*)
hwd = 0.25;(*hole width*)

region2D = RegionDifference[
Rectangle[{0, 0}, {Len, wd}],
Rectangle[{(Len - hwd)/2, (wd - hwd)/2}, {(Len + hwd)/2, (wd + hwd)/2}]
];

Needs["MeshTools"];
mesh2D = SmoothenMesh@TriangleToQuadMesh@ToElementMesh[
region2D,
"MeshOrder" -> 1,
MaxCellMeasure -> {"Length" -> 0.1}
]

mesh2D["Wireframe"]


mesh3D = ExtrudeMesh[mesh2D, ht, 5]

mesh3D["Wireframe"["MeshElementStyle" -> FaceForm@LightBlue]]


• Package looks excellent. I will look further. Are the elements produced capable of being used in NDSolve for finite element analysis? I think NDSolve can only use cuboid or tetrahedral elements. Am I correct?
– Hugh
Mar 14, 2019 at 17:34
• @Hugh Thank you! I am constantly improving the package to make it of production quality. Yes, of course, you can use this mesh with HexahedronElements in NDSolve` and related functions. You can also create a "structured" mesh on you simple shape and get very high quality mesh with lower number of DOF. Mar 15, 2019 at 7:45