Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosStatusTestGeneralOutput.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_GENERAL_OUTPUT_HPP
44 #define BELOS_STATUS_TEST_GENERAL_OUTPUT_HPP
45 
52 #include "BelosConfigDefs.hpp"
53 #include "BelosTypes.hpp"
54 #include "BelosIteration.hpp"
55 
56 #include "BelosStatusTest.hpp"
58 #include "BelosOutputManager.hpp"
59 
60 namespace Belos {
61 
71 template <class ScalarType, class MV, class OP>
72 class StatusTestGeneralOutput : public StatusTestOutput<ScalarType,MV,OP> {
73 
74  public:
76 
77 
94  int mod = 1,
95  int printStates = Passed)
96  : printer_(printer),
97  test_(test),
98  state_(Undefined),
99  stateTest_(printStates),
100  modTest_(mod),
101  numCalls_(0)
102  {}
103 
107 
109 
110 
128  TEUCHOS_TEST_FOR_EXCEPTION(test_ == Teuchos::null,StatusTestError,"StatusTestGeneralOutput::checkStatus(): child pointer is null.");
129  state_ = test_->checkStatus(solver);
130 
131  if (numCalls_++ % modTest_ == 0) {
132  if ( (state_ & stateTest_) == state_) {
133  if ( printer_->isVerbosity(StatusTestDetails) ) {
134  print( printer_->stream(StatusTestDetails) );
135  }
136  else if ( printer_->isVerbosity(Debug) ) {
137  print( printer_->stream(Debug) );
138  }
139  }
140  }
141 
142  return state_;
143  }
144 
147  return state_;
148  }
150 
151 
153 
154 
157  void setOutputManager(const Teuchos::RCP<OutputManager<ScalarType> > &printer) { printer_ = printer; }
158 
161  void setOutputFrequency(int mod) { modTest_ = mod; }
162 
168  test_ = test;
169  state_ = Undefined;
170  }
171 
174  return test_;
175  }
176 
179  void setSolverDesc(const std::string& solverDesc) { solverDesc_ = solverDesc; }
180 
183  void setPrecondDesc(const std::string& precondDesc) { precondDesc_ = precondDesc; }
184 
186 
187 
189 
190 
195  void reset() {
196  state_ = Undefined;
197  test_->reset();
198  numCalls_ = 0;
199  }
200 
202  void resetNumCalls() { numCalls_ = 0; }
203 
205 
207 
208 
210  void print(std::ostream& os, int indent = 0) const {
211  std::string ind(indent,' ');
212  os << std::endl << ind << "Belos::StatusTestGeneralOutput: ";
213  switch (state_) {
214  case Passed:
215  os << "Passed" << std::endl;
216  break;
217  case Failed:
218  os << "Failed" << std::endl;
219  break;
220  case Undefined:
221  os << "Undefined" << std::endl;
222  break;
223  }
224  os << ind << " (Num calls,Mod test,State test): " << "(" << numCalls_ << ", " << modTest_ << ",";
225  if (stateTest_ == 0) {
226  os << " none)" << std::endl;
227  }
228  else {
229  if ( stateTest_ & Passed ) os << " Passed";
230  if ( stateTest_ & Failed ) os << " Failed";
231  if ( stateTest_ & Undefined ) os << " Undefined";
232  os << ")" << std::endl;
233  }
234  // print child, with extra indention
235  test_->print(os,indent+3);
236  }
237 
239 
240  private:
243  std::string solverDesc_;
244  std::string precondDesc_;
245  StatusType state_;
246  int stateTest_;
247  int modTest_;
248  int numCalls_;
249 };
250 
251 } // end of Belos namespace
252 
253 #endif /* BELOS_STATUS_TEST_OUTPUT_HPP */
StatusTestGeneralOutput(const Teuchos::RCP< OutputManager< ScalarType > > &printer, Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test, int mod=1, int printStates=Passed)
Constructor.
Collection of types and exceptions used within the Belos solvers.
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
Class which manages the output and verbosity of the Belos solvers.
void setChild(Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test)
Set child test.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > getChild() const
Get child test.
Exception thrown to signal error in a status test during Belos::StatusTest::checkStatus().
Virtual base class for StatusTest that printing status tests.
Pure virtual base class for defining the status testing capabilities of Belos.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void setOutputFrequency(int mod)
Set how often the child test is printed.
void setPrecondDesc(const std::string &precondDesc)
Set a short preconditioner description for output clarity.
Pure virtual base class which describes the basic interface to the linear solver iteration.
A pure virtual class for defining the status tests for the Belos iterative solvers.
StatusType
Whether the StatusTest wants iteration to stop.
Definition: BelosTypes.hpp:189
void setSolverDesc(const std::string &solverDesc)
Set a short solver description for output clarity.
StatusType checkStatus(Iteration< ScalarType, MV, OP > *solver)
void reset()
Informs the status test that it should reset its internal configuration to the uninitialized state...
void setOutputManager(const Teuchos::RCP< OutputManager< ScalarType > > &printer)
Set the output manager.
A special StatusTest for printing other status tests.
void print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
Belos header file which uses auto-configuration information to include necessary C++ headers...
void resetNumCalls()
Informs the outputting status test that it should reset the number of calls to zero.
A virtual base class for StatusTest that print other status tests.
StatusType getStatus() const
Return the result of the most recent checkStatus call, or undefined if it has not been run...

Generated on Mon Nov 4 2024 09:26:14 for Belos by doxygen 1.8.5