Skip to content

DeformationRenderer

DeformationRenderer

DeformationRenderer(results)

Render recorded translations as a deformed-mesh MP4 movie.

Obtain this object with ResultSet.deformation_renderer() and keep its result set open until write() finishes. Configuration methods return this renderer, so they can be called separately or chained. They do not write files.

Parameters:

Name Type Description Default
results ResultSet

Open results providing meshes and point-response frames.

required

Raises:

Type Description
UnsupportedResultOperation

Any reader lacks mesh or point-frame access.

Example
from femora.results import open_results

with open_results("results/building_response*.vtkhdf") as results:
    movie = results.deformation_renderer()
    movie.deform_by("displacement", scale=20)
    movie.color_by("displacement", reduction="magnitude", cmap="viridis")
    movie.style_mesh(show_edges=True, line_width=3)
    movie.set_view(background="white")
    movie.write("building.mp4", stride=2, frame_rate=25)
Note

All partition meshes are shown together, without merging shared nodes. Members are drawn using mesh connectivity, not reconstructed curved beam shapes from nodal rotations. No clipping/cutaway is performed. Movie creation requires off-screen VTK/OpenGL support and an imageio/FFmpeg writer; this class does not install either dependency.

Methods:

Name Description
deform_by

Choose the vector added to the undeformed mesh coordinates.

color_by

Color the movie by a recorded field or a static mesh array.

style_mesh

Set appearance options for every partition's mesh actor.

set_view

Configure one camera for all displayed partitions.

write

Write selected recorded samples as an off-screen MP4 movie.

Methods:

deform_by

deform_by(response: str = 'displacement', *, scale: float = 1.0) -> 'DeformationRenderer'

Choose the vector added to the undeformed mesh coordinates.

Parameters:

Name Type Description Default
response str

Point-vector field name; normally "displacement".

'displacement'
scale float

Positive visual multiplier; 1 means true model-unit deformation.

1.0

Returns:

Type Description
'DeformationRenderer'

This renderer for further configuration.

Raises:

Type Description
ValueError

Scale is not positive.

Note

Coordinates are original XYZ + scale * response XYZ. Additional components such as rotations are ignored. Gravity displacement is not subtracted. Using velocity here is not a displacement movie.

color_by

color_by(field: str, *, location: str = 'point', reduction: Optional[Union[str, int]] = None, **options: Any) -> 'DeformationRenderer'

Color the movie by a recorded field or a static mesh array.

Parameters:

Name Type Description Default
field str

Available response name, or a static array in every mesh.

required
location str

"point" or "cell".

'point'
reduction Optional[Union[str, int]]

None to pass values through; "magnitude" for vector norms; 0, 1, or 2 for a component. Color values are not multiplied by the deformation scale. Reduction applies to transient fields; static mesh arrays are passed through unchanged.

None
**options Any

PyVista coloring options, such as cmap, clim, or scalar_bar_args. Use a fixed clim to choose a common color range.

{}

Returns:

Type Description
'DeformationRenderer'

This renderer.

Raises:

Type Description
ValueError

Location or reduction is unsupported. Missing arrays are detected when write() is called.

Example
movie.color_by("acceleration", reduction=0, cmap="coolwarm", clim=(-2, 2))

style_mesh

style_mesh(**options: Any) -> 'DeformationRenderer'

Set appearance options for every partition's mesh actor.

Parameters:

Name Type Description Default
**options Any

Options passed to PyVista Plotter.add_mesh(), for example show_edges, color, opacity, line_width, and lighting. Coloring configured by color_by() takes precedence for scalar options.

{}

Returns:

Type Description
'DeformationRenderer'

This renderer. Existing style options are updated, not cleared.

set_view

set_view(camera_position: Any = None, *, parallel_projection: bool = False, zoom: Optional[float] = None, background: Any = None) -> 'DeformationRenderer'

Configure one camera for all displayed partitions.

Parameters:

Name Type Description Default
camera_position Any

PyVista camera preset or (position, focal_point, view_up) tuple. None leaves the default automatic view.

None
parallel_projection bool

Use orthographic rather than perspective view.

False
zoom Optional[float]

Optional PyVista camera zoom factor.

None
background Any

Optional PyVista color, for example "white".

None

Returns:

Type Description
'DeformationRenderer'

This renderer. Settings are applied when write() creates the plotter.

write

write(filename: Union[str, Path], *, stride: int = 1, frame_rate: int = 30, quality: int = 5, progress: bool = True, window_size: tuple[int, int] = (960, 544)) -> Path

Write selected recorded samples as an off-screen MP4 movie.

Parameters:

Name Type Description Default
filename Union[str, Path]

Movie path; its parent directory is created if necessary. Existing output may be overwritten by the movie writer.

required
stride int

Positive sample interval. 1 renders every recorded sample; 5 renders indices 0, 5, 10, and so on.

1
frame_rate int

Positive output frames per second; not the solver time step.

30
quality int

Quality forwarded to PyVista/imageio, normally 0-10.

5
progress bool

Display a tqdm progress bar if True.

True
window_size tuple[int, int]

Output width and height in pixels.

(960, 544)

Returns:

Type Description
Path

pathlib.Path to the written movie.

Raises:

Type Description
ValueError

Stride/frame rate is not positive or deformation is not a usable vector field.

KeyError

The deformation or coloring field is unavailable.

Note

For uniform recorder spacing dt_record, physical-speed playback uses frame_rate = 1 / (stride * dt_record). Frames have equal video duration even if recorder timestamps are irregular. Lower stride alone does not improve analysis accuracy. Geometry is loaded for every partition, while response fields are read one frame at a time. Rendering/encoder failures are propagated, not silently ignored.