Skip to content

Commit 0e0ee31

Browse files
shimwellchurch89
authored andcommitted
added check for length of value passed into EnergyFilter (openmc-dev#2887)
1 parent b35c822 commit 0e0ee31

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎openmc/filter.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,10 @@ class EnergyFilter(RealFilter):
13771377
"""
13781378
units = 'eV'
13791379

1380+
def __init__(self, values, filter_id=None):
1381+
cv.check_length('values', values, 2)
1382+
super().__init__(values, filter_id)
1383+
13801384
def get_bin_index(self, filter_bin):
13811385
# Use lower energy bound to find index for RealFilters
13821386
deltas = np.abs(self.bins[:, 1] - filter_bin[1]) / filter_bin[1]

‎tests/unit_tests/test_filters.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
import openmc
3-
from pytest import fixture, approx
3+
from pytest import fixture, approx, raises
44

55

66
@fixture(scope='module')
@@ -248,6 +248,11 @@ def test_energy():
248248
assert len(f.values) == 710
249249

250250

251+
def test_energyfilter_error_handling():
252+
with raises(ValueError):
253+
openmc.EnergyFilter([1e6])
254+
255+
251256
def test_lethargy_bin_width():
252257
f = openmc.EnergyFilter.from_group_structure('VITAMIN-J-175')
253258
assert len(f.lethargy_bin_width) == 175

0 commit comments

Comments
 (0)