Skip to content

Commit

Permalink
Fix result query on zones (#445)
Browse files Browse the repository at this point in the history
* Refactor Dataframe.plot

* Fix result query for regions (zone_ids or qualifiers["zone"]) by adding a mesh query

* Add testing

* Update example to showcase this feature

* Add case with MeshProvider

* Add case with MeshProvider
  • Loading branch information
PProfizi authored Jul 31, 2023
1 parent 8e25b46 commit fcf3dc2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
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
18 changes: 18 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,20 @@ 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)
result_op.connect(7, meshes_provider_op.outputs.meshes)
wf.add_operator(meshes_provider_op)
else:
# Results have been queried on the whole mesh,
# A MeshProvider is required to give the mesh as input of the source operator
mesh_provider_op = self._model.operator("mesh_provider")
result_op.connect(7, mesh_provider_op.outputs.mesh)
wf.add_operator(mesh_provider_op)

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()

0 comments on commit fcf3dc2

Please sign in to comment.