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" 103 template<
class ScalarType,
class MV,
class OP>
109 typedef Teuchos::ScalarTraits<ScalarType> SCT;
110 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
111 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
142 const Teuchos::RCP<Teuchos::ParameterList> &pl );
157 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
const;
168 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
169 return Teuchos::tuple(timerSolve_);
204 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms );
245 std::string description()
const;
252 bool checkStatusTest();
255 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
258 Teuchos::RCP<OutputManager<ScalarType> > printer_;
259 Teuchos::RCP<std::ostream> outputStream_;
262 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
263 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
264 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
265 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
266 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
269 Teuchos::RCP<Teuchos::ParameterList> params_;
272 static const MagnitudeType convtol_default_;
273 static const MagnitudeType impTolScale_default_;
274 static const int maxIters_default_;
275 static const bool expResTest_default_;
276 static const int verbosity_default_;
277 static const int outputStyle_default_;
278 static const int outputFreq_default_;
279 static const int defQuorum_default_;
280 static const std::string impResScale_default_;
281 static const std::string expResScale_default_;
282 static const std::string label_default_;
283 static const Teuchos::RCP<std::ostream> outputStream_default_;
286 MagnitudeType convtol_, impTolScale_, achievedTol_;
287 int maxIters_, numIters_;
288 int verbosity_, outputStyle_, outputFreq_, defQuorum_;
290 std::string impResScale_, expResScale_;
294 Teuchos::RCP<Teuchos::Time> timerSolve_;
297 bool isSet_, isSTSet_;
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>
365 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
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_),
384 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
387 if ( !is_null(pl) ) {
392 template<
class ScalarType,
class MV,
class OP>
396 if (params_ == Teuchos::null) {
404 if (params->isParameter(
"Maximum Iterations")) {
405 maxIters_ = params->get(
"Maximum Iterations",maxIters_default_);
408 params_->set(
"Maximum Iterations", maxIters_);
409 if (maxIterTest_!=Teuchos::null)
410 maxIterTest_->setMaxIters( maxIters_ );
414 if (params->isParameter(
"Timer Label")) {
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 423 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
429 if (params->isParameter(
"Verbosity")) {
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_);
443 if (params->isParameter(
"Output Style")) {
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_);
456 if (params->isParameter(
"Output Stream")) {
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_ );
467 if (params->isParameter(
"Output Frequency")) {
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) {
536 if (params->isParameter(
"Deflation Quorum")) {
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 551 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
561 template<
class ScalarType,
class MV,
class OP>
573 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
574 Teuchos::rcp(
new StatusTestGenResNorm_t( impTolScale_*convtol_, defQuorum_ ) );
576 impConvTest_ = tmpImpConvTest;
579 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
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_ ) );
591 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
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>
620 Teuchos::RCP<const Teuchos::ParameterList>
623 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
626 if(is_null(validPL)) {
627 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
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.");
666 template<
class ScalarType,
class MV,
class OP>
677 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not a valid object.");
680 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
684 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
690 int numCurrRHS = numRHS2Solve;
692 std::vector<int> currIdx( numRHS2Solve );
693 for (
int i=0; i<numRHS2Solve; ++i) {
694 currIdx[i] = startPtr+i;
698 problem_->setLSIndex( currIdx );
702 Teuchos::ParameterList plist;
705 outputTest_->reset();
708 bool isConverged =
true;
713 Teuchos::RCP<PseudoBlockTFQMRIter<ScalarType,MV,OP> > block_tfqmr_iter =
718 #ifdef BELOS_TEUCHOS_TIME_MONITOR 719 Teuchos::TimeMonitor slvtimer(*timerSolve_);
722 while ( numRHS2Solve > 0 ) {
725 std::vector<int> convRHSIdx;
726 std::vector<int> currRHSIdx( currIdx );
727 currRHSIdx.resize(numCurrRHS);
730 block_tfqmr_iter->resetNumIters();
733 outputTest_->resetNumCalls();
736 Teuchos::RCP<MV> R_0 =
MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx );
741 block_tfqmr_iter->initializeTFQMR(newstate);
747 block_tfqmr_iter->iterate();
754 if ( convTest_->getStatus() ==
Passed ) {
757 std::vector<int> convIdx = expConvTest_->convIndices();
761 if (convIdx.size() == currRHSIdx.size())
765 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
768 problem_->setCurrLS();
772 std::vector<int> unconvIdx( currRHSIdx.size() );
773 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
775 for (
unsigned int j=0; j<convIdx.size(); ++j) {
776 if (currRHSIdx[i] == convIdx[j]) {
783 currRHSIdx[have++] = currRHSIdx[i];
786 unconvIdx.resize(have);
787 currRHSIdx.resize(have);
790 problem_->setLSIndex( currRHSIdx );
808 for (std::vector<int>::iterator uIter = unconvIdx.begin(); uIter != unconvIdx.end(); uIter++)
810 defstate.
alpha.push_back( currentState.
alpha[ *uIter ] );
811 defstate.
eta.push_back( currentState.
eta[ *uIter ] );
812 defstate.
rho.push_back( currentState.
rho[ *uIter ] );
813 defstate.
tau.push_back( currentState.
tau[ *uIter ] );
814 defstate.
theta.push_back( currentState.
theta[ *uIter ] );
817 block_tfqmr_iter->initializeTFQMR(defstate);
824 else if ( maxIterTest_->getStatus() ==
Passed ) {
838 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
839 "Belos::PseudoBlockTFQMRSolMgr::solve(): Invalid return from PseudoBlockTFQMRIter::iterate().");
842 catch (
const std::exception &e) {
843 printer_->stream(
Errors) <<
"Error! Caught std::exception in PseudoBlockTFQMRIter::iterate() at iteration " 844 << block_tfqmr_iter->getNumIters() << std::endl
845 << e.what() << std::endl;
851 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
854 problem_->setCurrLS();
857 startPtr += numCurrRHS;
858 numRHS2Solve -= numCurrRHS;
859 if ( numRHS2Solve > 0 ) {
860 numCurrRHS = numRHS2Solve;
861 currIdx.resize( numCurrRHS );
862 for (
int i=0; i<numCurrRHS; ++i)
863 { currIdx[i] = startPtr+i; }
866 if (defQuorum_ > numCurrRHS) {
867 if (impConvTest_ != Teuchos::null)
868 impConvTest_->setQuorum( numCurrRHS );
869 if (expConvTest_ != Teuchos::null)
870 expConvTest_->setQuorum( numCurrRHS );
874 problem_->setLSIndex( currIdx );
877 currIdx.resize( numRHS2Solve );
888 #ifdef BELOS_TEUCHOS_TIME_MONITOR 893 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
897 numIters_ = maxIterTest_->getNumIters();
910 const std::vector<MagnitudeType>* pTestValues = NULL;
912 pTestValues = expConvTest_->getTestValue();
913 if (pTestValues == NULL || pTestValues->size() < 1) {
914 pTestValues = impConvTest_->getTestValue();
919 pTestValues = impConvTest_->getTestValue();
921 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
922 "Belos::PseudoBlockTFQMRSolMgr::solve(): The implicit convergence test's " 923 "getTestValue() method returned NULL. Please report this bug to the " 924 "Belos developers.");
925 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
926 "Belos::TMQMRSolMgr::solve(): The implicit convergence test's " 927 "getTestValue() method returned a vector of length zero. Please report " 928 "this bug to the Belos developers.");
933 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
943 template<
class ScalarType,
class MV,
class OP>
946 std::ostringstream oss;
947 oss <<
"Belos::PseudoBlockTFQMRSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
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< 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.
Structure to contain pointers to PseudoBlockTFQMRIter state variables.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
A factory class for generating StatusTestOutput objects.
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).
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
An implementation of StatusTestResNorm using a family of residual norms.
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
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the parameters the solver manager should use to solve the linear problem.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
std::string description() const
Method to return description of the pseudo-block TFQMR 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.
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...
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).
PseudoBlockTFQMRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
ResetType
How to reset the solver.
Pure virtual base class which describes the basic interface for a solver manager. ...
PseudoBlockTFQMRSolMgrOrthoFailure(const std::string &what_arg)
ReturnType solve()
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
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
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.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
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.
std::vector< ScalarType > rho
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< const MV > V