added check for length of value passed into EnergyFilter (#2887)

This commit is contained in:
Jonathan Shimwell 2024-04-11 16:35:29 +01:00 committed by GitHub
parent 26280bc9d5
commit cfebe16127
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View file

@ -1377,6 +1377,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]

View file

@ -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