| 1 |
""" |
| 2 |
.. _pump_bracket_example: |
| 3 |
|
| 4 |
Visualize Modal Analysis of a Pump Bracket |
| 5 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6 |
The following example demonstrates how to use PyVista to visualize the modal |
| 7 |
analysis of a pump bracket based on point arrays representing mode shapes for |
| 8 |
different modes of vibration. |
| 9 |
|
| 10 |
**Background** |
| 11 |
Modal analysis is the study of the dynamic properties of mechanical structures |
| 12 |
in the frequency domain. It is a common technique in structural dynamics, |
| 13 |
particularly for automotive, aerospace, and civil engineering applications. |
| 14 |
|
| 15 |
A mode shape is the deformation pattern that occurs at a specific natural |
| 16 |
frequency, or mode, of a structure. When a structure is excited by an external |
| 17 |
force, it responds at all its natural frequencies with each mode shape being |
| 18 |
independent of the others. In this example, we will visualize the mode shapes |
| 19 |
to get an understanding of how the pump bracket responds to different modes of |
| 20 |
vibration. |
| 21 |
|
| 22 |
""" |
| 23 |
|
| 24 |
import numpy as np |
| 25 |
import pyvista as pv |
| 26 |
from pyvista import examples |
| 27 |
|
| 28 |
# %% |
| 29 |
# Load the dataset |
| 30 |
# ~~~~~~~~~~~~~~~~ |
| 31 |
# Start by loading the dataset using :func:`download_pump_bracket() |
| 32 |
# <pyvista.examples.downloads.download_pump_bracket>`. |
| 33 |
# |
| 34 |
# This example demonstrates the visualization of the pump bracket's mode shape, |
| 35 |
# the representation of its magnitude, and an animation of its displacement. The |
| 36 |
# dataset used in this example contains 10 mode shapes (disp_0 to disp_9). |
| 37 |
|
| 38 |
dataset = examples.download_pump_bracket() |
| 39 |
dataset |
| 40 |
|
| 41 |
|
| 42 |
# %% |
| 43 |
# Plot the Dataset |
| 44 |
# ~~~~~~~~~~~~~~~~ |
| 45 |
# Choose a mode shape from the available arrays in the dataset. Each "disp_N" |
| 46 |
# array represents an eigen solution or a single mode shape for a given mode of |
| 47 |
# vibration. |
| 48 |
# |
| 49 |
# Plot the 4th mode of the dataset. This is the first torsional mode for the |
| 50 |
# bracket. |
| 51 |
|
| 52 |
cpos = pv.CameraPosition( |
| 53 |
position=(0.744, -0.502, -0.830), |
| 54 |
focal_point=(0.0520, -0.160, 0.0743), |
| 55 |
viewup=(-0.180, -0.958, 0.224), |
| 56 |
) |
| 57 |
|
| 58 |
dataset.plot( |
| 59 |
scalars='disp_3', |
| 60 |
cpos=cpos, |
| 61 |
show_scalar_bar=False, |
| 62 |
ambient=0.2, |
| 63 |
anti_aliasing='fxaa', |
| 64 |
) |
| 65 |
|
| 66 |
|
| 67 |
# %% |
| 68 |
# Visualize Displaced Mode Shape |
| 69 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 70 |
# We will now visualize the mode shapes of the pump bracket by displacing the |
| 71 |
# original dataset using :func:`warp_by_vector <pyvista.DataSetFilters.warp_by_vector>`. |
| 72 |
|
| 73 |
# Create a plotter |
| 74 |
pl = pv.Plotter() |
| 75 |
|
| 76 |
# Add the undeformed pump bracket |
| 77 |
pl.add_mesh(dataset, color='white', opacity=0.5) |
| 78 |
|
| 79 |
# Add the deformed pump bracket with the mode shape |
| 80 |
warp = dataset.warp_by_vector('disp_2', factor=0.1) |
| 81 |
pl.add_mesh(warp, show_scalar_bar=False, ambient=0.2) |
| 82 |
|
| 83 |
pl.camera_position = cpos |
| 84 |
pl.enable_anti_aliasing('fxaa') |
| 85 |
pl.show() |
| 86 |
|
| 87 |
|
| 88 |
# %% |
| 89 |
# Animate the Mode Shape Displacement |
| 90 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 91 |
# Animate the mode shape's displacement by updating the vertex positions at |
| 92 |
# each time step. For a more realistic animation, we use a sinusoidal function |
| 93 |
# to vary the displacement. |
| 94 |
|
| 95 |
# feel free to change this to visualize different mode shapes |
| 96 |
mode_shape = 'disp_6' |
| 97 |
|
| 98 |
# copy the dataset as we will modify its coordinates |
| 99 |
ds = dataset.copy() |
| 100 |
|
| 101 |
pl = pv.Plotter(off_screen=True) |
| 102 |
pl.add_mesh(ds, lighting=True, color='w') |
| 103 |
pl.camera_position = cpos |
| 104 |
pl.enable_anti_aliasing('fxaa') |
| 105 |
|
| 106 |
n_frames = 10 |
| 107 |
pl.open_gif('pump_bracket_mode_shape.gif') |
| 108 |
for phase in np.linspace(0, 2 * np.pi, n_frames, endpoint=False): |
| 109 |
# use the original unmodified points, modify copy inplace |
| 110 |
ds.points = dataset.points + ds[mode_shape] * np.cos(phase) * 0.05 |
| 111 |
pl.write_frame() |
| 112 |
|
| 113 |
pl.close() |