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 // Belos: Block Linear Solvers Package
4 //
5 // Copyright 2004-2016 NTESS and the Belos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 //
10 
11 #ifndef BELOS_STATUS_TEST_MAXITERS_HPP
12 #define BELOS_STATUS_TEST_MAXITERS_HPP
13 
19 #include "BelosStatusTest.hpp"
20 
28 namespace Belos {
29 
30 template <class ScalarType, class MV, class OP>
31 class StatusTestMaxIters: public StatusTest<ScalarType,MV,OP> {
32 
33  public:
34 
36 
37 
39  StatusTestMaxIters(int maxIters);
40 
42  virtual ~StatusTestMaxIters() {};
44 
46 
47 
49 
53 
55  StatusType getStatus() const {return(status_);}
56 
58 
60 
61 
63  void reset();
64 
66  void setMaxIters(int maxIters) { maxIters_ = maxIters; }
67 
69 
71 
72 
74  int getMaxIters() const { return(maxIters_); }
75 
77  int getNumIters() const { return(nIters_); }
78 
80 
82 
83 
85  void print(std::ostream& os, int indent = 0) const;
86 
88  void printStatus(std::ostream& os, StatusType type) const;
89 
91 
94 
96  std::string description() const
97  {
98  std::ostringstream oss;
99  oss << "Belos::StatusTestMaxIters<>: [ " << getNumIters() << " / " << getMaxIters() << " ]";
100  return oss.str();
101  }
103 
104 private:
105 
107 
108  int maxIters_;
110 
112  int nIters_;
113 
115  StatusType status_;
117 
118 };
119 
120  template <class ScalarType, class MV, class OP>
122  {
123  if (maxIters < 1)
124  maxIters_ = 1;
125  else
126  maxIters_ = maxIters;
127 
128  nIters_ = 0;
129  status_ = Undefined;
130  }
131 
132  template <class ScalarType, class MV, class OP>
134  {
135  status_ = Failed;
136  nIters_ = iSolver->getNumIters();
137  if (nIters_ >= maxIters_)
138  status_ = Passed;
139  return status_;
140  }
141 
142  template <class ScalarType, class MV, class OP>
144  {
145  nIters_ = 0;
146  status_ = Undefined;
147  }
148 
149  template <class ScalarType, class MV, class OP>
150  void StatusTestMaxIters<ScalarType,MV,OP>::print(std::ostream& os, int indent) const
151  {
152  for (int j = 0; j < indent; j ++)
153  os << ' ';
154  printStatus(os, status_);
155  os << "Number of Iterations = ";
156  os << nIters_;
157  os << ((nIters_ < maxIters_) ? " < " : ((nIters_ == maxIters_) ? " == " : " > "));
158  os << maxIters_;
159  os << std::endl;
160  }
161 
162  template <class ScalarType, class MV, class OP>
164  {
165  os << std::left << std::setw(13) << std::setfill('.');
166  switch (type) {
167  case Passed:
168  os << "Failed";
169  break;
170  case Failed:
171  os << "OK";
172  break;
173  case Undefined:
174  default:
175  os << "**";
176  break;
177  }
178  os << std::left << std::setfill(' ');
179  return;
180  }
181 
182 } // end Belos namespace
183 
184 #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:157
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 Mon Oct 14 2024 09:24:08 for Belos by doxygen 1.8.5