Skip to content

Commit

Permalink
Merge pull request #2154 from shimwell/adding_log_width_bins_to_energ…
Browse files Browse the repository at this point in the history
…y_filter

added bin_log_width to EnergyFilter() to help with plotting
  • Loading branch information
paulromano committed Aug 10, 2022
2 parents 30c561c + 7004ff5 commit 9060866
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions openmc/filter.py
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions tests/unit_tests/test_filters.py
@@ -1,3 +1,4 @@
import math
import numpy as np
import openmc
from pytest import fixture, approx
Expand Down Expand Up @@ -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])

0 comments on commit 9060866

Please sign in to comment.