From b62b62ac3115701e1baff4c028fd1360a3e3d051 Mon Sep 17 00:00:00 2001 From: rlbarker Date: Sat, 19 Aug 2023 06:20:22 +0100 Subject: [PATCH] Added inf check in VolumeCalculation. (#2634) Co-authored-by: Rosie Barker Co-authored-by: Paul Romano --- openmc/volume.py | 4 ++++ tests/unit_tests/test_volume.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/unit_tests/test_volume.py diff --git a/openmc/volume.py b/openmc/volume.py index 72fe89fbc4..dddd30a524 100644 --- a/openmc/volume.py +++ b/openmc/volume.py @@ -122,6 +122,10 @@ class VolumeCalculation: 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 0000000000..f49bb35018 --- /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)