Note
Go to the end to download the full example code.
Mesh8#
Meshing of a grooved 3D part with calculation of element quality.

Element type: TETRA4
Ne = 12305, Nn = 3996
volume = 658.400
12 from EasyFEA import Display, np, Mesher, ElemType, gmsh, PyVista
13 from EasyFEA.Geoms import Point, Circle, Points
14
15 if __name__ == "__main__":
16 Display.Clear()
17
18 # ----------------------------------------------
19 # Geom
20 # ----------------------------------------------
21 R = 10
22 e = 2
23 r = R - e
24 h = R * 2 / 3
25
26 meshSize = e / 3
27
28 center = Point()
29
30 circle_ext = Circle(center, R * 2, meshSize)
31 circle_int = Circle(center, r * 2, meshSize, True)
32
33 useFillet = circle_int.isHollow
34 addCylinder = True
35 addBox = True
36 addRevolve = True
37
38 # ----------------------------------------------
39 # Mesh
40 # ----------------------------------------------
41
42 mesher = Mesher(False, False)
43 # dim, elemType = 2, ElemType.TRI3
44 dim, elemType = 3, ElemType.TETRA4
45
46 factory = mesher._factory
47
48 surfaces = mesher._Surfaces(circle_ext, [circle_int])[0]
49 mesher._Extrude(surfaces, [0, 0, R], elemType)
50 vol1 = factory.getEntities(3)
51
52 mesher._Synchronize()
53
54 if useFillet:
55 surfs = gmsh.model.getBoundary(vol1)
56 lines = gmsh.model.getBoundary(surfs, False)
57 gmsh.model.occ.fillet([vol1[0][1]], [abs(line[1]) for line in lines], [e / 3])
58
59 if addCylinder:
60 cylinder = factory.addCylinder(R + e, 0, h, -2 * R - e, 0, 0, e)
61 factory.cut(vol1, [(3, cylinder)])
62
63 if addBox:
64 box = factory.addBox(-R / 4, -R - e, R / 2, R / 2, 2 * R + e, R / 2)
65 factory.cut(factory.getEntities(3), [(3, box)])
66
67 if addRevolve:
68 p1 = Point(R - e / 2, 0, e, r=e / 4)
69 p2 = Point(R, 0, e)
70 p3 = Point(R, 0, e * 4)
71 p4 = Point(R - e / 2, 0, e * 4, r=e / 4)
72 contour = Points([p1, p2, p3, p4])
73 surf = mesher._Surfaces(contour, [])[0][0]
74
75 rev1 = factory.revolve([(2, surf)], 0, 0, 0, 0, 0, R, np.pi)
76 rev2 = factory.revolve([(2, surf)], 0, 0, 0, 0, 0, R, -np.pi)
77 factory.cut(factory.getEntities(3), [rev1[1], rev2[1]])
78
79 mesher._Synchronize()
80
81 if meshSize > 0:
82 mesher.Set_meshSize(meshSize)
83
84 mesher._Set_PhysicalGroups(
85 setPoints=False, setLines=True, setSurfaces=True, setVolumes=False
86 )
87
88 mesher._Mesh_Generate(dim, elemType)
89
90 mesh = mesher._Mesh_Get_Mesh()
91
92 # ----------------------------------------------
93 # Plot
94 # ----------------------------------------------
95
96 print(mesh)
97
98 if dim == 3:
99 print(f"volume = {mesh.volume:.3f}")
100
101 plotter = PyVista._Plotter(shape=(1, 2))
102
103 PyVista.Plot_Mesh(mesh, plotter=plotter)
104
105 plotter.subplot(0, 1)
106 plotter.add_title("aspect ratio")
107 qual = mesh.Get_Quality()
108 PyVista.Plot_Elements(mesh, dimElem=1, plotter=plotter, color="k")
109 PyVista.Plot(
110 mesh,
111 qual,
112 nodeValues=False,
113 cmap="viridis",
114 clim=(0, 1),
115 plotMesh=True,
116 plotter=plotter,
117 ).show()
Total running time of the script: (0 minutes 2.659 seconds)