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
00111
00112 private:
00113
00115
00116
00117 int maxIters_;
00118
00120 int nIters_;
00121
00123 StatusType status_;
00125
00126 };
00127
00128 template <class ScalarType, class MV, class OP>
00129 StatusTestMaxIters<ScalarType,MV,OP>::StatusTestMaxIters(int maxIters)
00130 {
00131 if (maxIters < 1)
00132 maxIters_ = 1;
00133 else
00134 maxIters_ = maxIters;
00135
00136 nIters_ = 0;
00137 status_ = Undefined;
00138 }
00139
00140 template <class ScalarType, class MV, class OP>
00141 StatusType StatusTestMaxIters<ScalarType,MV,OP>::checkStatus(Iteration<ScalarType,MV,OP> *iSolver )
00142 {
00143 status_ = Failed;
00144 nIters_ = iSolver->getNumIters();
00145 if (nIters_ >= maxIters_)
00146 status_ = Passed;
00147 return status_;
00148 }
00149
00150 template <class ScalarType, class MV, class OP>
00151 void StatusTestMaxIters<ScalarType,MV,OP>::reset()
00152 {
00153 nIters_ = 0;
00154 status_ = Undefined;
00155 }
00156
00157 template <class ScalarType, class MV, class OP>
00158 void StatusTestMaxIters<ScalarType,MV,OP>::print(std::ostream& os, int indent) const
00159 {
00160 for (int j = 0; j < indent; j ++)
00161 os << ' ';
00162 printStatus(os, status_);
00163 os << "Number of Iterations = ";
00164 os << nIters_;
00165 os << ((nIters_ < maxIters_) ? " < " : ((nIters_ == maxIters_) ? " == " : " > "));
00166 os << maxIters_;
00167 os << std::endl;
00168 }
00169
00170 template <class ScalarType, class MV, class OP>
00171 void StatusTestMaxIters<ScalarType,MV,OP>::printStatus(std::ostream& os, StatusType type) const
00172 {
00173 os << std::left << std::setw(13) << std::setfill('.');
00174 switch (type) {
00175 case Passed:
00176 os << "Failed";
00177 break;
00178 case Failed:
00179 os << "OK";
00180 break;
00181 case Undefined:
00182 default:
00183 os << "**";
00184 break;
00185 }
00186 os << std::left << std::setfill(' ');
00187 return;
00188 }
00189
00190 }
00191
00192 #endif