.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/WeakForms/LinearElasticity1.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_WeakForms_LinearElasticity1.py: LinearElasticity1 ================= A cantilever beam undergoing bending deformation. Note that this simulation is also performed in `examples/Elastic/Elas1.py`. .. GENERATED FROM PYTHON SOURCE LINES 14-113 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/WeakForms/images/sphx_glr_LinearElasticity1_001.png :alt: $uy$ :srcset: /examples/WeakForms/images/sphx_glr_LinearElasticity1_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/WeakForms/images/sphx_glr_LinearElasticity1_002.png :alt: LinearElasticity1 :srcset: /examples/WeakForms/images/sphx_glr_LinearElasticity1_002.png :class: sphx-glr-multi-img .. code-block:: Python :lineno-start: 15 import matplotlib.pyplot as plt import numpy as np from EasyFEA import Display, ElemType, Models, Simulations from EasyFEA.FEM import Field, BiLinearForm, FeArray, Sym_Grad, Trace from EasyFEA.Geoms import Domain if __name__ == "__main__": Display.Clear() # ---------------------------------------------- # Configuration # ---------------------------------------------- dim = 2 # geom L = 120 # mm h = 13 # load F = -800 # N # model E = 210000 # MPa v = 0.3 elastic = Models.Elastic.Isotropic(dim, E, v, planeStress=True, thickness=h) lmbda = elastic.get_lambda() mu = elastic.get_mu() # ---------------------------------------------- # Mesh # ---------------------------------------------- contour = Domain((0, 0), (L, h), h / 3) if dim == 2: mesh = contour.Mesh_2D([], ElemType.QUAD9, isOrganised=True) else: mesh = contour.Mesh_Extrude( [], [0, 0, h], [3], ElemType.HEXA27, isOrganised=True ) nodesX0 = mesh.Nodes_Conditions(lambda x, y, z: x == 0) nodesXL = mesh.Nodes_Conditions(lambda x, y, z: x == L) # ---------------------------------------------- # Formulations # ---------------------------------------------- field = Field(mesh.groupElem, dim) def S(u: Field) -> FeArray: Eps = Sym_Grad(u) return 2 * mu * Eps + lmbda * Trace(Eps) * np.eye(dim) @BiLinearForm def ComputeK(u: Field, v: Field): Sig = S(u) Eps = Sym_Grad(v) return Sig.ddot(Eps) weakForms = Models.WeakForms(field, ComputeK) # ---------------------------------------------- # Simulations # ---------------------------------------------- simu = Simulations.WeakForms(mesh, weakForms) simu.add_dirichlet(nodesX0, [0] * dim, simu.Get_unknowns()) simu.add_surfLoad(nodesXL, [F / h**2], ["y"]) simu.Solve() # ---------------------------------------------- # Results # ---------------------------------------------- Display.Plot_Result(simu, "uy", 10, plotMesh=True) def von_mises_stress(u): Stress = S(u) if dim == 2: xx = Stress[..., 0, 0] yy = Stress[..., 1, 1] xy = Stress[..., 0, 1] return np.sqrt(xx**2 + yy**2 - xx * yy + 3 * xy**2) else: Stress_d = Stress - 1 / 3 * Trace(Stress) * np.eye(3) return np.sqrt(3 / 2 * Stress_d.ddot(Stress_d)) Svm_e = field.Evaluate_e(von_mises_stress, simu.u) Display.Plot_Result(simu, Svm_e, plotMesh=True, ncolors=11) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.206 seconds) .. _sphx_glr_download_examples_WeakForms_LinearElasticity1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: LinearElasticity1.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: LinearElasticity1.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: LinearElasticity1.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_