mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
added check for length of value passed into EnergyFilter (#2887)
This commit is contained in:
parent
26280bc9d5
commit
cfebe16127
2 changed files with 10 additions and 1 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue