.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/quickstart/example_quickstart_modal.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_quickstart_example_quickstart_modal.py: Modal cantilever — first modal example ====================================== A 60-second introduction to free-vibration analysis in femorph-solver: build a steel plate, clamp one edge, extract the first 5 modes, render the lowest mode shape. .. GENERATED FROM PYTHON SOURCE LINES 9-17 .. code-block:: Python from __future__ import annotations import numpy as np import pyvista as pv import femorph_solver .. GENERATED FROM PYTHON SOURCE LINES 18-20 Build a 20 × 20 × 2 hex plate ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 20-33 .. code-block:: Python E, NU, RHO = 2.0e11, 0.30, 7850.0 LX, LY, LZ = 1.0, 1.0, 0.01 NX, NY, NZ = 20, 20, 2 grid = pv.StructuredGrid( *np.meshgrid( np.linspace(0.0, LX, NX + 1), np.linspace(0.0, LY, NY + 1), np.linspace(0.0, LZ, NZ + 1), indexing="ij", ) ).cast_to_unstructured_grid() .. GENERATED FROM PYTHON SOURCE LINES 34-36 Wrap and stamp material ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 36-47 .. code-block:: Python m = femorph_solver.Model.from_grid(grid) m.et(1, "SOLID185") m.mp("EX", 1, E) m.mp("PRXY", 1, NU) m.mp("DENS", 1, RHO) 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") .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/_work/solver/solver/examples/quickstart/example_quickstart_modal.py:37: 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/quickstart/example_quickstart_modal.py:38: 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, E) /home/runner/_work/solver/solver/examples/quickstart/example_quickstart_modal.py:39: 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, NU) /home/runner/_work/solver/solver/examples/quickstart/example_quickstart_modal.py:40: 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, RHO) /home/runner/_work/solver/solver/examples/quickstart/example_quickstart_modal.py:45: 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 48-50 Extract 5 modes --------------- .. GENERATED FROM PYTHON SOURCE LINES 50-56 .. code-block:: Python res = m.modal_solve(n_modes=5) print("Mode f [Hz]") for i, f in enumerate(res.frequency, start=1): print(f"{i:>3} {f:>10.3f}") .. rst-class:: sphx-glr-script-out .. code-block:: none Mode f [Hz] 1 26.507 2 33.751 3 166.483 4 175.654 5 175.890 .. GENERATED FROM PYTHON SOURCE LINES 57-59 Visualise mode 1 ---------------- .. GENERATED FROM PYTHON SOURCE LINES 59-73 .. code-block:: Python grid_plot = femorph_solver.io.modal_result_to_grid(m, res) phi1 = grid_plot.point_data["mode_1_disp"] factor = 0.15 / (np.max(np.abs(phi1)) + 1e-30) plotter = pv.Plotter(off_screen=True) plotter.add_mesh(grid_plot, style="wireframe", color="gray", opacity=0.3) plotter.add_mesh( grid_plot.warp_by_vector("mode_1_disp", factor=factor), scalars="mode_1_magnitude", show_scalar_bar=True, scalar_bar_args={"title": f"mode 1 ({res.frequency[0]:.1f} Hz)"}, ) plotter.add_axes() plotter.show() .. image-sg:: /gallery/quickstart/images/sphx_glr_example_quickstart_modal_001.png :alt: example quickstart modal :srcset: /gallery/quickstart/images/sphx_glr_example_quickstart_modal_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.596 seconds) .. _sphx_glr_download_gallery_quickstart_example_quickstart_modal.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_quickstart_modal.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_quickstart_modal.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_quickstart_modal.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_