diff --git a/dumux/common/math.hh b/dumux/common/math.hh index c1fb3db5a3be9df5c5f4270f4e0e13ea16514255..0c2dd6e89d8257472a0d8bb8f8d9ad54aac517cf 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;