diff --git a/openmc/filter.py b/openmc/filter.py index f2bbf2f5050..7a21c976b41 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -1349,6 +1349,10 @@ class EnergyFilter(RealFilter): """ units = 'eV' + def __init__(self, values, filter_id=None): + cv.check_length('values', values, 2) + super().__init__(values, filter_id) + def get_bin_index(self, filter_bin): # Use lower energy bound to find index for RealFilters deltas = np.abs(self.bins[:, 1] - filter_bin[1]) / filter_bin[1] diff --git a/tests/unit_tests/test_filters.py b/tests/unit_tests/test_filters.py index 4ace59e723e..55bb62075bd 100644 --- a/tests/unit_tests/test_filters.py +++ b/tests/unit_tests/test_filters.py @@ -1,6 +1,6 @@ import numpy as np import openmc -from pytest import fixture, approx +from pytest import fixture, approx, raises @fixture(scope='module') @@ -248,6 +248,11 @@ def test_energy(): assert len(f.values) == 710 +def test_energyfilter_error_handling(): + with raises(ValueError): + openmc.EnergyFilter([1e6]) + + def test_lethargy_bin_width(): f = openmc.EnergyFilter.from_group_structure('VITAMIN-J-175') assert len(f.lethargy_bin_width) == 175