7
7
from os import PathLike
8
8
from typing import List , Union
9
9
10
+ from ansys .dpf .core import Workflow
10
11
from ansys .dpf .core .server_types import BaseServer
11
12
12
13
from ansys .dpf import core as dpf
13
14
from ansys .dpf .post import locations
14
15
from ansys .dpf .post .dataframe import DataFrame
15
16
from ansys .dpf .post .mesh_info import FluidMeshInfo
16
17
from ansys .dpf .post .phase import PhasesDict
17
- from ansys .dpf .post .selection import Selection
18
- from ansys .dpf .post .simulation import ResultCategory , Simulation
18
+ from ansys .dpf .post .result_workflows ._component_helper import (
19
+ ResultCategory ,
20
+ _create_components ,
21
+ )
22
+ from ansys .dpf .post .result_workflows ._connect_workflow_inputs import (
23
+ _connect_initial_results_inputs ,
24
+ )
25
+ from ansys .dpf .post .result_workflows ._sub_workflows import _create_norm_workflow
26
+ from ansys .dpf .post .result_workflows ._utils import _append_workflows
27
+ from ansys .dpf .post .selection import Selection , _WfNames
28
+ from ansys .dpf .post .simulation import Simulation
19
29
from ansys .dpf .post .species import SpeciesDict
20
30
21
31
@@ -223,16 +233,37 @@ def _get_result_workflow(
223
233
qualifiers : Union [dict , None ] = None ,
224
234
) -> (dpf .Workflow , Union [str , list [str ], None ], str ):
225
235
"""Generate (without evaluating) the Workflow to extract results."""
226
- comp , to_extract , columns = self ._create_components (
227
- base_name , category , components
236
+ comp , to_extract , columns = _create_components (base_name , category , components )
237
+
238
+ initial_result_workflow = Workflow (server = self ._model ._server )
239
+
240
+ initial_result_op = self ._model .operator (name = base_name )
241
+ initial_result_workflow .set_input_name (_WfNames .mesh , initial_result_op , 7 )
242
+ initial_result_workflow .set_input_name (_WfNames .location , initial_result_op , 9 )
243
+
244
+ initial_result_workflow .add_operator (initial_result_op )
245
+ initial_result_workflow .set_output_name (
246
+ _WfNames .output_data , initial_result_op , 0
247
+ )
248
+ initial_result_workflow .set_input_name (
249
+ "time_scoping" , initial_result_op .inputs .time_scoping
250
+ )
251
+ initial_result_workflow .set_input_name (
252
+ "mesh_scoping" , initial_result_op .inputs .mesh_scoping
228
253
)
229
254
230
- # Initialize a workflow
231
- wf , result_op = self ._build_result_workflow (
232
- name = base_name ,
233
- location = location ,
255
+ _connect_initial_results_inputs (
256
+ initial_result_workflow = initial_result_workflow ,
234
257
force_elemental_nodal = False ,
258
+ location = location ,
259
+ selection = selection ,
260
+ expand_cyclic = False ,
261
+ phase_angle_cyclic = None ,
262
+ mesh = self .mesh ._meshed_region ,
263
+ streams_provider = self ._model .metadata .streams_provider ,
264
+ data_sources = self ._model .metadata .data_sources ,
235
265
)
266
+
236
267
query_regions_meshes = False
237
268
lists = []
238
269
lists_labels = []
@@ -268,7 +299,7 @@ def _get_result_workflow(
268
299
label_space = {}
269
300
for j , label in enumerate (lists_labels ):
270
301
label_space [label ] = c [j ]
271
- result_op .connect (1000 + i , label_space )
302
+ initial_result_op .connect (1000 + i , label_space )
272
303
# Its output is selected as future workflow output for now
273
304
# print(result_op)
274
305
@@ -277,44 +308,35 @@ def _get_result_workflow(
277
308
# A MeshesProvider is required to give meshes as input of the source operator
278
309
meshes_provider_op = self ._model .operator ("meshes_provider" )
279
310
meshes_provider_op .connect (25 , query_regions_meshes )
280
- result_op .connect (7 , meshes_provider_op .outputs .meshes )
281
- wf .add_operator (meshes_provider_op )
311
+ initial_result_workflow .connect (
312
+ _WfNames .mesh , meshes_provider_op .outputs .meshes
313
+ )
314
+
315
+ initial_result_workflow .add_operator (meshes_provider_op )
282
316
else :
283
317
# Results have been queried on the whole mesh,
284
318
# A MeshProvider is required to give the mesh as input of the source operator
285
319
mesh_provider_op = self ._model .operator ("mesh_provider" )
286
- result_op .connect (7 , mesh_provider_op .outputs .mesh )
287
- wf .add_operator (mesh_provider_op )
288
-
289
- out = result_op .outputs .fields_container
290
- # Its inputs are selected as workflow inputs for merging with selection workflows
291
- wf .set_input_name ("time_scoping" , result_op .inputs .time_scoping )
292
- wf .set_input_name ("mesh_scoping" , result_op .inputs .mesh_scoping )
293
-
294
- wf .connect_with (
295
- selection .time_freq_selection ._selection ,
296
- output_input_names = ("scoping" , "time_scoping" ),
297
- )
298
- wf .connect_with (
299
- selection .spatial_selection ._selection ,
300
- output_input_names = ("scoping" , "mesh_scoping" ),
301
- )
302
-
303
- # Connect data_sources and streams_container inputs of selection if necessary
304
- if "streams" in wf .input_names :
305
- wf .connect ("streams" , self ._model .metadata .streams_provider )
306
- if "data_sources" in wf .input_names :
307
- wf .connect ("data_sources" , self ._model .metadata .data_sources )
320
+ initial_result_workflow .connect (
321
+ _WfNames .mesh , mesh_provider_op .outputs .mesh
322
+ )
323
+ initial_result_workflow .add_operator (mesh_provider_op )
308
324
309
- # Add an optional norm operation if requested
325
+ output_wf = initial_result_workflow
310
326
if norm :
311
- wf , out , comp , base_name = self ._append_norm (wf , out , base_name )
327
+ norm_workflow , base_name = _create_norm_workflow (
328
+ create_operator_callable = self ._model .operator ,
329
+ base_name = base_name ,
330
+ server = self ._model ._server ,
331
+ )
332
+
333
+ output_wf = _append_workflows (
334
+ [norm_workflow ], current_output_workflow = initial_result_workflow
335
+ )
312
336
313
- # Set the workflow output
314
- wf .set_output_name ("out" , out )
315
- wf .progress_bar = False
337
+ output_wf .progress_bar = False
316
338
317
- return wf , comp , base_name
339
+ return output_wf , comp , base_name
318
340
319
341
def _get_result (
320
342
self ,
@@ -510,14 +532,14 @@ def _get_result(
510
532
)
511
533
512
534
# Evaluate the workflow
513
- fc = wf .get_output ("out" , dpf .types .fields_container )
535
+ fc = wf .get_output (_WfNames . output_data , dpf .types .fields_container )
514
536
# print(fc)
515
537
if location is None and len (fc ) > 0 :
516
538
location = fc [0 ].location
517
539
if location == locations .elemental :
518
540
location = "cells"
519
541
520
- _ , _ , columns = self . _create_components (base_name , category , components )
542
+ _ , _ , columns = _create_components (base_name , category , components )
521
543
return self ._create_dataframe (
522
544
fc , location , columns , comp , base_name .split ("::" )[- 1 ], None
523
545
)
0 commit comments