mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
2nd round of review improvments from paulromano
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
e6d8e3f4a7
commit
853ef5ea49
2 changed files with 9 additions and 3 deletions
|
|
@ -1352,12 +1352,15 @@ class EnergyFilter(RealFilter):
|
|||
Tabular distribution with histogram interpolation
|
||||
"""
|
||||
|
||||
probabilities = np.array(values) / sum(values)
|
||||
probabilities = np.array(values, dtype=float)
|
||||
probabilities /= probabilities.sum()
|
||||
|
||||
# Determine probability per eV, adding extra 0 at the end since it is a histogram
|
||||
probability_per_ev = probabilities / np.diff(self.values)
|
||||
probability_per_ev = np.append(probability_per_ev, 0.0)
|
||||
|
||||
kwargs.setdefault('interpolation', 'histogram')
|
||||
return openmc.stats.Tabular(self.bins, probability_per_ev, **kwargs)
|
||||
return openmc.stats.Tabular(self.values, probability_per_ev, **kwargs)
|
||||
|
||||
@property
|
||||
def lethargy_bin_width(self):
|
||||
|
|
|
|||
|
|
@ -275,12 +275,15 @@ def test_tabular_from_energyfilter():
|
|||
efilter = openmc.EnergyFilter([0.0, 10.0, 20.0, 25.0])
|
||||
tab = efilter.get_tabular(values=[5, 10, 10])
|
||||
|
||||
assert tab.x.tolist() == [[0.0, 10.0], [10.0, 20.0], [20.0, 25.0]]
|
||||
assert tab.x.tolist() == [0.0, 10.0, 20.0, 25.0]
|
||||
|
||||
# combination of different values passed into get_tabular and different
|
||||
# width energy bins results in a doubling value for each p value
|
||||
assert tab.p.tolist() == [0.02, 0.04, 0.08]
|
||||
|
||||
# distribution should integrate to unity
|
||||
assert tab.integral() == approx(1.0)
|
||||
|
||||
# 'histogram' is the default
|
||||
assert tab.interpolation == 'histogram'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue