Skip to content

Adds mode number and frequency value with unit in animator #1700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/ansys/dpf/core/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,18 @@
)

# Get fields
available_mode_numbers = fields_container.get_available_ids_for_label("time")


if not mode_number in available_mode_numbers:
raise ValueError(

Check warning on line 101 in src/ansys/dpf/core/animation.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/animation.py#L101

Added line #L101 was not covered by tests
f"The mode {mode_number} data is not available in field container."
)
fields_mode = fields_container.get_fields({"time": mode_number})
mode_frequencies_field = fields_container.time_freq_support.time_frequencies
mode_frequencies = mode_frequencies_field.data
mode_frequency = mode_frequencies[available_mode_numbers.index(mode_number)]


# Merge fields if needed
if len(fields_mode) > 1:
Expand All @@ -107,6 +118,7 @@

max_data = float(np.max(field_mode.data))
loop_over = dpf.fields_factory.field_from_array(scale_factor_per_frame)
loop_over.unit = mode_frequencies_field.unit

# Create workflow
wf = dpf.Workflow()
Expand All @@ -119,6 +131,7 @@

wf.set_input_name("ponderation", scaling_op.inputs.ponderation)
wf.set_output_name("field", scaling_op.outputs.field)
wf.set_output_name("deform_by", scaling_op.outputs.field)

anim = Animator(workflow=wf, **kwargs)

Expand All @@ -128,6 +141,8 @@
output_name="field",
save_as=save_as,
mode_number=mode_number,
mode_frequency = mode_frequency,
clim=[0, max_data],
scale_factor=deform_scale_factor,
**kwargs,
)
8 changes: 5 additions & 3 deletions src/ansys/dpf/core/animator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def animate_workflow(
input_name="loop_over",
save_as="",
mode_number=None,
mode_frequency = None,
scale_factor=1.0,
**kwargs,
):
Expand All @@ -68,7 +69,7 @@ def animate_workflow(
scale_factor = [False] * len(indices)
type_scale = type(scale_factor)
if type_scale in [int, float]:
scale_factor = [scale_factor] * len(indices)
scale_factor = [float(scale_factor)] * len(indices)
elif type_scale == list:
pass
# elif type_scale in [core.field.Field, core.fields_container.FieldsContainer]:
Expand Down Expand Up @@ -119,6 +120,7 @@ def render_frame(frame):
self.add_field(
field,
deform_by=deform,
scale_factor=scale_factor[frame],
scale_factor_legend=scale_factor[frame],
**kwargs,
)
Expand All @@ -129,9 +131,9 @@ def render_frame(frame):
str_template.format(indices[frame], unit, freq_fmt), **kwargs_in
)
else:
str_template = "frq={0:{2}} {1}"
str_template = "mode={3}\nfrq={0:{2}} {1}"
self._plotter.add_text(
str_template.format(mode_number, unit, freq_fmt), **kwargs_in
str_template.format(mode_frequency, unit, freq_fmt, mode_number), **kwargs_in
)

if cpos:
Expand Down
Loading