From f33ea966b21802e206bb46c04c7aa8e45943e01b Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 17 Sep 2022 11:10:27 -0500 Subject: [PATCH] Compute interpolation value in loop. Correction to from_tab1D. --- include/openmc/interpolate.h | 9 +++------ openmc/filter.py | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/openmc/interpolate.h b/include/openmc/interpolate.h index 33167fa2ab..05353f1306 100644 --- a/include/openmc/interpolate.h +++ b/include/openmc/interpolate.h @@ -36,9 +36,7 @@ inline double interpolate_log_log( inline double interpolate_lagrangian(gsl::span xs, gsl::span ys, int idx, double x, int order) { - Expects(order <= 3); - std::array coeffs; - coeffs.fill(0.0); + double output {0.0}; for (int i = 0; i < order + 1; i++) { double numerator {1.0}; @@ -49,11 +47,10 @@ inline double interpolate_lagrangian(gsl::span xs, numerator *= (x - xs[idx + j]); denominator *= (xs[idx + i] - xs[idx + j]); } - coeffs[i] = numerator / denominator; + output += (numerator / denominator) * ys[i]; } - return std::inner_product( - coeffs.begin(), coeffs.end(), ys.begin() + idx, 0.0); + return output; } double interpolate(gsl::span xs, gsl::span ys, diff --git a/openmc/filter.py b/openmc/filter.py index 326572c4a4..2af5fe5b79 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -1995,11 +1995,11 @@ class EnergyFunctionFilter(Filter): if tab1d.n_regions > 1: raise ValueError('Only Tabulated1Ds with a single interpolation ' 'region are supported') - interpolation = tab1d.interpolation[0] - if interpolation not in cls.INTERPOLATION_SCHEMES.keys(): + interpolation_val = tab1d.interpolation[0] + if interpolation_val not in cls.INTERPOLATION_SCHEMES.keys(): raise ValueError('Only histogram, linear-linear, linear-log, log-linear, and ' 'log-log Tabulated1Ds are supported') - return cls(tab1d.x, tab1d.y, interpolation) + return cls(tab1d.x, tab1d.y, cls.INTERPOLATION_SCHEMES[interpolation_val]) @property def energy(self):