Skip to content
Snippets Groups Projects
Commit 83d5b415 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

Merge branch 'feature/weightedMeans' into 'master'

[math] Implement weighted means

See merge request !1024
parents 93e03e18 2abec55c
No related branches found
No related tags found
1 merge request!1024[math] Implement weighted means
......@@ -36,19 +36,40 @@ namespace Dumux
{
/*!
* \ingroup Common
* \brief Calculate the harmonic mean of two scalar values.
* \brief Calculate the (weighted) arithmetic mean of two scalar values.
*
* \param x The first input value
* \param y The second input value
* \param wx The first weight
* \param wy The second weight
*/
template <class Scalar>
constexpr Scalar harmonicMean(Scalar x, Scalar y) noexcept
constexpr Scalar arithmeticMean(Scalar x, Scalar y, Scalar wx = 1.0, Scalar wy = 1.0) noexcept
{
static_assert(Dune::IsNumber<Scalar>::value, "The arguments x and y have to be numbers!");
static_assert(Dune::IsNumber<Scalar>::value, "The arguments x, y, wx, and wy have to be numbers!");
if (x*y <= 0)
return 0;
return (x * wx + y * wy)/(wx + wy);
}
/*!
* \ingroup Common
* \brief Calculate the (weighted) harmonic mean of two scalar values.
*
* \param x The first input value
* \param y The second input value
* \param wx The first weight
* \param wy The second weight
*/
template <class Scalar>
constexpr Scalar harmonicMean(Scalar x, Scalar y, Scalar wx = 1.0, Scalar wy = 1.0) noexcept
{
static_assert(Dune::IsNumber<Scalar>::value, "The arguments x, y, wx, and wy have to be numbers!");
if (x*y <= 0)
return 0;
return (2*x*y)/(x + y);
return (wx + wy) / (wx / x + wy / y);
}
/*!
......
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