From 4e6b588b12e7573973a27e37985cc238da9a0f94 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maximilian=20H=C3=B6rl?=
 <maximilian.hoerl@mathematik.uni-stuttgart.de>
Date: Wed, 20 May 2020 12:16:21 +0200
Subject: [PATCH] check for diagonal matrix in eigenvaluehelper

---
 dune/mmdg/eigenvaluehelper.hh | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/dune/mmdg/eigenvaluehelper.hh b/dune/mmdg/eigenvaluehelper.hh
index 63bde0f..a3e9cf0 100644
--- a/dune/mmdg/eigenvaluehelper.hh
+++ b/dune/mmdg/eigenvaluehelper.hh
@@ -36,6 +36,13 @@ public:
   static void eigenValues(const Dune::FieldMatrix<K, 2, 2>& matrix,
                           Dune::FieldVector<K, 2>& eigenvalues)
   {
+    if ( std::abs(matrix[1][0]) < 1e-15 && std::abs(matrix[0][1]) < 1e-15 )
+    { //diagonal matrix
+      eigenvalues[0] = std::min(matrix[0][0], matrix[1][1]);
+      eigenvalues[1] = std::max(matrix[0][0], matrix[1][1]);
+      return;
+    }
+
     using std::sqrt;
     const K detM = matrix[0][0] * matrix[1][1] - matrix[1][0] * matrix[0][1];
     const K p = 0.5 * (matrix[0][0] + matrix [1][1]);
-- 
GitLab