43#ifndef BELOS_STATUS_TEST_RESNORM_OUTPUT_HPP
44#define BELOS_STATUS_TEST_RESNORM_OUTPUT_HPP
73template <
class ScalarType,
class MV,
class OP>
106 headerPrinted_(false),
107 stateTest_(printStates),
147 TEUCHOS_TEST_FOR_EXCEPTION(iterTest_ == Teuchos::null,
StatusTestError,
"StatusTestResNormOutput::checkStatus(): iteration test pointer is null.");
148 TEUCHOS_TEST_FOR_EXCEPTION(resTestVec_.size() == 0,
StatusTestError,
"StatusTestResNormOutput::checkStatus(): residual test pointer is null.");
149 state_ = test_->checkStatus(solver);
158 currNumRHS_ = currIdx_.size();
160 numIterDgts_ = (int)std::floor(std::log10((
double)iterTest_->getMaxIters()))+1;
163 if (((iterTest_->getNumIters() % modTest_ == 0) && (iterTest_->getNumIters()!=lastNumIters_)) || (state_ ==
Passed)) {
164 lastNumIters_ = iterTest_->getNumIters();
165 if ( (state_ & stateTest_) == state_) {
169 else if ( printer_->isVerbosity(
Debug) ) {
203 Teuchos::RCP<StatusTestCombo_t> comboTest = Teuchos::rcp_dynamic_cast<StatusTestCombo_t>(test);
204 TEUCHOS_TEST_FOR_EXCEPTION(comboTest == Teuchos::null,
StatusTestError,
"StatusTestResNormOutput(): test must be a Belos::StatusTestCombo.");
205 std::vector<Teuchos::RCP<StatusTest<ScalarType,MV,OP> > > tmpVec = comboTest->getStatusTests();
208 int numTests = tmpVec.size();
211 for (
int i=0; i<numTests; ++i) {
214 Teuchos::RCP<StatusTestMaxIters_t> tmpItrTest = Teuchos::rcp_dynamic_cast<StatusTestMaxIters_t>(tmpVec[i]);
215 if (tmpItrTest != Teuchos::null) {
216 iterTest_ = tmpItrTest;
221 Teuchos::RCP<StatusTestResNorm_t> tmpResTest = Teuchos::rcp_dynamic_cast<StatusTestResNorm_t>(tmpVec[i]);
223 if (tmpResTest != Teuchos::null) {
225 resTestVec_.resize( numResTests_ );
226 resTestVec_[0] = tmpResTest;
231 Teuchos::RCP<StatusTestCombo_t> tmpComboTest = Teuchos::rcp_dynamic_cast<StatusTestCombo_t>(tmpVec[i]);
232 TEUCHOS_TEST_FOR_EXCEPTION(tmpComboTest == Teuchos::null,
StatusTestError,
"StatusTestResNormOutput(): test must be Belos::StatusTest[MaxIters|ResNorm|Combo].");
233 tmpVec = tmpComboTest->getStatusTests();
234 comboType_ = tmpComboTest->getComboType();
235 numResTests_ = tmpVec.size();
236 resTestVec_.resize( numResTests_ );
237 for (
int j=0; j<numResTests_; ++j) {
238 tmpResTest = Teuchos::rcp_dynamic_cast<StatusTestResNorm_t>(tmpVec[j]);
239 TEUCHOS_TEST_FOR_EXCEPTION(tmpResTest == Teuchos::null,
StatusTestError,
"StatusTestResNormOutput(): test must be a vector of Belos::StatusTestResNorm.");
240 resTestVec_[j] = tmpResTest;
251 Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
getChild()
const {
257 void setSolverDesc(
const std::string& solverDesc) { solverDesc_ = solverDesc; }
261 void setPrecondDesc(
const std::string& precondDesc) { precondDesc_ = precondDesc; }
276 headerPrinted_ =
false;
291 void print(std::ostream& os,
int indent = 0)
const {
292 std::string ind(indent,
' ');
293 std::string starLine(55,
'*');
294 std::string starFront(5,
'*');
296 std::ios_base::fmtflags osFlags(os.flags());
298 os.setf(std::ios::scientific, std::ios::floatfield);
302 if (!headerPrinted_) {
303 os << std::endl << ind << starLine << std::endl;
304 os << ind << starFront <<
" Belos Iterative Solver: " << solverDesc_ << std::endl;
305 if (precondDesc_ !=
"")
306 os << ind << starFront <<
" Preconditioner: " << precondDesc_ << std::endl;
307 os << ind << starFront <<
" Maximum Iterations: " << iterTest_->getMaxIters() << std::endl;
308 os << ind << starFront <<
" Block Size: " << blockSize_ << std::endl;
309 if (numResTests_ > 1) {
310 os << ind << starFront <<
" Residual Tests ("
312 <<
"): " << std::endl;
314 os << ind << starFront <<
" Residual Test: " << std::endl;
316 for (
int i=0; i<numResTests_; ++i) {
317 os << ind << starFront <<
" Test " << i+1 <<
" : " << resTestVec_[i]->description() << std::endl;
319 os << ind << starLine << std::endl;
320 headerPrinted_ =
true;
324 os.setf(std::ios_base::right, std::ios_base::adjustfield);
325 std::string ind2( 7 + numIterDgts_,
' ' );
326 os << ind <<
"Iter " << std::setw(numIterDgts_) << iterTest_->getNumIters() <<
", ";
327 for (
int i=0; i<currNumRHS_; ++i) {
328 if ( i > 0 && currIdx_[i]!=-1 ) {
332 os <<
"[" << std::setw(numLSDgts_) << currIdx_[i]+1 <<
"] : ";
333 for (
int j=0; j<numResTests_; ++j) {
335 os << std::setw(15) << (*resTestVec_[j]->getTestValue())[currIdx_[i]];
337 os << std::setw(15) <<
"---";
350 Teuchos::RCP<OutputManager<ScalarType> > printer_;
353 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test_;
356 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > iterTest_;
359 std::vector<Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > > resTestVec_;
361 std::string solverDesc_;
362 std::string precondDesc_;
363 std::vector<int> currIdx_;
365 mutable bool headerPrinted_;
366 int stateTest_, modTest_;
367 int lastNumIters_, comboType_;
368 int numResTests_, blockSize_;
369 int currNumRHS_, currLSNum_;
370 int numLSDgts_, numIterDgts_;
Belos header file which uses auto-configuration information to include necessary C++ headers.
Pure virtual base class which describes the basic interface to the linear solver iteration.
Belos::StatusTest for logically combining several status tests.
Belos::StatusTest class for specifying a maximum number of iterations.
Virtual base class for StatusTest that printing status tests.
Belos::StatusTest abstract class for specifying a residual norm stopping criteria.
Pure virtual base class for defining the status testing capabilities of Belos.
Collection of types and exceptions used within the Belos solvers.
virtual int getBlockSize() const =0
Get the blocksize to be used by the iterative solver in solving this linear problem.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const =0
Get a constant reference to the linear problem.
A linear system to solve, and its associated information.
int getLSNumber() const
The number of linear systems that have been set.
const std::vector< int > & getLSIndex() const
(Zero-based) indices of the linear system(s) currently being solved.
Teuchos::RCP< const MV > getRHS() const
A pointer to the right-hand side B.
Traits class which defines basic operations on multivectors.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
A class for extending the status testing capabilities of Belos via logical combinations.
Exception thrown to signal error in a status test during Belos::StatusTest::checkStatus().
A Belos::StatusTest class for specifying a maximum number of iterations.
A virtual base class for StatusTest that print other status tests.
A special StatusTest for printing other status tests in a simple format.
void setOutputManager(const Teuchos::RCP< OutputManager< ScalarType > > &printer)
Set the output manager.
StatusTestResNormOutput(const Teuchos::RCP< OutputManager< ScalarType > > &printer, Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test, int mod=1, int printStates=Passed)
Constructor.
void reset()
Informs the status test that it should reset its internal configuration to the uninitialized state.
void print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
StatusType checkStatus(Iteration< ScalarType, MV, OP > *solver)
void setSolverDesc(const std::string &solverDesc)
Set a short solver description for output clarity.
void setChild(Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test)
Set child test, which must be a combination of a Belos::StatusTestMaxIters AND a single or combinatio...
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > getChild() const
Get child test.
void resetNumCalls()
Informs the outputting status test that it should reset the number of calls to zero.
StatusType getStatus() const
Return the result of the most recent checkStatus call, or undefined if it has not been run.
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.
virtual ~StatusTestResNormOutput()
Destructor.
An abstract class of StatusTest for stopping criteria using residual norms.
A pure virtual class for defining the status tests for the Belos iterative solvers.
StatusType
Whether the StatusTest wants iteration to stop.