|
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_MAXITERS_HPP 00044 #define BELOS_STATUS_TEST_MAXITERS_HPP 00045 00051 #include "BelosStatusTest.hpp" 00052 00060 namespace Belos { 00061 00062 template <class ScalarType, class MV, class OP> 00063 class StatusTestMaxIters: public StatusTest<ScalarType,MV,OP> { 00064 00065 public: 00066 00068 00069 00071 StatusTestMaxIters(int maxIters); 00072 00074 virtual ~StatusTestMaxIters() {}; 00076 00078 00079 00081 00084 StatusType checkStatus(Iteration<ScalarType,MV,OP> *iSolver ); 00085 00087 StatusType getStatus() const {return(status_);} 00088 00090 00092 00093 00095 void reset(); 00096 00098 void setMaxIters(int maxIters) { maxIters_ = maxIters; } 00099 00101 00103 00104 00106 int getMaxIters() const { return(maxIters_); } 00107 00109 int getNumIters() const { return(nIters_); } 00110 00112 00114 00115 00117 void print(std::ostream& os, int indent = 0) const; 00118 00120 void printStatus(std::ostream& os, StatusType type) const; 00121 00123 00126 00128 std::string description() const 00129 { 00130 std::ostringstream oss; 00131 oss << "Belos::StatusTestMaxIters<>: [ " << getNumIters() << " / " << getMaxIters() << " ]"; 00132 return oss.str(); 00133 } 00135 00136 private: 00137 00139 00140 00141 int maxIters_; 00142 00144 int nIters_; 00145 00147 StatusType status_; 00149 00150 }; 00151 00152 template <class ScalarType, class MV, class OP> 00153 StatusTestMaxIters<ScalarType,MV,OP>::StatusTestMaxIters(int maxIters) 00154 { 00155 if (maxIters < 1) 00156 maxIters_ = 1; 00157 else 00158 maxIters_ = maxIters; 00159 00160 nIters_ = 0; 00161 status_ = Undefined; 00162 } 00163 00164 template <class ScalarType, class MV, class OP> 00165 StatusType StatusTestMaxIters<ScalarType,MV,OP>::checkStatus(Iteration<ScalarType,MV,OP> *iSolver ) 00166 { 00167 status_ = Failed; 00168 nIters_ = iSolver->getNumIters(); 00169 if (nIters_ >= maxIters_) 00170 status_ = Passed; 00171 return status_; 00172 } 00173 00174 template <class ScalarType, class MV, class OP> 00175 void StatusTestMaxIters<ScalarType,MV,OP>::reset() 00176 { 00177 nIters_ = 0; 00178 status_ = Undefined; 00179 } 00180 00181 template <class ScalarType, class MV, class OP> 00182 void StatusTestMaxIters<ScalarType,MV,OP>::print(std::ostream& os, int indent) const 00183 { 00184 for (int j = 0; j < indent; j ++) 00185 os << ' '; 00186 printStatus(os, status_); 00187 os << "Number of Iterations = "; 00188 os << nIters_; 00189 os << ((nIters_ < maxIters_) ? " < " : ((nIters_ == maxIters_) ? " == " : " > ")); 00190 os << maxIters_; 00191 os << std::endl; 00192 } 00193 00194 template <class ScalarType, class MV, class OP> 00195 void StatusTestMaxIters<ScalarType,MV,OP>::printStatus(std::ostream& os, StatusType type) const 00196 { 00197 os << std::left << std::setw(13) << std::setfill('.'); 00198 switch (type) { 00199 case Passed: 00200 os << "Failed"; 00201 break; 00202 case Failed: 00203 os << "OK"; 00204 break; 00205 case Undefined: 00206 default: 00207 os << "**"; 00208 break; 00209 } 00210 os << std::left << std::setfill(' '); 00211 return; 00212 } 00213 00214 } // end Belos namespace 00215 00216 #endif /* BELOS_STATUS_TEST_MAXITERS_HPP */
1.7.6.1