1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
"""
Creates meshes on a cube.
"""
import meshpy.tet
import numpy as np
def create_mesh(maxvol):
# get the file name to be written to
# circumcirlce radius
cc_radius = 5.0
lx = 2.0 / np.sqrt(3.0) * cc_radius
ly = lx
lz = lx
# Corner points of the cube
points = [
(-0.5 * lx, -0.5 * ly, -0.5 * lz),
(0.5 * lx, -0.5 * ly, -0.5 * lz),
(0.5 * lx, 0.5 * ly, -0.5 * lz),
(-0.5 * lx, 0.5 * ly, -0.5 * lz),
(-0.5 * lx, -0.5 * ly, 0.5 * lz),
(0.5 * lx, -0.5 * ly, 0.5 * lz),
(0.5 * lx, 0.5 * ly, 0.5 * lz),
(-0.5 * lx, 0.5 * ly, 0.5 * lz),
]
facets = [
[0, 1, 2, 3],
[4, 5, 6, 7],
[0, 4, 5, 1],
[1, 5, 6, 2],
[2, 6, 7, 3],
[3, 7, 4, 0],
]
# create the mesh
info = meshpy.tet.MeshInfo()
info.set_points(points)
info.set_facets(facets)
meshpy_mesh = meshpy.tet.build(info, max_volume=maxvol)
return np.array(meshpy_mesh.points), np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_mesh(0.1)
meshio.write("cube.e", points, {"tetra": cells})
|