From c204ff57cdb40002562802d0a648e9f112d66dd0 Mon Sep 17 00:00:00 2001
From: Patrick Jaap <patrick.jaap@tu-dresden.de>
Date: Fri, 3 Jul 2020 13:17:32 +0200
Subject: [PATCH] CholmodSolver: Add error code member

Cholmod is able to report errors and warnings in the status entry of the
cholmodCommonObject.

Details about the possible integer values can be found in the Cholmod User Guide
---
 CHANGELOG.md                          |  2 +-
 dune/solvers/solvers/cholmodsolver.hh | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4a5d1c70..5746cb97 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
 # Master (will become release 2.8)
 
-- ...
+- CholmodSolver: Added `errorCode_` member to report errors and warnings during the matrix decomposition
 
 ## Deprecations and removals
 
diff --git a/dune/solvers/solvers/cholmodsolver.hh b/dune/solvers/solvers/cholmodsolver.hh
index 50114c64..7cbe2fb8 100644
--- a/dune/solvers/solvers/cholmodsolver.hh
+++ b/dune/solvers/solvers/cholmodsolver.hh
@@ -93,7 +93,12 @@ public:
     {
       // the apply() method doesn't like constant values
       auto mutableRhs = *rhs_;
+
+      // setMatrix will decompose the matrix
       solver.setMatrix(*matrix_);
+      // get the error code from Cholmod in case something happened
+      errorCode_ = solver.cholmodCommonObject().status;
+
       solver.apply(*x_, mutableRhs, statistics);
     }
     else
@@ -102,6 +107,8 @@ public:
 
       // The setMatrix method stores only the selected entries of the matrix (determined by the ignore field)
       solver.setMatrix(*matrix_,&ignore);
+      // get the error code from Cholmod in case something happened
+      errorCode_ = solver.cholmodCommonObject().status;
 
       auto modifiedRhs = *rhs_;
 
@@ -149,6 +156,19 @@ public:
     }
   }
 
+  /** \brief return the error code of the Cholmod factorize call
+   *
+   * In setMatrix() the matrix factorization takes place and Cholmod is
+   * able to communicate error codes of the factorization in the status
+   * field of the cholmodCommonObject.
+   * The return value 0 means "good" and the other values can be found
+   * in the Cholmod User Guide.
+   */
+  int errorCode() const
+  {
+    return errorCode_;
+  }
+
   //! Pointer to the system matrix
   const MatrixType* matrix_;
 
@@ -157,6 +177,9 @@ public:
 
   //! Pointer to the right hand side
   const VectorType* rhs_;
+
+  //! error code of Cholmod factorize call
+  int errorCode_ = 0;
 };
 
 }   // namespace Solvers
-- 
GitLab