AnasaziStatusTestOutput.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                 Anasazi: Block Eigensolvers 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 ANASAZI_STATUS_TEST_OUTPUT_HPP
00031 #define ANASAZI_STATUS_TEST_OUTPUT_HPP
00032 
00039 #include "AnasaziConfigDefs.hpp"
00040 #include "AnasaziTypes.hpp"
00041 #include "AnasaziEigensolver.hpp"
00042 
00043 #include "AnasaziStatusTest.hpp"
00044 
00045 
00046 
00047 namespace Anasazi {
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::RefCountPtr<OutputManager<ScalarType> > &printer, 
00080                    Teuchos::RefCountPtr<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   TestStatus checkStatus( Eigensolver<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   TestStatus getStatus() const {
00128     return state_;
00129   }
00131 
00132 
00134 
00135 
00140   void setChild(Teuchos::RefCountPtr<StatusTest<ScalarType,MV,OP> > test) {
00141     test_ = test;
00142     state_ = Undefined;
00143   }
00144 
00146   Teuchos::RefCountPtr<StatusTest<ScalarType,MV,OP> > getChild() const {
00147     return test_;
00148   }
00149 
00151 
00152 
00154 
00155 
00160   void reset() { 
00161     state_ = Undefined;
00162     test_->reset();
00163     numCalls_ = 0;
00164   }
00165 
00168   void clearStatus() {
00169     state_ = Undefined;
00170     test_->clearStatus();
00171   }
00172 
00174 
00176 
00177   
00179   ostream& print(ostream& os, int indent = 0) const {
00180     string ind(indent,' ');
00181     os << ind << "- StatusTestOutput: ";
00182     switch (state_) {
00183     case Passed:
00184       os << "Passed" << endl;
00185       break;
00186     case Failed:
00187       os << "Failed" << endl;
00188       break;
00189     case Undefined:
00190       os << "Undefined" << endl;
00191       break;
00192     }
00193     os << ind << "  (Num calls,Mod test,State test): " << "(" << numCalls_ << ", " << modTest_ << ",";
00194     if (stateTest_ == 0) {
00195       os << " none )" << endl;
00196     }
00197     else {
00198       if ( stateTest_ & Passed == Passed ) os << " Passed";
00199       if ( stateTest_ & Failed == Failed ) os << " Failed";
00200       if ( stateTest_ & Undefined == Undefined ) os << " Undefined";
00201       os << " )" << endl;
00202     }
00203     // print child, with extra indention
00204     test_->print(os,indent+3);
00205     return os;
00206   }
00207  
00209 
00210   private:
00211     Teuchos::RefCountPtr<OutputManager<ScalarType> > printer_;
00212     Teuchos::RefCountPtr<StatusTest<ScalarType,MV,OP> > test_;
00213     TestStatus state_;
00214     int stateTest_;
00215     int modTest_;
00216     int numCalls_;
00217 };
00218 
00219 } // end of Anasazi namespace
00220 
00221 #endif /* ANASAZI_STATUS_TEST_OUTPUT_HPP */

Generated on Thu Sep 18 12:31:38 2008 for Anasazi by doxygen 1.3.9.1