Merge pull request #2230 from shimwell/adding_material_names_to_DAGMCUniverse

This commit is contained in:
Patrick Shriwise 2022-09-29 17:01:49 -05:00 committed by GitHub
commit c96f2bc376
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View file

@ -647,6 +647,11 @@ class DAGMCUniverse(UniverseBase):
bounding_box : 2-tuple of numpy.array
Lower-left and upper-right coordinates of an axis-aligned bounding box
of the universe.
material_name : list of str
Return a sorted list of materials names that are contained within the
DAGMC h5m file. This is useful when naming openmc.Material() objects
as each material name present in the DAGMC h5m file must have a
matching openmc.Material() with the same name.
.. versionadded:: 0.13.1
"""
@ -699,6 +704,21 @@ class DAGMCUniverse(UniverseBase):
def auto_mat_ids(self):
return self._auto_mat_ids
@property
def material_names(self):
dagmc_file_contents = h5py.File(self.filename)
material_tags_hex=dagmc_file_contents['/tstt/tags/NAME'].get('values')
material_tags_ascii=[]
for tag in material_tags_hex:
candidate_tag = tag.tobytes().decode().replace('\x00', '')
# tags might be for temperature or reflective surfaces
if candidate_tag.startswith('mat:'):
# removes first 4 characters as openmc.Material name should be
# set without the 'mat:' part of the tag
material_tags_ascii.append(candidate_tag[4:])
return sorted(set(material_tags_ascii))
@auto_mat_ids.setter
def auto_mat_ids(self, val):
cv.check_type('DAGMC automatic material ids', val, bool)

View file

@ -71,3 +71,12 @@ def test_bounded_universe(request):
surfaces = list(cells[0][1].region.get_surfaces().items())
assert surfaces[0][1].type == "sphere"
assert surfaces[0][1].id == 43
def test_material_names(request):
"""Checks that the DAGMCUniverse.material_names() returns a list of the
name present in the dagmc.h5m file in the expected order"""
u = openmc.DAGMCUniverse(Path(request.fspath).parent / "dagmc.h5m")
assert u.material_names == ['41', 'Graveyard', 'no-void fuel']