Commit 5662f943 authored by Timo Koch's avatar Timo Koch
Browse files

[math] Add linear table interpolation with two arguments

parent 9b9db541
...@@ -500,9 +500,9 @@ namespace InterpolationPolicy { struct Linear; } ...@@ -500,9 +500,9 @@ namespace InterpolationPolicy { struct Linear; }
* \param params the parameters used for interpolation (depends on the policy used) * \param params the parameters used for interpolation (depends on the policy used)
* \param ip the interpolation point * \param ip the interpolation point
*/ */
template <class Policy = InterpolationPolicy::Linear, class Scalar, class Parameter> template <class Policy = InterpolationPolicy::Linear, class Scalar, class ... Parameter>
Scalar interpolate(Scalar ip, Parameter&& params) Scalar interpolate(Scalar ip, Parameter&& ... params)
{ return Policy::interpolate(ip, std::forward<Parameter>(params)); } { return Policy::interpolate(ip, std::forward<Parameter>(params) ...); }
/*! /*!
* \ingroup Common * \ingroup Common
...@@ -540,12 +540,9 @@ struct LinearTable ...@@ -540,12 +540,9 @@ struct LinearTable
* \param table the table as a pair of sorted vectors (have to be same size) * \param table the table as a pair of sorted vectors (have to be same size)
* \note if the interpolation point is out of bounds this will return the bounds * \note if the interpolation point is out of bounds this will return the bounds
*/ */
template<class Scalar, class RandomAccessContainer> template<class Scalar, class RandomAccessContainer0, class RandomAccessContainer1>
static constexpr Scalar interpolate(Scalar ip, const std::pair<RandomAccessContainer, RandomAccessContainer>& table) static constexpr Scalar interpolate(Scalar ip, const RandomAccessContainer0& range, const RandomAccessContainer1& values)
{ {
const auto& range = table.first;
const auto& values = table.second;
// check bounds // check bounds
if (ip > range.back()) return values.back(); if (ip > range.back()) return values.back();
if (ip < range[0]) return values[0]; if (ip < range[0]) return values[0];
...@@ -558,6 +555,13 @@ struct LinearTable ...@@ -558,6 +555,13 @@ struct LinearTable
const auto ipLinear = (ip - range[lookUpIndex-1])/(range[lookUpIndex] - range[lookUpIndex-1]); const auto ipLinear = (ip - range[lookUpIndex-1])/(range[lookUpIndex] - range[lookUpIndex-1]);
return Dumux::interpolate<Linear>(ipLinear, std::array<Scalar, 2>{{values[lookUpIndex-1], values[lookUpIndex]}}); return Dumux::interpolate<Linear>(ipLinear, std::array<Scalar, 2>{{values[lookUpIndex-1], values[lookUpIndex]}});
} }
template<class Scalar, class RandomAccessContainer>
static constexpr Scalar interpolate(Scalar ip, const std::pair<RandomAccessContainer, RandomAccessContainer>& table)
{
const auto& [range, values] = table;
return interpolate(ip, range, values);
}
}; };
} // end namespace InterpolationPolicy } // end namespace InterpolationPolicy
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment