.. 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-20 .. code-block:: Python from __future__ import annotations import numpy as np import pyvista as pv import femorph_solver .. GENERATED FROM PYTHON SOURCE LINES 21-23 Build a quick cantilever plate + solve -------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 23-46 .. 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.et(1, "SOLID185") m.mp("EX", 1, 2.0e11) m.mp("PRXY", 1, 0.30) m.mp("DENS", 1, 7850.0) pts = np.asarray(grid.points) node_nums = np.asarray(grid.point_data["ansys_node_num"]) for nn in node_nums[pts[:, 0] < 1e-9]: m.d(int(nn), "ALL") res = m.modal_solve(n_modes=6) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/_work/solver/solver/examples/post-processing/example_mode_shape_plot.py:34: DeprecationWarning: Model.et(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).et(et_id, name)` for line-by-line APDL deck porting, or the native `Model.assign("HEX8", material)` for new code. m.et(1, "SOLID185") /home/runner/_work/solver/solver/examples/post-processing/example_mode_shape_plot.py:35: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("EX", 1, 2.0e11) /home/runner/_work/solver/solver/examples/post-processing/example_mode_shape_plot.py:36: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("PRXY", 1, 0.30) /home/runner/_work/solver/solver/examples/post-processing/example_mode_shape_plot.py:37: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("DENS", 1, 7850.0) /home/runner/_work/solver/solver/examples/post-processing/example_mode_shape_plot.py:42: DeprecationWarning: Model.d(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).d(node, label, value)` for line-by-line APDL deck porting, or the native `Model.fix(nodes=..., where=..., dof=...)` for new code. m.d(int(nn), "ALL") .. GENERATED FROM PYTHON SOURCE LINES 47-49 Attach every mode to the grid ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python grid_plot = femorph_solver.io.modal_result_to_grid(m, res) .. GENERATED FROM PYTHON SOURCE LINES 52-54 Render modes 1..6 in a 2 × 3 viewport grid ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 54-73 .. 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.849 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 `_