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(IterativeSolver<ScalarType,MV,OP> *iSolver );
00072
00074 StatusType GetStatus() const {return(status_);};
00075
00077
00079
00080
00082 void Reset();
00083
00085
00087
00088
00090 int GetMaxIters() const { return(maxIters_); };
00091
00093 int GetNumIters() const { return(nIters_); };
00094
00096
00098
00099
00101 bool ResidualVectorRequired() const { return(false); } ;
00103
00105
00106
00108 ostream& Print(ostream& os, int indent = 0) const;
00109
00111
00112
00113 private:
00114
00116
00117
00118 int maxIters_;
00119
00121 int nIters_;
00122
00124 StatusType status_;
00126
00127 };
00128
00129 template <class ScalarType, class MV, class OP>
00130 StatusTestMaxIters<ScalarType,MV,OP>::StatusTestMaxIters(int maxIters)
00131 {
00132 if (maxIters < 1)
00133 maxIters_ = 1;
00134 else
00135 maxIters_ = maxIters;
00136
00137 nIters_ = 0;
00138 status_ = Unchecked;
00139 }
00140
00141 template <class ScalarType, class MV, class OP>
00142 StatusType StatusTestMaxIters<ScalarType,MV,OP>::CheckStatus(IterativeSolver<ScalarType,MV,OP> *iSolver )
00143 {
00144 status_ = Unconverged;
00145 nIters_ = iSolver->GetNumIters();
00146 if (nIters_ >= maxIters_)
00147 status_ = Failed;
00148 return status_;
00149 }
00150
00151 template <class ScalarType, class MV, class OP>
00152 void StatusTestMaxIters<ScalarType,MV,OP>::Reset()
00153 {
00154 nIters_ = 0;
00155 status_ = Unchecked;
00156 }
00157
00158 template <class ScalarType, class MV, class OP>
00159 ostream& StatusTestMaxIters<ScalarType,MV,OP>::Print(ostream& os, int indent) const
00160 {
00161 for (int j = 0; j < indent; j ++)
00162 os << ' ';
00163 this->PrintStatus(os, status_);
00164 os << "Number of Iterations = ";
00165 os << nIters_;
00166 os << ((nIters_ < maxIters_) ? " < " : ((nIters_ == maxIters_) ? " == " : " > "));
00167 os << maxIters_;
00168 os << endl;
00169 return os;
00170 }
00171
00172 }
00173
00174 #endif