|
Belos
Version of the Day
|
00001 //@HEADER 00002 // ************************************************************************ 00003 // 00004 // Belos: Block Linear Solvers Package 00005 // Copyright 2004 Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // ************************************************************************ 00040 //@HEADER 00041 // 00042 00043 #ifndef BELOS_STATUS_TEST_GENERAL_OUTPUT_HPP 00044 #define BELOS_STATUS_TEST_GENERAL_OUTPUT_HPP 00045 00052 #include "BelosConfigDefs.hpp" 00053 #include "BelosTypes.hpp" 00054 #include "BelosIteration.hpp" 00055 00056 #include "BelosStatusTest.hpp" 00057 #include "BelosStatusTestOutput.hpp" 00058 #include "BelosOutputManager.hpp" 00059 00060 namespace Belos { 00061 00071 template <class ScalarType, class MV, class OP> 00072 class StatusTestGeneralOutput : public StatusTestOutput<ScalarType,MV,OP> { 00073 00074 public: 00076 00077 00092 StatusTestGeneralOutput(const Teuchos::RCP<OutputManager<ScalarType> > &printer, 00093 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test, 00094 int mod = 1, 00095 int printStates = Passed) 00096 : printer_(printer), 00097 test_(test), 00098 state_(Undefined), 00099 stateTest_(printStates), 00100 modTest_(mod), 00101 numCalls_(0) 00102 {} 00103 00105 virtual ~StatusTestGeneralOutput() {}; 00107 00109 00110 00127 StatusType checkStatus( Iteration<ScalarType,MV,OP>* solver ) { 00128 TEUCHOS_TEST_FOR_EXCEPTION(test_ == Teuchos::null,StatusTestError,"StatusTestGeneralOutput::checkStatus(): child pointer is null."); 00129 state_ = test_->checkStatus(solver); 00130 00131 if (numCalls_++ % modTest_ == 0) { 00132 if ( (state_ & stateTest_) == state_) { 00133 if ( printer_->isVerbosity(StatusTestDetails) ) { 00134 print( printer_->stream(StatusTestDetails) ); 00135 } 00136 else if ( printer_->isVerbosity(Debug) ) { 00137 print( printer_->stream(Debug) ); 00138 } 00139 } 00140 } 00141 00142 return state_; 00143 } 00144 00146 StatusType getStatus() const { 00147 return state_; 00148 } 00150 00151 00153 00154 00157 void setOutputManager(const Teuchos::RCP<OutputManager<ScalarType> > &printer) { printer_ = printer; } 00158 00161 void setOutputFrequency(int mod) { modTest_ = mod; } 00162 00167 void setChild(Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test) { 00168 test_ = test; 00169 state_ = Undefined; 00170 } 00171 00173 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > getChild() const { 00174 return test_; 00175 } 00176 00179 void setSolverDesc(const std::string& solverDesc) { solverDesc_ = solverDesc; } 00180 00183 void setPrecondDesc(const std::string& precondDesc) { precondDesc_ = precondDesc; } 00184 00186 00187 00189 00190 00195 void reset() { 00196 state_ = Undefined; 00197 test_->reset(); 00198 numCalls_ = 0; 00199 } 00200 00202 void resetNumCalls() { numCalls_ = 0; } 00203 00205 00207 00208 00210 void print(std::ostream& os, int indent = 0) const { 00211 std::string ind(indent,' '); 00212 os << std::endl << ind << "Belos::StatusTestGeneralOutput: "; 00213 switch (state_) { 00214 case Passed: 00215 os << "Passed" << std::endl; 00216 break; 00217 case Failed: 00218 os << "Failed" << std::endl; 00219 break; 00220 case Undefined: 00221 os << "Undefined" << std::endl; 00222 break; 00223 } 00224 os << ind << " (Num calls,Mod test,State test): " << "(" << numCalls_ << ", " << modTest_ << ","; 00225 if (stateTest_ == 0) { 00226 os << " none)" << std::endl; 00227 } 00228 else { 00229 if ( stateTest_ & Passed ) os << " Passed"; 00230 if ( stateTest_ & Failed ) os << " Failed"; 00231 if ( stateTest_ & Undefined ) os << " Undefined"; 00232 os << ")" << std::endl; 00233 } 00234 // print child, with extra indention 00235 test_->print(os,indent+3); 00236 } 00237 00239 00240 private: 00241 Teuchos::RCP<OutputManager<ScalarType> > printer_; 00242 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test_; 00243 std::string solverDesc_; 00244 std::string precondDesc_; 00245 StatusType state_; 00246 int stateTest_; 00247 int modTest_; 00248 int numCalls_; 00249 }; 00250 00251 } // end of Belos namespace 00252 00253 #endif /* BELOS_STATUS_TEST_OUTPUT_HPP */
1.7.6.1