Skip to content

Commit f136e31

Browse files
Added method exposing operator_as_input connection (#935)
* Added method exposing operator_as_input connection * Corrected server version and skip test if unsupported --------- Co-authored-by: Paul Profizi <[email protected]>
1 parent d770f5e commit f136e31

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/ansys/dpf/core/dpf_operator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,18 @@ def connect(self, pin, inpt, pin_out=0):
267267
errormsg = f"input type {inpt.__class__} cannot be connected"
268268
raise TypeError(errormsg)
269269

270+
@version_requires("6.2")
271+
def connect_operator_as_input(self, pin, op):
272+
"""Connects an operator as an input on a pin.
273+
Parameters
274+
----------
275+
pin : int
276+
Number of the output pin. The default is ``0``.
277+
op : :class:`ansys.dpf.core.dpf_operator.Operator`
278+
Requested type of the output. The default is ``None``.
279+
"""
280+
self._api.operator_connect_operator_as_input(self, pin, op)
281+
270282
@property
271283
def _type_to_output_method(self):
272284
from ansys.dpf.core import (

tests/test_operator.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,25 @@ def test_connect_operator_output_operator(server_type):
260260
assert len(fOut.data) == 3
261261

262262

263+
@pytest.mark.skipif(
264+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_2,
265+
reason="Connect an operator as an input is supported starting server version 6.2",
266+
)
267+
def test_connect_operator_as_input(server_type):
268+
op_for_each = dpf.core.Operator("for_each", server=server_type)
269+
fieldify = dpf.core.Operator("fieldify", server=server_type)
270+
op_merge = dpf.core.Operator("incremental::merge::field", server=server_type)
271+
272+
op_for_each.connect_operator_as_input(0, fieldify)
273+
op_for_each.connect(1, [1.0, 2.0, 3.0, 4.0])
274+
op_for_each.connect(3, op_merge, 0)
275+
op_merge.connect(0, fieldify, 0)
276+
op_merge.connect(-2, True)
277+
278+
op_for_each.run()
279+
assert op_for_each.get_output(3, dpf.core.types.field).get_entity_data(0) == 10.0
280+
281+
263282
def test_eval_operator(server_type):
264283
op = dpf.core.Operator("min_max", server=server_type)
265284
inpt = dpf.core.Field(nentities=3, server=server_type)

0 commit comments

Comments
 (0)