From fbce363784e2b9d4b95c246317bccc2230f18703 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 7 Sep 2022 23:05:15 -0500 Subject: [PATCH] Using a separate dictionary for interpolation values --- include/openmc/interpolate.h | 3 +++ openmc/data/function.py | 2 +- openmc/filter.py | 10 +++++++--- tests/regression_tests/filter_energyfun/test.py | 2 -- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/openmc/interpolate.h b/include/openmc/interpolate.h index 2764b7ffc2..d02d87ff21 100644 --- a/include/openmc/interpolate.h +++ b/include/openmc/interpolate.h @@ -61,6 +61,9 @@ inline double interpolate(const std::vector& xs, { int idx = lower_bound_index(xs.begin(), xs.end(), x); + if (idx == xs.size()) + idx--; + switch (i) { case Interpolation::lin_lin: return interpolate_lin_lin(xs[idx], xs[idx + 1], ys[idx], ys[idx + 1], x); diff --git a/openmc/data/function.py b/openmc/data/function.py index 59f549d6fd..b0390d19cd 100644 --- a/openmc/data/function.py +++ b/openmc/data/function.py @@ -13,7 +13,7 @@ from openmc.mixin import EqualityMixin from .data import EV_PER_MEV INTERPOLATION_SCHEME = {1: 'histogram', 2: 'linear-linear', 3: 'linear-log', - 4: 'log-linear', 5: 'log-log', 6 : 'quadratic', 7 : 'cubic'} + 4: 'log-linear', 5: 'log-log'} def sum_functions(funcs): diff --git a/openmc/filter.py b/openmc/filter.py index 8b0c84c7ea..c1ce573c9a 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -12,7 +12,6 @@ import pandas as pd import openmc import openmc.checkvalue as cv from .cell import Cell -from .data.function import INTERPOLATION_SCHEME from .material import Material from .mixin import IDManagerMixin from .surface import Surface @@ -1896,6 +1895,11 @@ class EnergyFunctionFilter(Filter): """ + # keys selected to match those in function.py where possible + INTERPOLATION_SCHEMES = {2: 'linear-linear', 3: 'linear-log', + 4: 'log-linear', 5: 'log-log', + 6 : 'quadratic', 7 : 'cubic'} + def __init__(self, energy, y, interpolation='linear-linear', filter_id=None): self.energy = energy self.y = y @@ -1963,7 +1967,7 @@ class EnergyFunctionFilter(Filter): out = cls(energy, y, filter_id=filter_id) if 'interpolation' in group: out.interpolation = \ - openmc.data.INTERPOLATION_SCHEME[group['interpolation'][()]] + cls.INTERPOLATION_SCHEMES[group['interpolation'][()]] return out @@ -2053,7 +2057,7 @@ class EnergyFunctionFilter(Filter): @interpolation.setter def interpolation(self, val): cv.check_type('interpolation', val, str) - cv.check_value('interpolation', val, INTERPOLATION_SCHEME.values()) + cv.check_value('interpolation', val, self.INTERPOLATION_SCHEMES.values()) self._interpolation = val def to_xml_element(self): diff --git a/tests/regression_tests/filter_energyfun/test.py b/tests/regression_tests/filter_energyfun/test.py index c297c094af..9c2be7be39 100644 --- a/tests/regression_tests/filter_energyfun/test.py +++ b/tests/regression_tests/filter_energyfun/test.py @@ -73,9 +73,7 @@ class FilterEnergyFunHarness(PyAPITestHarness): br_tally = sp.tallies[2] / sp.tallies[1] dataframes_string += br_tally.get_pandas_dataframe().to_string() + '\n' - for t_id in (3, 4, 5): - # Write out the log-log interpolation as well ef_tally = sp.tallies[t_id] dataframes_string += ef_tally.get_pandas_dataframe().to_string() + '\n'