00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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 }
00230
00231 #endif