Skip to content
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

Fix result query on zones #445

Merged
merged 6 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions examples/04-Fluid-Examples/00-explore-fluid-simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,10 @@
# water_temperature = simulation.temperature(phases=[2])
print(water_temperature)
# # The dataframe obtained now only stores data for the water phase.

###############################################################################
# To extract a result on given zones use the 'zone_ids' argument
# or the 'qualifiers' dictionary argument with key 'zone'
# Here we request and plot the temperature on all face zones
face_temperature = simulation.temperature(zone_ids=list(simulation.face_zones.keys()))
face_temperature.plot()
17 changes: 9 additions & 8 deletions src/ansys/dpf/post/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,14 +826,6 @@ def plot(self, shell_layer=shell_layers.top, **kwargs) -> Union[DpfPlotter, None
# )
# )
# return None
field_to_plot = fields[0]
# If multi-component, take the norm
if field_to_plot.component_count > 1:
field_to_plot = dpf.operators.math.norm(
field_to_plot, server=field_to_plot._server
).eval()
plotter = DpfPlotter(**kwargs)
plotter.add_field(field=fields[0], **kwargs)
# for field in fields:
if len(fields) > 1:
# try:
Expand All @@ -851,6 +843,15 @@ def plot(self, shell_layer=shell_layers.top, **kwargs) -> Union[DpfPlotter, None
# )
# return None
# field.plot(text="debug")
field_to_plot = fields[0]
# If multi-component, take the norm
if field_to_plot.component_count > 1:
field_to_plot = dpf.operators.math.norm(
field_to_plot, server=field_to_plot._server
).eval()
plotter = DpfPlotter(**kwargs)
plotter.add_field(field=field_to_plot, **kwargs)

return plotter.show_figure(
title=kwargs.pop("title", str(label_space)), **kwargs
)
Expand Down
12 changes: 12 additions & 0 deletions src/ansys/dpf/post/fluid_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,23 @@ def _get_result(
location=location,
force_elemental_nodal=False,
)
query_regions_meshes = False
lists = []
lists_labels = []
if qualifiers:
labels = list(qualifiers.keys())
lists_labels.extend(labels)
lists.extend([qualifiers[key] for key in labels])
if "zone" in labels:
query_regions_meshes = qualifiers["zone"]
else:
if set_ids:
lists.append(set_ids)
lists_labels.append("time")
if zone_ids:
lists.append(zone_ids)
lists_labels.append("zone")
query_regions_meshes = zone_ids
if phases:
phase_ids = []
available_phases = self.phases
Expand All @@ -423,6 +427,14 @@ def _get_result(
# Its output is selected as future workflow output for now
# print(result_op)

if query_regions_meshes:
# Results have been queried on regions,
# A MeshesProvider is required to give meshes as input of the source operator
meshes_provider_op = self._model.operator("meshes_provider")
meshes_provider_op.connect(25, query_regions_meshes)
wf.add_operator(meshes_provider_op)
result_op.connect(7, meshes_provider_op.outputs.meshes)
rafacanton marked this conversation as resolved.
Show resolved Hide resolved

out = result_op.outputs.fields_container
# Its inputs are selected as workflow inputs for merging with selection workflows
wf.set_input_name("time_scoping", result_op.inputs.time_scoping)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_fluid_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,24 @@ def test_results_fluent_cross_locations_on_cells(self, fluent_simulation):
""" # noqa: W291, E501
assert str(result) == ref
result.plot()

def test_plot_result_on_zones(self, fluent_simulation):
temperature = fluent_simulation.temperature(
zone_ids=list(fluent_simulation.cell_zones.keys())
)
temperature.plot()

temperature = fluent_simulation.temperature(
qualifiers={"zone": list(fluent_simulation.cell_zones.keys())}
)
temperature.plot()

temperature = fluent_simulation.temperature(
zone_ids=list(fluent_simulation.face_zones.keys())
)
temperature.plot()

temperature = fluent_simulation.temperature(
qualifiers={"zone": list(fluent_simulation.face_zones.keys())}
)
temperature.plot()
Loading