.. 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 12-165 .. 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 * .. image-sg:: /examples/Beam/images/sphx_glr_Beam2_006.png :alt: $M_z(x)$ :srcset: /examples/Beam/images/sphx_glr_Beam2_006.png :class: sphx-glr-multi-img * .. image-sg:: /examples/Beam/images/sphx_glr_Beam2_007.png :alt: $T_y(x)$ :srcset: /examples/Beam/images/sphx_glr_Beam2_007.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none err uy: 5.18e-13% err rz: 1.75e-12% err Mz: 3.97e-12% err Ty: 6.08e-11% ==================== 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: 11.378 ms Boundary Conditions: 16.212 µs Matrix: 14.444 ms Solver: 1.086 ms Display: 37.177 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 = 120 nL = 10 h = 13 b = 13 # model E = 210000 v = 0.3 useTimoshenko = False # load F = -800 # applied tip force in y (negative = downward) # ---------------------------------------------- # 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 # ---------------------------------------------- # Initialize the beam structure with the defined beam segments beamStructure = Models.Beam.BeamStructure([beam]) # Create the beam simulation simu = Simulations.Beam(mesh, beamStructure, useTimoshenko=useTimoshenko) 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), [F], ["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") # beam properties G = beam.mu A = section.area Iy = beam.Iy Iz = beam.Iz # ------------------------ # uy # ------------------------ x = np.linspace(0, L, 100) uy_x_eb = lambda x: F * (L * x**2 / 2 - x**3 / 6) / (E * Iz) if simu.useTimoshenko: # uy(x) = uy_EB(x) + F·x / (kGA) with k=1 (current default) uy_x = lambda x: uy_x_eb(x) + F * x / (G * A) else: uy_x = uy_x_eb uy = simu.Result("uy") x_n = mesh.coord[:, 0] err_uy = np.abs(uy_x(x_n) - uy).max() / np.abs(uy_x(L)) Display.MyPrint(f"\nerr uy: {err_uy * 100:.2e}%") axUy = Display.Init_Axes() axUy.plot(x, uy_x(x), label="Analytical", c="blue") axUy.scatter(x_n, uy, label="FE", c="red", marker="x", zorder=2) axUy.set_title("$u_y(x)$") axUy.legend() # ------------------------ # rz # ------------------------ rz_x = lambda x: F / E / Iz * (L * x - x**2 / 2) rz = simu.Result("rz") err_rz = np.abs(rz_x(x_n) - rz).max() / np.abs(rz_x(L)) Display.MyPrint(f"\nerr rz: {err_rz * 100:.2e}%") axRz = Display.Init_Axes() axRz.plot(x, rz_x(x), label="Analytical", c="blue") axRz.scatter(x_n, rz, label="FE", c="red", marker="x", zorder=2) axRz.set_title("$r_z(x)$") axRz.legend() # ------------------------ # Mz # ------------------------ Mz_x = lambda x: F * (L - x) x_e = x_n[mesh.connect].mean(1) # element centroid x-coords Mz = simu.Result("Mz", nodeValues=False) err_Mz = np.abs(Mz_x(x_e) - Mz).max() / np.abs(Mz_x(x_e)).max() Display.MyPrint(f"\nerr Mz: {err_Mz * 100:.2e}%") axMz = Display.Init_Axes() axMz.plot(x, Mz_x(x), label="Analytical", c="blue") axMz.scatter(x_e, Mz, label="FE", c="red", marker="x", zorder=2) axMz.set_title("$M_z(x)$") axMz.legend() # ------------------------ # Ty # ------------------------ Ty = simu.Result("Ty", nodeValues=False) err_Ty = np.abs(F - Ty).max() / np.abs(F) Display.MyPrint(f"\nerr Ty: {err_Ty * 100:.2e}%") axTy = Display.Init_Axes() axTy.axhline(F, label="Analytical", c="blue") axTy.scatter(x_e, Ty, label="FE", c="red", marker="x", zorder=2) axTy.set_ylim(min(1.5 * F, -0.5 * F), max(1.5 * F, -0.5 * F)) axTy.set_title("$T_y(x)$") axTy.legend() print(simu) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.455 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 `_