Skip to content
Open
18 changes: 18 additions & 0 deletions src/ansys/dpf/core/any.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ def _type_to_new_from_get_as_method(self, obj): # noqa: PLR0911, PLR0912, C901
fields_container,
generic_data_container,
generic_support,
meshed_region,
meshes_container,
property_field,
scoping,
scopings_container,
string_field,
workflow,
)
Expand Down Expand Up @@ -178,6 +181,11 @@ def _type_to_new_from_get_as_method(self, obj): # noqa: PLR0911, PLR0912, C901
self._api.any_new_from_scoping,
self._api.any_get_as_scoping,
)
elif issubclass(obj, scopings_container.ScopingsContainer):
return (
self._api.any_new_from_scopings_container,
self._api.any_get_as_scopings_container,
)
elif issubclass(obj, data_tree.DataTree):
return (
self._api.any_new_from_data_tree,
Expand Down Expand Up @@ -223,6 +231,16 @@ def _type_to_new_from_get_as_method(self, obj): # noqa: PLR0911, PLR0912, C901
self._api.any_new_from_cyclic_support,
self._api.any_get_as_cyclic_support,
)
elif issubclass(obj, meshed_region.MeshedRegion):
return (
self._api.any_new_from_meshed_region,
self._api.any_get_as_meshed_region,
)
elif issubclass(obj, meshes_container.MeshesContainer):
return (
self._api.any_new_from_meshes_container,
self._api.any_get_as_meshes_container,
)
elif issubclass(obj, Any):
return (
lambda x: x,
Expand Down
30 changes: 30 additions & 0 deletions src/ansys/dpf/gate/any_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ def _type_to_message_type():
data_sources,
generic_data_container,
generic_support,
meshed_region,
meshes_container,
string_field,
scoping,
scopings_container,
data_tree,
custom_type_field,
collection_base,
Expand All @@ -61,7 +64,10 @@ def _type_to_message_type():
(generic_data_container.GenericDataContainer, base_pb2.Type.GENERIC_DATA_CONTAINER),
(generic_support.GenericSupport, base_pb2.Type.GENERIC_SUPPORT),
(cyclic_support.CyclicSupport, base_pb2.Type.CYCLIC_SUPPORT),
(meshed_region.MeshedRegion, base_pb2.Type.MESHED_REGION),
(meshes_container.MeshesContainer, base_pb2.Type.COLLECTION, base_pb2.Type.MESHED_REGION),
(scoping.Scoping, base_pb2.Type.SCOPING),
(scopings_container.ScopingsContainer, base_pb2.Type.COLLECTION.SCOPING),
Comment thread
janvonrickenbach marked this conversation as resolved.
Outdated
(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),
Expand Down Expand Up @@ -143,6 +149,10 @@ def any_get_as_generic_data_container(any):
def any_get_as_scoping(any):
return AnyGRPCAPI._get_as(any).scoping

@staticmethod
def any_get_as_scopings_container(any):
return AnyGRPCAPI._get_as(any).scopings_container
Comment thread
janvonrickenbach marked this conversation as resolved.
Outdated

@staticmethod
def any_get_as_data_sources(any):
return AnyGRPCAPI._get_as(any).data_sources
Expand Down Expand Up @@ -175,6 +185,13 @@ def any_get_as_generic_support(any):
def any_get_as_cyclic_support(any):
return AnyGRPCAPI._get_as(any).cyc_support

@staticmethod
def any_get_as_meshed_region(any):
return AnyGRPCAPI._get_as(any).meshed_region
Comment thread
janvonrickenbach marked this conversation as resolved.
Outdated
@staticmethod
def any_get_as_meshes_container(any):
return AnyGRPCAPI._get_as(any).meshes_container
Comment thread
janvonrickenbach marked this conversation as resolved.
Outdated

@staticmethod
def _new_from(any, client=None):
from ansys.grpc.dpf import dpf_any_pb2
Expand Down Expand Up @@ -257,6 +274,10 @@ def any_new_from_generic_data_container(any):
def any_new_from_scoping(any):
return AnyGRPCAPI._new_from(any, any._server)

@staticmethod
def any_new_from_scopings_container(any):
return AnyGRPCAPI._new_from(any, any._server)

@staticmethod
def any_new_from_data_sources(any):
return AnyGRPCAPI._new_from(any, any._server)
Expand All @@ -280,3 +301,12 @@ def any_new_from_generic_support(any):
@staticmethod
def any_new_from_cyclic_support(any):
return AnyGRPCAPI._new_from(any, any._server)

@staticmethod
def any_new_from_meshed_region(any):
return AnyGRPCAPI._new_from(any, any._server)

@staticmethod
def any_new_from_meshes_container(any):
return AnyGRPCAPI._new_from(any, any._server)

40 changes: 40 additions & 0 deletions tests/test_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,43 @@ def test_cast_fields_container_any(server_type):
new_entity = any_dpf.cast()

assert entity.name == new_entity.name

@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0,
reason="any does not support operator below 10.0",
)
def test_cast_meshed_region_any(server_type):
entity = dpf.MeshedRegion(server=server_type)
entity.unit = "mm"
any_dpf = dpf.Any.new_from(entity)
new_entity = any_dpf.cast()

assert entity.unit == new_entity.unit

@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0,
reason="any does not support operator below 10.0",
)
def test_cast_meshes_container_any(server_type):
entity = dpf.MeshesContainer(server=server_type)
entity.add_label("idx")
entity.add_mesh({"idx": 0}, dpf.MeshedRegion(server=server_type))

any_dpf = dpf.Any.new_from(entity)
new_entity = any_dpf.cast()

assert entity.get_label_space(0) == new_entity.get_label_space(0)

@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0,
reason="any does not support operator below 10.0",
)
def test_cast_scopings_container_any(server_type):
entity = dpf.ScopingsContainer(server=server_type)
entity.add_label("idx")
entity.add_scoping({"idx": 0}, dpf.Scoping(server=server_type))

any_dpf = dpf.Any.new_from(entity)
new_entity = any_dpf.cast()

assert entity.get_label_space(0) == new_entity.get_label_space(0)
Loading