mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
added ability to find material names in DAG
This commit is contained in:
parent
e535d17ae0
commit
3891cef4f1
2 changed files with 39 additions and 0 deletions
|
|
@ -699,6 +699,36 @@ class DAGMCUniverse(UniverseBase):
|
|||
def auto_mat_ids(self):
|
||||
return self._auto_mat_ids
|
||||
|
||||
@property
|
||||
def material_names(self):
|
||||
"""Return the names of the materials 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.
|
||||
|
||||
Returns
|
||||
-------
|
||||
materials : List[str]
|
||||
Sorted list of material names present in the DAGMC h5m file
|
||||
|
||||
"""
|
||||
|
||||
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:
|
||||
raw_tag= np.array2string(tag)
|
||||
tag_in_hex=raw_tag.replace("\\x00", '').replace("\\x", '')
|
||||
tag_in_hex =tag_in_hex.lstrip("b'").rstrip("'")
|
||||
candidate_tag = bytes.fromhex(tag_in_hex).decode()
|
||||
# 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)
|
||||
|
|
|
|||
|
|
@ -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']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue