.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/Beam/Beam1.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_Beam_Beam1.py: Beam1 ===== Beam subjected to pure tensile loading. .. GENERATED FROM PYTHON SOURCE LINES 11-103 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/Beam/images/sphx_glr_Beam1_001.png :alt: SEG2: Ne = 10, Nn = 11 :srcset: /examples/Beam/images/sphx_glr_Beam1_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/Beam/images/sphx_glr_Beam1_002.png :alt: Boundary conditions :srcset: /examples/Beam/images/sphx_glr_Beam1_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/Beam/images/sphx_glr_Beam1_003.png :alt: $ux^{e}$ :srcset: /examples/Beam/images/sphx_glr_Beam1_003.png :class: sphx-glr-multi-img * .. image-sg:: /examples/Beam/images/sphx_glr_Beam1_004.png :alt: $u_x(x)$ :srcset: /examples/Beam/images/sphx_glr_Beam1_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none err ux: 6.09e-14 % ==================== Mesh ==================== Element type: SEG2 Ne = 10, Nn = 11, dof = 11 ==================== Model ==================== solver : pypardiso ============= Boundary Conditions ============= Unspecified. =================== Results =================== Ux max = 4.45e-05 Ux min = 0.00e+00 =================== TicTac =================== Mesh : 17.927 ms Boundary Conditions : 35.763 µs Matrix : 13.168 ms Solver : 41.186 ms Display : 94.270 ms PostProcessing : 168.324 µs | .. code-block:: Python :lineno-start: 12 from EasyFEA import Display, Models, plt, np, Mesher, ElemType, Simulations from EasyFEA.Geoms import Domain, Line if __name__ == "__main__": Display.Clear() # ---------------------------------------------- # Configuration # ---------------------------------------------- # geom L = 10 nL = 10 h = 0.1 b = 0.1 # model E = 200000e6 ro = 7800 v = 0.3 # load g = 10 q = ro * g * (h * b) load = 5000 # ---------------------------------------------- # Mesh # ---------------------------------------------- elemType = ElemType.SEG2 beamDim = 1 # Create a section for the beam mesher = Mesher() section = mesher.Mesh_2D(Domain((0, 0), (b, h))) p1 = (0, 0) p2 = (L, 0) line = Line(p1, p2, L / nL) beam = Models.BeamElasIsot(beamDim, line, section, E, v) mesh = mesher.Mesh_Beams([beam], elemType=elemType) # ---------------------------------------------- # Simulation # ---------------------------------------------- # Initialize the beam structure with the defined beam segments beamStructure = Models.BeamStructure([beam]) # Create the beam simulation simu = Simulations.BeamSimu(mesh, beamStructure) dof_n = simu.Get_dof_n() # Apply boundary conditions simu.add_dirichlet(mesh.Nodes_Point(p1), [0] * dof_n, simu.Get_unknowns()) simu.add_lineLoad(mesh.nodes, [q], ["x"]) simu.add_neumann(mesh.Nodes_Point(p2), [load], ["x"]) # Solve the beam problem and get displacement results sol = simu.Solve() simu.Save_Iter() # ---------------------------------------------- # Results # ---------------------------------------------- Display.Plot_Mesh(simu, deformFactor=L / 10 / sol.max()) Display.Plot_BoundaryConditions(simu) Display.Plot_Result(simu, "ux") ux = simu.Result("ux") x_array = np.linspace(0, L, 100) u_x = (load * x_array / (E * (section.area))) + ( ro * g * x_array / 2 / E * (2 * L - x_array) ) err_ux = np.abs(u_x[-1] - ux.max()) / ux.max() Display.MyPrint(f"err ux: {err_ux * 100:.2e} %") # Plot the analytical and finite element solutions for displacement (u) ax = Display.Init_Axes() ax.plot(x_array, u_x, label="Analytical", c="blue") ax.scatter(mesh.coord[:, 0], ux, label="FE", c="red", marker="x", zorder=2) ax.set_title("$u_x(x)$") ax.legend() print(simu) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.225 seconds) .. _sphx_glr_download_examples_Beam_Beam1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Beam1.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Beam1.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: Beam1.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_