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>
302 template<
class ScalarType,
class MV,
class OP>
305 template<
class ScalarType,
class MV,
class OP>
308 template<
class ScalarType,
class MV,
class OP>
311 template<
class ScalarType,
class MV,
class OP>
314 template<
class ScalarType,
class MV,
class OP>
317 template<
class ScalarType,
class MV,
class OP>
320 template<
class ScalarType,
class MV,
class OP>
323 template<
class ScalarType,
class MV,
class OP>
326 template<
class ScalarType,
class MV,
class OP>
329 template<
class ScalarType,
class MV,
class OP>
332 template<
class ScalarType,
class MV,
class OP>
335 template<
class ScalarType,
class MV,
class OP>
340 template<
class ScalarType,
class MV,
class OP>
342 outputStream_(outputStream_default_),
343 convtol_(convtol_default_),
344 impTolScale_(impTolScale_default_),
345 achievedTol_(
Teuchos::ScalarTraits<typename
Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
346 maxIters_(maxIters_default_),
348 verbosity_(verbosity_default_),
349 outputStyle_(outputStyle_default_),
350 outputFreq_(outputFreq_default_),
351 defQuorum_(defQuorum_default_),
352 expResTest_(expResTest_default_),
353 impResScale_(impResScale_default_),
354 expResScale_(expResScale_default_),
355 label_(label_default_),
362 template<
class ScalarType,
class MV,
class OP>
367 outputStream_(outputStream_default_),
368 convtol_(convtol_default_),
369 impTolScale_(impTolScale_default_),
370 achievedTol_(
Teuchos::ScalarTraits<typename
Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
371 maxIters_(maxIters_default_),
373 verbosity_(verbosity_default_),
374 outputStyle_(outputStyle_default_),
375 outputFreq_(outputFreq_default_),
376 defQuorum_(defQuorum_default_),
377 expResTest_(expResTest_default_),
378 impResScale_(impResScale_default_),
379 expResScale_(expResScale_default_),
380 label_(label_default_),
392 template<
class ScalarType,
class MV,
class OP>
396 if (params_ == Teuchos::null) {
405 maxIters_ = params->
get(
"Maximum Iterations",maxIters_default_);
408 params_->set(
"Maximum Iterations", maxIters_);
409 if (maxIterTest_!=Teuchos::null)
410 maxIterTest_->setMaxIters( maxIters_ );
415 std::string tempLabel = params->
get(
"Timer Label", label_default_);
418 if (tempLabel != label_) {
420 params_->set(
"Timer Label", label_);
421 std::string solveLabel = label_ +
": PseudoBlockTFQMRSolMgr total solve time";
422 #ifdef BELOS_TEUCHOS_TIME_MONITOR 430 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
431 verbosity_ = params->
get(
"Verbosity", verbosity_default_);
433 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
437 params_->set(
"Verbosity", verbosity_);
438 if (printer_ != Teuchos::null)
439 printer_->setVerbosity(verbosity_);
444 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
445 outputStyle_ = params->
get(
"Output Style", outputStyle_default_);
447 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
451 params_->set(
"Output Style", outputStyle_);
457 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
460 params_->set(
"Output Stream", outputStream_);
461 if (printer_ != Teuchos::null)
462 printer_->setOStream( outputStream_ );
468 outputFreq_ = params->
get(
"Output Frequency", outputFreq_default_);
472 params_->set(
"Output Frequency", outputFreq_);
473 if (outputTest_ != Teuchos::null)
474 outputTest_->setOutputFrequency( outputFreq_ );
478 if (printer_ == Teuchos::null) {
483 if (params->
isParameter(
"Convergence Tolerance")) {
484 convtol_ = params->
get(
"Convergence Tolerance",convtol_default_);
487 params_->set(
"Convergence Tolerance", convtol_);
491 if (params->
isParameter(
"Implicit Tolerance Scale Factor")) {
492 impTolScale_ = params->
get(
"Implicit Tolerance Scale Factor",impTolScale_default_);
495 params_->set(
"Implicit Tolerance Scale Factor", impTolScale_);
499 if (params->
isParameter(
"Implicit Residual Scaling")) {
500 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params,
"Implicit Residual Scaling" );
503 if (impResScale_ != tempImpResScale) {
504 impResScale_ = tempImpResScale;
507 params_->set(
"Implicit Residual Scaling", impResScale_);
512 if (params->
isParameter(
"Explicit Residual Scaling")) {
513 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params,
"Explicit Residual Scaling" );
516 if (expResScale_ != tempExpResScale) {
517 expResScale_ = tempExpResScale;
520 params_->set(
"Explicit Residual Scaling", expResScale_);
525 if (params->
isParameter(
"Explicit Residual Test")) {
526 expResTest_ = Teuchos::getParameter<bool>( *params,
"Explicit Residual Test" );
529 params_->set(
"Explicit Residual Test", expResTest_);
530 if (expConvTest_ == Teuchos::null) {
537 defQuorum_ = params->
get(
"Deflation Quorum", defQuorum_);
538 params_->set (
"Deflation Quorum", defQuorum_);
539 if (! impConvTest_.is_null ()) {
540 impConvTest_->setQuorum (defQuorum_);
542 if (! expConvTest_.is_null ()) {
543 expConvTest_->setQuorum (defQuorum_);
548 if (timerSolve_ == Teuchos::null) {
549 std::string solveLabel = label_ +
": PseudoBlockTFQMRSolMgr total solve time";
550 #ifdef BELOS_TEUCHOS_TIME_MONITOR 561 template<
class ScalarType,
class MV,
class OP>
574 Teuchos::rcp(
new StatusTestGenResNorm_t( impTolScale_*convtol_, defQuorum_ ) );
576 impConvTest_ = tmpImpConvTest;
580 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
581 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
583 expConvTest_ = tmpExpConvTest;
586 convTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
592 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
594 impConvTest_ = tmpImpConvTest;
597 expConvTest_ = impConvTest_;
598 convTest_ = impConvTest_;
600 sTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
608 std::string solverDesc =
" Pseudo Block TFQMR ";
609 outputTest_->setSolverDesc( solverDesc );
619 template<
class ScalarType,
class MV,
class OP>
628 pl->
set(
"Convergence Tolerance", convtol_default_,
629 "The relative residual tolerance that needs to be achieved by the\n" 630 "iterative solver in order for the linear system to be declared converged.");
631 pl->
set(
"Implicit Tolerance Scale Factor", impTolScale_default_,
632 "The scale factor used by the implicit residual test when explicit residual\n" 633 "testing is used. May enable faster convergence when TFQMR bound is too loose.");
634 pl->
set(
"Maximum Iterations", maxIters_default_,
635 "The maximum number of block iterations allowed for each\n" 636 "set of RHS solved.");
637 pl->
set(
"Verbosity", verbosity_default_,
638 "What type(s) of solver information should be outputted\n" 639 "to the output stream.");
640 pl->
set(
"Output Style", outputStyle_default_,
641 "What style is used for the solver information outputted\n" 642 "to the output stream.");
643 pl->
set(
"Output Frequency", outputFreq_default_,
644 "How often convergence information should be outputted\n" 645 "to the output stream.");
646 pl->
set(
"Deflation Quorum", defQuorum_default_,
647 "The number of linear systems that need to converge before they are deflated.");
648 pl->
set(
"Output Stream", outputStream_default_,
649 "A reference-counted pointer to the output stream where all\n" 650 "solver output is sent.");
651 pl->
set(
"Explicit Residual Test", expResTest_default_,
652 "Whether the explicitly computed residual should be used in the convergence test.");
653 pl->
set(
"Implicit Residual Scaling", impResScale_default_,
654 "The type of scaling used in the implicit residual convergence test.");
655 pl->
set(
"Explicit Residual Scaling", expResScale_default_,
656 "The type of scaling used in the explicit residual convergence test.");
657 pl->
set(
"Timer Label", label_default_,
658 "The string to use as a prefix for the timer labels.");
667 template<
class ScalarType,
class MV,
class OP>
674 setParameters(Teuchos::parameterList(*getValidParameters()));
678 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not a valid object.");
681 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
685 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
690 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
691 int numCurrRHS = numRHS2Solve;
693 std::vector<int> currIdx( numRHS2Solve );
694 for (
int i=0; i<numRHS2Solve; ++i) {
695 currIdx[i] = startPtr+i;
699 problem_->setLSIndex( currIdx );
706 outputTest_->reset();
709 bool isConverged =
true;
719 #ifdef BELOS_TEUCHOS_TIME_MONITOR 723 while ( numRHS2Solve > 0 ) {
726 std::vector<int> convRHSIdx;
727 std::vector<int> currRHSIdx( currIdx );
728 currRHSIdx.resize(numCurrRHS);
731 block_tfqmr_iter->resetNumIters();
734 outputTest_->resetNumCalls();
737 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx );
742 block_tfqmr_iter->initializeTFQMR(newstate);
748 block_tfqmr_iter->iterate();
755 if ( convTest_->getStatus() ==
Passed ) {
758 std::vector<int> convIdx = expConvTest_->convIndices();
762 if (convIdx.size() == currRHSIdx.size())
766 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
769 problem_->setCurrLS();
773 std::vector<int> unconvIdx( currRHSIdx.size() );
774 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
776 for (
unsigned int j=0; j<convIdx.size(); ++j) {
777 if (currRHSIdx[i] == convIdx[j]) {
784 currRHSIdx[have++] = currRHSIdx[i];
787 unconvIdx.resize(have);
788 currRHSIdx.resize(have);
791 problem_->setLSIndex( currRHSIdx );
801 defstate.
Rtilde = MVT::CloneView( *currentState.
Rtilde, unconvIdx);
802 defstate.
U = MVT::CloneView( *currentState.
U, unconvIdx );
803 defstate.
AU = MVT::CloneView( *currentState.
AU, unconvIdx );
804 defstate.
V = MVT::CloneView( *currentState.
V, unconvIdx );
805 defstate.
W = MVT::CloneView( *currentState.
W, unconvIdx );
806 defstate.
D = MVT::CloneView( *currentState.
D, unconvIdx );
809 for (std::vector<int>::iterator uIter = unconvIdx.begin(); uIter != unconvIdx.end(); uIter++)
811 defstate.
alpha.push_back( currentState.
alpha[ *uIter ] );
812 defstate.
eta.push_back( currentState.
eta[ *uIter ] );
813 defstate.
rho.push_back( currentState.
rho[ *uIter ] );
814 defstate.
tau.push_back( currentState.
tau[ *uIter ] );
815 defstate.
theta.push_back( currentState.
theta[ *uIter ] );
818 block_tfqmr_iter->initializeTFQMR(defstate);
825 else if ( maxIterTest_->getStatus() ==
Passed ) {
840 "Belos::PseudoBlockTFQMRSolMgr::solve(): Invalid return from PseudoBlockTFQMRIter::iterate().");
843 catch (
const std::exception &e) {
844 printer_->stream(
Errors) <<
"Error! Caught std::exception in PseudoBlockTFQMRIter::iterate() at iteration " 845 << block_tfqmr_iter->getNumIters() << std::endl
846 << e.what() << std::endl;
852 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
855 problem_->setCurrLS();
858 startPtr += numCurrRHS;
859 numRHS2Solve -= numCurrRHS;
860 if ( numRHS2Solve > 0 ) {
861 numCurrRHS = numRHS2Solve;
862 currIdx.resize( numCurrRHS );
863 for (
int i=0; i<numCurrRHS; ++i)
864 { currIdx[i] = startPtr+i; }
867 if (defQuorum_ > numCurrRHS) {
868 if (impConvTest_ != Teuchos::null)
869 impConvTest_->setQuorum( numCurrRHS );
870 if (expConvTest_ != Teuchos::null)
871 expConvTest_->setQuorum( numCurrRHS );
875 problem_->setLSIndex( currIdx );
878 currIdx.resize( numRHS2Solve );
889 #ifdef BELOS_TEUCHOS_TIME_MONITOR 898 numIters_ = maxIterTest_->getNumIters();
911 const std::vector<MagnitudeType>* pTestValues = NULL;
913 pTestValues = expConvTest_->getTestValue();
914 if (pTestValues == NULL || pTestValues->size() < 1) {
915 pTestValues = impConvTest_->getTestValue();
920 pTestValues = impConvTest_->getTestValue();
923 "Belos::PseudoBlockTFQMRSolMgr::solve(): The implicit convergence test's " 924 "getTestValue() method returned NULL. Please report this bug to the " 925 "Belos developers.");
927 "Belos::TMQMRSolMgr::solve(): The implicit convergence test's " 928 "getTestValue() method returned a vector of length zero. Please report " 929 "this bug to the Belos developers.");
934 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
944 template<
class ScalarType,
class MV,
class OP>
947 std::ostringstream oss;
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
int getNumIters() const
Get the iteration count for the most recent call to solve().
Collection of types and exceptions used within the Belos solvers.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
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)
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.
Teuchos::RCP< std::ostream > outputStream_
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...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > convTest_
T & get(ParameterList &l, const std::string &name)
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)
Teuchos::RCP< Teuchos::Time > timerSolve_
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > impConvTest_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
A factory class for generating StatusTestOutput objects.
MultiVecTraits< ScalarType, MV > MVT
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
An implementation of StatusTestResNorm using a family of residual norms.
static const int defQuorum_default_
Teuchos::RCP< const MV > AU
PseudoBlockTFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
Belos::StatusTest class for specifying a maximum number of iterations.
std::vector< ScalarType > alpha
MagnitudeType impTolScale_
static std::string name()
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver manager should use to solve the linear problem.
std::string description() const
Method to return description of the pseudo-block TFQMR solver manager.
A factory class for generating StatusTestOutput objects.
static const std::string label_default_
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > sTest_
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. ...
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)
OperatorTraits< ScalarType, MV, OP > OPT
static const bool expResTest_default_
PseudoBlockTFQMRSolMgrOrthoFailure(const std::string &what_arg)
static const MagnitudeType convtol_default_
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Teuchos::ScalarTraits< ScalarType > SCT
A linear system to solve, and its associated information.
static const int verbosity_default_
std::vector< MagnitudeType > theta
Class which describes the linear problem to be solved by the iterative solver.
static const int outputFreq_default_
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
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
Teuchos::RCP< const MV > U
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > expConvTest_
static const int outputStyle_default_
Teuchos::RCP< Teuchos::ParameterList > params_
std::vector< MagnitudeType > tau
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.
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > outputTest_
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
static const int maxIters_default_
Teuchos::RCP< const MV > W
The current residual basis.
bool isLOADetected() const
Whether loss of accuracy was detected during the last solve() invocation.
A class for extending the status testing capabilities of Belos via logical combinations.
virtual ~PseudoBlockTFQMRSolMgr()
Destructor.
bool isParameter(const std::string &name) const
std::vector< ScalarType > rho
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
Teuchos::RCP< OutputManager< ScalarType > > printer_
static const std::string impResScale_default_
Teuchos::ScalarTraits< MagnitudeType > MT
MagnitudeType achievedTol_
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
Belos header file which uses auto-configuration information to include necessary C++ headers...
static const MagnitudeType impTolScale_default_
static const Teuchos::RCP< std::ostream > outputStream_default_
Teuchos::RCP< const MV > V
static const std::string expResScale_default_
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_