.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/LinearizedElasticity/Elas6.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_LinearizedElasticity_Elas6.py: Elas6 ===== A bi-fixed beam undergoing bending deformation. .. GENERATED FROM PYTHON SOURCE LINES 11-158 .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_Elas6_001.png :alt: Elas6 :srcset: /examples/LinearizedElasticity/images/sphx_glr_Elas6_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.7.1/docs/examples/LinearizedElasticity/images/sphx_glr_Elas6_001.vtksz .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_Elas6_002.png :alt: Elas6 :srcset: /examples/LinearizedElasticity/images/sphx_glr_Elas6_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_Elas6_003.png :alt: $uy^{e}$ :srcset: /examples/LinearizedElasticity/images/sphx_glr_Elas6_003.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none err beam model : 0.00 % err 3d model : 0.45 % | .. code-block:: Python :lineno-start: 12 import matplotlib.pyplot as plt import numpy as np from EasyFEA import Display, Models, Mesher, ElemType, Simulations, PyVista from EasyFEA.Geoms import Point, Points, Line if __name__ == "__main__": Display.Clear() # ---------------------------------------------- # Configuration # ---------------------------------------------- # geom L = 500 # mm hx = 13 hy = 20 e = 2 # model E = 210000 # MPa (Young's modulus) v = 0.3 # Poisson's ratio coef = 1 # load load = 800 # N # ---------------------------------------------- # Section # ---------------------------------------------- elemType = ElemType.TETRA4 def DoSym(p: Point, n: np.ndarray) -> Point: pc = p.copy() pc.Symmetry(n=n) return pc p1 = Point(-hx / 2, -hy / 2) p2 = Point(hx / 2, -hy / 2) p3 = Point(hx / 2, -hy / 2 + e) p4 = Point(e / 2, -hy / 2 + e, r=e) p5 = DoSym(p4, (0, 1)) p6 = DoSym(p3, (0, 1)) p7 = DoSym(p2, (0, 1)) p8 = DoSym(p1, (0, 1)) p9 = DoSym(p6, (1, 0)) p10 = DoSym(p5, (1, 0)) p11 = DoSym(p4, (1, 0)) p12 = DoSym(p3, (1, 0)) section = Points([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12], e / 1) meshSection = Mesher().Mesh_2D(section) section.Get_Contour().Plot() section.Rotate(-90, direction=(0, 1)) # ---------------------------------------------- # Mesh # ---------------------------------------------- mesher = Mesher() fact = mesher._factory surfaces = mesher._Surfaces(section, [], elemType)[0] layers = [50] # layers = [2*L/meshSize/10] mesher._Extrude(surfaces, [-L / 2, 0, 0], elemType, layers) mesher._Extrude(surfaces, [L / 2, 0, 0], elemType, layers) mesher._Set_PhysicalGroups() mesher._Mesh_Generate(3, elemType) mesh = mesher._Mesh_Get_Mesh() nodes_fixed = mesh.Nodes_Conditions(lambda x, y, z: (x == -L / 2) | (x == L / 2)) nodes_load = mesh.Nodes_Line(Line(p7, p8)) # ---------------------------------------------- # Beam simulation # ---------------------------------------------- beam = Models.Beam.Isotropic( 2, Line(Point(-L / 2), Point(L / 2), L / 10), meshSection, E, v ) mesh_beam = Mesher().Mesh_Beams([beam], ElemType.SEG3) beams = Models.Beam.BeamStructure([beam]) simu_beam = Simulations.Beam(mesh_beam, beams) simu_beam.add_dirichlet( mesh_beam.Nodes_Conditions(lambda x, y, z: (x == -L / 2) | (x == L / 2)), [0] * simu_beam.Get_dof_n(), simu_beam.Get_unknowns(), ) simu_beam.add_neumann( mesh_beam.Nodes_Conditions(lambda x, y, z: (x == 0)), [-load], ["y"] ) simu_beam.Solve() Display.Plot_Result(simu_beam, "uy") u_an = load * L**3 / (192 * E * beam.Iz) uy_1d = np.abs(simu_beam.Result("uy").min()) print(f"err beam model : {np.abs(u_an - uy_1d) / u_an * 100:.2f} %") # ---------------------------------------------- # Elastic simulation # ---------------------------------------------- material = Models.Elastic.Isotropic(3, E, v) simu = Simulations.Elastic(mesh, material) simu.add_dirichlet(nodes_fixed, [0] * 3, simu.Get_unknowns()) simu.add_lineLoad(nodes_load, [-load / hx], ["y"]) sol = simu.Solve() uy_3d = np.abs(simu.Result("uy").min()) print(f"err 3d model : {np.abs(u_an - uy_3d) / u_an * 100:.2f} %") # ---------------------------------------------- # Results # ---------------------------------------------- plotter = PyVista._Plotter(shape=(2, 1)) PyVista.Plot( simu, "ux", coef=1 / coef, nColors=20, plotMesh=True, plotter=plotter, verticalColobar=False, ) PyVista.Plot_BoundaryConditions(simu, plotter=plotter) plotter.subplot(1, 0) PyVista.Plot( simu, "uy", coef=1 / coef, nColors=20, plotter=plotter, verticalColobar=False ) plotter.show() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.634 seconds) .. _sphx_glr_download_examples_LinearizedElasticity_Elas6.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Elas6.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Elas6.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: Elas6.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_