Note
Go to the end to download the full example code.
Mesh9#
Meshing of a perforated plate with a structured mesh.


============= Init GMSH interface =============
gmsh.model.mesh.generate (1.429 ms)
Remove duplicate nodes and elements (1.280 ms)
Create SEG2 (8.979 ms)
Create QUAD4 (2.890 ms)
Create POINT (7.232 ms)
Construct mesh object (35.048 µs)
Element type: QUAD4
Ne = 200, Nn = 240
13 import numpy as np
14
15 from EasyFEA import Display, Mesher, ElemType, PyVista
16 from EasyFEA.Geoms import Point, Circle, Points, Line, CircleArc, Contour
17
18 if __name__ == "__main__":
19 dim = 2
20
21 if dim == 2:
22 elemType = ElemType.QUAD4
23 else:
24 elemType = ElemType.HEXA8
25
26 Display.Clear()
27
28 # ----------------------------------------------
29 # Geom
30 # ----------------------------------------------
31 H = 90
32 L = 45
33 D = 10
34 e = 20
35
36 N = 5
37 mS = (np.pi / 4 * D / 2) / N
38
39 # PI for Points
40 # pi for gmsh points
41 PC = Point(L / 2, H / 2, 0)
42 circle = Circle(PC, D, mS)
43
44 P1 = Point()
45 P2 = Point(L, 0)
46 P3 = Point(L, H)
47 P4 = Point(0, H)
48 contour1 = Points(
49 [
50 (P3 + P2) / 2,
51 P3,
52 (P3 + P4) / 2,
53 P4,
54 (P4 + P1) / 2,
55 P1,
56 (P1 + P2) / 2,
57 P2,
58 (P3 + P2) / 2,
59 ],
60 mS,
61 )
62
63 # ----------------------------------------------
64 # Mesh
65 # ----------------------------------------------
66 mesher = Mesher(False, True, True)
67 factory = mesher._factory
68
69 contours1: list[Contour] = []
70
71 for c in range(4):
72 pc = circle.center
73 contour = circle.Get_Contour()
74 pc1 = contour.geoms[c].pt1
75 pc2 = contour.geoms[c].pt2
76 pc3 = contour.geoms[c].pt3
77
78 p1, p2, p3 = contour1.points[c * 2 : c * 2 + 3]
79
80 cont1 = Contour(
81 [Line(pc1, p1), Line(p1, p2), Line(p2, pc3), CircleArc(pc3, pc1, pc)]
82 )
83 loop1, lines1, points1 = mesher._Loop_From_Geom(cont1)
84
85 cont2 = Contour(
86 [Line(pc3, p2), Line(p2, p3), Line(p3, pc2), CircleArc(pc2, pc3, pc)]
87 )
88 loop2, lines2, points2 = mesher._Loop_From_Geom(cont2)
89
90 surf1 = factory.addSurfaceFilling(loop1)
91 surf2 = factory.addSurfaceFilling(loop2)
92
93 mesher._Surfaces_Organize([surf1, surf2], elemType, True, [N] * 4)
94
95 contours1.extend([cont1, cont2])
96
97 PyVista.Plot_Geoms(contours1).show()
98
99 if dim == 3:
100 for cont1 in contours1:
101 cont2 = cont1.copy()
102 cont2.Translate(dz=e)
103 # cont2.rotate(np.pi/8, PC.coord)
104 mesher._Link_Contours(cont1, cont2, elemType, 3, [N] * 4)
105
106 mesher._Set_PhysicalGroups()
107
108 mesher._Mesh_Generate(dim, elemType)
109
110 mesh = mesher._Mesh_Get_Mesh()
111
112 if len(mesh.orphanNodes) > 0:
113 plotter = PyVista.Plot_Nodes(mesh, mesh.orphanNodes)
114 plotter.add_title("Orphan nodes detected")
115 plotter.show()
116
117 PyVista.Plot_Mesh(mesh).show()
Total running time of the script: (0 minutes 0.622 seconds)