Skip to content

Commit feded14

Browse files
feat: add WorkflowTopology class and workflow_to_workflow_topology operator
1 parent 7b33c37 commit feded14

File tree

9 files changed

+456
-2
lines changed

9 files changed

+456
-2
lines changed

src/ansys/dpf/core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
CustomTypeFieldsCollection:type = _CollectionFactory(CustomTypeField)
119119
GenericDataContainersCollection:type = _CollectionFactory(GenericDataContainer)
120120
StringFieldsCollection:type = _CollectionFactory(StringField)
121+
OperatorsCollection: type = _CollectionFactory(Operator)
121122
AnyCollection:type = _Collection
122123

123124
# for matplotlib
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
from ansys.dpf.core.generic_data_container import GenericDataContainer
24+
25+
26+
class CustomContainerBase:
27+
def __init__(self, container: GenericDataContainer) -> None:
28+
self._container = container

src/ansys/dpf/core/dpf_operator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,10 @@ def default_config(name, server=None):
726726

727727
def __del__(self):
728728
try:
729-
if self._internal_obj is not None:
730-
self._deleter_func[0](self._deleter_func[1](self))
729+
if hasattr(self, "_deleter_func"):
730+
obj = self._deleter_func[1](self)
731+
if obj is not None:
732+
self._deleter_func[0](obj)
731733
except:
732734
warnings.warn(traceback.format_exc())
733735

src/ansys/dpf/core/helpers/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,19 @@ def _sort_supported_kwargs(bound_method, **kwargs):
4848
warnings.warn(txt)
4949
# Return the accepted arguments
5050
return kwargs_in
51+
52+
53+
def indent(text, subsequent_indent="", initial_indent=None):
54+
if initial_indent is None:
55+
initial_indent = subsequent_indent
56+
57+
if not isinstance(text, str):
58+
text = str(text)
59+
60+
lines = text.rstrip().splitlines()
61+
indented_lines = [
62+
f"{initial_indent if index == 0 else subsequent_indent}{line}"
63+
for (index, line) in enumerate(lines)
64+
]
65+
66+
return "\n".join(indented_lines)

