43#ifndef BELOS_GMRES_POLY_SOLMGR_HPP
44#define BELOS_GMRES_POLY_SOLMGR_HPP
58#include "Teuchos_as.hpp"
59#ifdef BELOS_TEUCHOS_TIME_MONITOR
60#include "Teuchos_TimeMonitor.hpp"
151template<
class ScalarType,
class MV,
class OP>
155 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
MagnitudeType;
157 typedef Teuchos::ScalarTraits<MagnitudeType>
MTS;
192 const Teuchos::RCP<Teuchos::ParameterList> &pl );
198 Teuchos::RCP<SolverManager<ScalarType, MV, OP> >
clone ()
const override {
245 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
268 void setParameters(
const Teuchos::RCP<Teuchos::ParameterList> ¶ms )
override;
326 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >
problem_;
371 mutable Teuchos::RCP<const Teuchos::ParameterList>
validPL_;
375template<
class ScalarType,
class MV,
class OP>
397template<
class ScalarType,
class MV,
class OP>
400 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
419 TEUCHOS_TEST_FOR_EXCEPTION(
420 problem_.is_null (), std::invalid_argument,
421 "Belos::GmresPolySolMgr: The given linear problem is null. "
422 "Please call this constructor with a nonnull LinearProblem argument, "
423 "or call the constructor that does not take a LinearProblem.");
427 if (! pl.is_null ()) {
433template<
class ScalarType,
class MV,
class OP>
434Teuchos::RCP<const Teuchos::ParameterList>
438 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList ();
443 "The type of GMRES polynomial that is used as a preconditioner: Roots, Arnoldi, or Gmres.");
445 "The relative residual tolerance that used to construct the GMRES polynomial.");
447 "The maximum degree allowed for any GMRES polynomial.");
449 "The outer solver that this polynomial is used to precondition.");
450 pl->set(
"Outer Solver Params", Teuchos::ParameterList(),
451 "Parameter list for the outer solver.");
453 "What type(s) of solver information should be outputted\n"
454 "to the output stream.");
455 pl->set(
"Output Stream", Teuchos::rcpFromRef(std::cout),
456 "A reference-counted pointer to the output stream where all\n"
457 "solver output is sent.");
459 "The string to use as a prefix for the timer labels.");
461 "The type of orthogonalization to use to generate polynomial: DGKS, ICGS, or IMGS.");
463 "Add roots to polynomial for stability.");
465 "Add roots to polynomial for stability.");
467 "Damp polynomial for ill-conditioned problems.");
474template<
class ScalarType,
class MV,
class OP>
476setParameters (
const Teuchos::RCP<Teuchos::ParameterList>& params)
487 if (params->isParameter(
"Polynomial Type")) {
495 if (params->isParameter(
"Outer Solver")) {
503 if (params->isSublist(
"Outer Solver Params")) {
504 outerParams_ = Teuchos::parameterList( params->get<Teuchos::ParameterList>(
"Outer Solver Params") );
508 if (params->isParameter(
"Maximum Degree")) {
516 if (params->isParameter(
"Timer Label")) {
517 std::string tempLabel = params->get(
"Timer Label",
label_default_);
520 if (tempLabel !=
label_) {
522#ifdef BELOS_TEUCHOS_TIME_MONITOR
523 std::string polyLabel =
label_ +
": GmresPolyOp creation time";
524 timerPoly_ = Teuchos::TimeMonitor::getNewCounter(polyLabel);
533 if (params->isParameter(
"Orthogonalization")) {
538 std::ostringstream os;
539 os <<
"Belos::GCRODRSolMgr: Invalid orthogonalization name \""
540 << tempOrthoType <<
"\". The following are valid options "
541 <<
"for the \"Orthogonalization\" name parameter: ";
543 throw std::invalid_argument (os.str());
553 if (params->isParameter(
"Verbosity")) {
554 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
557 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
565 if (params->isParameter(
"Output Stream")) {
566 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
574 if (params->isParameter(
"Polynomial Tolerance")) {
575 if (params->isType<
MagnitudeType> (
"Polynomial Tolerance")) {
576 polyTol_ = params->get (
"Polynomial Tolerance",
588 if (params->isParameter(
"Random RHS")) {
597 if (params->isParameter(
"Damped Poly")) {
604 if (params->isParameter(
"Add Roots")) {
612#ifdef BELOS_TEUCHOS_TIME_MONITOR
614 std::string polyLabel =
label_ +
": GmresPolyOp creation time";
615 timerPoly_ = Teuchos::TimeMonitor::getNewCounter(polyLabel);
629template<
class ScalarType,
class MV,
class OP>
634 using Teuchos::rcp_const_cast;
647 TEUCHOS_TEST_FOR_EXCEPTION(
649 "Belos::GmresPolySolMgr::solve: The linear problem has not been set yet, "
650 "or was set to null. Please call setProblem() with a nonnull input before "
653 TEUCHOS_TEST_FOR_EXCEPTION(
655 "Belos::GmresPolySolMgr::solve: The linear problem is not ready. Please "
656 "call setProblem() on the LinearProblem object before calling solve().");
661#ifdef BELOS_TEUCHOS_TIME_MONITOR
668 "Belos::GmresPolyOp: Failed to generate polynomial that satisfied requirements.");
679 TEUCHOS_TEST_FOR_EXCEPTION( solver == Teuchos::null, std::invalid_argument,
680 "Belos::GmresPolySolMgr::solve(): Selected solver is not valid.");
689 std::string solverLabel =
label_ +
": Hybrid Gmres";
690 newProblem->setLabel(solverLabel);
693 if (
problem_->getLeftPrec() != Teuchos::null)
694 newProblem->setLeftPrec(
poly_Op_ );
696 newProblem->setRightPrec(
poly_Op_ );
699 if (
problem_->getInitResVec() != Teuchos::null)
701 newProblem->setProblem();
703 solver->setProblem( newProblem );
705 ret = solver->solve();
716 TEUCHOS_TEST_FOR_EXCEPTION( solver == Teuchos::null, std::invalid_argument,
717 "Belos::GmresPolySolMgr::solve(): Selected solver is not valid.");
721 ret = solver->solve();
739template<
class ScalarType,
class MV,
class OP>
742 std::ostringstream out;
744 out <<
"\"Belos::GmresPolySolMgr\": {"
745 <<
"ScalarType: " << Teuchos::TypeNameTraits<ScalarType>::name ()
Belos header file which uses auto-configuration information to include necessary C++ headers.
Defines the GMRES polynomial operator hybrid-GMRES iterative linear solver.
Class which describes the linear problem to be solved by the iterative solver.
Pure virtual base class which describes the basic interface for a solver manager.
Collection of types and exceptions used within the Belos solvers.
BelosError(const std::string &what_arg)
Belos's class for applying the GMRES polynomial operator that is used by the hybrid-GMRES linear solv...
GmresPolySolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
GmresPolySolMgrLinearProblemFailure(const std::string &what_arg)
GmresPolySolMgrPolynomialFailure is thrown when their is a problem generating the GMRES polynomial fo...
GmresPolySolMgrPolynomialFailure(const std::string &what_arg)
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
static constexpr const char * orthoType_default_
Teuchos::RCP< std::ostream > outputStream_
static constexpr const char * label_default_
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.
std::string description() const override
Method to return description of the hybrid block GMRES solver manager.
static constexpr bool randomRHS_default_
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve.
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
Teuchos::ScalarTraits< MagnitudeType > MTS
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Get current linear problem being solved for in this object.
virtual ~GmresPolySolMgr()
Destructor.
static constexpr const char * outerSolverType_default_
Teuchos::RCP< Teuchos::ParameterList > outerParams_
GmresPolySolMgr()
Empty constructor for GmresPolySolMgr. This constructor takes no arguments and sets the default value...
MagnitudeType achievedTol_
Belos::GmresPolyOp< ScalarType, MV, OP > gmres_poly_t
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
std::string outerSolverType_
static constexpr int verbosity_default_
Teuchos::RCP< Teuchos::ParameterList > params_
Teuchos::RCP< const Teuchos::ParameterList > validPL_
Cached default (valid) parameters.
Belos::GmresPolyMv< ScalarType, MV > gmres_poly_mv_t
static constexpr bool dampPoly_default_
void reset(const ResetType type) override
Reset the solver.
static constexpr int maxDegree_default_
Teuchos::RCP< Teuchos::Time > timerPoly_
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Teuchos::RCP< gmres_poly_t > poly_Op_
static constexpr const char * polyType_default_
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms) override
Set the parameters the solver manager should use to solve the linear problem.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
static constexpr bool addRoots_default_
virtual Teuchos::RCP< solver_base_type > create(const std::string &solverName, const Teuchos::RCP< Teuchos::ParameterList > &solverParams)
Create, configure, and return the specified solver.
Interface for multivectors used by Belos' linear solvers.
Alternative run-time polymorphic interface for operators.
Enumeration of all valid Belos (Mat)OrthoManager classes.
std::ostream & printValidNames(std::ostream &out) const
Print all recognized MatOrthoManager names to the given ostream.
bool isValidName(const std::string &name) const
Whether this factory recognizes the MatOrthoManager with the given name.
SolverManager()
Empty constructor.
ReturnType
Whether the Belos solve converged for all linear systems.
typename ::Belos::Impl::SolverFactorySelector< SC, MV, OP >::type SolverFactory
ResetType
How to reset the solver.
Default parameters common to most Belos solvers.
static const double polyTol
Relative residual tolerance for matrix polynomial construction.