From 635ded82a0ea1b277903510d1a6b2f1a7809d64f Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 29 Nov 2023 15:44:50 +0100 Subject: [PATCH 01/10] Fix/update selection workflow metadata for visualization --- src/ansys/dpf/post/selection.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ansys/dpf/post/selection.py b/src/ansys/dpf/post/selection.py index e2cad3f45..9d19bd781 100644 --- a/src/ansys/dpf/post/selection.py +++ b/src/ansys/dpf/post/selection.py @@ -246,6 +246,7 @@ def select_named_selection( named_selection_name=named_selection, server=self._server, ) + self._selection.add_operator(op) self._selection.set_input_name( _WfNames.data_sources, op.inputs.data_sources ) @@ -257,6 +258,7 @@ def select_named_selection( op = operators.utility.merge_scopings(server=self._server) forward_ds = operators.utility.forward(any=None, server=self._server) forward_sc = operators.utility.forward(any=None, server=self._server) + self._selection.add_operators([op, forward_ds, forward_sc]) self._selection.set_input_name(_WfNames.data_sources, forward_ds.inputs.any) # self._selection.set_input_name(_WfNames.streams, forward_sc.inputs.any) for pin, ns in enumerate(named_selection): @@ -267,13 +269,12 @@ def select_named_selection( # data_sources=forward_ds.outputs.any, # streams_container=forward_sc.outputs.any, ) + self._selection.add_operator(mesh_scoping_op) mesh_scoping_op.connect(3, forward_sc.outputs.any) mesh_scoping_op.connect(4, forward_ds.outputs.any) op.connect(pin, mesh_scoping_op.outputs.mesh_scoping) self._selection.set_output_name(_WfNames.scoping, op.outputs.merged_scoping) - self._selection.add_operator(op) - def select_external_layer( self, location: Union[locations, str] = locations.elemental, @@ -312,9 +313,11 @@ def select_external_layer( ): location = result_native_location op = operators.mesh.external_layer(server=self._server) + self._selection.add_operator(op) if _is_model_cyclic(is_model_cyclic): mesh_provider_cyc = operators.mesh.mesh_provider() + self._selection.add_operator(mesh_provider_cyc) self._selection.set_input_name(_WfNames.read_cyclic, mesh_provider_cyc, 14) self._selection.set_input_name( _WfNames.cyclic_sectors_to_expand, mesh_provider_cyc, 18 @@ -335,6 +338,7 @@ def select_external_layer( scoping=elements, server=self._server, ) + self._selection.add_operator(mesh_by_scop_op) op.inputs.mesh.connect(mesh_by_scop_op) else: op.inputs.mesh.connect(mesh_provider_cyc) @@ -349,6 +353,7 @@ def select_external_layer( mesh_by_scop_op = operators.mesh.from_scoping( scoping=elements, server=self._server ) + self._selection.add_operator(mesh_by_scop_op) self._selection.set_input_name( _WfNames.initial_mesh, mesh_by_scop_op.inputs.mesh ) @@ -367,8 +372,6 @@ def select_external_layer( _WfNames.scoping, op.outputs.elements_mesh_scoping ) - self._selection.add_operator(op) - def select_skin( self, location: Union[locations, str] = locations.elemental, @@ -402,10 +405,12 @@ def select_skin( on the expanded mesh. """ op = operators.mesh.skin(server=self._server) + self._selection.add_operator(op) mesh_input = op.inputs.mesh if _is_model_cyclic(is_model_cyclic): mesh_provider_cyc = operators.mesh.mesh_provider() + self._selection.add_operator(mesh_provider_cyc) self._selection.set_input_name(_WfNames.read_cyclic, mesh_provider_cyc, 14) self._selection.set_input_name( _WfNames.cyclic_sectors_to_expand, mesh_provider_cyc, 18 @@ -430,6 +435,7 @@ def select_skin( scoping=elements, server=self._server, ) + self._selection.add_operator(mesh_by_scop_op) op.inputs.mesh.connect(mesh_by_scop_op) else: op.inputs.mesh.connect(mesh_provider_cyc) @@ -446,6 +452,7 @@ def select_skin( mesh_by_scop_op = operators.mesh.from_scoping( scoping=elements, server=self._server ) + self._selection.add_operator(mesh_by_scop_op) mesh_input = mesh_by_scop_op.inputs.mesh op.inputs.mesh.connect(mesh_by_scop_op) @@ -466,6 +473,7 @@ def select_skin( transpose_op = operators.scoping.transpose( mesh_scoping=op.outputs.nodes_mesh_scoping, server=self._server ) + self._selection.add_operator(transpose_op) self._selection.set_input_name( _WfNames.initial_mesh, transpose_op.inputs.meshed_region ) @@ -473,8 +481,6 @@ def select_skin( _WfNames.scoping, transpose_op.outputs.mesh_scoping_as_scoping ) - self._selection.add_operator(op) - def select_with_scoping(self, scoping: Scoping): """Directly sets the scoping as the spatial selection. From e9db013d1e3be43ff8a672f85aadcfee7080df4e Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 29 Nov 2023 15:45:12 +0100 Subject: [PATCH 02/10] Fix/update result workflow metadata for visualization --- src/ansys/dpf/post/simulation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ansys/dpf/post/simulation.py b/src/ansys/dpf/post/simulation.py index 02536a8e6..ec97388cb 100644 --- a/src/ansys/dpf/post/simulation.py +++ b/src/ansys/dpf/post/simulation.py @@ -542,6 +542,7 @@ def _build_result_workflow( elif location: op.connect(9, location) wf = Workflow(server=self._model._server) + wf.add_operator(op) wf.set_input_name(_WfNames.read_cyclic, op, 14) wf.set_input_name(_WfNames.cyclic_sectors_to_expand, op, 18) wf.set_input_name(_WfNames.cyclic_phase, op, 19) From c2d775c8314c8ef770992158c8f1c3063621592c Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 29 Nov 2023 15:45:34 +0100 Subject: [PATCH 03/10] Fix/update StaticMechanical workflow metadata for visualization --- src/ansys/dpf/post/static_mechanical_simulation.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index f604db6ec..2bd46a474 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -56,6 +56,7 @@ def _get_result_workflow( ) if selection.requires_mesh: mesh_wf = core.Workflow(server=self._model._server) + mesh_wf.add_operator(self._model.metadata.mesh_provider) mesh_wf.set_output_name( _WfNames.initial_mesh, self._model.metadata.mesh_provider ) @@ -89,10 +90,10 @@ def _get_result_workflow( # Instantiate the required operator principal_op = self._model.operator(name="invariants_fc") # Corresponds to scripting name principal_invariants - if average_op is not None: average_op[0].connect(0, out) principal_op.connect(0, average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow average_op = None else: @@ -117,12 +118,13 @@ def _get_result_workflow( ): equivalent_op.connect(0, out) average_op[0].connect(0, equivalent_op) - wf.add_operator(operator=average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow out = average_op[1].outputs.fields_container elif average_op is not None: average_op[0].connect(0, out) equivalent_op.connect(0, average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow out = equivalent_op.outputs.fields_container else: @@ -134,6 +136,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) + wf.add_operators(average_op) out = average_op[1].outputs.fields_container # Add an optional component selection step if result is vector, matrix, or principal From e816646602079da13f02e4ddc37371897e14f011 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 29 Nov 2023 15:53:08 +0100 Subject: [PATCH 04/10] Fix/update ModalMechanical workflow metadata for visualization --- src/ansys/dpf/post/modal_mechanical_simulation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ansys/dpf/post/modal_mechanical_simulation.py b/src/ansys/dpf/post/modal_mechanical_simulation.py index 7fd1f9c9d..fd3c327a8 100644 --- a/src/ansys/dpf/post/modal_mechanical_simulation.py +++ b/src/ansys/dpf/post/modal_mechanical_simulation.py @@ -56,6 +56,7 @@ def _get_result_workflow( ) if selection.requires_mesh: mesh_wf = dpf.Workflow(server=self._model._server) + mesh_wf.add_operator(self._model.metadata.mesh_provider) mesh_wf.set_output_name( _WfNames.initial_mesh, self._model.metadata.mesh_provider ) @@ -94,6 +95,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) principal_op.connect(0, average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow average_op = None else: @@ -118,12 +120,13 @@ def _get_result_workflow( ): equivalent_op.connect(0, out) average_op[0].connect(0, equivalent_op) - wf.add_operator(operator=average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow out = average_op[1].outputs.fields_container elif average_op is not None: average_op[0].connect(0, out) equivalent_op.connect(0, average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow out = equivalent_op.outputs.fields_container else: @@ -134,6 +137,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) + wf.add_operators(average_op) out = average_op[1].outputs.fields_container # Add an optional component selection step if result is vector, matrix, or principal From 1152f85521cb7a8d56c2cf462d19be045d29eb2c Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 29 Nov 2023 15:55:18 +0100 Subject: [PATCH 05/10] Fix/update TransientMechanical workflow metadata for visualization --- src/ansys/dpf/post/transient_mechanical_simulation.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ansys/dpf/post/transient_mechanical_simulation.py b/src/ansys/dpf/post/transient_mechanical_simulation.py index 8730adb96..cfd434480 100644 --- a/src/ansys/dpf/post/transient_mechanical_simulation.py +++ b/src/ansys/dpf/post/transient_mechanical_simulation.py @@ -28,9 +28,6 @@ def _get_result_workflow( """Generate (without evaluating) the Workflow to extract results.""" comp, to_extract, _ = self._create_components(base_name, category, components) - # Initialize a workflow - wf = dpf.Workflow(server=self._model._server) - force_elemental_nodal = self._requires_manual_averaging( base_name=base_name, location=location, @@ -57,6 +54,7 @@ def _get_result_workflow( if selection.requires_mesh: # wf.set_input_name(_WfNames.mesh, result_op.inputs.mesh) mesh_wf = dpf.Workflow(server=self._model._server) + mesh_wf.add_operator(self._model.metadata.mesh_provider) mesh_wf.set_output_name( _WfNames.initial_mesh, self._model.metadata.mesh_provider ) @@ -91,10 +89,12 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) principal_op.connect(0, average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow average_op = None else: principal_op.connect(0, out) + wf.add_operator(operator=principal_op) # Set as future output of the workflow if len(to_extract) == 1: out = getattr(principal_op.outputs, f"fields_eig_{to_extract[0]+1}") @@ -114,12 +114,13 @@ def _get_result_workflow( ): equivalent_op.connect(0, out) average_op[0].connect(0, equivalent_op) - wf.add_operator(operator=average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow out = average_op[1].outputs.fields_container elif average_op is not None: average_op[0].connect(0, out) equivalent_op.connect(0, average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow out = equivalent_op.outputs.fields_container else: @@ -130,6 +131,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) + wf.add_operators(average_op) out = average_op[1].outputs.fields_container # Add an optional component selection step if result is vector, matrix, or principal From 6286c46d6d183036f61783deef10ec934c571260 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 29 Nov 2023 15:58:18 +0100 Subject: [PATCH 06/10] Fix/update HarmonicMechanical workflow metadata for visualization --- src/ansys/dpf/post/harmonic_mechanical_simulation.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ansys/dpf/post/harmonic_mechanical_simulation.py b/src/ansys/dpf/post/harmonic_mechanical_simulation.py index 298a7c2af..8618e58d2 100644 --- a/src/ansys/dpf/post/harmonic_mechanical_simulation.py +++ b/src/ansys/dpf/post/harmonic_mechanical_simulation.py @@ -41,9 +41,6 @@ def _get_result_workflow( """Generate (without evaluating) the Workflow to extract results.""" comp, to_extract, _ = self._create_components(base_name, category, components) - # Initialize a workflow - wf = dpf.Workflow(server=self._model._server) - force_elemental_nodal = self._requires_manual_averaging( base_name=base_name, location=location, @@ -71,6 +68,7 @@ def _get_result_workflow( if selection.requires_mesh: # wf.set_input_name(_WfNames.mesh, result_op.inputs.mesh) mesh_wf = dpf.Workflow(server=self._model._server) + mesh_wf.add_operator(self._model.metadata.mesh_provider) mesh_wf.set_output_name( _WfNames.initial_mesh, self._model.metadata.mesh_provider ) @@ -109,6 +107,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) principal_op.connect(0, average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow average_op = None else: @@ -133,12 +132,13 @@ def _get_result_workflow( ): equivalent_op.connect(0, out) average_op[0].connect(0, equivalent_op) - wf.add_operator(operator=average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow out = average_op[1].outputs.fields_container elif average_op is not None: average_op[0].connect(0, out) equivalent_op.connect(0, average_op[1]) + wf.add_operators(average_op) # Set as future output of the workflow out = equivalent_op.outputs.fields_container else: @@ -149,6 +149,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) + wf.add_operators(average_op) out = average_op[1].outputs.fields_container # Add an optional component selection step if result is vector, or matrix From 401be4ce2bc67124bfc27a1da176045a3151cfba Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 29 Nov 2023 16:13:00 +0100 Subject: [PATCH 07/10] Add Simulation._append_norm() --- src/ansys/dpf/post/fluid_simulation.py | 5 +---- src/ansys/dpf/post/harmonic_mechanical_simulation.py | 7 +------ src/ansys/dpf/post/modal_mechanical_simulation.py | 7 +------ src/ansys/dpf/post/simulation.py | 10 ++++++++++ src/ansys/dpf/post/static_mechanical_simulation.py | 7 +------ src/ansys/dpf/post/transient_mechanical_simulation.py | 7 +------ 6 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/ansys/dpf/post/fluid_simulation.py b/src/ansys/dpf/post/fluid_simulation.py index b7420c2d0..1dce247ec 100644 --- a/src/ansys/dpf/post/fluid_simulation.py +++ b/src/ansys/dpf/post/fluid_simulation.py @@ -469,10 +469,7 @@ def _get_result( # Add an optional norm operation if requested if norm: - norm_op = self._model.operator(name="norm_fc") - norm_op.connect(0, out) - wf.add_operator(operator=norm_op) - out = norm_op.outputs.fields_container + wf, out, comp, base_name = self._append_norm(wf, out, base_name) # if averaging_op_name: # average_op = self._model.operator(name=averaging_op_name) diff --git a/src/ansys/dpf/post/harmonic_mechanical_simulation.py b/src/ansys/dpf/post/harmonic_mechanical_simulation.py index 8618e58d2..bbb279e60 100644 --- a/src/ansys/dpf/post/harmonic_mechanical_simulation.py +++ b/src/ansys/dpf/post/harmonic_mechanical_simulation.py @@ -197,12 +197,7 @@ def _get_result_workflow( # Add an optional norm operation if requested # (must be after sweeping_phase for U) if norm: - norm_op = self._model.operator(name="norm_fc") - norm_op.connect(0, out) - wf.add_operator(operator=norm_op) - out = norm_op.outputs.fields_container - comp = None - base_name += "_N" + wf, out, comp, base_name = self._append_norm(wf, out, base_name) # Set the workflow output wf.set_output_name("out", out) diff --git a/src/ansys/dpf/post/modal_mechanical_simulation.py b/src/ansys/dpf/post/modal_mechanical_simulation.py index fd3c327a8..fd98b156c 100644 --- a/src/ansys/dpf/post/modal_mechanical_simulation.py +++ b/src/ansys/dpf/post/modal_mechanical_simulation.py @@ -159,12 +159,7 @@ def _get_result_workflow( # Add an optional norm operation if requested if norm: - norm_op = self._model.operator(name="norm_fc") - norm_op.connect(0, out) - wf.add_operator(operator=norm_op) - out = norm_op.outputs.fields_container - comp = None - base_name += "_N" + wf, out, comp, base_name = self._append_norm(wf, out, base_name) # Set the workflow output wf.set_output_name("out", out) diff --git a/src/ansys/dpf/post/simulation.py b/src/ansys/dpf/post/simulation.py index ec97388cb..12614410f 100644 --- a/src/ansys/dpf/post/simulation.py +++ b/src/ansys/dpf/post/simulation.py @@ -549,6 +549,16 @@ def _build_result_workflow( wf.set_output_name(_WfNames.result, op, 0) return wf, op + def _append_norm(self, wf, out, base_name): + """Append a norm operator to the current result workflow.""" + norm_op = self._model.operator(name="norm_fc") + norm_op.connect(0, out) + wf.add_operator(operator=norm_op) + base_name += "_N" + out = norm_op.outputs.fields_container + comp = None + return wf, out, comp, base_name + def _create_components(self, base_name, category, components): comp = None # Build the list of requested results diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index 2bd46a474..b19737360 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -158,12 +158,7 @@ def _get_result_workflow( # Add an optional norm operation if requested if norm: - norm_op = self._model.operator(name="norm_fc") - norm_op.connect(0, out) - wf.add_operator(operator=norm_op) - out = norm_op.outputs.fields_container - comp = None - base_name += "_N" + wf, out, comp, base_name = self._append_norm(wf, out, base_name) # Set the workflow output wf.set_output_name("out", out) diff --git a/src/ansys/dpf/post/transient_mechanical_simulation.py b/src/ansys/dpf/post/transient_mechanical_simulation.py index cfd434480..b7bfc2872 100644 --- a/src/ansys/dpf/post/transient_mechanical_simulation.py +++ b/src/ansys/dpf/post/transient_mechanical_simulation.py @@ -157,12 +157,7 @@ def _get_result_workflow( # Add an optional norm operation if requested if norm: - norm_op = self._model.operator(name="norm_fc") - norm_op.connect(0, out) - wf.add_operator(operator=norm_op) - out = norm_op.outputs.fields_container - comp = None - base_name += "_N" + wf, out, comp, base_name = self._append_norm(wf, out, base_name) # Set the workflow output wf.set_output_name("out", out) From 96edd0cb43d4b428e1e8d44e1f8b67d3071d86ac Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 29 Nov 2023 16:22:34 +0100 Subject: [PATCH 08/10] Refactor fluid_simulation.py to add FluidSimulation._get_result_workflow() --- src/ansys/dpf/post/fluid_simulation.py | 220 ++++++++++++++----------- 1 file changed, 127 insertions(+), 93 deletions(-) diff --git a/src/ansys/dpf/post/fluid_simulation.py b/src/ansys/dpf/post/fluid_simulation.py index 1dce247ec..ae05ef23b 100644 --- a/src/ansys/dpf/post/fluid_simulation.py +++ b/src/ansys/dpf/post/fluid_simulation.py @@ -205,6 +205,120 @@ def _filter_zones(self, zone_ids: List[int], keep: locations): ref = set(self.face_zones.keys()) return [i for i in zone_ids if i in ref] + def _get_result_workflow( + self, + base_name: str, + location: str, + category: ResultCategory, + components: Union[str, List[str], int, List[int], None] = None, + norm: bool = False, + selection: Union[Selection, None] = None, + set_ids: Union[int, List[int], None] = None, + zone_ids: Union[List[int], None] = None, + phases: Union[List[Union[int, str]], None] = None, + species: Union[List[int], None] = None, + qualifiers: Union[dict, None] = None, + ) -> (dpf.Workflow, Union[str, list[str], None], str): + """Generate (without evaluating) the Workflow to extract results.""" + comp, to_extract, columns = self._create_components( + base_name, category, components + ) + + # Initialize a workflow + wf, result_op = self._build_result_workflow( + name=base_name, + 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 + for phase in phases: + phase_ids.append(available_phases[phase].id) + lists.append(phase_ids) + lists_labels.append("phase") + if species: + lists.append(species) + lists_labels.append("species") + + if lists: + import itertools + + for i, c in enumerate(itertools.product(*lists)): + label_space = {} + for j, label in enumerate(lists_labels): + label_space[label] = c[j] + result_op.connect(1000 + i, label_space) + # 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) + wf.set_input_name("mesh_scoping", result_op.inputs.mesh_scoping) + + wf.connect_with( + selection.time_freq_selection._selection, + output_input_names=("scoping", "time_scoping"), + ) + wf.connect_with( + selection.spatial_selection._selection, + output_input_names=("scoping", "mesh_scoping"), + ) + + # Connect data_sources and streams_container inputs of selection if necessary + if "streams" in wf.input_names: + wf.connect("streams", self._model.metadata.streams_provider) + if "data_sources" in wf.input_names: + wf.connect("data_sources", self._model.metadata.data_sources) + + # if averaging_op_name: + # average_op = self._model.operator(name=averaging_op_name) + # average_op.connect(0, out) + # wf.add_operator(operator=average_op) + # out = average_op.outputs.fields_container + + # Add an optional norm operation if requested + if norm: + wf, out, comp, base_name = self._append_norm(wf, out, base_name) + + # Set the workflow output + wf.set_output_name("out", out) + wf.progress_bar = False + + return wf, comp, base_name + def _get_result( self, base_name: str, @@ -384,102 +498,20 @@ def _get_result( location=location, ) - comp, to_extract, columns = self._create_components( - base_name, category, components - ) - - # Initialize a workflow - wf, result_op = self._build_result_workflow( - name=base_name, + wf, comp, base_name = self._get_result_workflow( + base_name=base_name, 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 - for phase in phases: - phase_ids.append(available_phases[phase].id) - lists.append(phase_ids) - lists_labels.append("phase") - if species: - lists.append(species) - lists_labels.append("species") - - if lists: - import itertools - - for i, c in enumerate(itertools.product(*lists)): - label_space = {} - for j, label in enumerate(lists_labels): - label_space[label] = c[j] - result_op.connect(1000 + i, label_space) - # 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) - wf.set_input_name("mesh_scoping", result_op.inputs.mesh_scoping) - - wf.connect_with( - selection.time_freq_selection._selection, - output_input_names=("scoping", "time_scoping"), - ) - wf.connect_with( - selection.spatial_selection._selection, - output_input_names=("scoping", "mesh_scoping"), + category=category, + components=components, + norm=norm, + selection=selection, + set_ids=set_ids, + zone_ids=zone_ids, + phases=phases, + species=species, + qualifiers=qualifiers, ) - # Connect data_sources and streams_container inputs of selection if necessary - if "streams" in wf.input_names: - wf.connect("streams", self._model.metadata.streams_provider) - if "data_sources" in wf.input_names: - wf.connect("data_sources", self._model.metadata.data_sources) - - # Add an optional norm operation if requested - if norm: - wf, out, comp, base_name = self._append_norm(wf, out, base_name) - - # if averaging_op_name: - # average_op = self._model.operator(name=averaging_op_name) - # average_op.connect(0, out) - # wf.add_operator(operator=average_op) - # out = average_op.outputs.fields_container - - # Set the workflow output - wf.set_output_name("out", out) - wf.progress_bar = False # Evaluate the workflow fc = wf.get_output("out", dpf.types.fields_container) # print(fc) @@ -487,6 +519,8 @@ def _get_result( location = fc[0].location if location == locations.elemental: location = "cells" + + _, _, columns = self._create_components(base_name, category, components) return self._create_dataframe( fc, location, columns, comp, base_name.split("::")[-1], None ) From 8b7e6552a4b527fc9b60b3d585754096629b4e17 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 29 Nov 2023 16:28:40 +0100 Subject: [PATCH 09/10] Clean FluidSimulation._get_result_workflow --- src/ansys/dpf/post/fluid_simulation.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/ansys/dpf/post/fluid_simulation.py b/src/ansys/dpf/post/fluid_simulation.py index ae05ef23b..a3253dca5 100644 --- a/src/ansys/dpf/post/fluid_simulation.py +++ b/src/ansys/dpf/post/fluid_simulation.py @@ -303,12 +303,6 @@ def _get_result_workflow( if "data_sources" in wf.input_names: wf.connect("data_sources", self._model.metadata.data_sources) - # if averaging_op_name: - # average_op = self._model.operator(name=averaging_op_name) - # average_op.connect(0, out) - # wf.add_operator(operator=average_op) - # out = average_op.outputs.fields_container - # Add an optional norm operation if requested if norm: wf, out, comp, base_name = self._append_norm(wf, out, base_name) From 32b2e2f3645b1cceba7c365d05762b0dad9b7ec9 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 29 Nov 2023 16:33:19 +0100 Subject: [PATCH 10/10] Fix wf.add_operators for average_op --- src/ansys/dpf/post/harmonic_mechanical_simulation.py | 8 ++++---- src/ansys/dpf/post/modal_mechanical_simulation.py | 8 ++++---- src/ansys/dpf/post/static_mechanical_simulation.py | 8 ++++---- src/ansys/dpf/post/transient_mechanical_simulation.py | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ansys/dpf/post/harmonic_mechanical_simulation.py b/src/ansys/dpf/post/harmonic_mechanical_simulation.py index bbb279e60..c0e028db3 100644 --- a/src/ansys/dpf/post/harmonic_mechanical_simulation.py +++ b/src/ansys/dpf/post/harmonic_mechanical_simulation.py @@ -107,7 +107,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) principal_op.connect(0, average_op[1]) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow average_op = None else: @@ -132,13 +132,13 @@ def _get_result_workflow( ): equivalent_op.connect(0, out) average_op[0].connect(0, equivalent_op) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow out = average_op[1].outputs.fields_container elif average_op is not None: average_op[0].connect(0, out) equivalent_op.connect(0, average_op[1]) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow out = equivalent_op.outputs.fields_container else: @@ -149,7 +149,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) out = average_op[1].outputs.fields_container # Add an optional component selection step if result is vector, or matrix diff --git a/src/ansys/dpf/post/modal_mechanical_simulation.py b/src/ansys/dpf/post/modal_mechanical_simulation.py index fd98b156c..6ac8feefb 100644 --- a/src/ansys/dpf/post/modal_mechanical_simulation.py +++ b/src/ansys/dpf/post/modal_mechanical_simulation.py @@ -95,7 +95,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) principal_op.connect(0, average_op[1]) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow average_op = None else: @@ -120,13 +120,13 @@ def _get_result_workflow( ): equivalent_op.connect(0, out) average_op[0].connect(0, equivalent_op) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow out = average_op[1].outputs.fields_container elif average_op is not None: average_op[0].connect(0, out) equivalent_op.connect(0, average_op[1]) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow out = equivalent_op.outputs.fields_container else: @@ -137,7 +137,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) out = average_op[1].outputs.fields_container # Add an optional component selection step if result is vector, matrix, or principal diff --git a/src/ansys/dpf/post/static_mechanical_simulation.py b/src/ansys/dpf/post/static_mechanical_simulation.py index b19737360..3f9d5c8b2 100644 --- a/src/ansys/dpf/post/static_mechanical_simulation.py +++ b/src/ansys/dpf/post/static_mechanical_simulation.py @@ -93,7 +93,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) principal_op.connect(0, average_op[1]) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow average_op = None else: @@ -118,13 +118,13 @@ def _get_result_workflow( ): equivalent_op.connect(0, out) average_op[0].connect(0, equivalent_op) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow out = average_op[1].outputs.fields_container elif average_op is not None: average_op[0].connect(0, out) equivalent_op.connect(0, average_op[1]) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow out = equivalent_op.outputs.fields_container else: @@ -136,7 +136,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) out = average_op[1].outputs.fields_container # Add an optional component selection step if result is vector, matrix, or principal diff --git a/src/ansys/dpf/post/transient_mechanical_simulation.py b/src/ansys/dpf/post/transient_mechanical_simulation.py index b7bfc2872..baba2e7c2 100644 --- a/src/ansys/dpf/post/transient_mechanical_simulation.py +++ b/src/ansys/dpf/post/transient_mechanical_simulation.py @@ -89,7 +89,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) principal_op.connect(0, average_op[1]) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow average_op = None else: @@ -114,13 +114,13 @@ def _get_result_workflow( ): equivalent_op.connect(0, out) average_op[0].connect(0, equivalent_op) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow out = average_op[1].outputs.fields_container elif average_op is not None: average_op[0].connect(0, out) equivalent_op.connect(0, average_op[1]) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) # Set as future output of the workflow out = equivalent_op.outputs.fields_container else: @@ -131,7 +131,7 @@ def _get_result_workflow( if average_op is not None: average_op[0].connect(0, out) - wf.add_operators(average_op) + wf.add_operators(list(average_op)) out = average_op[1].outputs.fields_container # Add an optional component selection step if result is vector, matrix, or principal