From df22a5f4a071aef0c5a975c9e2139c69fc86c707 Mon Sep 17 00:00:00 2001 From: DennisGlaeser <dennis.glaeser@iws.uni-stuttgart.de> Date: Fri, 1 Dec 2017 21:55:14 +0100 Subject: [PATCH] [math] introduce vtmv function projects a vector and calculates the scalar product with a second vector --- dumux/common/math.hh | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/dumux/common/math.hh b/dumux/common/math.hh index cc5eb1d58a..5497dde5dd 100644 --- a/dumux/common/math.hh +++ b/dumux/common/math.hh @@ -618,6 +618,51 @@ Scalar trace(const Dune::DynamicMatrix<Scalar>& M) return trace; } +/*! + * \brief Evaluates the scalar product of a vector v2, projected by + * a matrix M, with a vector v1. + * + * Note: We use DenseVector and DenseMatrix here so that + * it can be used with the statically and dynamically + * allocated Dune Vectors/Matrices. Size mismatch + * assertions are done in the respective Dune classes. + * + * \param v1 The first vector + * \param M The matrix + * \param v2 The second vector + */ +template <class V1, class MAT, class V2> +typename Dune::DenseMatrix<MAT>::value_type +vtmv(const Dune::DenseVector<V1>& v1, + const Dune::DenseMatrix<MAT>& M, + const Dune::DenseVector<V2>& v2) +{ + auto tmp(v2); + M.mv(v2, tmp); + return v1*tmp; +} + +/*! + * \brief Evaluates the scalar product of a vector v2, scaled by + * a scalar m, with a vector v1. + * + * Note: We use DenseVector and DenseMatrix here so that + * it can be used with the statically and dynamically + * allocated Dune Vectors/Matrices. Size mismatch + * assertions are done in the respective Dune classes. + * + * \param v1 The first vector + * \param m The scale factor + * \param v2 The second vector + */ +template <class V1, class FieldScalar, class V2> +FieldScalar vtmv(const Dune::DenseVector<V1>& v1, + const FieldScalar m, + const Dune::DenseVector<V2>& v2) +{ + return m*(v1*v2); +} + } // end namespace Dumux #endif -- GitLab