Skip to content

Commit d9113dc

Browse files
authored
Fix deformation in fields container animate (#582)
* WIP * WIP * Fix error in deformation field for fields_container.py::animate * Fix error in deformation field for fields_container.py::animate * Update example due to fix
1 parent c7f29e4 commit d9113dc

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

ansys/dpf/core/fields_container.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,11 @@ def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs):
517517
# Define the field extraction using the fields_container and indices
518518
extract_field_op = dpf.core.operators.utility.extract_field(self)
519519

520+
loop_over = self.get_time_scoping()
521+
frequencies = self.time_freq_support.time_frequencies
522+
if frequencies is None:
523+
raise ValueError("The fields_container has no time_frequencies.")
524+
520525
# TODO /!\ We should be using a mechanical::time_selector, however it is not wrapped.
521526

522527
wf.set_input_name("indices", extract_field_op.inputs.indices) # Have to do it this way
@@ -543,8 +548,8 @@ def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs):
543548
f"!= len(self)={len(self)}).")
544549
else:
545550
deform = False
546-
if deform:
547551

552+
if deform:
548553
scale_factor_fc = dpf.core.animator.scale_factor_to_fc(scale_factor, deform_by)
549554
scale_factor_invert = dpf.core.operators.math.invert_fc(scale_factor_fc)
550555
# Extraction of the field of interest based on index
@@ -559,22 +564,12 @@ def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs):
559564

560565
divide_op = dpf.core.operators.math.component_wise_divide(
561566
extract_field_op_2.outputs.field, extract_scale_factor_op.outputs.field)
562-
# Get the mesh from the field to render
563-
get_mesh_op = dpf.core.operators.mesh.from_field(extract_field_op.outputs.field)
564-
# Get the coordinates field from the mesh
565-
get_coordinates_op = dpf.core.operators.mesh.node_coordinates(get_mesh_op.outputs.mesh)
566-
# Addition to the scaled deformation field
567-
add_op = dpf.core.operators.math.add(divide_op.outputs.field,
568-
get_coordinates_op.outputs.coordinates_as_field)
569-
wf.set_output_name("deform_by", add_op.outputs.field)
570-
add_op.progress_bar = False
567+
wf.set_output_name("deform_by", divide_op.outputs.field)
571568
else:
572569
scale_factor = None
573570
wf.set_output_name("to_render", extract_field_op.outputs.field)
574571
wf.progress_bar = False
575572

576-
loop_over = self.get_time_scoping()
577-
frequencies = self.time_freq_support.time_frequencies
578573
loop_over_field = dpf.core.fields_factory.field_from_array(
579574
frequencies.data[loop_over.ids-1])
580575
loop_over_field.scoping.ids = loop_over.ids

examples/05-plotting/06-animate_results.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@
9292

9393
# import copy
9494
# camera_pos_list = []
95-
# init_pos = [(2.341999327925363, 2.2535751881950388, 3.241992870018055),
96-
# (0.10000000000000725, 0.01157586026968312, 0.9999935420927001),
95+
# init_pos = [(1.1710286191854873, 1.1276044794551632, 1.62102216127818),
96+
# (0.05000000000000724, 0.006575860269683119, 0.4999935420927001),
9797
# (0.0, 0.0, 1.0)]
9898
# camera_pos_list.append(init_pos)
9999
# for i in range(1, len(displacement_fields)):

0 commit comments

Comments
 (0)