BelosStatusTestOutput.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_OUTPUT_HPP
00031 #define BELOS_STATUS_TEST_OUTPUT_HPP
00032 
00039 #include "BelosConfigDefs.hpp"
00040 #include "BelosTypes.hpp"
00041 #include "BelosIteration.hpp"
00042 
00043 #include "BelosStatusTest.hpp"
00044 
00045 
00046 
00047 namespace Belos {
00048 
00058 template <class ScalarType, class MV, class OP>
00059 class StatusTestOutput : public StatusTest<ScalarType,MV,OP> {
00060 
00061  public:
00063 
00064 
00079   StatusTestOutput(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), test_(test), state_(Undefined), stateTest_(printStates), modTest_(mod), numCalls_(0) {}
00084 
00086   virtual ~StatusTestOutput() {};
00088 
00090 
00091 
00108   StatusType checkStatus( Iteration<ScalarType,MV,OP>* solver ) {
00109     TEST_FOR_EXCEPTION(test_ == Teuchos::null,StatusTestError,"StatusTestOutput::checkStatus(): child pointer is null.");
00110     state_ = test_->checkStatus(solver);
00111 
00112     if (numCalls_++ % modTest_ == 0) {
00113       if ( (state_ & stateTest_) == state_) {
00114         if ( printer_->isVerbosity(StatusTestDetails) ) {
00115           print( printer_->stream(StatusTestDetails) );
00116         }
00117         else if ( printer_->isVerbosity(Debug) ) {
00118           print( printer_->stream(Debug) );
00119         }
00120       }
00121     }
00122 
00123     return state_;
00124   }
00125 
00127   StatusType getStatus() const {
00128     return state_;
00129   }
00131 
00132 
00134 
00135 
00138   void setOutputManager(const Teuchos::RCP<OutputManager<ScalarType> > &printer) { printer_ = printer; }
00139 
00142   void setOutputFrequency(int mod) { modTest_ = mod; }
00143 
00148   void setChild(Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test) {
00149     test_ = test;
00150     state_ = Undefined;
00151   }
00152 
00154   Teuchos::RCP<StatusTest<ScalarType,MV,OP> > getChild() const {
00155     return test_;
00156   }
00157 
00159 
00160 
00162 
00163 
00168   void reset() { 
00169     state_ = Undefined;
00170     test_->reset();
00171     numCalls_ = 0;
00172   }
00173 
00175   void resetNumCalls() { numCalls_ = 0; }
00176 
00179   void clearStatus() {
00180     state_ = Undefined;
00181     test_->clearStatus();
00182   }
00183 
00185 
00187 
00188   
00190   void print(std::ostream& os, int indent = 0) const {
00191     std::string ind(indent,' ');
00192     os << std::endl << ind << "Belos::StatusTestOutput: ";
00193     switch (state_) {
00194     case Passed:
00195       os << "Passed" << std::endl;
00196       break;
00197     case Failed:
00198       os << "Failed" << std::endl;
00199       break;
00200     case Undefined:
00201       os << "Undefined" << std::endl;
00202       break;
00203     }
00204     os << ind << "  (Num calls,Mod test,State test): " << "(" << numCalls_ << ", " << modTest_ << ",";
00205     if (stateTest_ == 0) {
00206       os << " none)" << std::endl;
00207     }
00208     else {
00209       if ( stateTest_ & Passed ) os << " Passed";
00210       if ( stateTest_ & Failed ) os << " Failed";
00211       if ( stateTest_ & Undefined ) os << " Undefined";
00212       os << ")" << std::endl;
00213     }
00214     // print child, with extra indention
00215     test_->print(os,indent+3);
00216   }
00217  
00219 
00220   private:
00221     Teuchos::RCP<OutputManager<ScalarType> > printer_;
00222     Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test_;
00223     StatusType state_;
00224     int stateTest_;
00225     int modTest_;
00226     int numCalls_;
00227 };
00228 
00229 } // end of Belos namespace
00230 
00231 #endif /* BELOS_STATUS_TEST_OUTPUT_HPP */

Generated on Tue Oct 20 12:48:34 2009 for Belos by doxygen 1.4.7