Skip to content

Commit

Permalink
Added method exposing operator_as_input connection (#935)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ansys-akarcher and PProfizi committed Jun 14, 2023
1 parent d770f5e commit f136e31
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ansys/dpf/core/dpf_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
19 changes: 19 additions & 0 deletions tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f136e31

Please sign in to comment.