ToElementMesh of Region with Hole
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 ">"]}]
May I suggest using MeshTools package? It offers more flexibility and alternative solutions for generating meshes on simple geometries.
Needs["NDSolve`FEM`"];
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]]