42#ifndef BELOS_TFQMR_SOLMGR_HPP
43#define BELOS_TFQMR_SOLMGR_HPP
61#ifdef BELOS_TEUCHOS_TIME_MONITOR
62#include "Teuchos_TimeMonitor.hpp"
93 template<
class ScalarType,
class MV,
class OP>
99 typedef Teuchos::ScalarTraits<ScalarType>
SCT;
100 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
MagnitudeType;
101 typedef Teuchos::ScalarTraits<MagnitudeType>
MT;
132 const Teuchos::RCP<Teuchos::ParameterList> &pl );
138 Teuchos::RCP<SolverManager<ScalarType, MV, OP> >
clone ()
const override {
163 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
198 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms )
override;
247 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >
problem_;
254 Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
sTest_;
291template<
class ScalarType,
class MV,
class OP>
296 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
313template<
class ScalarType,
class MV,
class OP>
316 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
321 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
335 TEUCHOS_TEST_FOR_EXCEPTION(
problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
338 if ( !is_null(pl) ) {
343template<
class ScalarType,
class MV,
class OP>
347 if (
params_ == Teuchos::null) {
355 if (params->isParameter(
"Maximum Iterations")) {
365 if (params->isParameter(
"Block Size")) {
367 TEUCHOS_TEST_FOR_EXCEPTION(
blockSize_ != 1, std::invalid_argument,
368 "Belos::TFQMRSolMgr: \"Block Size\" must be 1.");
375 if (params->isParameter(
"Timer Label")) {
376 std::string tempLabel = params->get(
"Timer Label",
label_default_);
379 if (tempLabel !=
label_) {
382 std::string solveLabel =
label_ +
": TFQMRSolMgr total solve time";
383#ifdef BELOS_TEUCHOS_TIME_MONITOR
384 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
390 if (params->isParameter(
"Verbosity")) {
391 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
394 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
404 if (params->isParameter(
"Output Style")) {
405 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
408 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
417 if (params->isParameter(
"Output Stream")) {
418 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
428 if (params->isParameter(
"Output Frequency")) {
444 if (params->isParameter(
"Convergence Tolerance")) {
445 if (params->isType<
MagnitudeType> (
"Convergence Tolerance")) {
446 convtol_ = params->get (
"Convergence Tolerance",
459 if (params->isParameter(
"Implicit Tolerance Scale Factor")) {
460 if (params->isType<
MagnitudeType> (
"Implicit Tolerance Scale Factor")) {
461 impTolScale_ = params->get (
"Implicit Tolerance Scale Factor",
466 impTolScale_ = params->get (
"Implicit Tolerance Scale Factor",
476 if (params->isParameter(
"Implicit Residual Scaling")) {
477 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params,
"Implicit Residual Scaling" );
491 if (params->isParameter(
"Explicit Residual Scaling")) {
492 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params,
"Explicit Residual Scaling" );
506 if (params->isParameter(
"Explicit Residual Test")) {
507 expResTest_ = Teuchos::getParameter<bool>( *params,
"Explicit Residual Test" );
518 std::string solveLabel =
label_ +
": TFQMRSolMgr total solve time";
519#ifdef BELOS_TEUCHOS_TIME_MONITOR
520 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
530template<
class ScalarType,
class MV,
class OP>
542 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
548 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
549 Teuchos::rcp(
new StatusTestGenResNorm_t(
convtol_ ) );
550 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
560 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
561 Teuchos::rcp(
new StatusTestGenResNorm_t(
convtol_ ) );
577 std::string solverDesc =
" TFQMR ";
588template<
class ScalarType,
class MV,
class OP>
589Teuchos::RCP<const Teuchos::ParameterList>
592 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
595 if(is_null(validPL)) {
596 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
601 "The relative residual tolerance that needs to be achieved by the\n"
602 "iterative solver in order for the linear system to be declared converged.");
604 "The scale factor used by the implicit residual test when explicit residual\n"
605 "testing is used. May enable faster convergence when TFQMR bound is too loose.");
607 "The maximum number of block iterations allowed for each\n"
608 "set of RHS solved.");
610 "What type(s) of solver information should be outputted\n"
611 "to the output stream.");
613 "What style is used for the solver information outputted\n"
614 "to the output stream.");
616 "How often convergence information should be outputted\n"
617 "to the output stream.");
618 pl->set(
"Output Stream", Teuchos::rcpFromRef(std::cout),
619 "A reference-counted pointer to the output stream where all\n"
620 "solver output is sent.");
622 "Whether the explicitly computed residual should be used in the convergence test.");
624 "The type of scaling used in the implicit residual convergence test.");
626 "The type of scaling used in the explicit residual convergence test.");
628 "The string to use as a prefix for the timer labels.");
636template<
class ScalarType,
class MV,
class OP>
647 "Belos::TFQMRSolMgr::solve(): Linear problem is not a valid object.");
650 "Belos::TFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
654 "Belos::TFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
662 std::vector<int> currIdx, currIdx2;
667 for (
int i=0; i<numCurrRHS; ++i)
668 { currIdx[i] = startPtr+i; currIdx2[i]=i; }
675 Teuchos::ParameterList plist;
682 bool isConverged =
true;
687 Teuchos::RCP<TFQMRIter<ScalarType,MV,OP> > tfqmr_iter =
692#ifdef BELOS_TEUCHOS_TIME_MONITOR
696 while ( numRHS2Solve > 0 ) {
699 std::vector<int> convRHSIdx;
700 std::vector<int> currRHSIdx( currIdx );
701 currRHSIdx.resize(numCurrRHS);
704 tfqmr_iter->resetNumIters();
715 tfqmr_iter->initializeTFQMR(newstate);
721 tfqmr_iter->iterate();
751 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
752 "Belos::TFQMRSolMgr::solve(): Invalid return from TFQMRIter::iterate().");
755 catch (
const std::exception &e) {
756 printer_->stream(
Errors) <<
"Error! Caught std::exception in TFQMRIter::iterate() at iteration "
757 << tfqmr_iter->getNumIters() << std::endl
758 << e.what() << std::endl;
764 problem_->updateSolution( tfqmr_iter->getCurrentUpdate(),
true );
770 startPtr += numCurrRHS;
771 numRHS2Solve -= numCurrRHS;
772 if ( numRHS2Solve > 0 ) {
777 for (
int i=0; i<numCurrRHS; ++i)
778 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
786 currIdx.resize( numRHS2Solve );
797#ifdef BELOS_TEUCHOS_TIME_MONITOR
819 const std::vector<MagnitudeType>* pTestValues = NULL;
822 if (pTestValues == NULL || pTestValues->size() < 1) {
830 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
831 "Belos::TFQMRSolMgr::solve(): The implicit convergence test's "
832 "getTestValue() method returned NULL. Please report this bug to the "
833 "Belos developers.");
834 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
835 "Belos::TMQMRSolMgr::solve(): The implicit convergence test's "
836 "getTestValue() method returned a vector of length zero. Please report "
837 "this bug to the Belos developers.");
842 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
852template<
class ScalarType,
class MV,
class OP>
855 std::ostringstream oss;
856 oss <<
"Belos::TFQMRSolMgr<...,"<<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.
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.
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
Collection of types and exceptions used within the Belos solvers.
BelosError(const std::string &what_arg)
Traits class which defines basic operations on multivectors.
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
Class which defines basic traits for the operator type.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
SolverManager()
Empty constructor.
A class for extending the status testing capabilities of Belos via logical combinations.
An implementation of StatusTestResNorm using a family of residual norms.
A Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > create(const Teuchos::RCP< OutputManager< ScalarType > > &printer, Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test, int mod, int printStates)
Create the StatusTestOutput object specified by the outputStyle.
This class implements the preconditioned transpose-free QMR algorithm for solving non-Hermitian linea...
TFQMRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
TFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Teuchos::ScalarTraits< MagnitudeType > MT
virtual ~TFQMRSolMgr()
Destructor.
static constexpr const char * impResScale_default_
Teuchos::RCP< Teuchos::Time > timerSolve_
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
static constexpr int outputFreq_default_
MagnitudeType impTolScale_
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > convTest_
static constexpr int outputStyle_default_
Teuchos::RCP< Teuchos::ParameterList > params_
MagnitudeType achievedTol_
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Teuchos::ScalarTraits< ScalarType > SCT
Teuchos::RCP< std::ostream > outputStream_
OperatorTraits< ScalarType, MV, OP > OPT
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_
static constexpr const char * label_default_
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
int getNumIters() const override
Get the iteration count for the most recent call to solve().
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > sTest_
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > outputTest_
static constexpr const char * expResScale_default_
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
static constexpr int verbosity_default_
Teuchos::RCP< OutputManager< ScalarType > > printer_
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > impConvTest_
static constexpr int maxIters_default_
std::string description() const override
Method to return description of the TFQMR solver manager.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
static constexpr bool expResTest_default_
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
TFQMRSolMgr()
Empty constructor for TFQMRSolMgr. This constructor takes no arguments and sets the default values fo...
bool isLOADetected() const override
Whether loss of accuracy was detected during the last solve() invocation.
MultiVecTraits< ScalarType, MV > MVT
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > expConvTest_
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms) override
Set the parameters the solver manager should use to solve the linear problem.
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.
Structure to contain pointers to TFQMRIter state variables.
Teuchos::RCP< const MV > R
The current residual basis.