remove OTF memory allocation from WMP

This commit is contained in:
Gavin Ridley 2021-01-07 15:43:32 -05:00
parent 66d76429a8
commit caecb84c38
2 changed files with 12 additions and 1 deletions

View file

@ -70,6 +70,10 @@ public:
xt::xtensor<int, 2> windows_; //!< Indices of pole at start/end of window
xt::xtensor<double, 3> curvefit_; //!< Fitting function (reaction, coeff index, window index)
xt::xtensor<bool, 1> broaden_poly_; //!< Whether to broaden curvefit
// Constant data
static constexpr int MAX_POLY_COEFFICIENTS =
10; //!< Max order of polynomial fit plus one
};
//========================================================================

View file

@ -56,6 +56,13 @@ WindowedMultipole::WindowedMultipole(hid_t group)
"array shape in WMP library for " + name_ + ".");
}
fit_order_ = curvefit_.shape()[1] - 1;
// Check the code is compiling to work with sufficiently high fit order
if (fit_order_ + 1 > MAX_POLY_COEFFICIENTS) {
fatal_error(fmt::format(
"Need to compile with WindowedMultipole::MAX_POLY_COEFFICIENTS = {}",
fit_order_ + 1));
}
}
std::tuple<double, double, double>
@ -87,7 +94,7 @@ WindowedMultipole::evaluate(double E, double sqrtkT)
if (sqrtkT > 0.0 && broaden_poly_(i_window)) {
// Broaden the curvefit.
double dopp = sqrt_awr_ / sqrtkT;
std::vector<double> broadened_polynomials(fit_order_ + 1);
std::array<double, MAX_POLY_COEFFICIENTS> broadened_polynomials;
broaden_wmp_polynomials(E, dopp, fit_order_ + 1, broadened_polynomials.data());
for (int i_poly = 0; i_poly < fit_order_ + 1; ++i_poly) {
sig_s += curvefit_(i_window, i_poly, FIT_S) * broadened_polynomials[i_poly];