From fc6e47dec5c0bbcd12e439aaa688a0e3fd66267e Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Thu, 22 Feb 2018 14:54:19 +0100 Subject: [PATCH] [math] Improve trace to work with all dense matrices --- dumux/common/math.hh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/dumux/common/math.hh b/dumux/common/math.hh index c1fb3db5a3..0c2dd6e89d 100644 --- a/dumux/common/math.hh +++ b/dumux/common/math.hh @@ -637,20 +637,21 @@ Dune::FieldMatrix<Scalar, rows1, cols2> multiplyMatrices(const Dune::FieldMatrix /*! * \ingroup Common - * \brief Trace of dynamic matrix + * \brief Trace of a dense matrix * - * \param M The dynamic matrix + * \param M The dense matrix */ -template <class Scalar> -Scalar trace(const Dune::DynamicMatrix<Scalar>& M) +template <class MatrixType> +typename Dune::DenseMatrix<MatrixType>::field_type +trace(const Dune::DenseMatrix<MatrixType>& M) { - std::size_t rows_T = M.M(); + const auto rows = M.N(); + DUNE_ASSERT_BOUNDS(rows == M.M()); // rows == cols - DUNE_ASSERT_BOUNDS(rows_T == M.N()); + using MatType = Dune::DenseMatrix<MatrixType>; + typename MatType::field_type trace = 0.0; - Scalar trace = 0.0; - - for (std::size_t i = 0; i < rows_T; ++i) + for (typename MatType::size_type i = 0; i < rows; ++i) trace += M[i][i]; return trace; -- GitLab