Skip to content

Commit 24523e3

Browse files
authored
Add MeshInfo.bodies (#1594)
* Add mesh_info.bodies helper Signed-off-by: paul.profizi <[email protected]> * Update example 00-fluids_model.py Signed-off-by: paul.profizi <[email protected]> --------- Signed-off-by: paul.profizi <[email protected]>
1 parent 0816c90 commit 24523e3

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

examples/12-fluids/00-fluids_model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
print(minfo.cell_zones)
8484
print(minfo.face_zones)
8585

86+
###############################################################################
87+
# As well as a map of body ID to body name.
88+
print(minfo.bodies)
89+
8690
###############################################################################
8791
# To facilitate the extraction of results, the body, cell and face zone ``Scoping``
8892
# are extracted. They can be used to scope results.

src/ansys/dpf/core/mesh_info.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464
self._zone_map = None
6565
self._cell_zone_map = None
6666
self._face_zone_map = None
67+
self._bodies_map = None
6768

6869
def __str__(self):
6970
txt = "DPF MeshInfo\n"
@@ -294,6 +295,29 @@ def body_scoping(self):
294295
else:
295296
return None
296297

298+
@property
299+
def bodies(self) -> dict:
300+
"""Dictionary of available body IDs to body names.
301+
302+
Returns
303+
-------
304+
bodies:
305+
Map of body IDs to body names.
306+
307+
.. warning:
308+
Currently unavailable for LegacyGrpc servers.
309+
"""
310+
if self._bodies_map:
311+
return self._bodies_map
312+
body_names = self.body_names
313+
bodies_map = {}
314+
if body_names:
315+
names = body_names.data
316+
for i, key in enumerate(body_names.scoping.ids):
317+
bodies_map[str(key)] = names[i]
318+
self._bodies_map = bodies_map
319+
return self._bodies_map
320+
297321
@property
298322
def zone_names(self):
299323
"""
@@ -362,12 +386,12 @@ def face_zones(self) -> dict:
362386

363387
@property
364388
def cell_zones(self) -> dict:
365-
"""Dictionary of available cell zone IDs to face zone names.
389+
"""Dictionary of available cell zone IDs to cell zone names.
366390
367391
Returns
368392
-------
369393
cell_zones:
370-
Map of cell zone IDs to face zone names.
394+
Map of cell zone IDs to cell zone names.
371395
372396
.. warning:
373397
Currently unavailable for LegacyGrpc servers.

tests/test_mesh_info.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,13 @@ def test_mesh_info_parts(server_type):
507507
mesh_info = dpf.MeshInfo(generic_data_container=gdc, server=server_type)
508508
ref = """{'1': 'part_1', '2': 'part_2'}"""
509509
assert str(mesh_info.parts) == ref
510+
511+
512+
@pytest.mark.skipif(
513+
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, reason="Available for servers >=7.0"
514+
)
515+
def test_mesh_info_bodies(fluent_multi_species, server_type):
516+
model = dpf.Model(fluent_multi_species(server_type), server=server_type)
517+
mesh_info = model.metadata.mesh_info
518+
ref_bodies = {'1': 'fluid-1'}
519+
assert mesh_info.bodies == ref_bodies

0 commit comments

Comments
 (0)