PetscException.cpp
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 #include "Warnings.hpp"
00034
00035
00036
00037
00038
00039
00040
00041 void PetscException(PetscInt petscError,
00042 unsigned line,
00043 const char* funct,
00044 const char* file)
00045 {
00046 if (petscError != 0)
00047 {
00048 const char* p_text;
00049 char default_message[30]="Unknown PETSc error code";
00050
00051
00052
00053
00054
00055 PetscErrorMessage(petscError, &p_text, NULL);
00056 if (p_text == 0)
00057 {
00058 p_text=default_message;
00059 }
00060 EXCEPTION(p_text << " in function '" << funct << "' on line "
00061 << line << " of file " << file);
00062 }
00063 }
00064
00065
00066
00067
00068
00069 std::string GetKspErrorMessage(PetscInt kspError)
00070 {
00071 std::string err_string;
00072
00073 #if (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 2) //PETSc 2.2
00074 switch (kspError)
00075 {
00076 case KSP_DIVERGED_ITS:
00077 err_string = "KSP_DIVERGED_ITS";
00078 break;
00079 case KSP_DIVERGED_DTOL:
00080 err_string = "KSP_DIVERGED_DTOL";
00081 break;
00082 case KSP_DIVERGED_BREAKDOWN:
00083 err_string = "KSP_DIVERGED_BREAKDOWN";
00084 break;
00085 case KSP_DIVERGED_BREAKDOWN_BICG:
00086 err_string = "KSP_DIVERGED_BREAKDOWN_BICG";
00087 break;
00088 case KSP_DIVERGED_NONSYMMETRIC:
00089 err_string = "KSP_DIVERGED_NONSYMMETRIC";
00090 break;
00091 case KSP_DIVERGED_INDEFINITE_PC:
00092 err_string = "KSP_DIVERGED_INDEFINITE_PC";
00093 break;
00094 default:
00095 err_string = "Unknown KSP error code";
00096 }
00097 #else
00098
00099
00100 extern const char **KSPConvergedReasons;
00101
00102
00103
00104 if (kspError >= -10)
00105 {
00106 err_string = KSPConvergedReasons[kspError];
00107 }
00108 else
00109 {
00110 err_string = "Unknown KSP error code";
00111 }
00112 #endif
00113
00114 return err_string;
00115 }
00116
00117
00118
00119
00120
00121 void KspException(PetscInt kspError,
00122 unsigned line,
00123 const char* funct,
00124 const char* file)
00125 {
00126 if (kspError < 0)
00127 {
00128 std::string err_string = GetKspErrorMessage(kspError);
00129
00130 err_string += " in function '";
00131 err_string += funct;
00132 err_string += "' on line ";
00133 err_string += line;
00134 err_string += " of file ";
00135 err_string += file;
00136
00137 EXCEPTION(err_string);
00138 }
00139 }
00140
00141 void KspWarnIfFailed(PetscInt kspError)
00142 {
00143 if (kspError < 0)
00144 {
00145 std::string message = "Linear solve failed: " + GetKspErrorMessage(kspError);
00146 WARNING(message);
00147 }
00148 }