BelosStatusTestMaxRestarts.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_MAXRESTARTS_HPP
00031 #define BELOS_STATUS_TEST_MAXRESTARTS_HPP
00032 
00038 #include "BelosStatusTest.hpp"
00039 
00048 namespace Belos {
00049 
00050 template <class ScalarType, class MV, class OP>
00051 class StatusTestMaxRestarts: public StatusTest<ScalarType,MV,OP> {
00052 
00053  public:
00054 
00056 
00057 
00059   StatusTestMaxRestarts(int maxIters);
00060 
00062   virtual ~StatusTestMaxRestarts() {};
00064 
00066 
00067 
00069 
00072   StatusType CheckStatus(IterativeSolver<ScalarType,MV,OP> *iSolver );
00073 
00075   StatusType GetStatus() const {return(status_);};
00076 
00078 
00080 
00081   
00083   void Reset();
00084 
00086 
00088 
00089 
00091   int GetMaxRestarts() const { return(maxRestarts_); };
00092 
00094   int GetNumRestarts() const { return(nRestarts_); };
00095 
00097 
00099 
00100 
00102   bool ResidualVectorRequired() const { return(false); } ;
00104 
00106 
00107 
00109   ostream& Print(ostream& os, int indent = 0) const;
00110 
00112   
00113 
00114 private:
00115 
00117 
00118 
00119   int maxRestarts_;
00120 
00122   int nRestarts_;
00123 
00125   StatusType status_;
00127 
00128 };
00129 
00130   template <class ScalarType, class MV, class OP> 
00131   StatusTestMaxRestarts<ScalarType,MV,OP>::StatusTestMaxRestarts(int maxRestarts)
00132   {
00133     if (maxRestarts < 1)
00134       maxRestarts_ = 1;
00135     else
00136       maxRestarts_ = maxRestarts;
00137     
00138     nRestarts_ = 0;
00139     status_ = Unchecked;
00140   }
00141   
00142   template <class ScalarType, class MV, class OP>
00143   StatusType StatusTestMaxRestarts<ScalarType,MV,OP>::CheckStatus(IterativeSolver<ScalarType,MV,OP> *iSolver )
00144   {
00145     status_ = Unconverged;
00146     nRestarts_ = iSolver->GetNumRestarts();
00147     if (nRestarts_ >= maxRestarts_)
00148       status_ = Failed;
00149     return status_;
00150   }
00151   
00152   template <class ScalarType, class MV, class OP>
00153   void StatusTestMaxRestarts<ScalarType,MV,OP>::Reset()
00154   {
00155     status_ = Unchecked;
00156     nRestarts_ = 0;
00157   }
00158 
00159   template <class ScalarType, class MV, class OP>
00160   ostream& StatusTestMaxRestarts<ScalarType,MV,OP>::Print(ostream& os, int indent) const
00161   {
00162     for (int j = 0; j < indent; j ++)
00163       os << ' ';
00164     this->PrintStatus(os, status_);
00165     os << "Number of Restarts = ";
00166     os << nRestarts_;
00167     os << ((nRestarts_ < maxRestarts_) ? " < " : ((nRestarts_ == maxRestarts_) ? " == " : " > "));
00168     os << maxRestarts_;
00169     os << endl;
00170     return os;
00171   }
00172   
00173 } // end Belos namespace
00174 
00175 #endif /* BELOS_STATUS_TEST_MAXRESTARTS_HPP */

Generated on Thu Sep 18 12:30:12 2008 for Belos by doxygen 1.3.9.1