10#ifndef BELOS_TFQMR_SOLMGR_HPP
11#define BELOS_TFQMR_SOLMGR_HPP
32#ifdef BELOS_TEUCHOS_TIME_MONITOR
33#include "Teuchos_TimeMonitor.hpp"
67 template<
class ScalarType,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int, ScalarType>>
73 typedef Teuchos::ScalarTraits<ScalarType> SCT;
74 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
75 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
106 const Teuchos::RCP<Teuchos::ParameterList> &
pl );
112 Teuchos::RCP<SolverManager<ScalarType, MV, OP, DM> >
clone ()
const override {
137 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
138 return Teuchos::tuple(timerSolve_);
224 bool checkStatusTest();
227 Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > problem_;
230 Teuchos::RCP<OutputManager<ScalarType> > printer_;
231 Teuchos::RCP<std::ostream> outputStream_;
234 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > sTest_;
235 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP,DM> > maxIterTest_;
236 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > convTest_;
237 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP,DM> > expConvTest_, impConvTest_;
238 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP,DM> > outputTest_;
241 Teuchos::RCP<StatusTest<ScalarType, MV, OP, DM> > debugStatusTest_;
244 Teuchos::RCP<Teuchos::ParameterList> params_;
247 static constexpr int maxIters_default_ = 1000;
248 static constexpr bool expResTest_default_ =
false;
251 static constexpr int outputFreq_default_ = -1;
252 static constexpr const char * impResScale_default_ =
"Norm of Preconditioned Initial Residual";
253 static constexpr const char * expResScale_default_ =
"Norm of Initial Residual";
254 static constexpr const char * label_default_ =
"Belos";
257 MagnitudeType convtol_, impTolScale_, achievedTol_;
258 int maxIters_, numIters_;
259 int verbosity_, outputStyle_, outputFreq_;
262 std::string impResScale_, expResScale_;
266 Teuchos::RCP<Teuchos::Time> timerSolve_;
269 bool isSet_, isSTSet_;
274template<
class ScalarType,
class MV,
class OP,
class DM>
280 maxIters_(maxIters_default_),
282 verbosity_(verbosity_default_),
283 outputStyle_(outputStyle_default_),
284 outputFreq_(outputFreq_default_),
286 expResTest_(expResTest_default_),
287 impResScale_(impResScale_default_),
288 expResScale_(expResScale_default_),
289 label_(label_default_),
296template<
class ScalarType,
class MV,
class OP,
class DM>
299 const Teuchos::RCP<Teuchos::ParameterList> &
pl ) :
305 maxIters_(maxIters_default_),
307 verbosity_(verbosity_default_),
308 outputStyle_(outputStyle_default_),
309 outputFreq_(outputFreq_default_),
311 expResTest_(expResTest_default_),
312 impResScale_(impResScale_default_),
313 expResScale_(expResScale_default_),
314 label_(label_default_),
326template<
class ScalarType,
class MV,
class OP,
class DM>
330 if (params_ == Teuchos::null) {
331 params_ = Teuchos::rcp(
new Teuchos::ParameterList(*getValidParameters()) );
334 params->validateParameters(*getValidParameters());
338 if (
params->isParameter(
"Maximum Iterations")) {
339 maxIters_ =
params->get(
"Maximum Iterations",maxIters_default_);
342 params_->set(
"Maximum Iterations", maxIters_);
343 if (maxIterTest_!=Teuchos::null)
344 maxIterTest_->setMaxIters( maxIters_ );
348 if (
params->isParameter(
"Block Size")) {
349 blockSize_ =
params->get(
"Block Size",1);
351 "Belos::TFQMRSolMgr: \"Block Size\" must be 1.");
354 params_->set(
"Block Size", blockSize_);
358 if (
params->isParameter(
"Timer Label")) {
364 params_->set(
"Timer Label", label_);
365 std::string
solveLabel = label_ +
": TFQMRSolMgr total solve time";
366#ifdef BELOS_TEUCHOS_TIME_MONITOR
367 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(
solveLabel);
373 if (
params->isParameter(
"Verbosity")) {
374 if (Teuchos::isParameterType<int>(*
params,
"Verbosity")) {
375 verbosity_ =
params->get(
"Verbosity", verbosity_default_);
377 verbosity_ = (
int)Teuchos::getParameter<Belos::MsgType>(*
params,
"Verbosity");
381 params_->set(
"Verbosity", verbosity_);
382 if (printer_ != Teuchos::null)
383 printer_->setVerbosity(verbosity_);
387 if (
params->isParameter(
"Output Style")) {
388 if (Teuchos::isParameterType<int>(*
params,
"Output Style")) {
389 outputStyle_ =
params->get(
"Output Style", outputStyle_default_);
391 outputStyle_ = (
int)Teuchos::getParameter<Belos::OutputType>(*
params,
"Output Style");
395 params_->set(
"Output Style", outputStyle_);
400 if (
params->isParameter(
"Output Stream")) {
401 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*
params,
"Output Stream");
404 params_->set(
"Output Stream", outputStream_);
405 if (printer_ != Teuchos::null)
406 printer_->setOStream( outputStream_ );
411 if (
params->isParameter(
"Output Frequency")) {
412 outputFreq_ =
params->get(
"Output Frequency", outputFreq_default_);
416 params_->set(
"Output Frequency", outputFreq_);
417 if (outputTest_ != Teuchos::null)
418 outputTest_->setOutputFrequency( outputFreq_ );
422 if (printer_ == Teuchos::null) {
427 if (
params->isParameter(
"Convergence Tolerance")) {
428 if (
params->isType<MagnitudeType> (
"Convergence Tolerance")) {
429 convtol_ =
params->get (
"Convergence Tolerance",
437 params_->set(
"Convergence Tolerance", convtol_);
442 if (
params->isParameter(
"Implicit Tolerance Scale Factor")) {
443 if (
params->isType<MagnitudeType> (
"Implicit Tolerance Scale Factor")) {
444 impTolScale_ =
params->get (
"Implicit Tolerance Scale Factor",
449 impTolScale_ =
params->get (
"Implicit Tolerance Scale Factor",
454 params_->set(
"Implicit Tolerance Scale Factor", impTolScale_);
459 if (
params->isParameter(
"Implicit Residual Scaling")) {
460 std::string
tempImpResScale = Teuchos::getParameter<std::string>( *
params,
"Implicit Residual Scaling" );
467 params_->set(
"Implicit Residual Scaling", impResScale_);
474 if (
params->isParameter(
"Explicit Residual Scaling")) {
475 std::string
tempExpResScale = Teuchos::getParameter<std::string>( *
params,
"Explicit Residual Scaling" );
482 params_->set(
"Explicit Residual Scaling", expResScale_);
489 if (
params->isParameter(
"Explicit Residual Test")) {
490 expResTest_ = Teuchos::getParameter<bool>( *
params,
"Explicit Residual Test" );
493 params_->set(
"Explicit Residual Test", expResTest_);
494 if (expConvTest_ == Teuchos::null) {
500 if (timerSolve_ == Teuchos::null) {
501 std::string
solveLabel = label_ +
": TFQMRSolMgr total solve time";
502#ifdef BELOS_TEUCHOS_TIME_MONITOR
503 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(
solveLabel);
513template<
class ScalarType,
class MV,
class OP,
class DM>
538 convTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
549 expConvTest_ = impConvTest_;
550 convTest_ = impConvTest_;
552 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
558 if (Teuchos::nonnull(debugStatusTest_)) {
559 sTest_ = Teuchos::rcp(
new StatusTestCombo_t( StatusTestCombo_t::OR, sTest_, debugStatusTest_ ) );
579template<
class ScalarType,
class MV,
class OP,
class DM>
580Teuchos::RCP<const Teuchos::ParameterList>
583 static Teuchos::RCP<const Teuchos::ParameterList>
validPL;
587 Teuchos::RCP<Teuchos::ParameterList>
pl = Teuchos::parameterList();
592 "The relative residual tolerance that needs to be achieved by the\n"
593 "iterative solver in order for the linear system to be declared converged.");
595 "The scale factor used by the implicit residual test when explicit residual\n"
596 "testing is used. May enable faster convergence when TFQMR bound is too loose.");
597 pl->set(
"Maximum Iterations",
static_cast<int>(maxIters_default_),
598 "The maximum number of block iterations allowed for each\n"
599 "set of RHS solved.");
600 pl->set(
"Verbosity",
static_cast<int>(verbosity_default_),
601 "What type(s) of solver information should be outputted\n"
602 "to the output stream.");
603 pl->set(
"Output Style",
static_cast<int>(outputStyle_default_),
604 "What style is used for the solver information outputted\n"
605 "to the output stream.");
606 pl->set(
"Output Frequency",
static_cast<int>(outputFreq_default_),
607 "How often convergence information should be outputted\n"
608 "to the output stream.");
609 pl->set(
"Output Stream", Teuchos::rcpFromRef(std::cout),
610 "A reference-counted pointer to the output stream where all\n"
611 "solver output is sent.");
612 pl->set(
"Explicit Residual Test",
static_cast<bool>(expResTest_default_),
613 "Whether the explicitly computed residual should be used in the convergence test.");
614 pl->set(
"Implicit Residual Scaling",
static_cast<const char *
>(impResScale_default_),
615 "The type of scaling used in the implicit residual convergence test.");
616 pl->set(
"Explicit Residual Scaling",
static_cast<const char *
>(expResScale_default_),
617 "The type of scaling used in the explicit residual convergence test.");
618 pl->set(
"Timer Label",
static_cast<const char *
>(label_default_),
619 "The string to use as a prefix for the timer labels.");
627template<
class ScalarType,
class MV,
class OP,
class DM>
635 setParameters(Teuchos::parameterList(*getValidParameters()));
639 "Belos::TFQMRSolMgr::solve(): Linear problem is not a valid object.");
642 "Belos::TFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
646 "Belos::TFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
651 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
663 problem_->setLSIndex(
currIdx );
667 Teuchos::ParameterList
plist;
668 plist.set(
"Block Size",blockSize_);
671 outputTest_->reset();
679 Teuchos::RCP<TFQMRIter<ScalarType,MV,OP,DM> >
tfqmr_iter =
684#ifdef BELOS_TEUCHOS_TIME_MONITOR
685 Teuchos::TimeMonitor
slvtimer(*timerSolve_);
699 outputTest_->resetNumCalls();
702 Teuchos::RCP<MV>
R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())),
currIdx );
720 if ( convTest_->getStatus() ==
Passed ) {
729 else if ( maxIterTest_->getStatus() ==
Passed ) {
743 else if (Teuchos::nonnull(debugStatusTest_) &&
744 debugStatusTest_->getStatus() ==
Passed) {
754 "Belos::TFQMRSolMgr::solve(): Invalid return from TFQMRIter::iterate().");
760 achievedTol_ = MT::one();
761 Teuchos::RCP<MV>
X = problem_->getLHS();
762 MVT::MvInit( *
X, SCT::zero() );
763 printer_->stream(
Warnings) <<
"Belos::TFQMRSolMgr::solve(): Warning! NaN has been detected!"
767 catch (
const std::exception &
e) {
769 printer_->stream(
Errors) <<
"Error! Caught std::exception in TFQMRIter::iterate() at iteration "
771 <<
e.what() << std::endl;
777 problem_->updateSolution(
tfqmr_iter->getCurrentUpdate(),
true );
780 problem_->setCurrLS();
793 problem_->setLSIndex(
currIdx );
810#ifdef BELOS_TEUCHOS_TIME_MONITOR
815 Teuchos::TimeMonitor::summarize( printer_->stream(
TimingDetails) );
819 numIters_ = maxIterTest_->getNumIters();
844 "Belos::TFQMRSolMgr::solve(): The implicit convergence test's "
845 "getTestValue() method returned NULL. Please report this bug to the "
846 "Belos developers.");
848 "Belos::TMQMRSolMgr::solve(): The implicit convergence test's "
849 "getTestValue() method returned a vector of length zero. Please report "
850 "this bug to the Belos developers.");
865template<
class ScalarType,
class MV,
class OP,
class DM>
868 std::ostringstream
oss;
869 oss <<
"Belos::TFQMRSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<
">";
876#ifdef HAVE_BELOS_TPETRA
879#define BELOS_TPETRA_TFQMRSOLMGR_NOEXTERN_CALL(SC, LO, GO, NT) \
880 BELOS_TPETRA_CALL(Belos::TFQMRSolMgr, SC, LO, GO, NT)
882#define BELOS_TPETRA_TFQMRSOLMGR_EXTERN_CALL(SC, LO, GO, NT) \
883 BELOS_TPETRA_EXTERN_CALL(Belos::TFQMRSolMgr, SC, LO, GO, NT)
885TPETRA_INSTANTIATE_SLGN_NO_ORDINAL_SCALAR(BELOS_TPETRA_TFQMRSOLMGR_EXTERN_CALL)
Belos header file which uses auto-configuration information to include necessary C++ headers.
Full specialization of Belos::DenseMatTraits for Kokkos::DualView with arbitrary scalarType....
Class which describes the linear problem to be solved by the iterative solver.
Class which manages the output and verbosity of the Belos solvers.
Pure virtual base class which describes the basic interface for a solver manager.
Belos::StatusTest for logically combining several status tests.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
Full specialization of Belos::DenseMatTraits for Teuchos::SerialDenseMatrix with ordinal type int and...
Collection of types and exceptions used within the Belos solvers.
Parent class to all Belos exceptions.
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
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...
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem) override
Set the linear problem that needs to be solved.
bool isLOADetected() const override
Whether loss of accuracy was detected during the last solve() invocation.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
std::string description() const override
Method to return description of the TFQMR solver manager.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms) override
Set the parameters the solver manager should use to solve the linear problem.
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
TFQMRSolMgr()
Empty constructor for TFQMRSolMgr. This constructor takes no arguments and sets the default values fo...
Teuchos::RCP< SolverManager< ScalarType, MV, OP, DM > > clone() const override
clone for Inverted Injection (DII)
int getNumIters() const override
Get the iteration count for the most recent call to solve().
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP, DM > > &debugStatusTest) override
Set a debug status test, OR-combined into the top-level status test.
virtual ~TFQMRSolMgr()
Destructor.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
TFQMRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
TFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
ReturnType
Whether the Belos solve converged for all linear systems.
ResetType
How to reset the solver.
Default parameters common to most Belos solvers.
static const double impTolScale
"Implicit Tolerance Scale Factor"
static const double convTol
Default convergence tolerance.