From 35255bb2c7f3878ffd31c77770ff33dd90ce8a90 Mon Sep 17 00:00:00 2001
From: Simon Praetorius <simon.praetorius@tu-dresden.de>
Date: Mon, 6 May 2019 11:17:55 +0200
Subject: [PATCH] add static size information for Eigen matrix type

---
 src/amdis/common/StaticSize.hpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/amdis/common/StaticSize.hpp b/src/amdis/common/StaticSize.hpp
index ec346a0e..187880c2 100644
--- a/src/amdis/common/StaticSize.hpp
+++ b/src/amdis/common/StaticSize.hpp
@@ -25,6 +25,12 @@ namespace Dune
   class MultiTypeBlockVector;
 }
 
+namespace Eigen
+{
+  template <typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+  class Matrix;
+}
+
 namespace AMDiS
 {
   namespace Impl
@@ -60,6 +66,14 @@ namespace AMDiS
     struct SizeImpl<Dune::MultiTypeBlockVector<Ts...>>
         : std::integral_constant<std::size_t, sizeof...(Ts)> {};
 
+    template <class T, int N, int... opts>
+    struct SizeImpl<Eigen::Matrix<T,N,1,opts...>>
+        : std::integral_constant<std::size_t, (N >= 0 ? std::size_t(N) : 0u)> {};
+
+    template <class T, int N, int... opts>
+    struct SizeImpl<Eigen::Matrix<T,1,N,opts...>>
+        : std::integral_constant<std::size_t, (N >= 0 ? std::size_t(N) : 0u)> {};
+
     // Specialization for arithmetic types
     template <class T>
     struct SizeImpl<T, std::enable_if_t<std::is_arithmetic<T>::value> >
@@ -93,6 +107,10 @@ namespace AMDiS
     struct RowsImpl<T, std::enable_if_t<std::is_arithmetic<T>::value> >
         : std::integral_constant<std::size_t, 1> {};
 
+    template <class T, int N, int M, int... opts>
+    struct RowsImpl<Eigen::Matrix<T,N,M,opts...>>
+        : std::integral_constant<std::size_t, (N >= 0 ? std::size_t(N) : 0u)> {};
+
   } // end namespace Impl
 
   /// Get the number of rows in a fixed-size matrix
@@ -121,6 +139,10 @@ namespace AMDiS
     struct ColsImpl<T, std::enable_if_t<std::is_arithmetic<T>::value> >
         : std::integral_constant<std::size_t, 1> {};
 
+    template <class T, int N, int M, int... opts>
+    struct ColsImpl<Eigen::Matrix<T,N,M,opts...>>
+        : std::integral_constant<std::size_t, (M >= 0 ? std::size_t(M) : 0u)> {};
+
   } // end namespace Impl
 
   /// Get the number of columns in a fixed-size matrix
-- 
GitLab