Note
Go to the end to download the full example code.
Beam2#
A cantilever beam undergoing bending deformation.
err uy: 1.21e-10%
err rz: 1.13e-10%
err Mz: 1.28e-10%
err Ty: 2.24e-10%
==================== Mesh ====================
Element type: SEG2
Ne = 10, Nn = 11
==================== Model ====================
<EasyFEA.Models.Beam._beam.BeamStructure object at 0x796ead75c5d0>
solver:scipy
============= Boundary Conditions =============
Unspecified.
=================== Results ===================
Ux max = 0.00e+00
Ux min = 0.00e+00
Uy max = 0.00e+00
Uy min = -9.22e-01
=================== TicTac ===================
Mesh: 8.670 ms
Boundary Conditions: 11.921 µs
Matrix: 10.101 ms
Solver: 738.621 µs
Display: 27.816 ms
13 import matplotlib.pyplot as plt
14 import numpy as np
15
16 from EasyFEA import Display, Models, Mesher, ElemType, Simulations
17 from EasyFEA.Geoms import Domain, Line
18
19 if __name__ == "__main__":
20 Display.Clear()
21
22 # ----------------------------------------------
23 # Configuration
24 # ----------------------------------------------
25
26 # geom
27 L = 120
28 nL = 10
29 h = 13
30 b = 13
31
32 # model
33 E = 210000
34 v = 0.3
35 useTimoshenko = False
36
37 # load
38 F = -800 # applied tip force in y (negative = downward)
39
40 # ----------------------------------------------
41 # Mesh
42 # ----------------------------------------------
43
44 elemType = ElemType.SEG2
45 beamDim = 2 # must be >= 2
46
47 # Create a section object for the beam mesh
48 mesher = Mesher()
49 section = mesher.Mesh_2D(Domain((0, 0), (b, h)))
50
51 p1 = (0, 0)
52 p2 = (L, 0)
53 line = Line(p1, p2, L / nL)
54 beam = Models.Beam.Isotropic(beamDim, line, section, E, v)
55
56 mesh = mesher.Mesh_Beams([beam], elemType=elemType)
57
58 # ----------------------------------------------
59 # Simulation
60 # ----------------------------------------------
61
62 # Initialize the beam structure with the defined beam segments
63 beamStructure = Models.Beam.BeamStructure([beam])
64
65 # Create the beam simulation
66 simu = Simulations.Beam(mesh, beamStructure, useTimoshenko=useTimoshenko)
67 dof_n = simu.Get_dof_n()
68
69 # Apply boundary conditions
70 simu.add_dirichlet(mesh.Nodes_Point(p1), [0] * dof_n, simu.Get_unknowns())
71 simu.add_neumann(mesh.Nodes_Point(p2), [F], ["y"])
72
73 # Solve the beam problem and get displacement results
74 sol = simu.Solve()
75 simu.Save_Iter()
76
77 # ----------------------------------------------
78 # Results
79 # ----------------------------------------------
80
81 Display.Plot_Mesh(simu, deformFactor=-L / 10 / sol.min())
82 Display.Plot_BoundaryConditions(simu)
83 Display.Plot_Result(simu, "uy")
84
85 # beam properties
86 G = beam.mu
87 A = section.area
88 Iy = beam.Iy
89 Iz = beam.Iz
90
91 # ------------------------
92 # uy
93 # ------------------------
94
95 x = np.linspace(0, L, 100)
96 uy_x_eb = lambda x: F * (L * x**2 / 2 - x**3 / 6) / (E * Iz)
97 if simu.useTimoshenko:
98 # uy(x) = uy_EB(x) + F·x / (kGA) with k=1 (current default)
99 uy_x = lambda x: uy_x_eb(x) + F * x / (G * A)
100 else:
101 uy_x = uy_x_eb
102
103 uy = simu.Result("uy")
104 x_n = mesh.coord[:, 0]
105 err_uy = np.abs(uy_x(x_n) - uy).max() / np.abs(uy_x(L))
106 Display.MyPrint(f"\nerr uy: {err_uy * 100:.2e}%")
107
108 axUy = Display.Init_Axes()
109 axUy.plot(x, uy_x(x), label="Analytical", c="blue")
110 axUy.scatter(x_n, uy, label="FE", c="red", marker="x", zorder=2)
111 axUy.set_title("$u_y(x)$")
112 axUy.legend()
113
114 # ------------------------
115 # rz
116 # ------------------------
117
118 rz_x = lambda x: F / E / Iz * (L * x - x**2 / 2)
119
120 rz = simu.Result("rz")
121 err_rz = np.abs(rz_x(x_n) - rz).max() / np.abs(rz_x(L))
122 Display.MyPrint(f"\nerr rz: {err_rz * 100:.2e}%")
123
124 axRz = Display.Init_Axes()
125 axRz.plot(x, rz_x(x), label="Analytical", c="blue")
126 axRz.scatter(x_n, rz, label="FE", c="red", marker="x", zorder=2)
127 axRz.set_title("$r_z(x)$")
128 axRz.legend()
129
130 # ------------------------
131 # Mz
132 # ------------------------
133
134 Mz_x = lambda x: F * (L - x)
135
136 x_e = x_n[mesh.connect].mean(1) # element centroid x-coords
137 Mz = simu.Result("Mz", nodeValues=False)
138 err_Mz = np.abs(Mz_x(x_e) - Mz).max() / np.abs(Mz_x(x_e)).max()
139 Display.MyPrint(f"\nerr Mz: {err_Mz * 100:.2e}%")
140
141 axMz = Display.Init_Axes()
142 axMz.plot(x, Mz_x(x), label="Analytical", c="blue")
143 axMz.scatter(x_e, Mz, label="FE", c="red", marker="x", zorder=2)
144 axMz.set_title("$M_z(x)$")
145 axMz.legend()
146
147 # ------------------------
148 # Ty
149 # ------------------------
150
151 Ty = simu.Result("Ty", nodeValues=False)
152 err_Ty = np.abs(F - Ty).max() / np.abs(F)
153 Display.MyPrint(f"\nerr Ty: {err_Ty * 100:.2e}%")
154
155 axTy = Display.Init_Axes()
156 axTy.axhline(F, label="Analytical", c="blue")
157 axTy.scatter(x_e, Ty, label="FE", c="red", marker="x", zorder=2)
158 axTy.set_ylim(min(1.5 * F, -0.5 * F), max(1.5 * F, -0.5 * F))
159 axTy.set_title("$T_y(x)$")
160 axTy.legend()
161
162 print(simu)
163
164 plt.show()
Total running time of the script: (0 minutes 0.337 seconds)






