42 #ifndef BELOS_PSEUDO_BLOCK_TFQMR_SOLMGR_HPP
43 #define BELOS_PSEUDO_BLOCK_TFQMR_SOLMGR_HPP
61 #ifdef BELOS_TEUCHOS_TIME_MONITOR
103 template<
class ScalarType,
class MV,
class OP>
174 return Teuchos::tuple(timerSolve_);
254 bool checkStatusTest();
274 static constexpr
int maxIters_default_ = 1000;
275 static constexpr
bool expResTest_default_ =
false;
278 static constexpr
int outputFreq_default_ = -1;
279 static constexpr
int defQuorum_default_ = 1;
280 static constexpr
const char * impResScale_default_ =
"Norm of Preconditioned Initial Residual";
281 static constexpr
const char * expResScale_default_ =
"Norm of Initial Residual";
282 static constexpr
const char * label_default_ =
"Belos";
283 static constexpr std::ostream * outputStream_default_ = &std::cout;
286 MagnitudeType convtol_, impTolScale_, achievedTol_;
287 int maxIters_, numIters_;
288 int verbosity_, outputStyle_, outputFreq_, defQuorum_;
290 std::string impResScale_, expResScale_;
297 bool isSet_, isSTSet_;
302 template<
class ScalarType,
class MV,
class OP>
304 outputStream_(Teuchos::
rcp(outputStream_default_,false)),
307 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
308 maxIters_(maxIters_default_),
310 verbosity_(verbosity_default_),
311 outputStyle_(outputStyle_default_),
312 outputFreq_(outputFreq_default_),
313 defQuorum_(defQuorum_default_),
314 expResTest_(expResTest_default_),
315 impResScale_(impResScale_default_),
316 expResScale_(expResScale_default_),
317 label_(label_default_),
324 template<
class ScalarType,
class MV,
class OP>
329 outputStream_(Teuchos::
rcp(outputStream_default_,false)),
332 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
333 maxIters_(maxIters_default_),
335 verbosity_(verbosity_default_),
336 outputStyle_(outputStyle_default_),
337 outputFreq_(outputFreq_default_),
338 defQuorum_(defQuorum_default_),
339 expResTest_(expResTest_default_),
340 impResScale_(impResScale_default_),
341 expResScale_(expResScale_default_),
342 label_(label_default_),
354 template<
class ScalarType,
class MV,
class OP>
358 if (params_ == Teuchos::null) {
367 maxIters_ = params->
get(
"Maximum Iterations",maxIters_default_);
370 params_->set(
"Maximum Iterations", maxIters_);
371 if (maxIterTest_!=Teuchos::null)
372 maxIterTest_->setMaxIters( maxIters_ );
377 std::string tempLabel = params->
get(
"Timer Label", label_default_);
380 if (tempLabel != label_) {
382 params_->set(
"Timer Label", label_);
383 std::string solveLabel = label_ +
": PseudoBlockTFQMRSolMgr total solve time";
384 #ifdef BELOS_TEUCHOS_TIME_MONITOR
392 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
393 verbosity_ = params->
get(
"Verbosity", verbosity_default_);
395 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
399 params_->set(
"Verbosity", verbosity_);
400 if (printer_ != Teuchos::null)
401 printer_->setVerbosity(verbosity_);
406 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
407 outputStyle_ = params->
get(
"Output Style", outputStyle_default_);
409 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
413 params_->set(
"Output Style", outputStyle_);
419 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
422 params_->set(
"Output Stream", outputStream_);
423 if (printer_ != Teuchos::null)
424 printer_->setOStream( outputStream_ );
430 outputFreq_ = params->
get(
"Output Frequency", outputFreq_default_);
434 params_->set(
"Output Frequency", outputFreq_);
435 if (outputTest_ != Teuchos::null)
436 outputTest_->setOutputFrequency( outputFreq_ );
440 if (printer_ == Teuchos::null) {
445 if (params->
isParameter(
"Convergence Tolerance")) {
446 if (params->
isType<MagnitudeType> (
"Convergence Tolerance")) {
447 convtol_ = params->
get (
"Convergence Tolerance",
455 params_->set(
"Convergence Tolerance", convtol_);
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",
471 params_->set(
"Implicit Tolerance Scale Factor", impTolScale_);
475 if (params->
isParameter(
"Implicit Residual Scaling")) {
476 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params,
"Implicit Residual Scaling" );
479 if (impResScale_ != tempImpResScale) {
480 impResScale_ = tempImpResScale;
483 params_->set(
"Implicit Residual Scaling", impResScale_);
488 if (params->
isParameter(
"Explicit Residual Scaling")) {
489 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params,
"Explicit Residual Scaling" );
492 if (expResScale_ != tempExpResScale) {
493 expResScale_ = tempExpResScale;
496 params_->set(
"Explicit Residual Scaling", expResScale_);
501 if (params->
isParameter(
"Explicit Residual Test")) {
502 expResTest_ = Teuchos::getParameter<bool>( *params,
"Explicit Residual Test" );
505 params_->set(
"Explicit Residual Test", expResTest_);
506 if (expConvTest_ == Teuchos::null) {
513 defQuorum_ = params->
get(
"Deflation Quorum", defQuorum_);
514 params_->set (
"Deflation Quorum", defQuorum_);
515 if (! impConvTest_.is_null ()) {
516 impConvTest_->setQuorum (defQuorum_);
518 if (! expConvTest_.is_null ()) {
519 expConvTest_->setQuorum (defQuorum_);
524 if (timerSolve_ == Teuchos::null) {
525 std::string solveLabel = label_ +
": PseudoBlockTFQMRSolMgr total solve time";
526 #ifdef BELOS_TEUCHOS_TIME_MONITOR
537 template<
class ScalarType,
class MV,
class OP>
550 Teuchos::rcp(
new StatusTestGenResNorm_t( impTolScale_*convtol_, defQuorum_ ) );
552 impConvTest_ = tmpImpConvTest;
556 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
557 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
559 expConvTest_ = tmpExpConvTest;
562 convTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
568 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
570 impConvTest_ = tmpImpConvTest;
573 expConvTest_ = impConvTest_;
574 convTest_ = impConvTest_;
576 sTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
580 StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
584 std::string solverDesc =
" Pseudo Block TFQMR ";
585 outputTest_->setSolverDesc( solverDesc );
595 template<
class ScalarType,
class MV,
class OP>
608 "The relative residual tolerance that needs to be achieved by the\n"
609 "iterative solver in order for the linear system to be declared converged.");
611 "The scale factor used by the implicit residual test when explicit residual\n"
612 "testing is used. May enable faster convergence when TFQMR bound is too loose.");
613 pl->
set(
"Maximum Iterations", static_cast<int>(maxIters_default_),
614 "The maximum number of block iterations allowed for each\n"
615 "set of RHS solved.");
616 pl->
set(
"Verbosity", static_cast<int>(verbosity_default_),
617 "What type(s) of solver information should be outputted\n"
618 "to the output stream.");
619 pl->
set(
"Output Style", static_cast<int>(outputStyle_default_),
620 "What style is used for the solver information outputted\n"
621 "to the output stream.");
622 pl->
set(
"Output Frequency", static_cast<int>(outputFreq_default_),
623 "How often convergence information should be outputted\n"
624 "to the output stream.");
625 pl->
set(
"Deflation Quorum", static_cast<int>(defQuorum_default_),
626 "The number of linear systems that need to converge before they are deflated.");
628 "A reference-counted pointer to the output stream where all\n"
629 "solver output is sent.");
630 pl->
set(
"Explicit Residual Test", static_cast<bool>(expResTest_default_),
631 "Whether the explicitly computed residual should be used in the convergence test.");
632 pl->
set(
"Implicit Residual Scaling", static_cast<const char *>(impResScale_default_),
633 "The type of scaling used in the implicit residual convergence test.");
634 pl->
set(
"Explicit Residual Scaling", static_cast<const char *>(expResScale_default_),
635 "The type of scaling used in the explicit residual convergence test.");
636 pl->
set(
"Timer Label", static_cast<const char *>(label_default_),
637 "The string to use as a prefix for the timer labels.");
645 template<
class ScalarType,
class MV,
class OP>
652 setParameters(Teuchos::parameterList(*getValidParameters()));
656 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not a valid object.");
659 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
663 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
668 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
669 int numCurrRHS = numRHS2Solve;
671 std::vector<int> currIdx( numRHS2Solve );
672 for (
int i=0; i<numRHS2Solve; ++i) {
673 currIdx[i] = startPtr+i;
677 problem_->setLSIndex( currIdx );
684 outputTest_->reset();
687 bool isConverged =
true;
697 #ifdef BELOS_TEUCHOS_TIME_MONITOR
701 while ( numRHS2Solve > 0 ) {
704 std::vector<int> convRHSIdx;
705 std::vector<int> currRHSIdx( currIdx );
706 currRHSIdx.resize(numCurrRHS);
709 block_tfqmr_iter->resetNumIters();
712 outputTest_->resetNumCalls();
715 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx );
720 block_tfqmr_iter->initializeTFQMR(newstate);
726 block_tfqmr_iter->iterate();
733 if ( convTest_->getStatus() ==
Passed ) {
736 std::vector<int> convIdx = expConvTest_->convIndices();
740 if (convIdx.size() == currRHSIdx.size())
744 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
747 problem_->setCurrLS();
751 std::vector<int> unconvIdx( currRHSIdx.size() );
752 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
754 for (
unsigned int j=0; j<convIdx.size(); ++j) {
755 if (currRHSIdx[i] == convIdx[j]) {
762 currRHSIdx[have++] = currRHSIdx[i];
765 unconvIdx.resize(have);
766 currRHSIdx.resize(have);
769 problem_->setLSIndex( currRHSIdx );
779 defstate.
Rtilde = MVT::CloneView( *currentState.
Rtilde, unconvIdx);
780 defstate.
U = MVT::CloneView( *currentState.
U, unconvIdx );
781 defstate.
AU = MVT::CloneView( *currentState.
AU, unconvIdx );
782 defstate.
V = MVT::CloneView( *currentState.
V, unconvIdx );
783 defstate.
W = MVT::CloneView( *currentState.
W, unconvIdx );
784 defstate.
D = MVT::CloneView( *currentState.
D, unconvIdx );
787 for (std::vector<int>::iterator uIter = unconvIdx.begin(); uIter != unconvIdx.end(); uIter++)
789 defstate.
alpha.push_back( currentState.
alpha[ *uIter ] );
790 defstate.
eta.push_back( currentState.
eta[ *uIter ] );
791 defstate.
rho.push_back( currentState.
rho[ *uIter ] );
792 defstate.
tau.push_back( currentState.
tau[ *uIter ] );
793 defstate.
theta.push_back( currentState.
theta[ *uIter ] );
796 block_tfqmr_iter->initializeTFQMR(defstate);
803 else if ( maxIterTest_->getStatus() ==
Passed ) {
818 "Belos::PseudoBlockTFQMRSolMgr::solve(): Invalid return from PseudoBlockTFQMRIter::iterate().");
821 catch (
const std::exception &e) {
822 printer_->stream(
Errors) <<
"Error! Caught std::exception in PseudoBlockTFQMRIter::iterate() at iteration "
823 << block_tfqmr_iter->getNumIters() << std::endl
824 << e.what() << std::endl;
830 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
833 problem_->setCurrLS();
836 startPtr += numCurrRHS;
837 numRHS2Solve -= numCurrRHS;
838 if ( numRHS2Solve > 0 ) {
839 numCurrRHS = numRHS2Solve;
840 currIdx.resize( numCurrRHS );
841 for (
int i=0; i<numCurrRHS; ++i)
842 { currIdx[i] = startPtr+i; }
845 if (defQuorum_ > numCurrRHS) {
846 if (impConvTest_ != Teuchos::null)
847 impConvTest_->setQuorum( numCurrRHS );
848 if (expConvTest_ != Teuchos::null)
849 expConvTest_->setQuorum( numCurrRHS );
853 problem_->setLSIndex( currIdx );
856 currIdx.resize( numRHS2Solve );
867 #ifdef BELOS_TEUCHOS_TIME_MONITOR
876 numIters_ = maxIterTest_->getNumIters();
889 const std::vector<MagnitudeType>* pTestValues = NULL;
891 pTestValues = expConvTest_->getTestValue();
892 if (pTestValues == NULL || pTestValues->size() < 1) {
893 pTestValues = impConvTest_->getTestValue();
898 pTestValues = impConvTest_->getTestValue();
901 "Belos::PseudoBlockTFQMRSolMgr::solve(): The implicit convergence test's "
902 "getTestValue() method returned NULL. Please report this bug to the "
903 "Belos developers.");
905 "Belos::TMQMRSolMgr::solve(): The implicit convergence test's "
906 "getTestValue() method returned a vector of length zero. Please report "
907 "this bug to the Belos developers.");
912 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
922 template<
class ScalarType,
class MV,
class OP>
925 std::ostringstream oss;
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Collection of types and exceptions used within the Belos solvers.
PseudoBlockTFQMRSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate...
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Class which manages the output and verbosity of the Belos solvers.
bool is_null(const boost::shared_ptr< T > &p)
Teuchos::RCP< const MV > Rtilde
This class implements the preconditioned transpose-free QMR algorithm for solving non-Hermitian linea...
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Structure to contain pointers to PseudoBlockTFQMRIter state variables.
bool is_null(const std::shared_ptr< T > &p)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
An implementation of StatusTestResNorm using a family of residual norms.
Teuchos::RCP< const MV > AU
PseudoBlockTFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
static const double convTol
Default convergence tolerance.
Belos::StatusTest class for specifying a maximum number of iterations.
std::vector< ScalarType > alpha
static std::string name()
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
A factory class for generating StatusTestOutput objects.
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
bool isParameter(const std::string &name) const
A Belos::StatusTest class for specifying a maximum number of iterations.
PseudoBlockTFQMRSolMgr()
Empty constructor for PseudoBlockTFQMRSolMgr. This constructor takes no arguments and sets the defaul...
PseudoBlockTFQMRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
ResetType
How to reset the solver.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Pure virtual base class which describes the basic interface for a solver manager. ...
bool isLOADetected() const override
Whether loss of accuracy was detected during the last solve() invocation.
static const double impTolScale
"Implicit Tolerance Scale Factor"
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
std::string description() const override
Method to return description of the pseudo-block TFQMR solver manager.
PseudoBlockTFQMRSolMgrOrthoFailure(const std::string &what_arg)
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
A linear system to solve, and its associated information.
std::vector< MagnitudeType > theta
Class which describes the linear problem to be solved by the iterative solver.
The Belos::PseudoBlockTFQMRSolMgr provides a powerful and fully-featured solver manager over the pseu...
Teuchos::RCP< const MV > D
ReturnType
Whether the Belos solve converged for all linear systems.
std::vector< ScalarType > eta
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().
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Teuchos::RCP< const MV > U
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
std::vector< MagnitudeType > tau
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Teuchos::RCP< const MV > W
The current residual basis.
bool isType(const std::string &name) const
A class for extending the status testing capabilities of Belos via logical combinations.
virtual ~PseudoBlockTFQMRSolMgr()
Destructor.
std::vector< ScalarType > rho
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
Default parameters common to most Belos solvers.
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< const MV > V
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms) override
Set the parameters the solver manager should use to solve the linear problem.