Note
Go to the end to download the full example code.
Mesh13#
Mesh a heterogeneous RVE with cracks.



/home/docs/checkouts/readthedocs.org/user_builds/easyfea/envs/v1.6.0/lib/python3.11/site-packages/EasyFEA/utilities/PyVista.py:973: PyVistaDeprecationWarning:
../../../../envs/v1.6.0/lib/python3.11/site-packages/EasyFEA/utilities/PyVista.py:973: Arguments 'pointa', 'pointb', 'center' must be passed as keyword arguments to function 'CircularArc'.
From version 0.50, passing these as positional arguments will result in a TypeError.
arc1 = pv.CircularArc(geom.pt1.coord, geom.pt3.coord, geom.center.coord)
/home/docs/checkouts/readthedocs.org/user_builds/easyfea/envs/v1.6.0/lib/python3.11/site-packages/EasyFEA/utilities/PyVista.py:974: PyVistaDeprecationWarning:
../../../../envs/v1.6.0/lib/python3.11/site-packages/EasyFEA/utilities/PyVista.py:974: Arguments 'pointa', 'pointb', 'center' must be passed as keyword arguments to function 'CircularArc'.
From version 0.50, passing these as positional arguments will result in a TypeError.
arc2 = pv.CircularArc(
12 from EasyFEA import Display, ElemType, PyVista
13 from EasyFEA.Geoms import Point, Line, Domain, Circle
14
15 if __name__ == "__main__":
16 Display.Clear()
17
18 # ----------------------------------------------
19 # Configuration
20 # ----------------------------------------------
21
22 # geom
23 L = 1
24
25 # mesh
26 elemType = ElemType.TRI3
27 meshSize = L / 40
28
29 # ----------------------------------------------
30 # Functions
31 # ----------------------------------------------
32
33 def Create_Crack(
34 pt1: tuple[float, float], pt2: tuple[float, float], isOpen=True
35 ) -> Line:
36 """Creates a crack.
37
38 Parameters
39 ----------
40 pt1 : tuple[float, float]
41 Point 1 (x, y)
42 pt2 : tuple[float, float]
43 Point 2 (x, y)
44 isOpen : bool, optional
45 The crack is open, by default True
46
47 Returns
48 -------
49 Line
50 The crack
51 """
52
53 assert len(pt1) == 2, "Must give 2 coordinates"
54 assert len(pt2) == 2, "Must give 2 coordinates"
55
56 pt1 = Point(*pt1)
57 pt2 = Point(*pt2)
58
59 return Line(pt1, pt2, meshSize, isOpen)
60
61 def Create_Circle(pt: tuple[float, float], diam: float, isHollow=False) -> Circle:
62 """Creates a circle.
63
64 Parameters
65 ----------
66 pt : tuple[float, float]
67 center point (x, y)
68 diam : float
69 diameter
70 isHollow : bool, optional
71 circle is hollow/empty, by default True
72
73 Returns
74 -------
75 Circle
76 The circle
77 """
78
79 assert len(pt) == 2, "Must give 2 coordinates"
80
81 center = Point(*pt)
82
83 return Circle(center, diam, meshSize / 2, isHollow)
84
85 # ----------------------------------------------
86 # Mesh
87 # ----------------------------------------------
88
89 # contour
90 contour = Domain(Point(), Point(L, L), meshSize)
91
92 # circles
93 circle1 = Create_Circle((L / 4, L / 4), L / 10)
94 circle2 = Create_Circle((3 * L / 4, L / 4), L / 8)
95 circle3 = Create_Circle((3 * L / 4, 3 * L / 4), L / 6)
96 circle4 = Create_Circle((L / 4, 3 * L / 4), L / 5)
97 circle5 = Create_Circle((L / 2, L / 2), L / 3, isHollow=True)
98 circle6 = Create_Circle((L, L), L / 6, isHollow=True)
99
100 inclusions = [circle1, circle2, circle3, circle4, circle5]
101
102 # cracks
103 crack1 = Create_Crack((3 * L / 5, L / 10), (4 * L / 5, L / 10))
104 crack2 = Create_Crack((L / 10, L / 2), (2 * L / 10, L / 2 - L / 10))
105 crack3 = Create_Crack(
106 (8 * L / 10, 5 * L / 10), (8 * L / 10 + L / 20, 5 * L / 10 + L / 20)
107 )
108
109 cracks = [crack1, crack2, crack3]
110
111 PyVista.Plot_Geoms([contour, *inclusions, *cracks, circle6]).show()
112
113 # mesh
114 mesh = contour.Mesh_2D(inclusions, elemType, cracks, additionalSurfaces=[circle6])
115
116 # ----------------------------------------------
117 # Display
118 # ----------------------------------------------
119
120 PyVista.Plot_Mesh(mesh).show()
121 PyVista.Plot_Tags(mesh).show()
Total running time of the script: (0 minutes 3.827 seconds)