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 check for length of value passed into EnergyFilter #2887

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/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
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
Loading