.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/LinearizedElasticity/Modal1.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_Modal1.py: Modal1 ====== Modal analysis of a wall structure. .. GENERATED FROM PYTHON SOURCE LINES 12-108 .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_Modal1_001.png :alt: Modal1 :srcset: /examples/LinearizedElasticity/images/sphx_glr_Modal1_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.10.0/docs/examples/LinearizedElasticity/images/sphx_glr_Modal1_001.vtksz .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_Modal1_002.png :alt: Modal1 :srcset: /examples/LinearizedElasticity/images/sphx_glr_Modal1_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.10.0/docs/examples/LinearizedElasticity/images/sphx_glr_Modal1_002.vtksz .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_Modal1_003.png :alt: Modal1 :srcset: /examples/LinearizedElasticity/images/sphx_glr_Modal1_003.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.10.0/docs/examples/LinearizedElasticity/images/sphx_glr_Modal1_003.vtksz .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_Modal1_004.png :alt: Modal1 :srcset: /examples/LinearizedElasticity/images/sphx_glr_Modal1_004.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.10.0/docs/examples/LinearizedElasticity/images/sphx_glr_Modal1_004.vtksz .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_Modal1_005.png :alt: Modal1 :srcset: /examples/LinearizedElasticity/images/sphx_glr_Modal1_005.png :class: sphx-glr-single-img .. code-block:: Python :lineno-start: 13 import matplotlib.pyplot as plt import numpy as np from scipy.sparse import linalg, eye from EasyFEA import Display, Models, ElemType, Simulations, PyVista from EasyFEA.Geoms import Domain if __name__ == "__main__": Display.Clear() # ---------------------------------------------- # Configuration # ---------------------------------------------- dim = 3 # outputs isFixed = True Nmode = 3 # ---------------------------------------------- # Mesh # ---------------------------------------------- contour = Domain((0, 0), (1, 1), 1 / 10) thickness = 1 / 10 if dim == 2: mesh = contour.Mesh_2D([], ElemType.QUAD9, isOrganised=True) else: mesh = contour.Mesh_Extrude( [], [0, 0, -thickness], [2], ElemType.HEXA27, isOrganised=True ) nodesY0 = mesh.Nodes_Conditions(lambda x, y, z: y == 0) nodesSupY0 = mesh.Nodes_Conditions(lambda x, y, z: y > 0) PyVista.Plot_Mesh(mesh).show() # ---------------------------------------------- # Simulation # ---------------------------------------------- material = Models.Elastic.Isotropic(dim, planeStress=True, thickness=thickness) simu = Simulations.Elastic(mesh, material) simu.Solver_Set_Hyperbolic_Algorithm(0.1) K, C, M, F = simu.Get_K_C_M_F() if isFixed: simu.add_dirichlet(nodesY0, [0] * dim, simu.Get_unknowns()) known, unknown = simu.Bc_dofs_known_unknown(simu.problemType) K_t = K[unknown, :].tocsc()[:, unknown].tocsr() M_t = M[unknown, :].tocsc()[:, unknown].tocsr() else: K_t = K + K.min() * eye(K.shape[0]) * 1e-12 M_t = M # eigenValues, eigenVectors = linalg.eigs(K_t, Nmode, M_t, which="SR") eigenValues, eigenVectors = linalg.eigs(K_t, Nmode, M_t, sigma=0, which="LR") eigenValues = eigenValues.real eigenVectors = eigenVectors.real freq_t = np.sqrt(eigenValues) / 2 / np.pi # ---------------------------------------------- # Plot modes # ---------------------------------------------- for n in range(eigenValues.size): if isFixed: mode = np.zeros((mesh.Nn, dim)) mode[nodesSupY0, :] = np.reshape(eigenVectors[:, n], (-1, dim)) else: mode = np.reshape(eigenVectors[:, n], (-1, dim)) simu._Set_solutions(simu.problemType, mode.ravel()) simu.Save_Iter() sol = np.linalg.norm(mode, axis=1) deformFactor = 1 / 5 / np.abs(sol).max() plotter = PyVista.Plot(simu, alpha=0.5) PyVista.Plot(simu, None, deformFactor, alpha=0.8, color="r", plotter=plotter) plotter.add_title(f"mode {n + 1}") plotter.show() axModes = Display.Init_Axes() axModes.plot(np.arange(eigenValues.size), freq_t, ls="", marker=".") axModes.set_xlabel("modes") axModes.set_xticks(np.arange(eigenValues.size)) axModes.set_ylabel("freq [Hz]") axModes.grid() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.003 seconds) .. _sphx_glr_download_examples_LinearizedElasticity_Modal1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Modal1.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Modal1.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: Modal1.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_