Fix missing volume checks in material activity/decay heat (#3939)

This commit is contained in:
Hridoy Kabiraj 2026-05-18 20:20:59 +06:00 committed by GitHub
parent d56cda2544
commit 195dff6d1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View file

@ -1418,6 +1418,9 @@ class Material(IDManagerMixin):
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':
@ -1474,6 +1477,8 @@ class Material(IDManagerMixin):
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':

View file

@ -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
@ -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