.. 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 12-125 .. 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 * .. image-sg:: /examples/Beam/images/sphx_glr_Beam1_005.png :alt: $N(x)$ :srcset: /examples/Beam/images/sphx_glr_Beam1_005.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none err ux: 1.52e-14% err N: 4.40e-14% ==================== Mesh ==================== Element type: SEG2 Ne = 10, Nn = 11 ==================== Model ==================== solver:scipy ============= Boundary Conditions ============= Unspecified. =================== Results =================== Ux max = 4.45e-05 Ux min = 0.00e+00 =================== TicTac =================== Mesh: 12.259 ms Boundary Conditions: 36.955 µs Matrix: 18.818 ms Solver: 2.685 ms Display: 39.283 ms | .. code-block:: Python :lineno-start: 13 import matplotlib.pyplot as plt import numpy as np from EasyFEA import Display, Models, 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 v = 0.3 rho = 7800 beamDim = 1 # load g = 10 q = rho * g * (h * b) F = 5000 # ---------------------------------------------- # Mesh # ---------------------------------------------- # 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.Beam.Isotropic(beamDim, line, section, E, v) mesh = mesher.Mesh_Beams([beam], elemType=ElemType.SEG2) # ---------------------------------------------- # Simulation # ---------------------------------------------- # Initialize the beam structure with the defined beam segments beamStructure = Models.Beam.BeamStructure([beam]) # Create the beam simulation simu = Simulations.Beam(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), [F], ["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 # ------------------------ A = section.area x = np.linspace(0, L, 100) ux_x = lambda x: (F * x / (E * A)) + (rho * g * x / 2 / E * (2 * L - x)) ux = simu.Result("ux") x_n = mesh.coord[:, 0] err_ux = np.abs(ux_x(x_n) - ux).max() / np.abs(ux_x(L)) Display.MyPrint(f"\nerr ux: {err_ux * 100:.2e}%") axUx = Display.Init_Axes() axUx.plot(x, ux_x(x), label="Analytical", c="blue") axUx.scatter(x_n, ux, label="FE", c="red", marker="x", zorder=2) axUx.set_title("$u_x(x)$") axUx.legend() # ------------------------ # N # ------------------------ N_x = lambda x: F + q * (L - x) x_e = x_n[mesh.connect].mean(1) # element centroid x-coords N = simu.Result("N", nodeValues=False) err_N = np.abs(N_x(x_e) - N).max() / np.abs(N_x(x_e)).max() Display.MyPrint(f"\nerr N: {err_N * 100:.2e}%") axN = Display.Init_Axes() axN.plot(x, N_x(x), label="Analytical", c="blue") axN.scatter(x_e, N, label="FE", c="red", marker="x", zorder=2) axN.set_title("$N(x)$") axN.legend() print(simu) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.347 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 `_