Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions openmc/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,9 @@ def get_activity(self, units: str = 'Bq/cm3', by_nuclide: bool = False,
if volume is None:
volume = self.volume

if units in {'Bq', 'Ci'} and volume is None:
raise ValueError(f"Volume must be set in order to compute activity in '{units}'.")

if units == 'Bq':
multiplier = volume
elif units == 'Bq/cm3':
Expand Down Expand Up @@ -1474,6 +1477,8 @@ def get_decay_heat(self, units: str = 'W', by_nuclide: bool = False,

if units == 'W':
multiplier = volume if volume is not None else self.volume
if multiplier is None:
raise ValueError("Volume must be set in order to compute total decay heat.")
elif units == 'W/cm3':
multiplier = 1
elif units == 'W/m3':
Expand Down
6 changes: 6 additions & 0 deletions tests/unit_tests/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ def test_get_activity():
m1.add_element("Fe", 0.7)
m1.add_element("Li", 0.3)
m1.set_density('g/cm3', 1.5)
with pytest.raises(ValueError, match="Volume must be set"):
m1.get_activity(units='Bq')
with pytest.raises(ValueError, match="Volume must be set"):
m1.get_activity(units='Ci')
# activity in Bq/cc and Bq/g should not require volume setting
assert m1.get_activity(units='Bq/cm3') == 0
assert m1.get_activity(units='Bq/g') == 0
Expand Down Expand Up @@ -619,6 +623,8 @@ def test_get_decay_heat():
m1.add_nuclide("U235", 0.2)
m1.add_nuclide("U238", 0.8)
m1.set_density('g/cm3', 10.5)
with pytest.raises(ValueError, match="Volume must be set"):
m1.get_decay_heat(units='W')
# decay heat in W/cc and W/g should not require volume setting
assert m1.get_decay_heat(units='W/cm3') == 0
assert m1.get_decay_heat(units='W/g') == 0
Expand Down
Loading