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   
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 } // end Belos namespace
00191 
00192 #endif /* BELOS_STATUS_TEST_MAXITERS_HPP */

Generated on Wed May 12 21:45:51 2010 for Belos by  doxygen 1.4.7