Note
Go to the end to download the full example code.
Beam6#
A cantilever beam undergoing bending deformation in dynamic.

Generate movie 01/20 (5.00 %) 3.98 s
Generate movie 02/20 (10.00 %) 1.67 s
Generate movie 03/20 (15.00 %) 1.58 s
Generate movie 04/20 (20.00 %) 1.49 s
Generate movie 05/20 (25.00 %) 1.38 s
Generate movie 06/20 (30.00 %) 1.33 s
Generate movie 07/20 (35.00 %) 1.23 s
Generate movie 08/20 (40.00 %) 1.10 s
Generate movie 09/20 (45.00 %) 1.01 s
Generate movie 10/20 (50.00 %) 914.34 ms
Generate movie 11/20 (55.00 %) 819.75 ms
Generate movie 12/20 (60.00 %) 736.10 ms
Generate movie 13/20 (65.00 %) 669.95 ms
Generate movie 14/20 (70.00 %) 562.10 ms
Generate movie 15/20 (75.00 %) 466.53 ms
Generate movie 16/20 (80.00 %) 372.67 ms
Generate movie 17/20 (85.00 %) 278.02 ms
Generate movie 18/20 (90.00 %) 183.85 ms
Generate movie 19/20 (95.00 %) 92.78 ms
Generate movie 20/20 (100.00 %) 0.00 µs
==================== Mesh ====================
Element type: SEG3
Ne = 10, Nn = 21
==================== Model ====================
<EasyFEA.Models.Beam._beam.BeamStructure object at 0x74a3aab1b590>
solver:scipy
============= Boundary Conditions =============
Unspecified.
=================== Results ===================
Ux max = -0.00e+00
Ux min = -0.00e+00
Uy max = 0.00e+00
Uy min = -5.75e-01
=================== TicTac ===================
Mesh: 18.784 ms
Boundary Conditions: 29.564 µs
Matrix: 18.968 ms
Solver: 92.484 ms
Display: 14.690 ms
PyVista_Interface: 3.135 s
13 import matplotlib.pyplot as plt
14
15 from EasyFEA import Folder, Display, Models, Mesher, Simulations, Paraview, PyVista
16 from EasyFEA.Geoms import Domain, Line
17
18 if __name__ == "__main__":
19 Display.Clear()
20
21 # ----------------------------------------------
22 # Configuration
23 # ----------------------------------------------
24
25 # outputs
26 folder = Folder.Results_Dir()
27 makeParaview = False
28 makeMovie = True
29 result = "uy"
30
31 # geom
32 L = 120
33 nL = 10
34 h = 13
35 b = 13
36 e = 3
37
38 # model
39 E = 210000
40 v = 0.3
41 rho = 7850 * 1e-9
42 beamDim = 2 # must be >= 2
43
44 # load
45 load = 800
46
47 # time
48 Tmax = 1 / 2
49 N = 50
50 dt = Tmax / N
51
52 # ----------------------------------------------
53 # Mesh
54 # ----------------------------------------------
55
56 # Create a section object for the beam mesh
57 domain1 = Domain((0, 0), (b, h), h / 10)
58 domain2 = Domain((e, e), (b - e, h - e), h / 10)
59 section = domain1.Mesh_2D([domain2])
60
61 p1 = (0, 0)
62 p2 = (L, 0)
63 line = Line(p1, p2, L / nL)
64 beam = Models.Beam.Isotropic(beamDim, line, section, E, v)
65
66 mesh = Mesher().Mesh_Beams([beam])
67
68 # ----------------------------------------------
69 # Simulation
70 # ----------------------------------------------
71
72 # Initialize the beam structure with the defined beam segments
73 beamStructure = Models.Beam.BeamStructure([beam])
74
75 # Create the beam simulation
76 simu = Simulations.Beam(mesh, beamStructure)
77 simu.rho = rho
78 dof_n = simu.Get_dof_n()
79
80 # Apply boundary conditions
81 simu.add_dirichlet(mesh.Nodes_Point(p1), [0] * dof_n, simu.Get_unknowns())
82 simu.add_neumann(mesh.Nodes_Point(p2), [-load], ["y"])
83
84 # Solve the beam problem and get displacement results
85 sol = simu.Solve()
86 simu.Save_Iter()
87
88 simu.Solver_Set_Hyperbolic_Algorithm(dt)
89 simu.Bc_Init()
90 simu.add_dirichlet(mesh.Nodes_Point(p1), [0] * dof_n, simu.Get_unknowns())
91
92 for _ in range(N):
93 simu.Solve()
94 simu.Save_Iter()
95
96 # ----------------------------------------------
97 # Results
98 # ----------------------------------------------
99
100 Display.Plot_BoundaryConditions(simu)
101
102 if makeParaview:
103 Paraview.Save_simu(simu, folder)
104
105 deform = 10
106 if makeMovie:
107 PyVista.Movie_simu(
108 simu,
109 f"{result}",
110 folder,
111 f"{result}.gif",
112 N=20,
113 deformFactor=deform,
114 plotMesh=True,
115 )
116
117 print(simu)
118
119 Display.Plot_Result(simu, result, deformFactor=deform)
120 ax = Display.Plot_Mesh(section)
121 ax.set_title("Section")
122 Display.Plot_Mesh(simu, deformFactor=deform)
123
124 plt.show()
Total running time of the script: (0 minutes 3.675 seconds)



