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
4 changes: 4 additions & 0 deletions examples/12-fluids/00-fluids_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
print(minfo.cell_zones)
print(minfo.face_zones)

###############################################################################
# As well as a map of body ID to body name.
print(minfo.bodies)

###############################################################################
# To facilitate the extraction of results, the body, cell and face zone ``Scoping``
# are extracted. They can be used to scope results.
Expand Down
28 changes: 26 additions & 2 deletions src/ansys/dpf/core/mesh_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(
self._zone_map = None
self._cell_zone_map = None
self._face_zone_map = None
self._bodies_map = None

def __str__(self):
txt = "DPF MeshInfo\n"
Expand Down Expand Up @@ -294,6 +295,29 @@ def body_scoping(self):
else:
return None

@property
def bodies(self) -> dict:
"""Dictionary of available body IDs to body names.

Returns
-------
bodies:
Map of body IDs to body names.

.. warning:
Currently unavailable for LegacyGrpc servers.
"""
if self._bodies_map:
return self._bodies_map
body_names = self.body_names
bodies_map = {}
if body_names:
names = body_names.data
for i, key in enumerate(body_names.scoping.ids):
bodies_map[str(key)] = names[i]
self._bodies_map = bodies_map
return self._bodies_map

@property
def zone_names(self):
"""
Expand Down Expand Up @@ -362,12 +386,12 @@ def face_zones(self) -> dict:

@property
def cell_zones(self) -> dict:
"""Dictionary of available cell zone IDs to face zone names.
"""Dictionary of available cell zone IDs to cell zone names.

Returns
-------
cell_zones:
Map of cell zone IDs to face zone names.
Map of cell zone IDs to cell zone names.

.. warning:
Currently unavailable for LegacyGrpc servers.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_mesh_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,13 @@ def test_mesh_info_parts(server_type):
mesh_info = dpf.MeshInfo(generic_data_container=gdc, server=server_type)
ref = """{'1': 'part_1', '2': 'part_2'}"""
assert str(mesh_info.parts) == ref


@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, reason="Available for servers >=7.0"
)
def test_mesh_info_bodies(fluent_multi_species, server_type):
model = dpf.Model(fluent_multi_species(server_type), server=server_type)
mesh_info = model.metadata.mesh_info
ref_bodies = {'1': 'fluid-1'}
assert mesh_info.bodies == ref_bodies