Skip to content

Commit

Permalink
Adding helpful info to keyerror for StepResults.get_material (#2674)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
shimwell and paulromano authored Sep 1, 2023
1 parent 27540c5 commit 20877c6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion openmc/deplete/stepresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,23 @@ def get_material(self, mat_id):
-------
openmc.Material
Equivalent material
Raises
------
KeyError
If specified material ID is not found in the StepResult
"""
with warnings.catch_warnings():
warnings.simplefilter('ignore', openmc.IDWarning)
material = openmc.Material(material_id=int(mat_id))
vol = self.volume[mat_id]
try:
vol = self.volume[mat_id]
except KeyError as e:
raise KeyError(
f'mat_id {mat_id} not found in StepResult. Available mat_id '
f'values are {list(self.volume.keys())}'
) from e
for nuc, _ in sorted(self.index_nuc.items(), key=lambda x: x[1]):
atoms = self[0, mat_id, nuc]
if atoms < 0.0:
Expand Down

0 comments on commit 20877c6

Please sign in to comment.