diff --git a/dumux/common/math.hh b/dumux/common/math.hh index 0c2dd6e89d8257472a0d8bb8f8d9ad54aac517cf..37c2baa440d968520b25eaeec137a3b8c812eda5 100644 --- a/dumux/common/math.hh +++ b/dumux/common/math.hh @@ -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 -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::value, "The arguments x and y have to be numbers!"); + static_assert(Dune::IsNumber::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 +constexpr Scalar harmonicMean(Scalar x, Scalar y, Scalar wx = 1.0, Scalar wy = 1.0) noexcept +{ + static_assert(Dune::IsNumber::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); } /*!