.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/post-processing/example_mode_shape_plot.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_gallery_post-processing_example_mode_shape_plot.py: Plotting mode shapes ==================== A recipe for rendering the lowest few modes of a structure as a grid of sub-plots. The key ingredients are :func:`femorph_solver.io.modal_result_to_grid` (which scatters every mode onto the mesh as a pyvista point-data array) and :meth:`pyvista.DataSet.warp_by_vector` (which deforms the mesh by the mode shape scaled to a fixed fraction of the bounding box). .. GENERATED FROM PYTHON SOURCE LINES 12-21 .. code-block:: Python from __future__ import annotations import numpy as np import pyvista as pv import femorph_solver from femorph_solver import ELEMENTS .. GENERATED FROM PYTHON SOURCE LINES 22-24 Build a quick cantilever plate + solve -------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 24-43 .. code-block:: Python LX, LY, LZ = 1.0, 1.0, 0.01 grid = pv.StructuredGrid( *np.meshgrid( np.linspace(0.0, LX, 21), np.linspace(0.0, LY, 21), np.linspace(0.0, LZ, 3), indexing="ij", ) ).cast_to_unstructured_grid() m = femorph_solver.Model.from_grid(grid) m.assign(ELEMENTS.HEX8, material={"EX": 2.0e11, "PRXY": 0.30, "DENS": 7850.0}) pts = np.asarray(grid.points) node_nums = np.asarray(grid.point_data["ansys_node_num"]) m.fix(nodes=node_nums[pts[:, 0] < 1e-9].tolist(), dof="ALL") res = m.modal_solve(n_modes=6) .. GENERATED FROM PYTHON SOURCE LINES 44-46 Attach every mode to the grid ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python grid_plot = femorph_solver.io.modal_result_to_grid(m, res) .. GENERATED FROM PYTHON SOURCE LINES 49-51 Render modes 1..6 in a 2 × 3 viewport grid ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 51-70 .. code-block:: Python plotter = pv.Plotter(shape=(2, 3), off_screen=True, window_size=(1200, 600)) for idx in range(6): row, col = divmod(idx, 3) plotter.subplot(row, col) phi_k = grid_plot.point_data[f"mode_{idx + 1}_disp"] factor = 0.1 / (np.max(np.abs(phi_k)) + 1e-30) plotter.add_mesh(grid_plot, style="wireframe", color="gray", opacity=0.3) plotter.add_mesh( grid_plot.warp_by_vector(f"mode_{idx + 1}_disp", factor=factor), scalars=f"mode_{idx + 1}_magnitude", cmap="viridis", show_scalar_bar=False, ) plotter.add_text( f"mode {idx + 1}: {res.frequency[idx]:.1f} Hz", position="upper_edge", font_size=10, ) plotter.show() .. image-sg:: /gallery/post-processing/images/sphx_glr_example_mode_shape_plot_001.png :alt: example mode shape plot :srcset: /gallery/post-processing/images/sphx_glr_example_mode_shape_plot_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.772 seconds) .. _sphx_glr_download_gallery_post-processing_example_mode_shape_plot.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_mode_shape_plot.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_mode_shape_plot.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_mode_shape_plot.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_