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(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 } // end Belos namespace
00173 
00174 #endif /* BELOS_STATUS_TEST_MAXITERS_HPP */

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