BelosStatusTestMaxIters.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                 Belos: Block Linear Solvers Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 // @HEADER
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 } // end Belos namespace
00202 
00203 #endif /* BELOS_STATUS_TEST_MAXITERS_HPP */

Generated on Wed May 12 21:30:09 2010 for Belos by  doxygen 1.4.7