42 #ifndef BELOS_TFQMR_SOLMGR_HPP
43 #define BELOS_TFQMR_SOLMGR_HPP
61 #ifdef BELOS_TEUCHOS_TIME_MONITOR
103 template<
class ScalarType,
class MV,
class OP>
169 return Teuchos::tuple(timerSolve_);
252 bool checkStatusTest();
272 static const MagnitudeType convtol_default_;
273 static const int maxIters_default_;
274 static const bool expResTest_default_;
275 static const int verbosity_default_;
276 static const int outputStyle_default_;
277 static const int outputFreq_default_;
278 static const std::string impResScale_default_;
279 static const std::string expResScale_default_;
280 static const std::string label_default_;
284 MagnitudeType convtol_, achievedTol_;
285 int maxIters_, numIters_;
286 int verbosity_, outputStyle_, outputFreq_;
289 std::string impResScale_, expResScale_;
296 bool isSet_, isSTSet_;
301 template<
class ScalarType,
class MV,
class OP>
302 const typename TFQMRSolMgr<ScalarType,MV,OP>::MagnitudeType TFQMRSolMgr<ScalarType,MV,OP>::convtol_default_ = 1e-8;
304 template<
class ScalarType,
class MV,
class OP>
305 const int TFQMRSolMgr<ScalarType,MV,OP>::maxIters_default_ = 1000;
307 template<
class ScalarType,
class MV,
class OP>
308 const bool TFQMRSolMgr<ScalarType,MV,OP>::expResTest_default_ =
false;
310 template<
class ScalarType,
class MV,
class OP>
311 const int TFQMRSolMgr<ScalarType,MV,OP>::verbosity_default_ =
Belos::Errors;
313 template<
class ScalarType,
class MV,
class OP>
314 const int TFQMRSolMgr<ScalarType,MV,OP>::outputStyle_default_ =
Belos::General;
316 template<
class ScalarType,
class MV,
class OP>
317 const int TFQMRSolMgr<ScalarType,MV,OP>::outputFreq_default_ = -1;
319 template<
class ScalarType,
class MV,
class OP>
320 const std::string TFQMRSolMgr<ScalarType,MV,OP>::impResScale_default_ =
"Norm of Preconditioned Initial Residual";
322 template<
class ScalarType,
class MV,
class OP>
323 const std::string TFQMRSolMgr<ScalarType,MV,OP>::expResScale_default_ =
"Norm of Initial Residual";
325 template<
class ScalarType,
class MV,
class OP>
326 const std::string TFQMRSolMgr<ScalarType,MV,OP>::label_default_ =
"Belos";
328 template<
class ScalarType,
class MV,
class OP>
333 template<
class ScalarType,
class MV,
class OP>
335 outputStream_(outputStream_default_),
336 convtol_(convtol_default_),
337 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
338 maxIters_(maxIters_default_),
340 verbosity_(verbosity_default_),
341 outputStyle_(outputStyle_default_),
342 outputFreq_(outputFreq_default_),
344 expResTest_(expResTest_default_),
345 impResScale_(impResScale_default_),
346 expResScale_(expResScale_default_),
347 label_(label_default_),
354 template<
class ScalarType,
class MV,
class OP>
359 outputStream_(outputStream_default_),
360 convtol_(convtol_default_),
361 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
362 maxIters_(maxIters_default_),
364 verbosity_(verbosity_default_),
365 outputStyle_(outputStyle_default_),
366 outputFreq_(outputFreq_default_),
368 expResTest_(expResTest_default_),
369 impResScale_(impResScale_default_),
370 expResScale_(expResScale_default_),
371 label_(label_default_),
383 template<
class ScalarType,
class MV,
class OP>
387 if (params_ == Teuchos::null) {
396 maxIters_ = params->
get(
"Maximum Iterations",maxIters_default_);
399 params_->set(
"Maximum Iterations", maxIters_);
400 if (maxIterTest_!=Teuchos::null)
401 maxIterTest_->setMaxIters( maxIters_ );
406 blockSize_ = params->
get(
"Block Size",1);
408 "Belos::TFQMRSolMgr: \"Block Size\" must be 1.");
411 params_->set(
"Block Size", blockSize_);
416 std::string tempLabel = params->
get(
"Timer Label", label_default_);
419 if (tempLabel != label_) {
421 params_->set(
"Timer Label", label_);
422 std::string solveLabel = label_ +
": TFQMRSolMgr total solve time";
423 #ifdef BELOS_TEUCHOS_TIME_MONITOR
431 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
432 verbosity_ = params->
get(
"Verbosity", verbosity_default_);
434 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
438 params_->set(
"Verbosity", verbosity_);
439 if (printer_ != Teuchos::null)
440 printer_->setVerbosity(verbosity_);
445 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
446 outputStyle_ = params->
get(
"Output Style", outputStyle_default_);
448 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
452 params_->set(
"Output Style", outputStyle_);
458 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
461 params_->set(
"Output Stream", outputStream_);
462 if (printer_ != Teuchos::null)
463 printer_->setOStream( outputStream_ );
469 outputFreq_ = params->
get(
"Output Frequency", outputFreq_default_);
473 params_->set(
"Output Frequency", outputFreq_);
474 if (outputTest_ != Teuchos::null)
475 outputTest_->setOutputFrequency( outputFreq_ );
479 if (printer_ == Teuchos::null) {
484 if (params->
isParameter(
"Convergence Tolerance")) {
485 convtol_ = params->
get(
"Convergence Tolerance",convtol_default_);
488 params_->set(
"Convergence Tolerance", convtol_);
489 if (impConvTest_ != Teuchos::null)
490 impConvTest_->setTolerance( convtol_ );
491 if (expConvTest_ != Teuchos::null)
492 expConvTest_->setTolerance( convtol_ );
496 if (params->
isParameter(
"Implicit Residual Scaling")) {
497 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params,
"Implicit Residual Scaling" );
500 if (impResScale_ != tempImpResScale) {
502 impResScale_ = tempImpResScale;
505 params_->set(
"Implicit Residual Scaling", impResScale_);
506 if (impConvTest_ != Teuchos::null) {
510 catch (std::exception& e) {
518 if (params->
isParameter(
"Explicit Residual Scaling")) {
519 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params,
"Explicit Residual Scaling" );
522 if (expResScale_ != tempExpResScale) {
524 expResScale_ = tempExpResScale;
527 params_->set(
"Explicit Residual Scaling", expResScale_);
528 if (expConvTest_ != Teuchos::null) {
532 catch (std::exception& e) {
540 if (params->
isParameter(
"Explicit Residual Test")) {
541 expResTest_ = Teuchos::getParameter<bool>( *params,
"Explicit Residual Test" );
544 params_->set(
"Explicit Residual Test", expResTest_);
545 if (expConvTest_ == Teuchos::null) {
551 if (timerSolve_ == Teuchos::null) {
552 std::string solveLabel = label_ +
": TFQMRSolMgr total solve time";
553 #ifdef BELOS_TEUCHOS_TIME_MONITOR
564 template<
class ScalarType,
class MV,
class OP>
579 impConvTest_ = tmpImpConvTest;
584 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
586 expConvTest_ = tmpExpConvTest;
589 convTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
597 impConvTest_ = tmpImpConvTest;
600 expConvTest_ = impConvTest_;
601 convTest_ = impConvTest_;
603 sTest_ =
Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
607 StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
611 std::string solverDesc =
" TFQMR ";
612 outputTest_->setSolverDesc( solverDesc );
622 template<
class ScalarType,
class MV,
class OP>
631 pl->
set(
"Convergence Tolerance", convtol_default_,
632 "The relative residual tolerance that needs to be achieved by the\n"
633 "iterative solver in order for the linear system to be declared converged.");
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(
"Output Stream", outputStream_default_,
647 "A reference-counted pointer to the output stream where all\n"
648 "solver output is sent.");
649 pl->
set(
"Explicit Residual Test", expResTest_default_,
650 "Whether the explicitly computed residual should be used in the convergence test.");
651 pl->
set(
"Implicit Residual Scaling", impResScale_default_,
652 "The type of scaling used in the implicit residual convergence test.");
653 pl->
set(
"Explicit Residual Scaling", expResScale_default_,
654 "The type of scaling used in the explicit residual convergence test.");
655 pl->
set(
"Timer Label", label_default_,
656 "The string to use as a prefix for the timer labels.");
665 template<
class ScalarType,
class MV,
class OP>
672 setParameters(Teuchos::parameterList(*getValidParameters()));
676 "Belos::TFQMRSolMgr::solve(): Linear problem is not a valid object.");
679 "Belos::TFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
683 "Belos::TFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
688 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
689 int numCurrRHS = blockSize_;
691 std::vector<int> currIdx, currIdx2;
694 currIdx.resize( blockSize_ );
695 currIdx2.resize( blockSize_ );
696 for (
int i=0; i<numCurrRHS; ++i)
697 { currIdx[i] = startPtr+i; currIdx2[i]=i; }
700 problem_->setLSIndex( currIdx );
705 plist.
set(
"Block Size",blockSize_);
708 outputTest_->reset();
711 bool isConverged =
true;
721 #ifdef BELOS_TEUCHOS_TIME_MONITOR
725 while ( numRHS2Solve > 0 ) {
728 std::vector<int> convRHSIdx;
729 std::vector<int> currRHSIdx( currIdx );
730 currRHSIdx.resize(numCurrRHS);
733 tfqmr_iter->resetNumIters();
736 outputTest_->resetNumCalls();
739 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx );
744 tfqmr_iter->initializeTFQMR(newstate);
750 tfqmr_iter->iterate();
757 if ( convTest_->getStatus() ==
Passed ) {
766 else if ( maxIterTest_->getStatus() ==
Passed ) {
781 "Belos::TFQMRSolMgr::solve(): Invalid return from TFQMRIter::iterate().");
784 catch (
const std::exception &e) {
785 printer_->stream(
Errors) <<
"Error! Caught std::exception in TFQMRIter::iterate() at iteration "
786 << tfqmr_iter->getNumIters() << std::endl
787 << e.what() << std::endl;
793 problem_->setCurrLS();
796 startPtr += numCurrRHS;
797 numRHS2Solve -= numCurrRHS;
798 if ( numRHS2Solve > 0 ) {
799 numCurrRHS = blockSize_;
801 currIdx.resize( blockSize_ );
802 currIdx2.resize( blockSize_ );
803 for (
int i=0; i<numCurrRHS; ++i)
804 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
806 problem_->setLSIndex( currIdx );
809 tfqmr_iter->setBlockSize( blockSize_ );
812 currIdx.resize( numRHS2Solve );
823 #ifdef BELOS_TEUCHOS_TIME_MONITOR
832 numIters_ = maxIterTest_->getNumIters();
845 const std::vector<MagnitudeType>* pTestValues = NULL;
847 pTestValues = expConvTest_->getTestValue();
848 if (pTestValues == NULL || pTestValues->size() < 1) {
849 pTestValues = impConvTest_->getTestValue();
854 pTestValues = impConvTest_->getTestValue();
857 "Belos::TFQMRSolMgr::solve(): The implicit convergence test's "
858 "getTestValue() method returned NULL. Please report this bug to the "
859 "Belos developers.");
861 "Belos::TMQMRSolMgr::solve(): The implicit convergence test's "
862 "getTestValue() method returned a vector of length zero. Please report "
863 "this bug to the Belos developers.");
868 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
878 template<
class ScalarType,
class MV,
class OP>
881 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.
This class implements the preconditioned transpose-free QMR algorithm for solving non-Hermitian linea...
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver manager should use to solve the linear problem.
Class which manages the output and verbosity of the Belos solvers.
bool is_null(const boost::shared_ptr< T > &p)
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
ScaleType
The type of scaling to use on the residual norm value.
std::string description() const
Method to return description of the TFQMR solver manager.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
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)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
An implementation of StatusTestResNorm using a family of residual norms.
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
Teuchos::RCP< const MV > R
The current residual basis.
Belos::StatusTest class for specifying a maximum number of iterations.
static std::string name()
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
A factory class for generating StatusTestOutput objects.
TFQMRSolMgrOrthoFailure(const std::string &what_arg)
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="")
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.
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. ...
A linear system to solve, and its associated information.
Structure to contain pointers to TFQMRIter state variables.
Class which describes the linear problem to be solved by the iterative solver.
TFQMRSolMgr()
Empty constructor for TFQMRSolMgr. This constructor takes no arguments and sets the default values fo...
virtual ~TFQMRSolMgr()
Destructor.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
ReturnType
Whether the Belos solve converged for all linear systems.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
The Belos::TFQMRSolMgr provides a powerful and fully-featured solver manager over the TFQMR linear so...
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
bool isLOADetected() const
Whether loss of accuracy was detected during the last solve() invocation.
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
A class for extending the status testing capabilities of Belos via logical combinations.
TFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
Class which defines basic traits for the operator type.
TFQMRSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate orthonorma...
int getNumIters() const
Get the iteration count for the most recent call to solve().
Parent class to all Belos exceptions.
TFQMRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i.e.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
Belos header file which uses auto-configuration information to include necessary C++ headers...
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.