Visualisation and export#
femorph-solver builds on pyvista for geometry and rendering. Every
Model carries its mesh as a
pyvista.UnstructuredGrid at Model.grid; post-processing
is a matter of attaching result arrays to that grid and using pyvista /
VTK tools on it.
Attaching result arrays#
# Static analysis
static = m.solve()
m.grid["u"] = static.displacement.reshape(-1, 3)
# Modal analysis — pick a single mode.
modal = m.modal_solve(n_modes=10)
m.grid["mode_7"] = modal.mode_shapes[:, 7].reshape(-1, 3)
# Strain
eps = m.eel(static.displacement)
m.grid["eps_von_mises"] = _von_mises_from_voigt(eps) # or a scalar field you compute
pyvista treats (n_nodes, 3) arrays as vector fields and (n_nodes,
k) arrays (k > 3 or k == 1) as scalar / general fields. Naming is
free — whatever you pass through as a dictionary key shows up as the
field name in ParaView.
Deformed-shape plot#
import pyvista as pv
modal = m.modal_solve(n_modes=10)
grid = m.grid.copy()
grid["u"] = modal.mode_shapes[:, 7].reshape(-1, 3)
warped = grid.warp_by_vector("u", factor=0.1) # 10% amplitude
plotter = pv.Plotter()
plotter.add_mesh(warped, scalars="u", component=2) # z-component colouring
plotter.add_mesh(grid, style="wireframe", color="grey", opacity=0.3)
plotter.show()
Off-screen / CI plots#
For headless rendering in CI or docs build, set pyvista.OFF_SCREEN =
True before the first plotter is constructed. femorph-solver’s Sphinx-gallery
examples do this in a notebook-boilerplate cell; see
doc/source/conf.py.
Writing to disk#
VTK writers are built into pyvista:
Target |
File extension |
Notes |
|---|---|---|
VTK legacy |
|
Widely compatible but text-heavy; large files. |
VTK XML unstructured |
|
ParaView / VisIt default; compact binary. |
pyvista-zstd |
|
femorph-solver’s preferred snapshot format (see
|
m.grid["u"] = static.displacement.reshape(-1, 3)
m.grid.save("static.vtu") # ParaView-friendly
m.grid.save("snapshot.pv") # zstd-compressed
The femorph_solver.io module provides a thin convenience wrapper
(write_modal_vtk) that writes one .vtu per mode with the mode
shape attached — useful for animating modes downstream.
Modal animation helper#
from femorph_solver.io import write_modal_vtk
write_modal_vtk(m.grid, modal, out_dir="modes/", prefix="blade")
# modes/blade_mode_00.vtu ... modes/blade_mode_09.vtu
Each file carries a u vector field (the mode shape) and a
frequency scalar metadata; ParaView’s Warp By Vector filter
makes instant animations.
See also#
Result objects — source arrays for every plot here.
Strain and stress recovery — deriving \(\varepsilon\) / \(\sigma\) for colour-mapped plots.
pyvista.UnstructuredGrid— the mesh type the Model wraps.