From f136e31252c4521de3491e452c33894bd625f628 Mon Sep 17 00:00:00 2001 From: ansys-akarcher <128720408+ansys-akarcher@users.noreply.github.com> Date: Wed, 14 Jun 2023 09:40:26 +0200 Subject: [PATCH] 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 <100710998+PProfizi@users.noreply.github.com> --- src/ansys/dpf/core/dpf_operator.py | 12 ++++++++++++ tests/test_operator.py | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/ansys/dpf/core/dpf_operator.py b/src/ansys/dpf/core/dpf_operator.py index fcfd6c8233..0ea979c091 100644 --- a/src/ansys/dpf/core/dpf_operator.py +++ b/src/ansys/dpf/core/dpf_operator.py @@ -267,6 +267,18 @@ def connect(self, pin, inpt, pin_out=0): errormsg = f"input type {inpt.__class__} cannot be connected" raise TypeError(errormsg) + @version_requires("6.2") + def connect_operator_as_input(self, pin, op): + """Connects an operator as an input on a pin. + Parameters + ---------- + pin : int + Number of the output pin. The default is ``0``. + op : :class:`ansys.dpf.core.dpf_operator.Operator` + Requested type of the output. The default is ``None``. + """ + self._api.operator_connect_operator_as_input(self, pin, op) + @property def _type_to_output_method(self): from ansys.dpf.core import ( diff --git a/tests/test_operator.py b/tests/test_operator.py index b05bbb3f21..ea1dae93d8 100644 --- a/tests/test_operator.py +++ b/tests/test_operator.py @@ -260,6 +260,25 @@ def test_connect_operator_output_operator(server_type): assert len(fOut.data) == 3 +@pytest.mark.skipif( + not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_2, + reason="Connect an operator as an input is supported starting server version 6.2", +) +def test_connect_operator_as_input(server_type): + op_for_each = dpf.core.Operator("for_each", server=server_type) + fieldify = dpf.core.Operator("fieldify", server=server_type) + op_merge = dpf.core.Operator("incremental::merge::field", server=server_type) + + op_for_each.connect_operator_as_input(0, fieldify) + op_for_each.connect(1, [1.0, 2.0, 3.0, 4.0]) + op_for_each.connect(3, op_merge, 0) + op_merge.connect(0, fieldify, 0) + op_merge.connect(-2, True) + + op_for_each.run() + assert op_for_each.get_output(3, dpf.core.types.field).get_entity_data(0) == 10.0 + + def test_eval_operator(server_type): op = dpf.core.Operator("min_max", server=server_type) inpt = dpf.core.Field(nentities=3, server=server_type)