Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosStatusTestMaxIters.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 //
42 
43 #ifndef BELOS_STATUS_TEST_MAXITERS_HPP
44 #define BELOS_STATUS_TEST_MAXITERS_HPP
45 
51 #include "BelosStatusTest.hpp"
52 
60 namespace Belos {
61 
62 template <class ScalarType, class MV, class OP>
63 class StatusTestMaxIters: public StatusTest<ScalarType,MV,OP> {
64 
65  public:
66 
68 
69 
71  StatusTestMaxIters(int maxIters);
72 
74  virtual ~StatusTestMaxIters() {};
76 
78 
79 
81 
85 
87  StatusType getStatus() const {return(status_);}
88 
90 
92 
93 
95  void reset();
96 
98  void setMaxIters(int maxIters) { maxIters_ = maxIters; }
99 
101 
103 
104 
106  int getMaxIters() const { return(maxIters_); }
107 
109  int getNumIters() const { return(nIters_); }
110 
112 
114 
115 
117  void print(std::ostream& os, int indent = 0) const;
118 
120  void printStatus(std::ostream& os, StatusType type) const;
121 
123 
126 
128  std::string description() const
129  {
130  std::ostringstream oss;
131  oss << "Belos::StatusTestMaxIters<>: [ " << getNumIters() << " / " << getMaxIters() << " ]";
132  return oss.str();
133  }
135 
136 private:
137 
139 
140  int maxIters_;
142 
144  int nIters_;
145 
147  StatusType status_;
149 
150 };
151 
152  template <class ScalarType, class MV, class OP>
154  {
155  if (maxIters < 1)
156  maxIters_ = 1;
157  else
158  maxIters_ = maxIters;
159 
160  nIters_ = 0;
161  status_ = Undefined;
162  }
163 
164  template <class ScalarType, class MV, class OP>
166  {
167  status_ = Failed;
168  nIters_ = iSolver->getNumIters();
169  if (nIters_ >= maxIters_)
170  status_ = Passed;
171  return status_;
172  }
173 
174  template <class ScalarType, class MV, class OP>
176  {
177  nIters_ = 0;
178  status_ = Undefined;
179  }
180 
181  template <class ScalarType, class MV, class OP>
182  void StatusTestMaxIters<ScalarType,MV,OP>::print(std::ostream& os, int indent) const
183  {
184  for (int j = 0; j < indent; j ++)
185  os << ' ';
186  printStatus(os, status_);
187  os << "Number of Iterations = ";
188  os << nIters_;
189  os << ((nIters_ < maxIters_) ? " < " : ((nIters_ == maxIters_) ? " == " : " > "));
190  os << maxIters_;
191  os << std::endl;
192  }
193 
194  template <class ScalarType, class MV, class OP>
196  {
197  os << std::left << std::setw(13) << std::setfill('.');
198  switch (type) {
199  case Passed:
200  os << "Failed";
201  break;
202  case Failed:
203  os << "OK";
204  break;
205  case Undefined:
206  default:
207  os << "**";
208  break;
209  }
210  os << std::left << std::setfill(' ');
211  return;
212  }
213 
214 } // end Belos namespace
215 
216 #endif /* BELOS_STATUS_TEST_MAXITERS_HPP */
StatusType getStatus() const
Return the result of the most recent CheckStatus call.
int getMaxIters() const
Returns the maximum number of iterations set in the constructor.
void print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
Pure virtual base class for defining the status testing capabilities of Belos.
void reset()
Resets the status test to the initial internal state.
A pure virtual class for defining the status tests for the Belos iterative solvers.
std::string description() const
Method to return description of the maximum iteration status test.
StatusType
Whether the StatusTest wants iteration to stop.
Definition: BelosTypes.hpp:189
A Belos::StatusTest class for specifying a maximum number of iterations.
virtual int getNumIters() const =0
Get the current iteration count.
StatusTestMaxIters(int maxIters)
Constructor.
int getNumIters() const
Returns the current number of iterations from the most recent StatusTest call.
void printStatus(std::ostream &os, StatusType type) const
Print message for each status specific to this stopping test.
StatusType checkStatus(Iteration< ScalarType, MV, OP > *iSolver)
Check convergence status of the iterative solver: Unconverged, Converged, Failed. ...
virtual ~StatusTestMaxIters()
Destructor.
void setMaxIters(int maxIters)
Sets the maximum number of iterations allowed.

Generated on Fri Jun 5 2020 10:20:48 for Belos by doxygen 1.8.5