Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ansys/dpf/core/dpf_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,11 @@ def _type_to_input_method(self):
workflow,
model,
generic_data_container,
any,
)

out = [
(any.Any, self._api.operator_connect_any),
(bool, self._api.operator_connect_bool),
((int, Enum), self._api.operator_connect_int),
(str, self._connect_string),
Expand Down
2 changes: 2 additions & 0 deletions src/ansys/dpf/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ def _type_to_input_method(self):
workflow,
model,
generic_data_container,
any,
)

out = [
(any.Any, self._api.work_flow_connect_any),
(bool, self._api.work_flow_connect_bool),
((int, Enum), self._api.work_flow_connect_int),
(str, self._connect_string),
Expand Down
6 changes: 6 additions & 0 deletions src/ansys/dpf/gate/operator_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ def operator_connect_label_space(op, pin, ptr):
request.label_space.CopyFrom(ptr._internal_obj)
OperatorGRPCAPI.update(op, request)

@staticmethod
def operator_connect_any(op, pin, ptr):
request = OperatorGRPCAPI.update_init(op, pin)
request.as_any.CopyFrom(ptr._internal_obj)
OperatorGRPCAPI.update(op, request)

@staticmethod
def operator_connect_generic_data_container(op, pin, ptr):
request = OperatorGRPCAPI.update_init(op, pin)
Expand Down
6 changes: 6 additions & 0 deletions src/ansys/dpf/gate/workflow_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ def work_flow_connect_data_tree(wf, pin_name, dataTree):
request.data_tree.CopyFrom(dataTree._internal_obj)
_get_stub(wf._server).UpdateConnection(request)

@staticmethod
def work_flow_connect_any(wf, pin_name, ptr):
request = WorkflowGRPCAPI._connect_init(wf, pin_name)
request.as_any.CopyFrom(ptr._internal_obj)
_get_stub(wf._server).UpdateConnection(request)

@staticmethod
def work_flow_connect_generic_data_container(wf, pin_name, container):
request = WorkflowGRPCAPI._connect_init(wf, pin_name)
Expand Down
24 changes: 22 additions & 2 deletions tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0,
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_2,
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
)

Expand Down Expand Up @@ -1336,12 +1337,14 @@ def test_connect_get_non_ascii_string(server_type):
assert str == str_out


@pytest.mark.skipif(not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, reason="Available for servers >=8.0")
@pytest.mark.skipif(not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
reason="Available for servers >=8.0")
def test_deep_copy_non_ascii_string(server_type):
str = "\N{GREEK CAPITAL LETTER DELTA}"
str_out = dpf.core.core._deep_copy(str, server_type)
assert str == str_out


def test_output_any(server_type):
inpt = dpf.core.Field(nentities=3, server=server_type)
data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Expand All @@ -1356,4 +1359,21 @@ def test_output_any(server_type):
output_field = op.get_output(0, dpf.core.types.any).cast(dpf.core.Field)
assert isinstance(output_field, dpf.core.Field)
assert output_field.data.size == 9
assert output_field.scoping.size == 3
assert output_field.scoping.size == 3


@pytest.mark.skipif(condition=not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
reason="Input of Any requires DPF 7.0 or above.")
def test_input_any(server_type):
field = dpf.core.Field(nentities=3, server=server_type)
data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
scop = dpf.core.Scoping(server=server_type)
scop.ids = [1, 2, 3]
field.data = data
field.scoping = scop
inpt = dpf.core.Any.new_from(field)
op = dpf.core.Operator(name="forward", server=server_type)
op.connect(pin=0, inpt=inpt)
output = op.get_output(pin=0, output_type=dpf.core.types.field)
assert isinstance(output, dpf.core.Field)
assert len(output.data_as_list) == len(data)
23 changes: 23 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,29 @@ def test_output_any(server_type):
assert output_field.scoping.size == 3


@pytest.mark.skipif(condition=not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
reason="Input of Any requires DPF 7.0 or above.")
def test_input_any(server_type):
field = dpf.core.Field(nentities=3, server=server_type)
data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
scop = dpf.core.Scoping(server=server_type)
scop.ids = [1, 2, 3]
field.data = data
field.scoping = scop

inpt = dpf.core.Any.new_from(field)
fwd = dpf.core.Operator(name="forward", server=server_type)

wf = dpf.core.Workflow(server=server_type)
wf.add_operator(fwd)
wf.set_input_name("in", fwd, 0)
wf.set_output_name("out", fwd, 0)

wf.connect(pin_name="in", inpt=inpt)
output = wf.get_output(pin_name="out", output_type=dpf.core.types.field)
assert isinstance(output, dpf.core.Field)


def main():
test_connect_field_workflow()
velocity_acceleration = conftest.resolve_test_file("velocity_acceleration.rst", "rst_operators")
Expand Down