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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "LOCA_ErrorCheck.H"
00043 #include "LOCA_GlobalData.H"
00044 #include "NOX_Utils.H"
00045
00046 LOCA::ErrorCheck::ErrorCheck(
00047 const Teuchos::RCP<LOCA::GlobalData>& global_data) :
00048 globalData(global_data)
00049 {
00050 }
00051
00052 LOCA::ErrorCheck::~ErrorCheck()
00053 {
00054 }
00055
00056
00057 void LOCA::ErrorCheck::throwError(const string& callingFunction,
00058 const string& message,
00059 const string& throwLabel)
00060 {
00061 if (globalData->locaUtils->isPrintType(NOX::Utils::Error)) {
00062 globalData->locaUtils->err() << "************************" << "\n";
00063 globalData->locaUtils->err() << "ERROR: " << callingFunction << "\n";
00064 if (message != "")
00065 globalData->locaUtils->err() << message << "\n";
00066 globalData->locaUtils->err() << "************************" << std::endl;
00067 }
00068 throw (throwLabel.c_str());
00069 return;
00070 }
00071
00072 void LOCA::ErrorCheck::printWarning(const string& callingFunction,
00073 const string& message)
00074 {
00075 if (globalData->locaUtils->isPrintType(NOX::Utils::Warning)) {
00076 globalData->locaUtils->out() << "WARNING: " << callingFunction << " - ";
00077 if (message != "")
00078 globalData->locaUtils->out() << message << std::endl;
00079 }
00080 return;
00081 }
00082
00083 void
00084 LOCA::ErrorCheck::checkReturnType(
00085 const NOX::Abstract::Group::ReturnType& status,
00086 const string& callingFunction)
00087 {
00088 if (status == NOX::Abstract::Group::Ok)
00089 return;
00090 else if (status == NOX::Abstract::Group::Failed ||
00091 status == NOX::Abstract::Group::NotDefined ||
00092 status == NOX::Abstract::Group::BadDependency)
00093 checkReturnType(status, LOCA::ErrorCheck::ThrowError, callingFunction);
00094 else if (status == NOX::Abstract::Group::NotConverged)
00095 checkReturnType(status, LOCA::ErrorCheck::PrintWarning,
00096 callingFunction);
00097 else
00098 throwError("LOCA::ErrorCheck::checkReturnType", "Unknown status");
00099 }
00100
00101 void LOCA::ErrorCheck::checkReturnType(
00102 const NOX::Abstract::Group::ReturnType& status,
00103 const ActionType& action,
00104 const string& callingFunction,
00105 const string& message)
00106 {
00107 if (status != NOX::Abstract::Group::Ok) {
00108
00109 if (action == ThrowError) {
00110 const string messageWithReturnType = message + "\n" + "Return Type = " +
00111 getReturnTypeString(status);
00112
00113 throwError(callingFunction, messageWithReturnType);
00114 }
00115 else if (action == PrintWarning) {
00116 const string messageWithReturnType = message + "\n" + "Return Type = " +
00117 getReturnTypeString(status);
00118
00119 printWarning(callingFunction, messageWithReturnType);
00120 }
00121 else {
00122 printWarning("LOCA::ErrorCheck::checkReturnType",
00123 "Unknown ActionType!");
00124 }
00125
00126 }
00127
00128 return;
00129 }
00130
00131 NOX::Abstract::Group::ReturnType
00132 LOCA::ErrorCheck::combineReturnTypes(
00133 const NOX::Abstract::Group::ReturnType& status1,
00134 const NOX::Abstract::Group::ReturnType& status2)
00135 {
00136 if (status1 == NOX::Abstract::Group::NotDefined ||
00137 status2 == NOX::Abstract::Group::NotDefined)
00138 return NOX::Abstract::Group::NotDefined;
00139 else if (status1 == NOX::Abstract::Group::BadDependency ||
00140 status2 == NOX::Abstract::Group::BadDependency)
00141 return NOX::Abstract::Group::BadDependency;
00142 else if (status1 == NOX::Abstract::Group::Failed ||
00143 status2 == NOX::Abstract::Group::Failed)
00144 return NOX::Abstract::Group::Failed;
00145 else if (status1 == NOX::Abstract::Group::NotConverged ||
00146 status2 == NOX::Abstract::Group::NotConverged)
00147 return NOX::Abstract::Group::NotConverged;
00148 else
00149 return NOX::Abstract::Group::Ok;
00150 }
00151
00152 NOX::Abstract::Group::ReturnType
00153 LOCA::ErrorCheck::combineAndCheckReturnTypes(
00154 const NOX::Abstract::Group::ReturnType& status1,
00155 const NOX::Abstract::Group::ReturnType& status2,
00156 const string& callingFunction)
00157 {
00158 NOX::Abstract::Group::ReturnType status3 =
00159 combineReturnTypes(status1, status2);
00160 checkReturnType(status3, callingFunction);
00161 return status3;
00162 }
00163
00164 string LOCA::ErrorCheck::getReturnTypeString(
00165 NOX::Abstract::Group::ReturnType status)
00166 {
00167 if (status == NOX::Abstract::Group::Ok)
00168 return "Ok";
00169 else if (status == NOX::Abstract::Group::NotDefined)
00170 return "NotDefined";
00171 else if (status == NOX::Abstract::Group::BadDependency)
00172 return "BadDependency";
00173 else if (status == NOX::Abstract::Group::NotConverged)
00174 return "NotConverged";
00175 else if (status == NOX::Abstract::Group::Failed)
00176 return "Failed";
00177
00178
00179 return "<Unknown Return Type>";
00180 }