38 #include "PetscException.hpp"
40 #include "Warnings.hpp"
49 void PetscException(
PetscInt petscError,
57 char default_message[30]=
"Unknown PETSc error code";
63 PetscErrorMessage(petscError, &p_text, NULL);
66 p_text=default_message;
72 EXCEPTION(p_text <<
" in function '" << funct <<
"' on line "
73 << line <<
" of file ./" << file+root_dir_length);
75 EXCEPTION(p_text <<
" in function '" << funct <<
"' on line "
76 << line <<
" of file " << file);
85 std::string GetKspErrorMessage(
PetscInt kspError)
87 std::string err_string;
89 #if (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 2) //PETSc 2.2
92 case KSP_DIVERGED_ITS:
93 err_string =
"KSP_DIVERGED_ITS";
95 case KSP_DIVERGED_DTOL:
96 err_string =
"KSP_DIVERGED_DTOL";
98 case KSP_DIVERGED_BREAKDOWN:
99 err_string =
"KSP_DIVERGED_BREAKDOWN";
101 case KSP_DIVERGED_BREAKDOWN_BICG:
102 err_string =
"KSP_DIVERGED_BREAKDOWN_BICG";
104 case KSP_DIVERGED_NONSYMMETRIC:
105 err_string =
"KSP_DIVERGED_NONSYMMETRIC";
107 case KSP_DIVERGED_INDEFINITE_PC:
108 err_string =
"KSP_DIVERGED_INDEFINITE_PC";
111 err_string =
"Unknown KSP error code";
116 #if (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 2) //PETSc 3.2 or later
118 extern const char *
const *KSPConvergedReasons;
120 extern const char **KSPConvergedReasons;
127 err_string = KSPConvergedReasons[kspError];
131 err_string =
"Unknown KSP error code";
142 void KspException(
PetscInt kspError,
149 std::stringstream err_string_stream;
153 err_string_stream << GetKspErrorMessage(kspError) <<
" in function '" << funct <<
"' on line "
154 << line <<
" of file ./" << file + root_dir_length;
156 err_string_stream << GetKspErrorMessage(kspError) <<
" in function '" << funct <<
"' on line "
157 << line <<
" of file " << file;
163 void KspWarnIfFailed(
PetscInt kspError)
167 std::string message =
"Linear solve failed: " + GetKspErrorMessage(kspError);
const char * ChasteSourceRootDir()
#define EXCEPTION(message)