diff --git a/examples/04-Fluid-Examples/00-explore-fluid-simulation.py b/examples/04-Fluid-Examples/00-explore-fluid-simulation.py index ff7e1d69c..c3f72c83e 100644 --- a/examples/04-Fluid-Examples/00-explore-fluid-simulation.py +++ b/examples/04-Fluid-Examples/00-explore-fluid-simulation.py @@ -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() diff --git a/src/ansys/dpf/post/dataframe.py b/src/ansys/dpf/post/dataframe.py index ad851d34d..7239aac66 100644 --- a/src/ansys/dpf/post/dataframe.py +++ b/src/ansys/dpf/post/dataframe.py @@ -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: @@ -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 ) diff --git a/src/ansys/dpf/post/fluid_simulation.py b/src/ansys/dpf/post/fluid_simulation.py index c4be464be..f80894bf7 100644 --- a/src/ansys/dpf/post/fluid_simulation.py +++ b/src/ansys/dpf/post/fluid_simulation.py @@ -388,12 +388,15 @@ 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) @@ -401,6 +404,7 @@ def _get_result( if zone_ids: lists.append(zone_ids) lists_labels.append("zone") + query_regions_meshes = zone_ids if phases: phase_ids = [] available_phases = self.phases @@ -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) diff --git a/tests/test_fluid_simulation.py b/tests/test_fluid_simulation.py index 2fca3e918..e1992f857 100644 --- a/tests/test_fluid_simulation.py +++ b/tests/test_fluid_simulation.py @@ -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()