.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/WeakForms/LinearElasticity2.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_LinearElasticity2.py: LinearElasticity2 ================= A cantilever beam undergoing bending deformation in dynamic. Note that this simulation is also performed in `examples/Dynamic/Dynamic1.py`. .. GENERATED FROM PYTHON SOURCE LINES 13-140 .. image-sg:: /examples/WeakForms/images/sphx_glr_LinearElasticity2_001.gif :alt: LinearElasticity2 :srcset: /examples/WeakForms/images/sphx_glr_LinearElasticity2_001.gif :class: sphx-glr-single-img .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/WeakForms/images/sphx_glr_LinearElasticity2_002.png :alt: LinearElasticity2 :srcset: /examples/WeakForms/images/sphx_glr_LinearElasticity2_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.5.4/docs/examples/WeakForms/images/sphx_glr_LinearElasticity2_002.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none 0.000 s 0.010 s 0.020 s 0.030 s 0.040 s 0.050 s 0.060 s 0.070 s 0.080 s 0.090 s 0.100 s 0.110 s 0.120 s 0.130 s 0.140 s 0.150 s 0.160 s 0.170 s 0.180 s 0.190 s 0.200 s 0.210 s 0.220 s 0.230 s 0.240 s 0.250 s 0.260 s 0.270 s 0.280 s 0.290 s 0.300 s 0.310 s 0.320 s 0.330 s 0.340 s 0.350 s 0.360 s 0.370 s 0.380 s 0.390 s 0.400 s 0.410 s 0.420 s 0.430 s 0.440 s 0.450 s 0.460 s 0.470 s 0.480 s 0.490 s 0.500 s Movie_func 0/51 Movie_func 1/51 (1.96 %) 5.22 s Movie_func 2/51 (3.92 %) 4.99 s Movie_func 3/51 (5.88 %) 5.00 s Movie_func 4/51 (7.84 %) 4.85 s Movie_func 5/51 (9.80 %) 4.77 s Movie_func 6/51 (11.76 %) 4.66 s Movie_func 7/51 (13.73 %) 4.54 s Movie_func 8/51 (15.69 %) 4.37 s Movie_func 9/51 (17.65 %) 4.51 s Movie_func 10/51 (19.61 %) 4.18 s Movie_func 11/51 (21.57 %) 4.05 s Movie_func 12/51 (23.53 %) 4.41 s Movie_func 13/51 (25.49 %) 3.89 s Movie_func 14/51 (27.45 %) 3.95 s Movie_func 15/51 (29.41 %) 3.78 s Movie_func 16/51 (31.37 %) 3.61 s Movie_func 17/51 (33.33 %) 3.50 s Movie_func 18/51 (35.29 %) 3.41 s Movie_func 19/51 (37.25 %) 3.25 s Movie_func 20/51 (39.22 %) 3.20 s Movie_func 21/51 (41.18 %) 3.05 s Movie_func 22/51 (43.14 %) 2.97 s Movie_func 23/51 (45.10 %) 2.85 s Movie_func 24/51 (47.06 %) 2.86 s Movie_func 25/51 (49.02 %) 2.70 s Movie_func 26/51 (50.98 %) 2.59 s Movie_func 27/51 (52.94 %) 2.46 s Movie_func 28/51 (54.90 %) 2.34 s Movie_func 29/51 (56.86 %) 2.22 s Movie_func 30/51 (58.82 %) 2.11 s Movie_func 31/51 (60.78 %) 2.03 s Movie_func 32/51 (62.75 %) 1.98 s Movie_func 33/51 (64.71 %) 1.86 s Movie_func 34/51 (66.67 %) 1.75 s Movie_func 35/51 (68.63 %) 1.67 s Movie_func 36/51 (70.59 %) 1.56 s Movie_func 37/51 (72.55 %) 1.47 s Movie_func 38/51 (74.51 %) 1.36 s Movie_func 39/51 (76.47 %) 1.27 s Movie_func 40/51 (78.43 %) 1.14 s Movie_func 41/51 (80.39 %) 1.03 s Movie_func 42/51 (82.35 %) 929.58 ms Movie_func 43/51 (84.31 %) 844.68 ms Movie_func 44/51 (86.27 %) 768.95 ms Movie_func 45/51 (88.24 %) 630.21 ms Movie_func 46/51 (90.20 %) 514.79 ms Movie_func 47/51 (92.16 %) 415.69 ms Movie_func 48/51 (94.12 %) 310.69 ms Movie_func 49/51 (96.08 %) 206.52 ms Movie_func 50/51 (98.04 %) 102.44 ms Movie_func 51/51 (100.00 %) 0.00 µs | .. code-block:: Python :lineno-start: 14 from EasyFEA import Folder, Display, ElemType, Models, Simulations, PyVista, np from EasyFEA.fem import Field, BiLinearForm, FeArray, Sym_Grad, Trace from EasyFEA.Geoms import Domain if __name__ == "__main__": Display.Clear() # ---------------------------------------------- # Configuration # ---------------------------------------------- dim = 3 # outputs makeMovie = True folder = Folder.Join(Folder.RESULTS_DIR, "WeakForms", "LinearElasticity2") # geom L = 120 # mm h = 13 # model elastic = Models.ElasIsot(dim, 210000, 0.3, planeStress=True, thickness=h) lmbda = elastic.get_lambda() mu = elastic.get_mu() rho = 8100 * 1e-9 # load Tmax = 0.5 N = 50 dt = Tmax / N time = -dt # ---------------------------------------------- # Mesh # ---------------------------------------------- contour = Domain((0, 0), (L, h), h / 3) if dim == 2: mesh = contour.Mesh_2D([], ElemType.QUAD4, isOrganised=True) else: mesh = contour.Mesh_Extrude( [], [0, 0, h], [3], ElemType.HEXA8, 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) @BiLinearForm def computeM(u: Field, v: Field): return rho * u.dot(v) @BiLinearForm def computeC(u: Field, v: Field): K = computeK(u, v) M = computeM(u, v) C = K * 1e-3 + M * 1e-3 return C weakForms = Models.WeakForms(field, computeK, computeC, computeM) # ---------------------------------------------- # Simulations # ---------------------------------------------- simu = Simulations.WeakFormSimu(mesh, weakForms) # static simulation simu.add_dirichlet(nodesX0, [0] * dim, simu.Get_unknowns()) simu.add_dirichlet(nodesXL, [-10], ["y"]) simu.Solve() # dynamic simulation simu.Solver_Set_Hyperbolic_Algorithm(dt) simu.Save_Iter() simu.Bc_Init() simu.add_dirichlet(nodesX0, [0] * dim, simu.Get_unknowns()) while time <= Tmax: time += dt simu.Solve() simu.Save_Iter() print(f"{time:.3f} s", end="\r") # ---------------------------------------------- # Results # ---------------------------------------------- if makeMovie: PyVista.Movie_simu( simu, "uy", folder, "uy.gif", deformFactor=1, plotMesh=True, N=400, nodeValues=True, ) simu.Set_Iter(0) PyVista.Plot(simu, "uy", 1, plotMesh=True).show() Display.plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 9.449 seconds) .. _sphx_glr_download_examples_WeakForms_LinearElasticity2.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: LinearElasticity2.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: LinearElasticity2.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: LinearElasticity2.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_