diff --git a/openmc/filter.py b/openmc/filter.py index be3d9767998..d7ab3f27e7a 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -1324,6 +1324,18 @@ def check_bins(self, bins): cv.check_greater_than('filter value', v0, 0., equality=True) cv.check_greater_than('filter value', v1, 0., equality=True) + @property + def lethargy_bin_width(self): + """Calculates the base 10 log width of energy bins which is useful when + plotting the normalized flux. + + Returns + ------- + numpy.array + Array of bin widths + """ + return np.log10(self.bins[:, 1]/self.bins[:, 0]) + @classmethod def from_group_structure(cls, group_structure): """Construct an EnergyFilter instance from a standard group structure. diff --git a/tests/unit_tests/test_filters.py b/tests/unit_tests/test_filters.py index 6b344b827e8..ec051d9fd02 100644 --- a/tests/unit_tests/test_filters.py +++ b/tests/unit_tests/test_filters.py @@ -1,3 +1,4 @@ +import math import numpy as np import openmc from pytest import fixture, approx @@ -246,3 +247,11 @@ def test_energy(): f = openmc.EnergyFilter.from_group_structure('CCFE-709') assert f.bins.shape == (709, 2) assert len(f.values) == 710 + + +def test_lethargy_bin_width(): + f = openmc.EnergyFilter.from_group_structure('VITAMIN-J-175') + assert len(f.lethargy_bin_width) == 175 + energy_bins = openmc.mgxs.GROUP_STRUCTURES['VITAMIN-J-175'] + assert f.lethargy_bin_width[0] == math.log10(energy_bins[1]/energy_bins[0]) + assert f.lethargy_bin_width[-1] == math.log10(energy_bins[-1]/energy_bins[-2])