From f994df79f55128c74a42a9ad72db7acbe86f1475 Mon Sep 17 00:00:00 2001
From: Michael Wimmer <wimmer@lorentz.leidenuniv.nl>
Date: Fri, 21 Dec 2012 14:40:53 +0100
Subject: [PATCH] more descriptive error messages for more common MUMPS errors;
 catch error -8 like error -9

---
 kwant/linalg/mumps.py | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/kwant/linalg/mumps.py b/kwant/linalg/mumps.py
index 6fe7438d..b9f33bb1 100644
--- a/kwant/linalg/mumps.py
+++ b/kwant/linalg/mumps.py
@@ -57,11 +57,26 @@ def possible_orderings():
     return _possible_orderings
 
 
+_error_messages = {
+    -5 : "Not enough memory during analysis phase",
+    -6 : "Matrix is singular in structure",
+    -7 : "Not enough memory during analysis phase",
+    -10 : "Matrix is numerically singular",
+    -11 : "That's an error the Mumps programmers would like to hear about",
+    -12 : "That's an error the Mumps programmers would like to hear about",
+    -13 : "Not enough memory"
+}
+
 class MUMPSError(RuntimeError):
-    def __init__(self, error):
-        self.error = error
-        RuntimeError.__init__(self, "MUMPS failed with error " +
-                              str(error))
+    def __init__(self, infog):
+        self.error = infog[1]
+        if self.error in _error_messages:
+            msg = _error_messages[self.error] + \
+                " (Mumps error " + str(self.error) +")"
+        else:
+            msg = "MUMPS failed with error " + str(self.error)
+
+        RuntimeError.__init__(self, msg)
 
 
 class AnalysisStatistics(object):
@@ -224,7 +239,7 @@ class MUMPSContext(object):
         self.factored = False
 
         if self.mumps_instance.infog[1] < 0:
-            raise MUMPSError(self.mumps_instance.infog[1])
+            raise MUMPSError(self.mumps_instance.infog)
 
         self.analysis_stats = AnalysisStatistics(self.mumps_instance,
                                                  t2 - t1)
@@ -309,10 +324,10 @@ class MUMPSContext(object):
             self.mumps_instance.call()
             t2 = time.clock()
 
-            # error -9 (not enough allocated memory) is treated
+            # error -8, -9 (not enough allocated memory) is treated
             # specially, by increasing the memory relaxation parameter
             if self.mumps_instance.infog[1] < 0:
-                if self.mumps_instance.infog[1] == -9:
+                if self.mumps_instance.infog[1] in (-8, -9):
                     # double the additional memory
                     self.mumps_instance.icntl[14] *= 2
                 else:
-- 
GitLab