Skip to content

Commit

Permalink
Added inf check in VolumeCalculation. (#2634)
Browse files Browse the repository at this point in the history
Co-authored-by: Rosie Barker <[email protected]>
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
3 people authored Aug 19, 2023
1 parent 471caa5 commit b62b62a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions openmc/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/unit_tests/test_volume.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b62b62a

Please sign in to comment.