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 #ifndef BELOS_STATUS_TEST_MAXITERS_HPP
00031 #define BELOS_STATUS_TEST_MAXITERS_HPP
00032
00038 #include "BelosStatusTest.hpp"
00039
00047 namespace Belos {
00048
00049 template <class ScalarType, class MV, class OP>
00050 class StatusTestMaxIters: public StatusTest<ScalarType,MV,OP> {
00051
00052 public:
00053
00055
00056
00058 StatusTestMaxIters(int maxIters);
00059
00061 virtual ~StatusTestMaxIters() {};
00063
00065
00066
00068
00071 StatusType checkStatus(Iteration<ScalarType,MV,OP> *iSolver );
00072
00074 StatusType getStatus() const {return(status_);}
00075
00077
00079
00080
00082 void reset();
00083
00085 void setMaxIters(int maxIters) { maxIters_ = maxIters; }
00086
00088
00090
00091
00093 int getMaxIters() const { return(maxIters_); }
00094
00096 int getNumIters() const { return(nIters_); }
00097
00099
00101
00102
00104 void print(std::ostream& os, int indent = 0) const;
00105
00107 void printStatus(std::ostream& os, StatusType type) const;
00108
00110
00113
00115 std::string description() const
00116 {
00117 std::ostringstream oss;
00118 oss << "Belos::StatusTestMaxIters<>: [ " << getNumIters() << " / " << getMaxIters() << " ]";
00119 return oss.str();
00120 }
00122
00123 private:
00124
00126
00127
00128 int maxIters_;
00129
00131 int nIters_;
00132
00134 StatusType status_;
00136
00137 };
00138
00139 template <class ScalarType, class MV, class OP>
00140 StatusTestMaxIters<ScalarType,MV,OP>::StatusTestMaxIters(int maxIters)
00141 {
00142 if (maxIters < 1)
00143 maxIters_ = 1;
00144 else
00145 maxIters_ = maxIters;
00146
00147 nIters_ = 0;
00148 status_ = Undefined;
00149 }
00150
00151 template <class ScalarType, class MV, class OP>
00152 StatusType StatusTestMaxIters<ScalarType,MV,OP>::checkStatus(Iteration<ScalarType,MV,OP> *iSolver )
00153 {
00154 status_ = Failed;
00155 nIters_ = iSolver->getNumIters();
00156 if (nIters_ >= maxIters_)
00157 status_ = Passed;
00158 return status_;
00159 }
00160
00161 template <class ScalarType, class MV, class OP>
00162 void StatusTestMaxIters<ScalarType,MV,OP>::reset()
00163 {
00164 nIters_ = 0;
00165 status_ = Undefined;
00166 }
00167
00168 template <class ScalarType, class MV, class OP>
00169 void StatusTestMaxIters<ScalarType,MV,OP>::print(std::ostream& os, int indent) const
00170 {
00171 for (int j = 0; j < indent; j ++)
00172 os << ' ';
00173 printStatus(os, status_);
00174 os << "Number of Iterations = ";
00175 os << nIters_;
00176 os << ((nIters_ < maxIters_) ? " < " : ((nIters_ == maxIters_) ? " == " : " > "));
00177 os << maxIters_;
00178 os << std::endl;
00179 }
00180
00181 template <class ScalarType, class MV, class OP>
00182 void StatusTestMaxIters<ScalarType,MV,OP>::printStatus(std::ostream& os, StatusType type) const
00183 {
00184 os << std::left << std::setw(13) << std::setfill('.');
00185 switch (type) {
00186 case Passed:
00187 os << "Failed";
00188 break;
00189 case Failed:
00190 os << "OK";
00191 break;
00192 case Undefined:
00193 default:
00194 os << "**";
00195 break;
00196 }
00197 os << std::left << std::setfill(' ');
00198 return;
00199 }
00200
00201 }
00202
00203 #endif