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 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 int defQuorum_default_;
279 static const std::string impResScale_default_;
280 static const std::string expResScale_default_;
281 static const std::string label_default_;
282 static const Teuchos::RCP<std::ostream> outputStream_default_;
285 MagnitudeType convtol_, achievedTol_;
286 int maxIters_, numIters_;
287 int verbosity_, outputStyle_, outputFreq_, defQuorum_;
289 std::string impResScale_, expResScale_;
293 Teuchos::RCP<Teuchos::Time> timerSolve_;
296 bool isSet_, isSTSet_;
301 template<
class ScalarType,
class MV,
class OP>
304 template<
class ScalarType,
class MV,
class OP>
307 template<
class ScalarType,
class MV,
class OP>
310 template<
class ScalarType,
class MV,
class OP>
313 template<
class ScalarType,
class MV,
class OP>
316 template<
class ScalarType,
class MV,
class OP>
319 template<
class ScalarType,
class MV,
class OP>
322 template<
class ScalarType,
class MV,
class OP>
325 template<
class ScalarType,
class MV,
class OP>
328 template<
class ScalarType,
class MV,
class OP>
331 template<
class ScalarType,
class MV,
class OP>
336 template<
class ScalarType,
class MV,
class OP>
338 outputStream_(outputStream_default_),
339 convtol_(convtol_default_),
340 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
341 maxIters_(maxIters_default_),
343 verbosity_(verbosity_default_),
344 outputStyle_(outputStyle_default_),
345 outputFreq_(outputFreq_default_),
346 defQuorum_(defQuorum_default_),
347 expResTest_(expResTest_default_),
348 impResScale_(impResScale_default_),
349 expResScale_(expResScale_default_),
350 label_(label_default_),
357 template<
class ScalarType,
class MV,
class OP>
360 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
362 outputStream_(outputStream_default_),
363 convtol_(convtol_default_),
364 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
365 maxIters_(maxIters_default_),
367 verbosity_(verbosity_default_),
368 outputStyle_(outputStyle_default_),
369 outputFreq_(outputFreq_default_),
370 defQuorum_(defQuorum_default_),
371 expResTest_(expResTest_default_),
372 impResScale_(impResScale_default_),
373 expResScale_(expResScale_default_),
374 label_(label_default_),
378 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
381 if ( !is_null(pl) ) {
386 template<
class ScalarType,
class MV,
class OP>
390 if (params_ == Teuchos::null) {
398 if (params->isParameter(
"Maximum Iterations")) {
399 maxIters_ = params->get(
"Maximum Iterations",maxIters_default_);
402 params_->set(
"Maximum Iterations", maxIters_);
403 if (maxIterTest_!=Teuchos::null)
404 maxIterTest_->setMaxIters( maxIters_ );
408 if (params->isParameter(
"Timer Label")) {
409 std::string tempLabel = params->get(
"Timer Label", label_default_);
412 if (tempLabel != label_) {
414 params_->set(
"Timer Label", label_);
415 std::string solveLabel = label_ +
": PseudoBlockTFQMRSolMgr total solve time";
416 #ifdef BELOS_TEUCHOS_TIME_MONITOR 417 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
423 if (params->isParameter(
"Verbosity")) {
424 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
425 verbosity_ = params->get(
"Verbosity", verbosity_default_);
427 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
431 params_->set(
"Verbosity", verbosity_);
432 if (printer_ != Teuchos::null)
433 printer_->setVerbosity(verbosity_);
437 if (params->isParameter(
"Output Style")) {
438 if (Teuchos::isParameterType<int>(*params,
"Output Style")) {
439 outputStyle_ = params->get(
"Output Style", outputStyle_default_);
441 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,
"Output Style");
445 params_->set(
"Output Style", outputStyle_);
450 if (params->isParameter(
"Output Stream")) {
451 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
454 params_->set(
"Output Stream", outputStream_);
455 if (printer_ != Teuchos::null)
456 printer_->setOStream( outputStream_ );
461 if (params->isParameter(
"Output Frequency")) {
462 outputFreq_ = params->get(
"Output Frequency", outputFreq_default_);
466 params_->set(
"Output Frequency", outputFreq_);
467 if (outputTest_ != Teuchos::null)
468 outputTest_->setOutputFrequency( outputFreq_ );
472 if (printer_ == Teuchos::null) {
477 if (params->isParameter(
"Convergence Tolerance")) {
478 convtol_ = params->get(
"Convergence Tolerance",convtol_default_);
481 params_->set(
"Convergence Tolerance", convtol_);
482 if (impConvTest_ != Teuchos::null)
483 impConvTest_->setTolerance( convtol_ );
484 if (expConvTest_ != Teuchos::null)
485 expConvTest_->setTolerance( convtol_ );
489 if (params->isParameter(
"Implicit Residual Scaling")) {
490 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params,
"Implicit Residual Scaling" );
493 if (impResScale_ != tempImpResScale) {
495 impResScale_ = tempImpResScale;
498 params_->set(
"Implicit Residual Scaling", impResScale_);
499 if (impConvTest_ != Teuchos::null) {
503 catch (std::exception& e) {
511 if (params->isParameter(
"Explicit Residual Scaling")) {
512 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params,
"Explicit Residual Scaling" );
515 if (expResScale_ != tempExpResScale) {
517 expResScale_ = tempExpResScale;
520 params_->set(
"Explicit Residual Scaling", expResScale_);
521 if (expConvTest_ != Teuchos::null) {
525 catch (std::exception& e) {
533 if (params->isParameter(
"Explicit Residual Test")) {
534 expResTest_ = Teuchos::getParameter<bool>( *params,
"Explicit Residual Test" );
537 params_->set(
"Explicit Residual Test", expResTest_);
538 if (expConvTest_ == Teuchos::null) {
544 if (params->isParameter(
"Deflation Quorum")) {
545 defQuorum_ = params->get(
"Deflation Quorum", defQuorum_);
546 params_->set (
"Deflation Quorum", defQuorum_);
547 if (! impConvTest_.is_null ()) {
548 impConvTest_->setQuorum (defQuorum_);
550 if (! expConvTest_.is_null ()) {
551 expConvTest_->setQuorum (defQuorum_);
556 if (timerSolve_ == Teuchos::null) {
557 std::string solveLabel = label_ +
": PseudoBlockTFQMRSolMgr total solve time";
558 #ifdef BELOS_TEUCHOS_TIME_MONITOR 559 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
569 template<
class ScalarType,
class MV,
class OP>
581 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
582 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
584 impConvTest_ = tmpImpConvTest;
587 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
588 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
589 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit,
Belos::TwoNorm );
591 expConvTest_ = tmpExpConvTest;
594 convTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
599 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
600 Teuchos::rcp(
new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
602 impConvTest_ = tmpImpConvTest;
605 expConvTest_ = impConvTest_;
606 convTest_ = impConvTest_;
608 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
616 std::string solverDesc =
" Pseudo Block TFQMR ";
617 outputTest_->setSolverDesc( solverDesc );
627 template<
class ScalarType,
class MV,
class OP>
628 Teuchos::RCP<const Teuchos::ParameterList>
631 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
634 if(is_null(validPL)) {
635 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
636 pl->set(
"Convergence Tolerance", convtol_default_,
637 "The relative residual tolerance that needs to be achieved by the\n" 638 "iterative solver in order for the linear system to be declared converged.");
639 pl->set(
"Maximum Iterations", maxIters_default_,
640 "The maximum number of block iterations allowed for each\n" 641 "set of RHS solved.");
642 pl->set(
"Verbosity", verbosity_default_,
643 "What type(s) of solver information should be outputted\n" 644 "to the output stream.");
645 pl->set(
"Output Style", outputStyle_default_,
646 "What style is used for the solver information outputted\n" 647 "to the output stream.");
648 pl->set(
"Output Frequency", outputFreq_default_,
649 "How often convergence information should be outputted\n" 650 "to the output stream.");
651 pl->set(
"Deflation Quorum", defQuorum_default_,
652 "The number of linear systems that need to converge before they are deflated.");
653 pl->set(
"Output Stream", outputStream_default_,
654 "A reference-counted pointer to the output stream where all\n" 655 "solver output is sent.");
656 pl->set(
"Explicit Residual Test", expResTest_default_,
657 "Whether the explicitly computed residual should be used in the convergence test.");
658 pl->set(
"Implicit Residual Scaling", impResScale_default_,
659 "The type of scaling used in the implicit residual convergence test.");
660 pl->set(
"Explicit Residual Scaling", expResScale_default_,
661 "The type of scaling used in the explicit residual convergence test.");
662 pl->set(
"Timer Label", label_default_,
663 "The string to use as a prefix for the timer labels.");
672 template<
class ScalarType,
class MV,
class OP>
683 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not a valid object.");
686 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
690 "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
696 int numCurrRHS = numRHS2Solve;
698 std::vector<int> currIdx( numRHS2Solve ), currIdx2( numRHS2Solve );
699 for (
int i=0; i<numRHS2Solve; ++i) {
700 currIdx[i] = startPtr+i;
705 problem_->setLSIndex( currIdx );
709 Teuchos::ParameterList plist;
712 outputTest_->reset();
715 bool isConverged =
true;
720 Teuchos::RCP<PseudoBlockTFQMRIter<ScalarType,MV,OP> > block_tfqmr_iter =
725 #ifdef BELOS_TEUCHOS_TIME_MONITOR 726 Teuchos::TimeMonitor slvtimer(*timerSolve_);
729 while ( numRHS2Solve > 0 ) {
732 std::vector<int> convRHSIdx;
733 std::vector<int> currRHSIdx( currIdx );
734 currRHSIdx.resize(numCurrRHS);
737 block_tfqmr_iter->resetNumIters();
740 outputTest_->resetNumCalls();
743 Teuchos::RCP<MV> R_0 =
MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx );
748 block_tfqmr_iter->initializeTFQMR(newstate);
754 block_tfqmr_iter->iterate();
761 if ( convTest_->getStatus() ==
Passed ) {
764 std::vector<int> convIdx = expConvTest_->convIndices();
768 if (convIdx.size() == currRHSIdx.size())
772 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
775 problem_->setCurrLS();
779 std::vector<int> unconvIdx(currRHSIdx.size());
780 for (
unsigned int i=0; i<currRHSIdx.size(); ++i) {
782 for (
unsigned int j=0; j<convIdx.size(); ++j) {
783 if (currRHSIdx[i] == convIdx[j]) {
789 currIdx2[have] = currIdx2[i];
790 currRHSIdx[have++] = currRHSIdx[i];
793 currRHSIdx.resize(have);
794 currIdx2.resize(have);
797 problem_->setLSIndex( currRHSIdx );
801 R_0 =
MVT::Clone( *(problem_->getInitPrecResVec()), currRHSIdx.size() );
802 problem_->computeCurrPrecResVec( &*R_0 );
807 block_tfqmr_iter->initializeTFQMR(defstate);
814 else if ( maxIterTest_->getStatus() ==
Passed ) {
828 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
829 "Belos::PseudoBlockTFQMRSolMgr::solve(): Invalid return from PseudoBlockTFQMRIter::iterate().");
832 catch (
const std::exception &e) {
833 printer_->stream(
Errors) <<
"Error! Caught std::exception in PseudoBlockTFQMRIter::iterate() at iteration " 834 << block_tfqmr_iter->getNumIters() << std::endl
835 << e.what() << std::endl;
841 problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
844 problem_->setCurrLS();
847 startPtr += numCurrRHS;
848 numRHS2Solve -= numCurrRHS;
849 if ( numRHS2Solve > 0 ) {
850 numCurrRHS = numRHS2Solve;
851 currIdx.resize( numCurrRHS );
852 currIdx2.resize( numCurrRHS );
853 for (
int i=0; i<numCurrRHS; ++i)
854 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
857 if (defQuorum_ > numCurrRHS) {
858 if (impConvTest_ != Teuchos::null)
859 impConvTest_->setQuorum( numCurrRHS );
860 if (expConvTest_ != Teuchos::null)
861 expConvTest_->setQuorum( numCurrRHS );
865 problem_->setLSIndex( currIdx );
868 currIdx.resize( numRHS2Solve );
879 #ifdef BELOS_TEUCHOS_TIME_MONITOR 884 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
888 numIters_ = maxIterTest_->getNumIters();
901 const std::vector<MagnitudeType>* pTestValues = NULL;
903 pTestValues = expConvTest_->getTestValue();
904 if (pTestValues == NULL || pTestValues->size() < 1) {
905 pTestValues = impConvTest_->getTestValue();
910 pTestValues = impConvTest_->getTestValue();
912 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
913 "Belos::PseudoBlockTFQMRSolMgr::solve(): The implicit convergence test's " 914 "getTestValue() method returned NULL. Please report this bug to the " 915 "Belos developers.");
916 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
917 "Belos::TMQMRSolMgr::solve(): The implicit convergence test's " 918 "getTestValue() method returned a vector of length zero. Please report " 919 "this bug to the Belos developers.");
924 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
934 template<
class ScalarType,
class MV,
class OP>
937 std::ostringstream oss;
938 oss <<
"Belos::PseudoBlockTFQMRSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
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)
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.
This class implements the preconditioned transpose-free QMR algorithm for solving non-Hermitian linea...
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
ScaleType
The type of scaling to use on the residual norm value.
Structure to contain pointers to PseudoBlockTFQMRIter state variables.
A factory class for generating StatusTestOutput objects.
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
Teuchos::RCP< const MV > R
The current residual basis.
bool isLOADetected() const
Whether loss of accuracy was detected during the last solve() invocation.
An implementation of StatusTestResNorm using a family of residual norms.
PseudoBlockTFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
Belos::StatusTest class for specifying a maximum number of iterations.
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.
A factory class for generating StatusTestOutput objects.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
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).
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
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. ...
std::string description() const
Method to return description of the pseudo-block TFQMR solver manager.
int getNumIters() const
Get the iteration count for the most recent call to solve().
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.
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...
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 ...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters for this object.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
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.
A class for extending the status testing capabilities of Belos via logical combinations.
virtual ~PseudoBlockTFQMRSolMgr()
Destructor.
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...