File: lshape3d.py

package info (click to toggle)
python-meshzoo 0.9.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 316 kB
  • sloc: python: 1,691; makefile: 8
file content (57 lines) | stat: -rw-r--r-- 1,497 bytes parent folder | download
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
51
52
53
54
55
56
57
"""Creates meshes on a 3D L-shape.
"""
import meshpy.tet
import numpy as np


def create_mesh(maxvol):
    # circumcirlce radius
    cc_radius = 10.0
    lx = 2.0 / np.sqrt(3.0) * cc_radius
    ly = lx
    lz = lx

    # create the mesh data structure
    # 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.0, -0.5 * ly, 0.5 * lz),
        (0.0, -0.5 * ly, 0.0),
        (0.5 * lx, -0.5 * ly, 0.0),
        (0.5 * lx, 0.0, 0.0),
        (0.5 * lx, 0.0, 0.5 * lz),
        (0.0, 0.0, 0.5 * lz),
        (0.0, 0.0, 0.0),
    ]
    facets = [
        [0, 1, 2, 3],
        [4, 7, 12, 11, 5, 6],
        [0, 1, 9, 8, 7, 4],
        [1, 2, 5, 11, 10, 9],
        [2, 5, 6, 3],
        [3, 6, 4, 0],
        [8, 13, 12, 7],
        [8, 9, 10, 13],
        [10, 11, 12, 13],
    ]
    # create the mesh
    # Set the geometry and build 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("lshape3d.e", points, {"tetra": cells})