Add check for equal value bins in an EnergyFilter (#3372)

This commit is contained in:
Jonathan Shimwell 2025-04-11 23:35:30 +02:00 committed by GitHub
parent cdc254ccf4
commit bd95b52f4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -1238,7 +1238,7 @@ class RealFilter(Filter):
cv.check_type('filter value', v1, Real)
# Make sure that each tuple has values that are increasing
if v1 < v0:
if v1 <= v0:
raise ValueError(f'Values {v0} and {v1} appear to be out of '
'order')
@ -1384,7 +1384,7 @@ class EnergyFilter(RealFilter):
----------
values : Iterable of Real
A list of values for which each successive pair constitutes a range of
energies in [eV] for a single bin
energies in [eV] for a single bin. Entries must be positive and ascending.
filter_id : int
Unique identifier for the filter

View file

@ -294,3 +294,21 @@ def test_tabular_from_energyfilter():
tab = efilter.get_tabular(values=np.array([10, 10, 5]), interpolation='linear-linear')
assert tab.interpolation == 'linear-linear'
def test_energy_filter():
# testing that bins descending value raises error
msg = "Values 1.0 and 0.5 appear to be out of order"
with raises(ValueError, match=msg):
openmc.EnergyFilter([0.0, 1.0, 0.5])
# testing that bins with same value raises error
msg = "Values 0.25 and 0.25 appear to be out of order"
with raises(ValueError, match=msg):
openmc.EnergyFilter([0.0, 0.25, 0.25])
# testing that negative bins values raises error
msg = 'Unable to set "filter value" to "-1.2" since it is less than "0.0"'
with raises(ValueError, match=msg):
openmc.EnergyFilter([-1.2, 0.25, 0.5])