2626Contains classes associated with the DPF FieldsContainer.
2727"""
2828
29+ from __future__ import annotations
30+
31+ from typing import TYPE_CHECKING , Union
32+
2933from ansys import dpf
3034from ansys .dpf .core import errors as dpf_errors , field
3135from ansys .dpf .core .collection_base import CollectionBase
36+ from ansys .dpf .core .common import shell_layers
37+
38+ if TYPE_CHECKING : # pragma: no cover
39+ from ansys .dpf .core import Operator , Result
3240
3341
3442class 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
@@ -571,11 +595,17 @@ def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs):
571595 # Define the field extraction using the fields_container and indices
572596 extract_field_op = dpf .core .operators .utility .extract_field (self )
573597 to_render = extract_field_op .outputs .field
598+ # Add the operators to the workflow
599+ wf .add_operators ([extract_field_op , forward_index ])
600+
601+ # Treat multi-component fields by taking their norm
574602 n_components = self [0 ].component_count
575603 if n_components > 1 :
576604 norm_op = dpf .core .operators .math .norm (extract_field_op .outputs .field )
605+ wf .add_operator (norm_op )
577606 to_render = norm_op .outputs .field
578607
608+ # Get time steps IDs and values
579609 loop_over = self .get_time_scoping ()
580610 frequencies = self .time_freq_support .time_frequencies
581611 if frequencies is None :
@@ -586,8 +616,6 @@ def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs):
586616
587617 wf .set_input_name ("indices" , extract_field_op .inputs .indices ) # Have to do it this way
588618 wf .connect ("indices" , forward_index ) # Otherwise not accepted
589- # Add the operators to the workflow
590- wf .add_operators ([extract_field_op , forward_index ])
591619
592620 deform = True
593621 # Define whether to deform and what with
@@ -627,6 +655,10 @@ def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs):
627655 extract_field_op_2 .outputs .field , extract_scale_factor_op .outputs .field
628656 )
629657 wf .set_output_name ("deform_by" , divide_op .outputs .field )
658+
659+ wf .add_operators (
660+ [scale_factor_invert , extract_field_op_2 , extract_scale_factor_op , divide_op ]
661+ )
630662 else :
631663 scale_factor = None
632664 wf .set_output_name ("to_render" , to_render )
@@ -647,6 +679,7 @@ def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs):
647679 loop_over = loop_over_field ,
648680 save_as = save_as ,
649681 scale_factor = scale_factor ,
682+ shell_layer = shell_layer ,
650683 ** kwargs ,
651684 )
652685
0 commit comments