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


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