src/ansys/dpf/core/workflow.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
server_meet_version_and_raise,
4444
)
4545
from ansys.dpf.core import server as server_module
46+
from ansys.dpf.core.workflow_topology.workflow_topology import WorkflowTopology
4647
from ansys.dpf.gate import (
4748
workflow_abstract_api,
4849
workflow_grpcapi,
@@ -953,6 +954,13 @@ def to_graphviz(self, path: Union[os.PathLike, str]):
953954
"""Saves the workflow to a GraphViz file."""
954955
return self._api.work_flow_export_graphviz(self, str(path))
955956

957+
def get_topology(self):
958+
workflow_to_workflow_topology_op = dpf_operator.Operator("workflow_to_workflow_topology")
959+
workflow_to_workflow_topology_op.inputs.workflow.connect(self)
960+
workflow_topology_container = workflow_to_workflow_topology_op.outputs.workflow_topology()
961+
962+
return WorkflowTopology(workflow_topology_container)
963+
956964
def __del__(self):
957965
try:
958966
if hasattr(self, "_internal_obj"):
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
from ansys.dpf.core.custom_container_base import CustomContainerBase
24+
25+
26+
class DataConnection(CustomContainerBase):
27+
def __init__(self, container):
28+
super().__init__(container)
29+
self._source_data = None
30+
self._target_operator = None
31+
self._target_pin_id = None
32+
33+
@property
34+
def source_data(self):
35+
if self._source_data is None:
36+
self._source_data = self._container.get_property("source_data")
37+
38+
return self._source_data
39+
40+
@property
41+
def target_operator(self):
42+
from ansys.dpf.core.dpf_operator import Operator
43+
44+
if self._target_operator is None:
45+
self._target_operator = self._container.get_property("target_operator", Operator)
46+
47+
return self._target_operator
48+
49+
@property
50+
def target_pin_id(self):
51+
if self._target_pin_id is None:
52+
self._target_pin_id = self._container.get_property("target_pin_id", int)
53+
54+
return self._target_pin_id
55+
56+
def __str__(self):
57+
from ansys.dpf.core.helpers.utils import indent
58+
59+
indents = " "
60+
return (
61+
"DataConnection with properties:\n"
62+
" - source_data:\n"
63+
f"{indent(self.source_data, indents)}\n"
64+
" - target_operator:\n"
65+
f"{indent(self.target_operator.name, indents)}\n"
66+
" - target_pin_id:\n"
67+
f"{indent(self.target_pin_id, indents)}"
68+
)
69+
70+
71+
class DataConnectionsCollection:
72+
def __init__(self, collection):
73+
self._collection = collection
74+
75+
def __len__(self):
76+
return len(self._collection)
77+
78+
def __getitem__(self, index):
79+
return DataConnection(self._collection[index])
80+
81+
def __iter__(self):
82+
for i in range(len(self)):
83+
yield self[i]
84+
85+
def __str__(self):
86+
from ansys.dpf.core.helpers.utils import indent
87+
88+
indents = (" ", " - ")
89+
return "\n".join([indent(data_connection, *indents) for data_connection in self])
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
from ansys.dpf.core.custom_container_base import CustomContainerBase
24+
25+
26+
class ExposedPin(CustomContainerBase):
27+
def __init__(self, container):
28+
super().__init__(container)
29+
self._name = None
30+
self._operator = None
31+
self._pin_id = None
32+
33+
@property
34+
def name(self):
35+
if self._name is None:
36+
self._name = self._container.get_property("name", str)
37+
38+
return self._name
39+
40+
@property
41+
def operator(self):
42+
from ansys.dpf.core.dpf_operator import Operator
43+
44+
if self._operator is None:
45+
self._operator = self._container.get_property("operator", Operator)
46+
47+
return self._operator
48+
49+
@property
50+
def pin_id(self):
51+
if self._pin_id is None:
52+
self._pin_id = self._container.get_property("pin_id", int)
53+
54+
return self._pin_id
55+
56+
def __str__(self):
57+
from ansys.dpf.core.helpers.utils import indent
58+
59+
indents = " "
60+
return (
61+
"ExposedPin with properties:\n"
62+
" - name:\n"
63+
f"{indent(self.name, indents)}\n"
64+
" - operator:\n"
65+
f"{indent(self.operator.name, indents)}\n"
66+
" - pin_id:\n"
67+
f"{indent(self.pin_id, indents)}"
68+
)
69+
70+
def __repr__(self) -> str:
71+
return self.__str__()
72+
73+
74+
class ExposedPinsCollection:
75+
def __init__(self, collection):
76+
self._collection = collection
77+
78+
def __len__(self):
79+
return len(self._collection)
80+
81+
def __getitem__(self, index):
82+
return ExposedPin(self._collection[index])
83+
84+
def __iter__(self):
85+
for i in range(len(self)):
86+
yield self[i]
87+
88+
def __str__(self):
89+
from ansys.dpf.core.helpers.utils import indent
90+
91+
indents = (" ", " - ")
92+
return "\n".join([indent(exposed_pin, *indents) for exposed_pin in self])
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
from ansys.dpf.core.custom_container_base import CustomContainerBase
24+
25+
26+
class OperatorConnection(CustomContainerBase):
27+
def __init__(self, container):
28+
super().__init__(container)
29+
self._source_operator = None
30+
self._source_pin_id = None
31+
self._target_operator = None
32+
self._target_pin_id = None
33+
34+
@property
35+
def source_operator(self):
36+
from ansys.dpf.core.dpf_operator import Operator
37+
38+
if self._source_operator is None:
39+
self._source_operator = self._container.get_property("source_operator", Operator)
40+
41+
return self._source_operator
42+
43+
@property
44+
def source_pin_id(self):
45+
if self._source_pin_id is None:
46+
self._source_pin_id = self._container.get_property("source_pin_id", int)
47+
48+
return self._source_pin_id
49+
50+
@property
51+
def target_operator(self):
52+
from ansys.dpf.core.dpf_operator import Operator
53+
54+
if self._target_operator is None:
55+
self._target_operator = self._container.get_property("target_operator", Operator)
56+
57+
return self._target_operator
58+
59+
@property
60+
def target_pin_id(self):
61+
if self._target_pin_id is None:
62+
self._target_pin_id = self._container.get_property("target_pin_id", int)
63+
64+
return self._target_pin_id
65+
66+
def __str__(self):
67+
from ansys.dpf.core.helpers.utils import indent
68+
69+
indents = " "
70+
return (
71+
"OperatorConnection with properties:\n"
72+
" - source_operator:\n"
73+
f"{indent(self.source_operator.name, indents)}\n"
74+
" - source_pin_id:\n"
75+
f"{indent(self.source_pin_id, indents)}\n"
76+
" - target_operator:\n"
77+
f"{indent(self.target_operator.name, indents)}\n"
78+
" - target_pin_id:\n"
79+
f"{indent(self.target_pin_id, indents)}"
80+
)
81+
82+
83+
class OperatorConnectionsCollection:
84+
def __init__(self, collection):
85+
self._collection = collection
86+
87+
def __len__(self):
88+
return len(self._collection)
89+
90+
def __getitem__(self, index):
91+
return OperatorConnection(self._collection[index])
92+
93+
def __iter__(self):
94+
for i in range(len(self)):
95+
yield self[i]
96+
97+
def __str__(self):
98+
from ansys.dpf.core.helpers.utils import indent
99+
100+
indents = (" ", " - ")
101+
return "\n".join([indent(operator_connection, *indents) for operator_connection in self])

0 commit comments

Comments
 (0)