Skip to content

Commit 4bda85f

Browse files
Allow StepResult.get_material to accept integer material ID (#3872)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent c44d2f0 commit 4bda85f

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

openmc/deplete/stepresult.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import numpy as np
1313

1414
import openmc
15-
from openmc.mpi import comm, MPI
1615
from openmc.checkvalue import PathLike
16+
from openmc.mpi import MPI, comm
17+
1718
from .reaction_rates import ReactionRates
1819

1920
VERSION_RESULTS = (1, 2)
@@ -196,15 +197,15 @@ def distribute(self, local_materials, ranges):
196197
new.rates = self.rates[ranges]
197198
return new
198199

199-
def get_material(self, mat_id):
200+
def get_material(self, mat_id: str | int) -> openmc.Material:
200201
"""Return material object for given depleted composition
201202
202203
.. versionadded:: 0.13.2
203204
204205
Parameters
205206
----------
206-
mat_id : str
207-
Material ID as a string
207+
mat_id : str or int
208+
Material ID as a string or integer
208209
209210
Returns
210211
-------
@@ -217,6 +218,9 @@ def get_material(self, mat_id):
217218
If specified material ID is not found in the StepResult
218219
219220
"""
221+
# Coerce to str since internal dictionaries use str keys
222+
mat_id = str(mat_id)
223+
220224
with warnings.catch_warnings():
221225
warnings.simplefilter('ignore', openmc.IDWarning)
222226
material = openmc.Material(material_id=int(mat_id))

tests/unit_tests/test_deplete_resultslist.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Tests the Results class"""
22

3-
from pathlib import Path
43
from math import inf
4+
from pathlib import Path
55

66
import numpy as np
77
import pytest
8+
89
import openmc.deplete
910

1011

@@ -221,3 +222,11 @@ def test_stepresult_get_material(res):
221222
densities = mat1.get_nuclide_atom_densities()
222223
assert densities['Xe135'] == pytest.approx(1e-14)
223224
assert densities['U234'] == pytest.approx(1.00506e-05)
225+
226+
227+
def test_stepresult_get_material_mat_id_as_int(res):
228+
# Get material at first timestep using int mat_id
229+
step_result = res[0]
230+
mat1 = step_result.get_material(1)
231+
assert mat1.id == 1
232+
assert mat1.volume == step_result.volume["1"]

0 commit comments

Comments
 (0)