From 4f1d9dda5e1fc35883742da9936f4eb7b8b13c0a Mon Sep 17 00:00:00 2001
From: DennisGlaeser <dennis.glaeser@iws.uni-stuttgart.de>
Date: Wed, 27 Dec 2017 16:58:02 +0100
Subject: [PATCH] [math] implement multiplymatrices() for field matrices

---
 dumux/common/math.hh | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/dumux/common/math.hh b/dumux/common/math.hh
index c6777d5f8d..905d5aab72 100644
--- a/dumux/common/math.hh
+++ b/dumux/common/math.hh
@@ -607,6 +607,29 @@ Dune::DynamicMatrix<Scalar> multiplyMatrices(const Dune::DynamicMatrix<Scalar> &
     return result;
 }
 
+/*!
+ * \ingroup Common
+ * \brief Multiply two field matrices
+ *
+ * \param M1 The first field matrix
+ * \param M2 The second field matrix (to be multiplied to M1 from the right side)
+ */
+template <class Scalar, int rows1, int cols1, int cols2>
+Dune::FieldMatrix<Scalar, rows1, cols2> multiplyMatrices(const Dune::FieldMatrix<Scalar, rows1, cols1> &M1,
+                                                         const Dune::FieldMatrix<Scalar, cols1, cols2> &M2)
+{
+    using size_type = typename Dune::FieldMatrix<Scalar, rows1, cols2>::size_type;
+
+    Dune::FieldMatrix<Scalar, rows1, cols2> result(0.0);
+    for (size_type i = 0; i < rows1; i++)
+        for (size_type j = 0; j < cols2; j++)
+            for (size_type k = 0; k < cols1; k++)
+                result[i][j] += M1[i][k]*M2[k][j];
+
+    return result;
+}
+
+
 /*!
  * \ingroup Common
  * \brief Trace of dynamic matrix
-- 
GitLab