42#ifndef BELOS_PSEUDO_BLOCK_TFQMR_SOLMGR_HPP
43#define BELOS_PSEUDO_BLOCK_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(
"Timer Label")) {
366 std::string tempLabel = params->get(
"Timer Label",
label_default_);
369 if (tempLabel !=
label_) {
372 std::string solveLabel =
label_ +
": PseudoBlockTFQMRSolMgr total solve time";
373#ifdef BELOS_TEUCHOS_TIME_MONITOR
374 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
380 if (params->isParameter(
"Verbosity")) {
381 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
384 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
394 if (params->isParameter(
"Output Style")) {
395 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
398 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
407 if (params->isParameter(
"Output Stream")) {
408 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
418 if (params->isParameter(
"Output Frequency")) {
434 if (params->isParameter(
"Convergence Tolerance")) {
435 if (params->isType<
MagnitudeType> (
"Convergence Tolerance")) {
436 convtol_ = params->get (
"Convergence Tolerance",
448 if (params->isParameter(
"Implicit Tolerance Scale Factor")) {
449 if (params->isType<
MagnitudeType> (
"Implicit Tolerance Scale Factor")) {
450 impTolScale_ = params->get (
"Implicit Tolerance Scale Factor",
455 impTolScale_ = params->get (
"Implicit Tolerance Scale Factor",
464 if (params->isParameter(
"Implicit Residual Scaling")) {
465 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params,
"Implicit Residual Scaling" );
477 if (params->isParameter(
"Explicit Residual Scaling")) {
478 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params,
"Explicit Residual Scaling" );
490 if (params->isParameter(
"Explicit Residual Test")) {
491 expResTest_ = Teuchos::getParameter<bool>( *params,
"Explicit Residual Test" );
501 if (params->isParameter(
"Deflation Quorum")) {
514 std::string solveLabel =
label_ +
": PseudoBlockTFQMRSolMgr total solve time";
515#ifdef BELOS_TEUCHOS_TIME_MONITOR
516 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
526template<
class ScalarType,
class MV,
class OP>
538 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
544 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
546 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
556 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
573 std::string solverDesc =
" Pseudo Block TFQMR ";
584template<
class ScalarType,
class MV,
class OP>
585Teuchos::RCP<const Teuchos::ParameterList>
588 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
591 if(is_null(validPL)) {
592 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
597 "The relative residual tolerance that needs to be achieved by the\n"
598 "iterative solver in order for the linear system to be declared converged.");
600 "The scale factor used by the implicit residual test when explicit residual\n"
601 "testing is used. May enable faster convergence when TFQMR bound is too loose.");
603 "The maximum number of block iterations allowed for each\n"
604 "set of RHS solved.");
606 "What type(s) of solver information should be outputted\n"
607 "to the output stream.");
609 "What style is used for the solver information outputted\n"
610 "to the output stream.");
612 "How often convergence information should be outputted\n"
613 "to the output stream.");
615 "The number of linear systems that need to converge before they are deflated.");
616 pl->set(
"Output Stream", Teuchos::rcpFromRef(std::cout),
617 "A reference-counted pointer to the output stream where all\n"
618 "solver output is sent.");
620 "Whether the explicitly computed residual should be used in the convergence test.");
622 "The type of scaling used in the implicit residual convergence test.");
624 "The type of scaling used in the explicit residual convergence test.");
626 "The string to use as a prefix for the timer labels.");
634template<
class ScalarType,
class MV,
class OP>
645 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not a valid object.");
648 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
652 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
658 int numCurrRHS = numRHS2Solve;
660 std::vector<int> currIdx( numRHS2Solve );
661 for (
int i=0; i<numRHS2Solve; ++i) {
662 currIdx[i] = startPtr+i;
670 Teuchos::ParameterList plist;
676 bool isConverged =
true;
681 Teuchos::RCP<PseudoBlockTFQMRIter<ScalarType,MV,OP> > block_tfqmr_iter =
686#ifdef BELOS_TEUCHOS_TIME_MONITOR
690 while ( numRHS2Solve > 0 ) {
693 std::vector<int> convRHSIdx;
694 std::vector<int> currRHSIdx( currIdx );
695 currRHSIdx.resize(numCurrRHS);
698 block_tfqmr_iter->resetNumIters();
709 block_tfqmr_iter->initializeTFQMR(newstate);
715 block_tfqmr_iter->iterate();
729 if (convIdx.size() == currRHSIdx.size())
733 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(),
true );
740 std::vector<int> unconvIdx( currRHSIdx.size() );
741 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
743 for (
unsigned int j=0; j<convIdx.size(); ++j) {
744 if (currRHSIdx[i] == convIdx[j]) {
751 currRHSIdx[have++] = currRHSIdx[i];
754 unconvIdx.resize(have);
755 currRHSIdx.resize(have);
776 for (std::vector<int>::iterator uIter = unconvIdx.begin(); uIter != unconvIdx.end(); uIter++)
778 defstate.
alpha.push_back( currentState.
alpha[ *uIter ] );
779 defstate.
eta.push_back( currentState.
eta[ *uIter ] );
780 defstate.
rho.push_back( currentState.
rho[ *uIter ] );
781 defstate.
tau.push_back( currentState.
tau[ *uIter ] );
782 defstate.
theta.push_back( currentState.
theta[ *uIter ] );
785 block_tfqmr_iter->initializeTFQMR(defstate);
806 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
807 "Belos::PseudoBlockTFQMRSolMgr::solve(): Invalid return from PseudoBlockTFQMRIter::iterate().");
810 catch (
const std::exception &e) {
811 printer_->stream(
Errors) <<
"Error! Caught std::exception in PseudoBlockTFQMRIter::iterate() at iteration "
812 << block_tfqmr_iter->getNumIters() << std::endl
813 << e.what() << std::endl;
819 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(),
true );
825 startPtr += numCurrRHS;
826 numRHS2Solve -= numCurrRHS;
827 if ( numRHS2Solve > 0 ) {
828 numCurrRHS = numRHS2Solve;
829 currIdx.resize( numCurrRHS );
830 for (
int i=0; i<numCurrRHS; ++i)
831 { currIdx[i] = startPtr+i; }
845 currIdx.resize( numRHS2Solve );
856#ifdef BELOS_TEUCHOS_TIME_MONITOR
878 const std::vector<MagnitudeType>* pTestValues = NULL;
881 if (pTestValues == NULL || pTestValues->size() < 1) {
889 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
890 "Belos::PseudoBlockTFQMRSolMgr::solve(): The implicit convergence test's "
891 "getTestValue() method returned NULL. Please report this bug to the "
892 "Belos developers.");
893 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
894 "Belos::TMQMRSolMgr::solve(): The implicit convergence test's "
895 "getTestValue() method returned a vector of length zero. Please report "
896 "this bug to the Belos developers.");
901 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
911template<
class ScalarType,
class MV,
class OP>
914 std::ostringstream oss;
915 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.
BelosError(const std::string &what_arg)
Traits class which defines basic operations on multivectors.
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
Creates a new const MV that shares the selected contents of mv (shallow copy).
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...
This class implements the preconditioned transpose-free QMR algorithm for solving non-Hermitian linea...
PseudoBlockTFQMRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
PseudoBlockTFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > sTest_
static constexpr const char * label_default_
Teuchos::RCP< Teuchos::Time > timerSolve_
MagnitudeType impTolScale_
static constexpr const char * impResScale_default_
static constexpr int maxIters_default_
static constexpr int verbosity_default_
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > expConvTest_
Teuchos::RCP< std::ostream > outputStream_
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< StatusTestOutput< ScalarType, MV, OP > > outputTest_
static constexpr const char * expResScale_default_
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_
Teuchos::ScalarTraits< MagnitudeType > MT
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Teuchos::RCP< OutputManager< ScalarType > > printer_
static constexpr int outputStyle_default_
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > impConvTest_
static constexpr int defQuorum_default_
MagnitudeType achievedTol_
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
OperatorTraits< ScalarType, MV, OP > OPT
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > convTest_
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
static constexpr int outputFreq_default_
std::string description() const override
Method to return description of the pseudo-block TFQMR solver manager.
static constexpr bool expResTest_default_
Teuchos::ScalarTraits< ScalarType > SCT
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.
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
MultiVecTraits< ScalarType, MV > MVT
int getNumIters() const override
Get the iteration count for the most recent call to solve().
Teuchos::RCP< Teuchos::ParameterList > params_
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...
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.
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 PseudoBlockTFQMRIter state variables.
std::vector< MagnitudeType > theta
std::vector< MagnitudeType > tau
Teuchos::RCP< const MV > AU
std::vector< ScalarType > rho
Teuchos::RCP< const MV > D
std::vector< ScalarType > alpha
Teuchos::RCP< const MV > Rtilde
Teuchos::RCP< const MV > W
The current residual basis.
Teuchos::RCP< const MV > U
Teuchos::RCP< const MV > V
std::vector< ScalarType > eta