diff --git a/src/ansys/dpf/core/any.py b/src/ansys/dpf/core/any.py index ad60e8b983..fc7d0f4738 100644 --- a/src/ansys/dpf/core/any.py +++ b/src/ansys/dpf/core/any.py @@ -122,6 +122,7 @@ def _type_to_new_from_get_as_method(self, obj): data_tree, custom_type_field, collection, + workflow, ) if issubclass(obj, int): @@ -185,6 +186,11 @@ def _type_to_new_from_get_as_method(self, obj): self._api.any_new_from_any_collection, self._api.any_get_as_any_collection, ) + elif issubclass(obj, workflow.Workflow): + return ( + self._api.any_new_from_workflow, + self._api.any_get_as_workflow, + ) elif issubclass(obj, dpf_vector.DPFVectorInt): return ( self._api.any_new_from_int_collection, diff --git a/src/ansys/dpf/core/server.py b/src/ansys/dpf/core/server.py index 2a4ed82d70..83e3abd8fb 100644 --- a/src/ansys/dpf/core/server.py +++ b/src/ansys/dpf/core/server.py @@ -73,7 +73,7 @@ def has_local_server(): return dpf.core.SERVER is not None -def _global_server(): +def _global_server() -> BaseServer: """Retrieve the global server if it exists. If the global server has not been specified, check the expected server type in diff --git a/src/ansys/dpf/gate/any_grpcapi.py b/src/ansys/dpf/gate/any_grpcapi.py index 28f9b10039..69e178d98c 100644 --- a/src/ansys/dpf/gate/any_grpcapi.py +++ b/src/ansys/dpf/gate/any_grpcapi.py @@ -41,6 +41,7 @@ def _type_to_message_type(): data_tree, custom_type_field, collection_base, + workflow, ) return [(int, base_pb2.Type.INT), @@ -54,6 +55,7 @@ def _type_to_message_type(): (generic_data_container.GenericDataContainer, base_pb2.Type.GENERIC_DATA_CONTAINER), (scoping.Scoping, base_pb2.Type.SCOPING), (data_tree.DataTree, base_pb2.Type.DATA_TREE), + (workflow.Workflow, base_pb2.Type.WORKFLOW), (collection_base.CollectionBase, base_pb2.Type.COLLECTION, base_pb2.Type.ANY), (dpf_vector.DPFVectorInt, base_pb2.Type.COLLECTION, base_pb2.Type.INT), ] @@ -139,6 +141,10 @@ def any_get_as_any_collection(any): def any_get_as_int_collection(any): return AnyGRPCAPI._get_as(any).collection + @staticmethod + def any_get_as_workflow(any): + return AnyGRPCAPI._get_as(any).workflow + @staticmethod def _new_from(any, client=None): from ansys.grpc.dpf import dpf_any_pb2 @@ -220,3 +226,7 @@ def any_new_from_scoping(any): @staticmethod def any_new_from_data_tree(any): return AnyGRPCAPI._new_from(any, any._server) + + @staticmethod + def any_new_from_workflow(any): + return AnyGRPCAPI._new_from(any, any._server) diff --git a/tests/test_any.py b/tests/test_any.py index bf3897fe1f..5ec9486282 100644 --- a/tests/test_any.py +++ b/tests/test_any.py @@ -120,3 +120,15 @@ def test_cast_scoping_any(server_type): new_entity = any_dpf.cast() assert entity.location == new_entity.location + + +@pytest.mark.skipif( + not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0, + reason="for_each not implemented below 8.0", +) +def test_cast_workflow_any(server_type): + entity = dpf.Workflow(server=server_type) + any_dpf = dpf.Any.new_from(entity) + new_entity = any_dpf.cast() + + assert new_entity.input_names == []