Note
Go to the end to download the full example code.
Elas9#
Wave propagation.

0.000 %
5.000 %
10.000 %
15.000 %
20.000 %
25.000 %
30.000 %
35.000 %
40.000 %
45.000 %
50.000 %
55.000 %
60.000 %
65.000 %
70.000 %
75.000 %
80.000 %
85.000 %
90.000 %
95.000 %
100.000 %
Generate movie 01/21 (4.76 %) 3.37 s
Generate movie 02/21 (9.52 %) 3.36 s
Generate movie 03/21 (14.29 %) 3.15 s
Generate movie 04/21 (19.05 %) 2.98 s
Generate movie 05/21 (23.81 %) 2.85 s
Generate movie 06/21 (28.57 %) 2.64 s
Generate movie 07/21 (33.33 %) 2.47 s
Generate movie 08/21 (38.10 %) 2.30 s
Generate movie 09/21 (42.86 %) 2.17 s
Generate movie 10/21 (47.62 %) 1.94 s
Generate movie 11/21 (52.38 %) 1.80 s
Generate movie 12/21 (57.14 %) 1.59 s
Generate movie 13/21 (61.90 %) 1.40 s
Generate movie 14/21 (66.67 %) 1.22 s
Generate movie 15/21 (71.43 %) 1.05 s
Generate movie 16/21 (76.19 %) 872.66 ms
Generate movie 17/21 (80.95 %) 697.22 ms
Generate movie 18/21 (85.71 %) 525.41 ms
Generate movie 19/21 (90.48 %) 351.22 ms
Generate movie 20/21 (95.24 %) 176.98 ms
Generate movie 21/21 (100.00 %) 0.00 µs
11 # TODO: Compare results with analytical values.
12
13 from EasyFEA import Folder, Display, Models, Tic, plt, ElemType, Simulations, PyVista
14 from EasyFEA.Geoms import Domain, Circle, Line
15
16 if __name__ == "__main__":
17 Display.Clear()
18
19 # ----------------------------------------------
20 # Configuration
21 # ----------------------------------------------
22
23 # outputs
24 folder = Folder.Results_Dir()
25 plotModel = False
26 plotIter = False
27 makeMovie = True
28 result = "speed_norm"
29
30 # Define geometric parameters
31 a = 1
32 meshSize = a / 50
33 diam = a / 10
34 r = diam / 2
35
36 # Time parameters
37 tMax = 1e-6
38 Nt = 20
39 dt = tMax / Nt
40
41 # Load parameters
42 load = 1e-3
43 f0 = 2
44 a0 = 1
45 t0 = dt * 4
46
47 # ----------------------------------------------
48 # Mesh
49 # ----------------------------------------------
50
51 # Define the domain and create the mesh
52 domain = Domain((-a / 2, -a / 2), (a / 2, a / 2), meshSize)
53 circle = Circle((0, 0), diam, meshSize, isHollow=False)
54 line = Line((0, 0), (diam / 4, 0))
55 mesh = domain.Mesh_2D([circle], ElemType.TRI6, cracks=[line])
56
57 # Plot the model if specified
58 if plotModel:
59 Display.Plot_Tags(mesh)
60 plt.show()
61
62 # Get nodes for boundary conditions and loading
63 nodesBorders = mesh.Nodes_Tags(["L0", "L1", "L2", "L3"])
64 nodesLoad = mesh.Nodes_Point((0, 0))
65
66 # ----------------------------------------------
67 # Simulation
68 # ----------------------------------------------
69
70 # Define material properties
71 material = Models.Elastic.Isotropic(
72 2, E=210000e6, v=0.3, planeStress=False, thickness=1
73 )
74 lmbda = material.get_lambda()
75 mu = material.get_mu()
76
77 # Create the simulation object
78 simu = Simulations.Elastic(mesh, material)
79 simu.Set_Rayleigh_Damping_Coefs(1e-10, 1e-10)
80 simu.Solver_Set_Hyperbolic_Algorithm(beta=1 / 4, gamma=1 / 2, dt=dt)
81
82 # Plot the result at the initial iteration if specified
83 if plotIter:
84 ax = Display.Plot_Result(simu, result, nodeValues=True, title=result)
85
86 # Create a timer object
87 tic = Tic()
88
89 # Time loop
90 t = 0
91 while t <= tMax:
92
93 simu.Bc_Init()
94
95 # Set displacement boundary conditions
96 simu.add_dirichlet(nodesBorders, [0, 0], ["x", "y"], description="[0,0]")
97
98 # Set Neumann boundary conditions (loading) at t = t0
99 if t == t0:
100 simu.add_neumann(nodesLoad, [load], ["x"])
101
102 # Solve the simulation
103 simu.Solve()
104
105 # Save the iteration results
106 simu.Save_Iter()
107
108 # Print the progress
109 print(f"{t / tMax * 100:.3f} %", end="\r")
110
111 # Update the plot at each iteration if specified
112 if plotIter:
113 ax = Display.Plot_Result(simu, result, nodeValues=True, ax=ax, title=result)
114 plt.pause(1e-12)
115
116 t += dt
117
118 # ----------------------------------------------
119 # Results
120 # ----------------------------------------------
121
122 if makeMovie:
123 PyVista.Movie_simu(
124 simu,
125 f"{result}",
126 folder,
127 f"{result}.gif",
128 )
129
130 plt.show()
Total running time of the script: (0 minutes 22.772 seconds)