Skip to content

Commit

Permalink
added check for length of value passed into EnergyFilter (#2887)
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Apr 11, 2024
1 parent 26280bc commit cfebe16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions openmc/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 6 additions & 1 deletion tests/unit_tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import openmc
from pytest import fixture, approx
from pytest import fixture, approx, raises


@fixture(scope='module')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cfebe16

Please sign in to comment.