10#ifndef BELOS_PSEUDO_BLOCK_TFQMR_SOLMGR_HPP
11#define BELOS_PSEUDO_BLOCK_TFQMR_SOLMGR_HPP
29#ifdef BELOS_TEUCHOS_TIME_MONITOR
30#include "Teuchos_TimeMonitor.hpp"
64 template<
class ScalarType,
class MV,
class OP>
70 typedef Teuchos::ScalarTraits<ScalarType> SCT;
71 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
72 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
103 const Teuchos::RCP<Teuchos::ParameterList> &
pl );
109 Teuchos::RCP<SolverManager<ScalarType, MV, OP> >
clone ()
const override {
134 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
135 return Teuchos::tuple(timerSolve_);
215 bool checkStatusTest();
218 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
221 Teuchos::RCP<OutputManager<ScalarType> > printer_;
222 Teuchos::RCP<std::ostream> outputStream_;
225 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
226 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
227 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
228 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
229 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
232 Teuchos::RCP<Teuchos::ParameterList> params_;
235 static constexpr int maxIters_default_ = 1000;
236 static constexpr bool expResTest_default_ =
false;
239 static constexpr int outputFreq_default_ = -1;
240 static constexpr int defQuorum_default_ = 1;
241 static constexpr const char * impResScale_default_ =
"Norm of Preconditioned Initial Residual";
242 static constexpr const char * expResScale_default_ =
"Norm of Initial Residual";
243 static constexpr const char * label_default_ =
"Belos";
246 MagnitudeType convtol_, impTolScale_, achievedTol_;
247 int maxIters_, numIters_;
248 int verbosity_, outputStyle_, outputFreq_, defQuorum_;
250 std::string impResScale_, expResScale_;
254 Teuchos::RCP<Teuchos::Time> timerSolve_;
257 bool isSet_, isSTSet_;
262template<
class ScalarType,
class MV,
class OP>
268 maxIters_(maxIters_default_),
270 verbosity_(verbosity_default_),
271 outputStyle_(outputStyle_default_),
272 outputFreq_(outputFreq_default_),
273 defQuorum_(defQuorum_default_),
274 expResTest_(expResTest_default_),
275 impResScale_(impResScale_default_),
276 expResScale_(expResScale_default_),
277 label_(label_default_),
284template<
class ScalarType,
class MV,
class OP>
287 const Teuchos::RCP<Teuchos::ParameterList> &
pl ) :
293 maxIters_(maxIters_default_),
295 verbosity_(verbosity_default_),
296 outputStyle_(outputStyle_default_),
297 outputFreq_(outputFreq_default_),
298 defQuorum_(defQuorum_default_),
299 expResTest_(expResTest_default_),
300 impResScale_(impResScale_default_),
301 expResScale_(expResScale_default_),
302 label_(label_default_),
314template<
class ScalarType,
class MV,
class OP>
318 if (params_ == Teuchos::null) {
319 params_ = Teuchos::rcp(
new Teuchos::ParameterList(*getValidParameters()) );
322 params->validateParameters(*getValidParameters());
326 if (
params->isParameter(
"Maximum Iterations")) {
327 maxIters_ =
params->get(
"Maximum Iterations",maxIters_default_);
330 params_->set(
"Maximum Iterations", maxIters_);
331 if (maxIterTest_!=Teuchos::null)
332 maxIterTest_->setMaxIters( maxIters_ );
336 if (
params->isParameter(
"Timer Label")) {
342 params_->set(
"Timer Label", label_);
343 std::string
solveLabel = label_ +
": PseudoBlockTFQMRSolMgr total solve time";
344#ifdef BELOS_TEUCHOS_TIME_MONITOR
345 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(
solveLabel);
351 if (
params->isParameter(
"Verbosity")) {
352 if (Teuchos::isParameterType<int>(*
params,
"Verbosity")) {
353 verbosity_ =
params->get(
"Verbosity", verbosity_default_);
355 verbosity_ = (
int)Teuchos::getParameter<Belos::MsgType>(*
params,
"Verbosity");
359 params_->set(
"Verbosity", verbosity_);
360 if (printer_ != Teuchos::null)
361 printer_->setVerbosity(verbosity_);
365 if (
params->isParameter(
"Output Style")) {
366 if (Teuchos::isParameterType<int>(*
params,
"Output Style")) {
367 outputStyle_ =
params->get(
"Output Style", outputStyle_default_);
369 outputStyle_ = (
int)Teuchos::getParameter<Belos::OutputType>(*
params,
"Output Style");
373 params_->set(
"Output Style", outputStyle_);
378 if (
params->isParameter(
"Output Stream")) {
379 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*
params,
"Output Stream");
382 params_->set(
"Output Stream", outputStream_);
383 if (printer_ != Teuchos::null)
384 printer_->setOStream( outputStream_ );
389 if (
params->isParameter(
"Output Frequency")) {
390 outputFreq_ =
params->get(
"Output Frequency", outputFreq_default_);
394 params_->set(
"Output Frequency", outputFreq_);
395 if (outputTest_ != Teuchos::null)
396 outputTest_->setOutputFrequency( outputFreq_ );
400 if (printer_ == Teuchos::null) {
405 if (
params->isParameter(
"Convergence Tolerance")) {
406 if (
params->isType<MagnitudeType> (
"Convergence Tolerance")) {
407 convtol_ =
params->get (
"Convergence Tolerance",
415 params_->set(
"Convergence Tolerance", convtol_);
419 if (
params->isParameter(
"Implicit Tolerance Scale Factor")) {
420 if (
params->isType<MagnitudeType> (
"Implicit Tolerance Scale Factor")) {
421 impTolScale_ =
params->get (
"Implicit Tolerance Scale Factor",
426 impTolScale_ =
params->get (
"Implicit Tolerance Scale Factor",
431 params_->set(
"Implicit Tolerance Scale Factor", impTolScale_);
435 if (
params->isParameter(
"Implicit Residual Scaling")) {
436 std::string
tempImpResScale = Teuchos::getParameter<std::string>( *
params,
"Implicit Residual Scaling" );
443 params_->set(
"Implicit Residual Scaling", impResScale_);
448 if (
params->isParameter(
"Explicit Residual Scaling")) {
449 std::string
tempExpResScale = Teuchos::getParameter<std::string>( *
params,
"Explicit Residual Scaling" );
456 params_->set(
"Explicit Residual Scaling", expResScale_);
461 if (
params->isParameter(
"Explicit Residual Test")) {
462 expResTest_ = Teuchos::getParameter<bool>( *
params,
"Explicit Residual Test" );
465 params_->set(
"Explicit Residual Test", expResTest_);
466 if (expConvTest_ == Teuchos::null) {
472 if (
params->isParameter(
"Deflation Quorum")) {
473 defQuorum_ =
params->get(
"Deflation Quorum", defQuorum_);
474 params_->set (
"Deflation Quorum", defQuorum_);
475 if (! impConvTest_.is_null ()) {
476 impConvTest_->setQuorum (defQuorum_);
478 if (! expConvTest_.is_null ()) {
479 expConvTest_->setQuorum (defQuorum_);
484 if (timerSolve_ == Teuchos::null) {
485 std::string
solveLabel = label_ +
": PseudoBlockTFQMRSolMgr total solve time";
486#ifdef BELOS_TEUCHOS_TIME_MONITOR
487 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(
solveLabel);
497template<
class ScalarType,
class MV,
class OP>
522 convTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
533 expConvTest_ = impConvTest_;
534 convTest_ = impConvTest_;
536 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
544 std::string
solverDesc =
" Pseudo Block TFQMR ";
555template<
class ScalarType,
class MV,
class OP>
556Teuchos::RCP<const Teuchos::ParameterList>
559 static Teuchos::RCP<const Teuchos::ParameterList>
validPL;
563 Teuchos::RCP<Teuchos::ParameterList>
pl = Teuchos::parameterList();
568 "The relative residual tolerance that needs to be achieved by the\n"
569 "iterative solver in order for the linear system to be declared converged.");
571 "The scale factor used by the implicit residual test when explicit residual\n"
572 "testing is used. May enable faster convergence when TFQMR bound is too loose.");
573 pl->set(
"Maximum Iterations",
static_cast<int>(maxIters_default_),
574 "The maximum number of block iterations allowed for each\n"
575 "set of RHS solved.");
576 pl->set(
"Verbosity",
static_cast<int>(verbosity_default_),
577 "What type(s) of solver information should be outputted\n"
578 "to the output stream.");
579 pl->set(
"Output Style",
static_cast<int>(outputStyle_default_),
580 "What style is used for the solver information outputted\n"
581 "to the output stream.");
582 pl->set(
"Output Frequency",
static_cast<int>(outputFreq_default_),
583 "How often convergence information should be outputted\n"
584 "to the output stream.");
585 pl->set(
"Deflation Quorum",
static_cast<int>(defQuorum_default_),
586 "The number of linear systems that need to converge before they are deflated.");
587 pl->set(
"Output Stream", Teuchos::rcpFromRef(std::cout),
588 "A reference-counted pointer to the output stream where all\n"
589 "solver output is sent.");
590 pl->set(
"Explicit Residual Test",
static_cast<bool>(expResTest_default_),
591 "Whether the explicitly computed residual should be used in the convergence test.");
592 pl->set(
"Implicit Residual Scaling",
static_cast<const char *
>(impResScale_default_),
593 "The type of scaling used in the implicit residual convergence test.");
594 pl->set(
"Explicit Residual Scaling",
static_cast<const char *
>(expResScale_default_),
595 "The type of scaling used in the explicit residual convergence test.");
596 pl->set(
"Timer Label",
static_cast<const char *
>(label_default_),
597 "The string to use as a prefix for the timer labels.");
605template<
class ScalarType,
class MV,
class OP>
612 setParameters(Teuchos::parameterList(*getValidParameters()));
616 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not a valid object.");
619 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
623 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
628 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
637 problem_->setLSIndex(
currIdx );
641 Teuchos::ParameterList
plist;
644 outputTest_->reset();
657#ifdef BELOS_TEUCHOS_TIME_MONITOR
658 Teuchos::TimeMonitor
slvtimer(*timerSolve_);
672 outputTest_->resetNumCalls();
675 Teuchos::RCP<MV>
R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())),
currIdx );
693 if ( convTest_->getStatus() ==
Passed ) {
696 std::vector<int>
convIdx = expConvTest_->convIndices();
707 problem_->setCurrLS();
714 for (
unsigned int j=0;
j<
convIdx.size(); ++
j) {
763 else if ( maxIterTest_->getStatus() ==
Passed ) {
778 "Belos::PseudoBlockTFQMRSolMgr::solve(): Invalid return from PseudoBlockTFQMRIter::iterate().");
783 achievedTol_ = MT::one();
784 Teuchos::RCP<MV>
X = problem_->getLHS();
785 MVT::MvInit( *
X, SCT::zero() );
786 printer_->stream(
Warnings) <<
"Belos::PseudoBlockTFQMRSolMgr::solve(): Warning! NaN has been detected!"
790 catch (
const std::exception &
e) {
791 printer_->stream(
Errors) <<
"Error! Caught std::exception in PseudoBlockTFQMRIter::iterate() at iteration "
793 <<
e.what() << std::endl;
802 problem_->setCurrLS();
815 if (impConvTest_ != Teuchos::null)
817 if (expConvTest_ != Teuchos::null)
822 problem_->setLSIndex(
currIdx );
836#ifdef BELOS_TEUCHOS_TIME_MONITOR
841 Teuchos::TimeMonitor::summarize( printer_->stream(
TimingDetails) );
845 numIters_ = maxIterTest_->getNumIters();
870 "Belos::PseudoBlockTFQMRSolMgr::solve(): The implicit convergence test's "
871 "getTestValue() method returned NULL. Please report this bug to the "
872 "Belos developers.");
874 "Belos::TMQMRSolMgr::solve(): The implicit convergence test's "
875 "getTestValue() method returned a vector of length zero. Please report "
876 "this bug to the Belos developers.");
891template<
class ScalarType,
class MV,
class OP>
894 std::ostringstream
oss;
895 oss <<
"Belos::PseudoBlockTFQMRSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
Belos header file which uses auto-configuration information to include necessary C++ headers.
Class which describes the linear problem to be solved by the iterative solver.
Class which manages the output and verbosity of the Belos solvers.
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
Pure virtual base class which describes the basic interface for a solver manager.
Belos::StatusTest for logically combining several status tests.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Collection of types and exceptions used within the Belos solvers.
Parent class to all Belos exceptions.
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
PseudoBlockTFQMRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
PseudoBlockTFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
The Belos::PseudoBlockTFQMRSolMgr provides a powerful and fully-featured solver manager over the pseu...
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
bool isLOADetected() const override
Whether loss of accuracy was detected during the last solve() invocation.
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
std::string description() const override
Method to return description of the pseudo-block TFQMR solver manager.
PseudoBlockTFQMRSolMgr()
Empty constructor for PseudoBlockTFQMRSolMgr. This constructor takes no arguments and sets the defaul...
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms) override
Set the parameters the solver manager should use to solve the linear problem.
int getNumIters() const override
Get the iteration count for the most recent call to solve().
virtual ~PseudoBlockTFQMRSolMgr()
Destructor.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
ReturnType
Whether the Belos solve converged for all linear systems.
ResetType
How to reset the solver.
Default parameters common to most Belos solvers.
static const double impTolScale
"Implicit Tolerance Scale Factor"
static const double convTol
Default convergence tolerance.