BelosStatusTestGeneralOutput.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_GENERAL_OUTPUT_HPP
00031 #define BELOS_STATUS_TEST_GENERAL_OUTPUT_HPP
00032 
00039 #include "BelosConfigDefs.hpp"
00040 #include "BelosTypes.hpp"
00041 #include "BelosIteration.hpp"
00042 
00043 #include "BelosStatusTest.hpp"
00044 #include "BelosStatusTestOutput.hpp"
00045 #include "BelosOutputManager.hpp"
00046 
00047 namespace Belos {
00048 
00058 template <class ScalarType, class MV, class OP>
00059 class StatusTestGeneralOutput : public StatusTestOutput<ScalarType,MV,OP> {
00060 
00061  public:
00063 
00064 
00079   StatusTestGeneralOutput(const Teuchos::RCP<OutputManager<ScalarType> > &printer, 
00080         Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test,
00081         int mod = 1,
00082         int printStates = Passed)
00083     : printer_(printer), 
00084       test_(test), 
00085       state_(Undefined), 
00086       stateTest_(printStates), 
00087       modTest_(mod), 
00088       numCalls_(0) 
00089   {}
00090 
00092   virtual ~StatusTestGeneralOutput() {};
00094 
00096 
00097 
00114   StatusType checkStatus( Iteration<ScalarType,MV,OP>* solver ) {
00115     TEST_FOR_EXCEPTION(test_ == Teuchos::null,StatusTestError,"StatusTestGeneralOutput::checkStatus(): child pointer is null.");
00116     state_ = test_->checkStatus(solver);
00117 
00118     if (numCalls_++ % modTest_ == 0) {
00119       if ( (state_ & stateTest_) == state_) {
00120         if ( printer_->isVerbosity(StatusTestDetails) ) {
00121           print( printer_->stream(StatusTestDetails) );
00122         }
00123         else if ( printer_->isVerbosity(Debug) ) {
00124           print( printer_->stream(Debug) );
00125         }
00126       }
00127     }
00128 
00129     return state_;
00130   }
00131 
00133   StatusType getStatus() const {
00134     return state_;
00135   }
00137 
00138 
00140 
00141 
00144   void setOutputManager(const Teuchos::RCP<OutputManager<ScalarType> > &printer) { printer_ = printer; }
00145 
00148   void setOutputFrequency(int mod) { modTest_ = mod; }
00149 
00154   void setChild(Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test) {
00155     test_ = test;
00156     state_ = Undefined;
00157   }
00158 
00160   Teuchos::RCP<StatusTest<ScalarType,MV,OP> > getChild() const {
00161     return test_;
00162   }
00163 
00166   void setSolverDesc(const std::string& solverDesc) { solverDesc_ = solverDesc; }
00167 
00170   void setPrecondDesc(const std::string& precondDesc) { precondDesc_ = precondDesc; }
00171 
00173 
00174 
00176 
00177 
00182   void reset() { 
00183     state_ = Undefined;
00184     test_->reset();
00185     numCalls_ = 0;
00186   }
00187 
00189   void resetNumCalls() { numCalls_ = 0; }
00190 
00192 
00194 
00195   
00197   void print(std::ostream& os, int indent = 0) const {
00198     std::string ind(indent,' ');
00199     os << std::endl << ind << "Belos::StatusTestGeneralOutput: ";
00200     switch (state_) {
00201     case Passed:
00202       os << "Passed" << std::endl;
00203       break;
00204     case Failed:
00205       os << "Failed" << std::endl;
00206       break;
00207     case Undefined:
00208       os << "Undefined" << std::endl;
00209       break;
00210     }
00211     os << ind << "  (Num calls,Mod test,State test): " << "(" << numCalls_ << ", " << modTest_ << ",";
00212     if (stateTest_ == 0) {
00213       os << " none)" << std::endl;
00214     }
00215     else {
00216       if ( stateTest_ & Passed ) os << " Passed";
00217       if ( stateTest_ & Failed ) os << " Failed";
00218       if ( stateTest_ & Undefined ) os << " Undefined";
00219       os << ")" << std::endl;
00220     }
00221     // print child, with extra indention
00222     test_->print(os,indent+3);
00223   }
00224  
00226 
00227   private:
00228     Teuchos::RCP<OutputManager<ScalarType> > printer_;
00229     Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test_;
00230     std::string solverDesc_;
00231     std::string precondDesc_;
00232     StatusType state_;
00233     int stateTest_;
00234     int modTest_;
00235     int numCalls_;
00236 };
00237 
00238 } // end of Belos namespace
00239 
00240 #endif /* BELOS_STATUS_TEST_OUTPUT_HPP */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:05:07 2011 for Belos by  doxygen 1.6.3