Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added inf check in VolumeCalculation. #2634

Merged
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
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)