diff --git a/openmc/volume.py b/openmc/volume.py index 72fe89fbc4a..dddd30a5241 100644 --- a/openmc/volume.py +++ b/openmc/volume.py @@ -122,6 +122,10 @@ def __init__(self, domains, samples, lower_left=None, upper_right=None): raise ValueError('Could not automatically determine bounding box ' 'for stochastic volume calculation.') + if np.isinf(self.lower_left).any() or np.isinf(self.upper_right).any(): + raise ValueError('Lower-left and upper-right bounding box ' + 'coordinates must be finite.') + @property def ids(self): return self._ids diff --git a/tests/unit_tests/test_volume.py b/tests/unit_tests/test_volume.py new file mode 100644 index 00000000000..f49bb35018c --- /dev/null +++ b/tests/unit_tests/test_volume.py @@ -0,0 +1,15 @@ +import numpy as np +import pytest + +import openmc + + +def test_infinity_handling(): + surf1 = openmc.Sphere(boundary_type="vacuum") + cell1 = openmc.Cell(region=-surf1) + + lower_left = (-2, -np.inf, -2) + upper_right = (np.inf, 2, 2) + + with pytest.raises(ValueError, match="must be finite"): + openmc.VolumeCalculation([cell1], 100, lower_left, upper_right)