00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <sstream>
00030
00031 #include "PetscException.hpp"
00032 #include "Exception.hpp"
00033
00034
00035
00036
00037
00038 void PetscException(PetscInt petscError,
00039 unsigned line,
00040 const char* funct,
00041 const char* file)
00042 {
00043 if (petscError != 0)
00044 {
00045 const char* p_text;
00046 char default_message[30]="Unknown PETSc error code";
00047
00048
00049
00050 PetscErrorMessage(petscError, &p_text, NULL);
00051 if (p_text == 0)
00052 {
00053 p_text=default_message;
00054 }
00055
00056 std::stringstream err_string;
00057 err_string << p_text;
00058 err_string << " in function '";
00059 err_string << funct;
00060 err_string << "' on line ";
00061 err_string << line;
00062 err_string << " of file ";
00063 err_string << file;
00064
00065 EXCEPTION(err_string.str());
00066 }
00067 }
00068
00069
00070
00071 void KspException(PetscInt kspError,
00072 unsigned line,
00073 const char* funct,
00074 const char* file)
00075 {
00076 if (kspError < 0)
00077 {
00078 std::string err_string;
00079
00080 #if (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 2) //PETSc 2.2
00081 switch (kspError)
00082 {
00083 case KSP_DIVERGED_ITS:
00084 err_string = "KSP_DIVERGED_ITS";
00085 break;
00086 case KSP_DIVERGED_DTOL:
00087 err_string = "KSP_DIVERGED_DTOL";
00088 break;
00089 case KSP_DIVERGED_BREAKDOWN:
00090 err_string = "KSP_DIVERGED_BREAKDOWN";
00091 break;
00092 case KSP_DIVERGED_BREAKDOWN_BICG:
00093 err_string = "KSP_DIVERGED_BREAKDOWN_BICG";
00094 break;
00095 case KSP_DIVERGED_NONSYMMETRIC:
00096 err_string = "KSP_DIVERGED_NONSYMMETRIC";
00097 break;
00098 case KSP_DIVERGED_INDEFINITE_PC:
00099 err_string = "KSP_DIVERGED_INDEFINITE_PC";
00100 break;
00101 default:
00102 err_string = "Unknown KSP error code";
00103 }
00104 #else
00105
00106
00107
00108 extern const char **KSPConvergedReasons;
00109
00110
00111
00112
00113 if (kspError >= -10) err_string = KSPConvergedReasons[kspError];
00114 else err_string = "Unknown KSP error code";
00115 #endif
00116
00117 err_string += " in function '";
00118 err_string += funct;
00119 err_string += "' on line ";
00120 err_string += line;
00121 err_string += " of file ";
00122 err_string += file;
00123
00124 EXCEPTION(err_string);
00125 }
00126 }