Skip to content
Snippets Groups Projects
Commit 5662f943 authored by Timo Koch's avatar Timo Koch
Browse files

[math] Add linear table interpolation with two arguments

parent 9b9db541
No related branches found
No related tags found
1 merge request!2216[math] Add linear table interpolation with two arguments
......@@ -500,9 +500,9 @@ namespace InterpolationPolicy { struct Linear; }
* \param params the parameters used for interpolation (depends on the policy used)
* \param ip the interpolation point
*/
template <class Policy = InterpolationPolicy::Linear, class Scalar, class Parameter>
Scalar interpolate(Scalar ip, Parameter&& params)
{ return Policy::interpolate(ip, std::forward<Parameter>(params)); }
template <class Policy = InterpolationPolicy::Linear, class Scalar, class ... Parameter>
Scalar interpolate(Scalar ip, Parameter&& ... params)
{ return Policy::interpolate(ip, std::forward<Parameter>(params) ...); }
/*!
* \ingroup Common
......@@ -540,12 +540,9 @@ struct LinearTable
* \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
*/
template<class Scalar, class RandomAccessContainer>
static constexpr Scalar interpolate(Scalar ip, const std::pair<RandomAccessContainer, RandomAccessContainer>& table)
template<class Scalar, class RandomAccessContainer0, class RandomAccessContainer1>
static constexpr Scalar interpolate(Scalar ip, const RandomAccessContainer0& range, const RandomAccessContainer1& values)
{
const auto& range = table.first;
const auto& values = table.second;
// check bounds
if (ip > range.back()) return values.back();
if (ip < range[0]) return values[0];
......@@ -558,6 +555,13 @@ struct LinearTable
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]}});
}
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment