Open dagmc model file within a context manager (#3706)

This commit is contained in:
Jonathan Shimwell 2026-01-05 21:57:05 +01:00 committed by GitHub
parent 9c91bddf04
commit 60ddafa9b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -223,21 +223,19 @@ class DAGMCUniverse(openmc.UniverseBase):
@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:'):
# if name ends with _comp remove it, it is not parsed
if candidate_tag.endswith('_comp'):
candidate_tag = candidate_tag[:-5]
# 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:])
with h5py.File(self.filename) as dagmc_file_contents:
material_tags_hex = dagmc_file_contents['/tstt/tags/NAME'].get('values')
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:'):
# if name ends with _comp remove it, it is not parsed
if candidate_tag.endswith('_comp'):
candidate_tag = candidate_tag[:-5]
# 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))
def _n_geom_elements(self, geom_type):