.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/Beam/Beam2.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_Beam2.py: Beam2 ===== A cantilever beam undergoing bending deformation. .. GENERATED FROM PYTHON SOURCE LINES 11-118 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/Beam/images/sphx_glr_Beam2_001.png :alt: SEG2: Ne = 10, Nn = 11 :srcset: /examples/Beam/images/sphx_glr_Beam2_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/Beam/images/sphx_glr_Beam2_002.png :alt: Boundary conditions :srcset: /examples/Beam/images/sphx_glr_Beam2_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/Beam/images/sphx_glr_Beam2_003.png :alt: $uy^{e}$ :srcset: /examples/Beam/images/sphx_glr_Beam2_003.png :class: sphx-glr-multi-img * .. image-sg:: /examples/Beam/images/sphx_glr_Beam2_004.png :alt: $u_y(x)$ :srcset: /examples/Beam/images/sphx_glr_Beam2_004.png :class: sphx-glr-multi-img * .. image-sg:: /examples/Beam/images/sphx_glr_Beam2_005.png :alt: $r_z(x)$ :srcset: /examples/Beam/images/sphx_glr_Beam2_005.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none err uy: 1.21e-10 %err rz: 1.12e-10 % ==================== Mesh ==================== Element type: SEG2 Ne = 10, Nn = 11 ==================== Model ==================== 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 : 15.353 ms Boundary Conditions : 21.935 µs Matrix : 8.173 ms Solver : 1.539 ms Display : 51.848 ms | .. code-block:: Python :lineno-start: 12 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 = 120 nL = 10 h = 13 b = 13 # model E = 210000 v = 0.3 # load load = 800 # ---------------------------------------------- # Mesh # ---------------------------------------------- elemType = ElemType.SEG2 beamDim = 2 # must be >= 2 # Create a section object for the beam mesh 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) # ---------------------------------------------- # Simulation # ---------------------------------------------- Iy = beam.Iy Iz = beam.Iz # 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_neumann(mesh.Nodes_Point(p2), [-load], ["y"]) # Solve the beam problem and get displacement results sol = simu.Solve() simu.Save_Iter() # ---------------------------------------------- # Results # ---------------------------------------------- Display.Plot_Mesh(simu, deformFactor=-L / 10 / sol.min()) Display.Plot_BoundaryConditions(simu) Display.Plot_Result(simu, "uy") rz = simu.Result("rz") v = simu.Result("uy") x = np.linspace(0, L, 100) uy_x = load / (E * Iz) * (x**3 / 6 - (L * x**2) / 2) flecheanalytique = load * L**3 / (3 * E * Iz) err_uy = np.abs(flecheanalytique + v.min()) / flecheanalytique Display.MyPrint(f"err uy: {err_uy * 100:.2e} %") # Plot the analytical and finite element solutions for vertical displacement (v) axUy = Display.Init_Axes() axUy.plot(x, uy_x, label="Analytical", c="blue") axUy.scatter(mesh.coord[:, 0], v, label="FE", c="red", marker="x", zorder=2) axUy.set_title("$u_y(x)$") axUy.legend() rz_x = load / E / Iz * (x**2 / 2 - L * x) rotalytique = load * L**2 / (2 * E * Iz) err_rz = np.abs(rotalytique + rz.min()) / rotalytique Display.MyPrint(f"err rz: {err_rz * 100:.2e} %") # Plot the analytical and finite element solutions for rotation (rz) axRz = Display.Init_Axes() axRz.plot(x, rz_x, label="Analytical", c="blue") axRz.scatter(mesh.coord[:, 0], rz, label="FE", c="red", marker="x", zorder=2) axRz.set_title("$r_z(x)$") axRz.legend() print(simu) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.432 seconds) .. _sphx_glr_download_examples_Beam_Beam2.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Beam2.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Beam2.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: Beam2.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_