Skip to content

Commit bd95b52

Browse files
authored
Add check for equal value bins in an EnergyFilter (#3372)
1 parent cdc254c commit bd95b52

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

openmc/filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ def check_bins(self, bins):
12381238
cv.check_type('filter value', v1, Real)
12391239

12401240
# Make sure that each tuple has values that are increasing
1241-
if v1 < v0:
1241+
if v1 <= v0:
12421242
raise ValueError(f'Values {v0} and {v1} appear to be out of '
12431243
'order')
12441244

@@ -1384,7 +1384,7 @@ class EnergyFilter(RealFilter):
13841384
----------
13851385
values : Iterable of Real
13861386
A list of values for which each successive pair constitutes a range of
1387-
energies in [eV] for a single bin
1387+
energies in [eV] for a single bin. Entries must be positive and ascending.
13881388
filter_id : int
13891389
Unique identifier for the filter
13901390

tests/unit_tests/test_filters.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,21 @@ def test_tabular_from_energyfilter():
294294

295295
tab = efilter.get_tabular(values=np.array([10, 10, 5]), interpolation='linear-linear')
296296
assert tab.interpolation == 'linear-linear'
297+
298+
299+
def test_energy_filter():
300+
301+
# testing that bins descending value raises error
302+
msg = "Values 1.0 and 0.5 appear to be out of order"
303+
with raises(ValueError, match=msg):
304+
openmc.EnergyFilter([0.0, 1.0, 0.5])
305+
306+
# testing that bins with same value raises error
307+
msg = "Values 0.25 and 0.25 appear to be out of order"
308+
with raises(ValueError, match=msg):
309+
openmc.EnergyFilter([0.0, 0.25, 0.25])
310+
311+
# testing that negative bins values raises error
312+
msg = 'Unable to set "filter value" to "-1.2" since it is less than "0.0"'
313+
with raises(ValueError, match=msg):
314+
openmc.EnergyFilter([-1.2, 0.25, 0.5])

0 commit comments

Comments
 (0)