.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\02-modal_analyses\01-plot_and_animate_modes.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_02-modal_analyses_01-plot_and_animate_modes.py: .. _ref_plot_and_animate_modes: Plot and animate mode shapes with DPF ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example shows how to extract mode shapes from a modal analysis result and how to plot and animate them. .. GENERATED FROM PYTHON SOURCE LINES 11-16 .. code-block:: Python from ansys.dpf import core as dpf from ansys.dpf.core import animation from ansys.dpf.core import examples .. GENERATED FROM PYTHON SOURCE LINES 17-19 Retrieve mode shapes ~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 19-27 .. code-block:: Python # Load the result file as a model model = dpf.Model(examples.download_modal_frame()) print(model) # Extract the displacement results which define mode shapes disp = model.results.displacement.on_all_time_freqs.eval() .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Model ------------------------------ Modal analysis Unit system: NMM: mm, ton, N, s, mV, mA, degC Physics Type: Mechanical Available results: - displacement: Nodal Displacement - stress: ElementalNodal Stress - elastic_strain: ElementalNodal Strain - element_euler_angles: ElementalNodal Element Euler Angles ------------------------------ DPF Meshed Region: 5886 nodes 2842 elements Unit: mm With solid (3D) elements ------------------------------ DPF Time/Freq Support: Number of sets: 6 Cumulative Frequency (Hz) LoadStep Substep 1 253.615690 1 1 2 317.918491 1 2 3 329.825709 1 3 4 575.619678 1 4 5 621.973976 1 5 6 667.364882 1 6 .. GENERATED FROM PYTHON SOURCE LINES 28-30 Plot mode shapes ~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 30-49 .. code-block:: Python # Get the frequency scoping (available frequency IDs for disp) freq_scoping = disp.get_time_scoping() # Get the frequency support (all available frequencies in the model) freq_support = disp.time_freq_support # Get the unit from the time_freq_support unit = freq_support.time_frequencies.unit # For each ID in the scoping for freq_set in freq_scoping: # Get the associated frequency in the time_freq_support freq = freq_support.get_frequency(cumulative_index=freq_set - 1) # Get the associated mode shape as a displacement field disp_mode = disp.get_field_by_time_complex_ids(freq_set, 0) # Extract the mode frequency and unit text = f"{freq:.3f}{unit}" # Plot the mode displacement field on the deformed mesh disp_mode.plot(deform_by=disp_mode, scale_factor=2.0, text=text) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_001.png :alt: 01 plot and animate modes :srcset: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_002.png :alt: 01 plot and animate modes :srcset: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_003.png :alt: 01 plot and animate modes :srcset: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_003.png :class: sphx-glr-multi-img * .. image-sg:: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_004.png :alt: 01 plot and animate modes :srcset: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_004.png :class: sphx-glr-multi-img * .. image-sg:: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_005.png :alt: 01 plot and animate modes :srcset: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_005.png :class: sphx-glr-multi-img * .. image-sg:: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_006.png :alt: 01 plot and animate modes :srcset: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_006.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 50-53 Animate a mode shape To suppress window pop-up, set the `off_screen` argument to True. ~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: Python animation.animate_mode(disp, mode_number=1, save_as="tmp.gif", off_screen=True) .. image-sg:: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_007.png :alt: 01 plot and animate modes :srcset: /examples/02-modal_analyses/images/sphx_glr_01-plot_and_animate_modes_007.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 23.061 seconds) .. _sphx_glr_download_examples_02-modal_analyses_01-plot_and_animate_modes.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01-plot_and_animate_modes.ipynb <01-plot_and_animate_modes.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01-plot_and_animate_modes.py <01-plot_and_animate_modes.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_