Note
Go to the end to download the full example code.
Beam1#
Beam subjected to pure tensile loading.
err ux: 6.09e-14 %
==================== Mesh ====================
Element type: SEG2
Ne = 10, Nn = 11
==================== Model ====================
<EasyFEA.models._beam.BeamStructure object at 0x79b8587044d0>
solver : pypardiso
============= Boundary Conditions =============
Unspecified.
=================== Results ===================
Ux max = 4.45e-05
Ux min = 0.00e+00
=================== TicTac ===================
Mesh : 18.340 ms
Boundary Conditions : 38.385 µs
Matrix : 14.158 ms
Solver : 48.042 ms
Display : 100.554 ms
PostProcessing : 189.543 µs
12 from EasyFEA import Display, Models, plt, np, Mesher, ElemType, Simulations
13 from EasyFEA.Geoms import Domain, Line
14
15 if __name__ == "__main__":
16 Display.Clear()
17
18 # ----------------------------------------------
19 # Configuration
20 # ----------------------------------------------
21
22 # geom
23 L = 10
24 nL = 10
25 h = 0.1
26 b = 0.1
27
28 # model
29 E = 200000e6
30 ro = 7800
31 v = 0.3
32
33 # load
34 g = 10
35 q = ro * g * (h * b)
36 load = 5000
37
38 # ----------------------------------------------
39 # Mesh
40 # ----------------------------------------------
41
42 elemType = ElemType.SEG2
43 beamDim = 1
44
45 # Create a section for the beam
46 mesher = Mesher()
47 section = mesher.Mesh_2D(Domain((0, 0), (b, h)))
48
49 p1 = (0, 0)
50 p2 = (L, 0)
51 line = Line(p1, p2, L / nL)
52 beam = Models.BeamElasIsot(beamDim, line, section, E, v)
53
54 mesh = mesher.Mesh_Beams([beam], elemType=elemType)
55
56 # ----------------------------------------------
57 # Simulation
58 # ----------------------------------------------
59
60 # Initialize the beam structure with the defined beam segments
61 beamStructure = Models.BeamStructure([beam])
62
63 # Create the beam simulation
64 simu = Simulations.BeamSimu(mesh, beamStructure)
65 dof_n = simu.Get_dof_n()
66
67 # Apply boundary conditions
68 simu.add_dirichlet(mesh.Nodes_Point(p1), [0] * dof_n, simu.Get_unknowns())
69 simu.add_lineLoad(mesh.nodes, [q], ["x"])
70 simu.add_neumann(mesh.Nodes_Point(p2), [load], ["x"])
71
72 # Solve the beam problem and get displacement results
73 sol = simu.Solve()
74 simu.Save_Iter()
75
76 # ----------------------------------------------
77 # Results
78 # ----------------------------------------------
79
80 Display.Plot_Mesh(simu, deformFactor=L / 10 / sol.max())
81 Display.Plot_BoundaryConditions(simu)
82 Display.Plot_Result(simu, "ux")
83
84 ux = simu.Result("ux")
85
86 x_array = np.linspace(0, L, 100)
87 u_x = (load * x_array / (E * (section.area))) + (
88 ro * g * x_array / 2 / E * (2 * L - x_array)
89 )
90 err_ux = np.abs(u_x[-1] - ux.max()) / ux.max()
91 Display.MyPrint(f"err ux: {err_ux * 100:.2e} %")
92
93 # Plot the analytical and finite element solutions for displacement (u)
94 ax = Display.Init_Axes()
95 ax.plot(x_array, u_x, label="Analytical", c="blue")
96 ax.scatter(mesh.coord[:, 0], ux, label="FE", c="red", marker="x", zorder=2)
97 ax.set_title("$u_x(x)$")
98 ax.legend()
99
100 print(simu)
101
102 plt.show()
Total running time of the script: (0 minutes 0.231 seconds)



