Skip to content

Commit 0ff10c9

Browse files
committed
Expose shell_layer parameter in Animator.animate() and FieldsContainer.animate()
1 parent 86ff813 commit 0ff10c9

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/ansys/dpf/core/animator.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def animate_workflow(
6060
save_as="",
6161
mode_number=None,
6262
scale_factor=1.0,
63+
shell_layer=core.shell_layers.top,
6364
**kwargs,
6465
):
6566
unit = loop_over.unit
@@ -121,6 +122,7 @@ def render_frame(frame):
121122
field,
122123
deform_by=deform,
123124
scale_factor_legend=scale_factor[frame],
125+
shell_layer=shell_layer,
124126
**kwargs,
125127
)
126128
kwargs_in = _sort_supported_kwargs(bound_method=self._plotter.add_text, **freq_kwargs)
@@ -267,33 +269,37 @@ def animate(
267269
save_as: str = None,
268270
scale_factor: Union[float, Sequence[float]] = 1.0,
269271
freq_kwargs: dict = None,
272+
shell_layer: core.shell_layers = core.shell_layers.top,
270273
**kwargs,
271274
):
272275
"""
273276
Animate the workflow of the Animator, using inputs.
274277
275278
Parameters
276279
----------
277-
loop_over : Field
280+
loop_over:
278281
Field of values to loop over.
279282
Can for example be a subset of sets of TimeFreqSupport.time_frequencies.
280283
The unit of the Field will be displayed if present.
281-
output_name : str, optional
284+
output_name:
282285
Name of the workflow output to use as Field for each frame's contour.
283286
Defaults to "to_render".
284-
input_name : list of str, optional
287+
input_name:
285288
Name of the workflow inputs to feed loop_over values into.
286289
Defaults to "loop_over".
287-
save_as : str, optional
290+
save_as:
288291
Path of file to save the animation to. Defaults to None. Can be of any format supported
289292
by pyvista.Plotter.write_frame (.gif, .mp4, ...).
290-
scale_factor : float, list, optional
293+
scale_factor:
291294
Scale factor to apply when warping the mesh. Defaults to 1.0. Can be a list to make
292295
scaling frequency-dependent.
293-
freq_kwargs : dict, optional
296+
freq_kwargs:
294297
Dictionary of kwargs given to the :func:`pyvista.Plotter.add_text` method, used to
295298
format the frequency information. Can also contain a "fmt" key,
296299
defining the format for the frequency displayed with a string such as ".3e".
300+
shell_layer:
301+
Enum used to set the shell layer if the field to plot
302+
contains shell elements. Defaults to top layer.
297303
**kwargs : optional
298304
Additional keyword arguments for the animator.
299305
Used by :func:`pyvista.Plotter` (off_screen, cpos, ...),
@@ -314,6 +320,7 @@ def animate(
314320
save_as=save_as,
315321
scale_factor=scale_factor,
316322
freq_kwargs=freq_kwargs,
323+
shell_layer=shell_layer,
317324
**kwargs,
318325
)
319326

src/ansys/dpf/core/fields_container.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@
2626
Contains classes associated with the DPF FieldsContainer.
2727
"""
2828

29+
from __future__ import annotations
30+
31+
from typing import TYPE_CHECKING
32+
2933
from ansys import dpf
3034
from ansys.dpf.core import errors as dpf_errors, field
3135
from ansys.dpf.core.collection_base import CollectionBase
36+
from ansys.dpf.core.common import shell_layers
37+
38+
if TYPE_CHECKING:
39+
from ansys.dpf.core import Operator, Result
3240

3341

3442
class FieldsContainer(CollectionBase["field.Field"]):
@@ -543,23 +551,39 @@ def plot(self, label_space: dict = None, **kwargs):
543551
plt.add_field(field=f, **kwargs)
544552
plt.show_figure(**kwargs)
545553

546-
def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs):
554+
def animate(
555+
self,
556+
save_as: str = None,
557+
deform_by: Union[FieldsContainer, Result, Operator] = None,
558+
scale_factor: Union[float, Sequence[float]] = 1.0,
559+
shell_layer: shell_layers = shell_layers.top,
560+
**kwargs,
561+
):
547562
"""Create an animation based on the Fields contained in the FieldsContainer.
548563
549564
This method creates a movie or a gif based on the time ids of a FieldsContainer.
550565
For kwargs see pyvista.Plotter.open_movie/add_text/show.
551566
552567
Parameters
553568
----------
554-
save_as : Path of file to save the animation to. Defaults to None. Can be of any format
569+
save_as:
570+
Path of file to save the animation to. Defaults to None. Can be of any format
555571
supported by pyvista.Plotter.write_frame (.gif, .mp4, ...).
556-
deform_by : FieldsContainer, Result, Operator, optional
572+
deform_by:
557573
Used to deform the plotted mesh. Must return a FieldsContainer of the same length as
558574
self, containing 3D vector Fields of distances.
559575
Defaults to None, which takes self if possible. Set as False to force static animation.
560576
scale_factor : float, list, optional
561577
Scale factor to apply when warping the mesh. Defaults to 1.0. Can be a list to make
562578
scaling frequency-dependent.
579+
shell_layer:
580+
Enum used to set the shell layer if the field to plot
581+
contains shell elements. Defaults to top layer.
582+
**kwargs:
583+
Additional keyword arguments for the animator.
584+
Used by :func:`pyvista.Plotter` (off_screen, cpos, ...),
585+
or by :func:`pyvista.Plotter.open_movie`
586+
(framerate, quality, ...)
563587
"""
564588
from ansys.dpf.core.animator import Animator
565589

@@ -655,6 +679,7 @@ def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs):
655679
loop_over=loop_over_field,
656680
save_as=save_as,
657681
scale_factor=scale_factor,
682+
shell_layer=shell_layer,
658683
**kwargs,
659684
)
660685

0 commit comments

Comments
 (0)