10 #ifndef BELOS_PSEUDO_BLOCK_TFQMR_SOLMGR_HPP
11 #define BELOS_PSEUDO_BLOCK_TFQMR_SOLMGR_HPP
29 #ifdef BELOS_TEUCHOS_TIME_MONITOR
64 template<
class ScalarType,
class MV,
class OP>
262 template<
class ScalarType,
class MV,
class OP>
264 outputStream_(Teuchos::rcpFromRef(std::cout)),
267 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
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_),
284 template<
class ScalarType,
class MV,
class OP>
289 outputStream_(Teuchos::rcpFromRef(std::cout)),
292 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
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_),
314 template<
class ScalarType,
class MV,
class OP>
327 maxIters_ = params->
get(
"Maximum Iterations",maxIters_default_);
330 params_->set(
"Maximum Iterations", maxIters_);
332 maxIterTest_->setMaxIters( maxIters_ );
337 std::string tempLabel = params->
get(
"Timer Label", label_default_);
340 if (tempLabel != label_) {
342 params_->set(
"Timer Label", label_);
343 std::string solveLabel = label_ +
": PseudoBlockTFQMRSolMgr total solve time";
344 #ifdef BELOS_TEUCHOS_TIME_MONITOR
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_);
361 printer_->setVerbosity(verbosity_);
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_);
379 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
382 params_->set(
"Output Stream", outputStream_);
384 printer_->setOStream( outputStream_ );
390 outputFreq_ = params->
get(
"Output Frequency", outputFreq_default_);
394 params_->set(
"Output Frequency", outputFreq_);
396 outputTest_->setOutputFrequency( outputFreq_ );
405 if (params->
isParameter(
"Convergence Tolerance")) {
407 convtol_ = params->
get (
"Convergence Tolerance",
415 params_->set(
"Convergence Tolerance", convtol_);
419 if (params->
isParameter(
"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" );
439 if (impResScale_ != tempImpResScale) {
440 impResScale_ = tempImpResScale;
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" );
452 if (expResScale_ != tempExpResScale) {
453 expResScale_ = tempExpResScale;
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_);
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_);
485 std::string solveLabel = label_ +
": PseudoBlockTFQMRSolMgr total solve time";
486 #ifdef BELOS_TEUCHOS_TIME_MONITOR
497 template<
class ScalarType,
class MV,
class OP>
510 Teuchos::rcp(
new StatusTestGenResNorm_t( impTolScale_*convtol_, defQuorum_ ) );
512 impConvTest_ = tmpImpConvTest;
516 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
517 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
519 expConvTest_ = tmpExpConvTest;
522 convTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
528 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
530 impConvTest_ = tmpImpConvTest;
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 ";
545 outputTest_->setSolverDesc( solverDesc );
555 template<
class ScalarType,
class MV,
class OP>
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.");
605 template<
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()) );
629 int numCurrRHS = numRHS2Solve;
631 std::vector<int> currIdx( numRHS2Solve );
632 for (
int i=0; i<numRHS2Solve; ++i) {
633 currIdx[i] = startPtr+i;
637 problem_->setLSIndex( currIdx );
644 outputTest_->reset();
647 bool isConverged =
true;
657 #ifdef BELOS_TEUCHOS_TIME_MONITOR
661 while ( numRHS2Solve > 0 ) {
664 std::vector<int> convRHSIdx;
665 std::vector<int> currRHSIdx( currIdx );
666 currRHSIdx.resize(numCurrRHS);
669 block_tfqmr_iter->resetNumIters();
672 outputTest_->resetNumCalls();
675 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx );
680 block_tfqmr_iter->initializeTFQMR(newstate);
686 block_tfqmr_iter->iterate();
693 if ( convTest_->getStatus() ==
Passed ) {
696 std::vector<int> convIdx = expConvTest_->convIndices();
700 if (convIdx.size() == currRHSIdx.size())
704 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
707 problem_->setCurrLS();
711 std::vector<int> unconvIdx( currRHSIdx.size() );
712 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
714 for (
unsigned int j=0; j<convIdx.size(); ++j) {
715 if (currRHSIdx[i] == convIdx[j]) {
722 currRHSIdx[have++] = currRHSIdx[i];
725 unconvIdx.resize(have);
726 currRHSIdx.resize(have);
729 problem_->setLSIndex( currRHSIdx );
739 defstate.
Rtilde = MVT::CloneView( *currentState.
Rtilde, unconvIdx);
740 defstate.
U = MVT::CloneView( *currentState.
U, unconvIdx );
741 defstate.
AU = MVT::CloneView( *currentState.
AU, unconvIdx );
742 defstate.
V = MVT::CloneView( *currentState.
V, unconvIdx );
743 defstate.
W = MVT::CloneView( *currentState.
W, unconvIdx );
744 defstate.
D = MVT::CloneView( *currentState.
D, unconvIdx );
747 for (std::vector<int>::iterator uIter = unconvIdx.begin(); uIter != unconvIdx.end(); uIter++)
749 defstate.
alpha.push_back( currentState.
alpha[ *uIter ] );
750 defstate.
eta.push_back( currentState.
eta[ *uIter ] );
751 defstate.
rho.push_back( currentState.
rho[ *uIter ] );
752 defstate.
tau.push_back( currentState.
tau[ *uIter ] );
753 defstate.
theta.push_back( currentState.
theta[ *uIter ] );
756 block_tfqmr_iter->initializeTFQMR(defstate);
763 else if ( maxIterTest_->getStatus() ==
Passed ) {
778 "Belos::PseudoBlockTFQMRSolMgr::solve(): Invalid return from PseudoBlockTFQMRIter::iterate().");
783 achievedTol_ = MT::one();
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 "
792 << block_tfqmr_iter->getNumIters() << std::endl
793 << e.what() << std::endl;
799 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
802 problem_->setCurrLS();
805 startPtr += numCurrRHS;
806 numRHS2Solve -= numCurrRHS;
807 if ( numRHS2Solve > 0 ) {
808 numCurrRHS = numRHS2Solve;
809 currIdx.resize( numCurrRHS );
810 for (
int i=0; i<numCurrRHS; ++i)
811 { currIdx[i] = startPtr+i; }
814 if (defQuorum_ > numCurrRHS) {
816 impConvTest_->setQuorum( numCurrRHS );
818 expConvTest_->setQuorum( numCurrRHS );
822 problem_->setLSIndex( currIdx );
825 currIdx.resize( numRHS2Solve );
836 #ifdef BELOS_TEUCHOS_TIME_MONITOR
845 numIters_ = maxIterTest_->getNumIters();
858 const std::vector<MagnitudeType>* pTestValues = NULL;
860 pTestValues = expConvTest_->getTestValue();
861 if (pTestValues == NULL || pTestValues->size() < 1) {
862 pTestValues = impConvTest_->getTestValue();
867 pTestValues = impConvTest_->getTestValue();
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.");
881 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
891 template<
class ScalarType,
class MV,
class OP>
894 std::ostringstream oss;
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
static constexpr const char * expResScale_default_
Collection of types and exceptions used within the Belos solvers.
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.
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< StatusTest< ScalarType, MV, OP > > convTest_
T & get(ParameterList &l, const std::string &name)
Structure to contain pointers to PseudoBlockTFQMRIter state variables.
bool is_null(const std::shared_ptr< T > &p)
Teuchos::RCP< Teuchos::Time > timerSolve_
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...
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
static constexpr int defQuorum_default_
An implementation of StatusTestResNorm using a family of residual norms.
static constexpr int verbosity_default_
Teuchos::RCP< const MV > AU
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static constexpr int outputStyle_default_
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
MagnitudeType impTolScale_
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
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. ...
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)
static constexpr const char * impResScale_default_
std::string description() const override
Method to return description of the pseudo-block TFQMR solver manager.
OperatorTraits< ScalarType, MV, OP > OPT
ReturnType solve() override
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.
std::vector< MagnitudeType > theta
Class which describes the linear problem to be solved by the iterative solver.
static constexpr bool expResTest_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_
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
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > expConvTest_
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.
Teuchos::RCP< Teuchos::ParameterList > params_
std::vector< MagnitudeType > tau
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
static constexpr int outputFreq_default_
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.
Teuchos::RCP< const MV > W
The current residual basis.
bool isType(const std::string &name) const
static constexpr const char * label_default_
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.
Teuchos::RCP< OutputManager< ScalarType > > printer_
Default parameters common to most Belos solvers.
Teuchos::ScalarTraits< MagnitudeType > MT
MagnitudeType achievedTol_
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< const MV > V
static constexpr int maxIters_default_
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms) override
Set the parameters the solver manager should use to solve the linear problem.
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_