Visualization of SDyPy models and results
Project description
The Plotter3D is a wrapper around the pyvista.BackgroundPlotter with some added functionality around convenient simplifications for use in structural dynamics.
Basic usage
import sdypy as sd
nodes = ... # Finite element nodes
elements ... # Finite elements
plotter = sd.view.Plotter3D(nodes, elements)
plotter.add_fem_mesh(nodes, elements)
plotter.show(show_grid=True, show_axes=True)
To animate a mode shape:
mode_shape = ... # Shape (n_nodes, 3)
plotter = sd.view.Plotter3D(nodes, elements)
plotter.add_fem_mesh(nodes, elements, animate=mode_shape)
To animate according to a time history:
time_history = ... # Shape (n_nodes, 3, n_timesteps)
plotter = sd.view.Plotter3D(nodes, elements)
plotter.add_fem_mesh(nodes, elements, animate=time_history)
To color the mesh according to a norm of the mode_shape:
plotter = sd.view.Plotter3D(nodes, elements)
plotter.add_fem_mesh(nodes, elements, animate=mode_shape, field="norm")
Here, if field="norm" is passed, the mesh will be colored according to the norm of the mode_shape (or more generally, according to the norm of the animate argument). To color the mesh according to an arbitrary field, the field argument must be of shape (n_nodes, n_timesteps).
Animation
The Plotter3D class also enables the user to animate the mesh. There are two way to animate the FEM mesh or points:
By passing a 3D array of shape (n_nodes, 3, n_timesteps) to the animate argument. The points/nodes will be animated according to the time history.
By passing a 2D array of shape (n_nodes, 3) to the animate argument. The animate defines the maximum displacement of the nodes. The animation is interpolated with a sine function.
The animate argument can also have the following shapes:
(n_nodes*3): The Plotter3D will automatically convert this to (n_nodes, 3).
(n_nodes*3, n_timesteps): The Plotter3D will automatically convert this to (n_nodes, 3, n_timesteps).
(n_nodes*N): The Plotter3D will automatically convert this to (n_nodes, 3), where N is an arbitrary number. Only the first 3 columns are used. This is useful when animating e.g. a mode shape of a shell (each node has 6 DOF).
(n_nodes*N, n_timesteps): The Plotter3D will automatically convert this to (n_nodes, 3, n_timesteps). Similar to previous point, but with time history.
The n_frames is set to 100 by default, but can be changed to alter the number of frames per one iteration. When providing the time history, the n_frames should match the last dimension of the animate argument.
Here is an example of animating a mode shape:
import sdypy as sd
nodes = ... # Finite element nodes (n_nodes, 3)
elements ... # Finite elements (n_elements, n_nodes_per_element)
mode_shape = ... # Mode shape (n_nodes, 3)
plotter = sd.view.Plotter3D(nodes, elements)
plotter.add_fem_mesh(nodes, elements, animate=mode_shape, field="norm")
plotter.configure_animation(interval=20) # To adjust the interval and camera position
plotter.start_animation() # Optional. To immediately start the animation. Otherwise, the controls are available in the plotter.
plotter.show()
Recording a GIF
To record a GIF, the configure_gif_recorder method must be called. Example:
import sdypy as sd
nodes = ... # Finite element nodes (n_nodes, 3)
elements ... # Finite elements (n_elements, n_nodes_per_element)
mode_shape = ... # Mode shape (n_nodes, 3)
plotter = sd.view.Plotter3D(nodes, elements)
plotter.gif_recorder("mode_shape.gif") # MUST BE CALLED BEFORE THE ANIMATION STARTS
plotter.add_fem_mesh(nodes, elements, animate=mode_shape, field="norm")
plotter.configure_gif_recorder('mode_shape.gif', fps=30) # Configure the GIF recorder
plotter.show()
The recording will start on pressing the “Record” button in the toolbar. Alternatively, the configure_gif_recorder can be called like this:
plotter.configure_gif_recorder('mode_shape.gif', fps=30, start_on_play=True)
This will start the recording when the animation starts. To start the animation, call the start_animation method or press the “Play” button in the toolbar.
The recording will last for 1 iteration of the animation.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sdypy_view-0.1.5.tar.gz.
File metadata
- Download URL: sdypy_view-0.1.5.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4405192c622269fff3285157e222be91fbe229fbb9f9ee8c34d2959cb0adc3de
|
|
| MD5 |
df78e00c89acf4d340c7ded01f9b4138
|
|
| BLAKE2b-256 |
cf1facad0e4607a798f3d05eda6110e1a96aa8fada167b2fa3695f7ef50ed03d
|
File details
Details for the file sdypy_view-0.1.5-py3-none-any.whl.
File metadata
- Download URL: sdypy_view-0.1.5-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0efe6d28d32ed9288c217d4a73ab3cab044a5e122757f162e73e3d6cecf1d287
|
|
| MD5 |
d057837aa469139383386d651b09a2e3
|
|
| BLAKE2b-256 |
a8c86f743755435c3cf59c7fa9124e6aeea500c1594074ddd3af6c96e2126c04
|