Skip to content

Commit 5e50920

Browse files
Add any tuples for operator and workflow output (#1715)
* Add any tuples for operator and workflow output * Added test for operator * Added test for workflow * Update dpf_operator.py * minor changes --------- Co-authored-by: Paul Profizi <[email protected]>
1 parent 25ba052 commit 5e50920

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

src/ansys/dpf/core/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def types_enum_to_types():
124124
streams_container,
125125
generic_data_container,
126126
mesh_info,
127+
Any
127128
)
128129
from ansys.dpf.gate import dpf_vector
129130

@@ -155,6 +156,7 @@ def types_enum_to_types():
155156
types.streams_container: streams_container.StreamsContainer,
156157
types.generic_data_container: generic_data_container.GenericDataContainer,
157158
types.mesh_info: mesh_info.MeshInfo,
159+
types.any: Any
158160
}
159161

160162

src/ansys/dpf/core/dpf_operator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def _type_to_output_method(self):
346346
)
347347

348348
out = [
349+
(any.Any, self._api.operator_getoutput_as_any),
349350
(bool, self._api.operator_getoutput_bool),
350351
(int, self._api.operator_getoutput_int),
351352
(str, self._getoutput_string),

src/ansys/dpf/core/workflow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,9 @@ def _type_to_output_method(self):
300300
any,
301301
collection_base,
302302
)
303-
303+
304304
out = [
305+
(any.Any, self._api.work_flow_getoutput_as_any),
305306
(bool, self._api.work_flow_getoutput_bool),
306307
(int, self._api.work_flow_getoutput_int),
307308
(str, self._getoutput_string),

tests/test_operator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,3 +1341,19 @@ def test_deep_copy_non_ascii_string(server_type):
13411341
str = "\N{GREEK CAPITAL LETTER DELTA}"
13421342
str_out = dpf.core.core._deep_copy(str, server_type)
13431343
assert str == str_out
1344+
1345+
def test_output_any(server_type):
1346+
inpt = dpf.core.Field(nentities=3, server=server_type)
1347+
data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
1348+
scop = dpf.core.Scoping(server=server_type)
1349+
scop.ids = [1, 2, 3]
1350+
inpt.data = data
1351+
inpt.scoping = scop
1352+
1353+
op = dpf.core.Operator("forward", server=server_type)
1354+
op.connect(0, inpt)
1355+
1356+
output_field = op.get_output(0, dpf.core.types.any).cast(dpf.core.Field)
1357+
assert isinstance(output_field, dpf.core.Field)
1358+
assert output_field.data.size == 9
1359+
assert output_field.scoping.size == 3

tests/test_workflow.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,26 @@ def test_connect_get_non_ascii_string_str(server_type):
931931
str_out = deep_copy_using_workflow(str, server_type, 0)
932932
assert str == str_out
933933

934+
def test_output_any(server_type):
935+
inpt = dpf.core.Field(nentities=3, server=server_type)
936+
data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
937+
scop = dpf.core.Scoping(server=server_type)
938+
scop.ids = [1, 2, 3]
939+
inpt.data = data
940+
inpt.scoping = scop
941+
942+
fwd = dpf.core.Operator("forward", server=server_type)
943+
fwd.connect(0, inpt)
944+
945+
wf = dpf.core.Workflow(server=server_type)
946+
wf.add_operator(fwd)
947+
wf.set_output_name("field", fwd, 0)
948+
949+
output_field = wf.get_output("field", dpf.core.types.any).cast(dpf.core.Field)
950+
assert isinstance(output_field, dpf.core.Field)
951+
assert output_field.data.size == 9
952+
assert output_field.scoping.size == 3
953+
934954

935955
def main():
936956
test_connect_field_workflow()

0 commit comments

Comments
 (0)