Anasazi  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AnasaziStatusTestMaxIters.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Anasazi: Block Eigensolvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under 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 ANASAZI_STATUS_TEST_MAXITER_HPP
44 #define ANASAZI_STATUS_TEST_MAXITER_HPP
45 
52 #include "AnasaziStatusTest.hpp"
53 
54 
73 namespace Anasazi {
74 
75 
76 template <class ScalarType, class MV, class OP>
77 class StatusTestMaxIters : public StatusTest<ScalarType,MV,OP> {
78 
79  public:
81 
82 
84  StatusTestMaxIters(int maxIter, bool negate = false) : state_(Undefined), negate_(negate) {
85  setMaxIters(maxIter);
86  };
87 
89  virtual ~StatusTestMaxIters() {};
91 
93 
94 
99  state_ = (solver->getNumIters() >= maxIters_) ? Passed : Failed;
100  if (negate_) {
101  if (state_ == Passed) state_ = Failed;
102  else state_ = Passed;
103  }
104  return state_;
105  }
106 
109  return state_;
110  }
111 
113  std::vector<int> whichVecs() const {
114  return std::vector<int>(0);
115  }
116 
118  int howMany() const {
119  return 0;
120  }
121 
123 
125 
126 
130  void setMaxIters(int maxIters) {
131  state_ = Undefined;
132  maxIters_ = maxIters;
133  }
134 
136  int getMaxIters() {return maxIters_;}
137 
141  void setNegate(bool negate) {
142  state_ = Undefined;
143  negate_ = negate;
144  }
145 
147  bool getNegate() const {
148  return negate_;
149  }
150 
152 
154 
155 
161  void reset() {
162  state_ = Undefined;
163  }
164 
166 
171  void clearStatus() {
172  state_ = Undefined;
173  }
174 
176 
178 
179 
181  std::ostream& print(std::ostream& os, int indent = 0) const {
182  std::string ind(indent,' ');
183  os << ind << "- StatusTestMaxIters: ";
184  switch (state_) {
185  case Passed:
186  os << "Passed" << std::endl;
187  break;
188  case Failed:
189  os << "Failed" << std::endl;
190  break;
191  case Undefined:
192  os << "Undefined" << std::endl;
193  break;
194  }
195  os << ind << " MaxIters: " << maxIters_ << std::endl;
196  return os;
197  }
198 
200  private:
201  int maxIters_;
202  TestStatus state_;
203  bool negate_;
204 
205 };
206 
207 } // end of Anasazi namespace
208 
209 #endif /* ANASAZI_STATUS_TEST_MAXITER_HPP */
std::vector< int > whichVecs() const
Get the indices for the vectors that passed the test.
int getMaxIters()
Get the maximum number of iterations.
TestStatus
Enumerated type used to pass back information from a StatusTest.
StatusTestMaxIters(int maxIter, bool negate=false)
Constructor.
void clearStatus()
Clears the results of the last status test.
void setNegate(bool negate)
Set the negation policy for the status test.
void reset()
Informs the status test that it should reset its internal configuration to the uninitialized state...
TestStatus getStatus() const
Return the result of the most recent checkStatus call.
A status test for testing the number of iterations.
void setMaxIters(int maxIters)
Set the maximum number of iterations.
std::ostream & print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
TestStatus checkStatus(Eigensolver< ScalarType, MV, OP > *solver)
Check status as defined by test.
Common interface of stopping criteria for Anasazi&#39;s solvers.
int howMany() const
Get the number of vectors that passed the test.
virtual int getNumIters() const =0
Get the current iteration count.
bool getNegate() const
Get the negation policy for the status test.
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
Declaration and definition of Anasazi::StatusTest.