Ensuring on 3D tets are generated
Hi,
I'm trying to mesh a geometry with periodic constraints using only 3D tetrahedral elements. At the moment I am struggling to avoid the formation of pyramids alongside the tet elements - is there any command I can use in the gmsh python api that will force all elements to be 3D tets regardless of the 3D geometry? Below is an example MWE of what I am trying to do:
import gmsh
import meshio
gmsh.initialize()
gmsh.option.setNumber("Geometry.OCCBoundsUseStl", 1)
gmsh.option.setNumber("Mesh.RecombineAll", 1)
gmsh.option.setNumber("Mesh.Algorithm3D", 1)
# Create cylinder as example geometry to be meshed
cyl = gmsh.model.occ.addCylinder(0,0.5,0.5,1,0,0,0.2)
gmsh.model.occ.synchronize()
# Periodicity constraint adapted from t18.py
eps = 1e-3
# Bounding box of domain
vin = gmsh.model.getEntitiesInBoundingBox(0 - eps, -eps, -eps, 1 + eps,
1 + eps, 1 + eps, 3)
p = gmsh.model.getBoundary(vin, False, False, True) # Get all points
x_translation = [1, 0, 0, 1,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1]
# Extract xmin surface
xmin_surfaces = gmsh.model.getEntitiesInBoundingBox(0 - eps, 0-eps, 0-eps,
0 + eps, 1 + eps, 1 + eps, 2)
for i in xmin_surfaces:
xmin, ymin, zmin, xmax, ymax, zmax = gmsh.model.getBoundingBox(i[0], i[1])
xmax_surfaces = gmsh.model.getEntitiesInBoundingBox(xmin - eps + 1, ymin - eps,
zmin - eps, xmax + eps + 1,
ymax + eps, zmax + eps, 2)
for j in xmax_surfaces:
xmin2, ymin2, zmin2, xmax2, ymax2, zmax2 = gmsh.model.getBoundingBox(
j[0], j[1])
xmin2 -= 1
xmax2 -= 1
# ...and if they match, we apply the periodicity constraint
if (abs(xmin2 - xmin) < eps and abs(xmax2 - xmax) < eps
and abs(ymin2 - ymin) < eps and abs(ymax2 - ymax) < eps
and abs(zmin2 - zmin) < eps and abs(zmax2 - zmax) < eps):
gmsh.model.mesh.setPeriodic(2, [j[1]], [i[1]], x_translation)
gmsh.model.addPhysicalGroup(3, [1], 101)
gmsh.model.mesh.recombine()
gmsh.model.mesh.setSize(p, 0.025)
# Enforce linear elements are used
gmsh.model.mesh.setOrder(1)
# Generate mesh
gmsh.model.mesh.generate(3)
gmsh.write("test.msh")
mesh = meshio.read("test.msh")
print (mesh)
# Number of points: 13621
# Number of cells:
# tetra: 76665
# pyramid: 1326 <<--- Avoid formation of pyramid