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