Skip to content
Open
12 changes: 12 additions & 0 deletions src/ansys/dpf/core/any.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ 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,
string_field,
Expand Down Expand Up @@ -223,6 +225,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
20 changes: 20 additions & 0 deletions src/ansys/dpf/gate/any_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def _type_to_message_type():
data_sources,
generic_data_container,
generic_support,
meshed_region,
meshes_container,
string_field,
scoping,
data_tree,
Expand All @@ -61,6 +63,8 @@ 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.MESHES_CONTAINER),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(meshes_container.MeshesContainer, base_pb2.Type.MESHES_CONTAINER),
(meshes_container.MeshesContainer, base_pb2.Type.COLLECTION, base_pb2.Type.MESHED_REGION),

(scoping.Scoping, base_pb2.Type.SCOPING),
(data_tree.DataTree, base_pb2.Type.DATA_TREE),
(workflow.Workflow, base_pb2.Type.WORKFLOW),
Expand Down Expand Up @@ -175,6 +179,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 @@ -280,3 +291,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)

26 changes: 26 additions & 0 deletions tests/test_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,29 @@ 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)
Loading