43 #ifndef BELOS_GMRES_POLY_SOLMGR_HPP
44 #define BELOS_GMRES_POLY_SOLMGR_HPP
59 #ifdef BELOS_TEUCHOS_TIME_MONITOR
151 template<
class ScalarType,
class MV,
class OP>
375 template<
class ScalarType,
class MV,
class OP>
377 outputStream_ (Teuchos::rcpFromRef(std::cout)),
379 achievedTol_(
MTS::zero()),
380 maxDegree_ (maxDegree_default_),
382 verbosity_ (verbosity_default_),
383 hasOuterSolver_ (false),
384 randomRHS_ (randomRHS_default_),
385 damp_ (dampPoly_default_),
386 addRoots_ (addRoots_default_),
387 polyType_ (polyType_default_),
388 outerSolverType_ (outerSolverType_default_),
389 orthoType_ (orthoType_default_),
391 label_ (label_default_),
397 template<
class ScalarType,
class MV,
class OP>
402 outputStream_ (Teuchos::rcpFromRef(std::cout)),
404 maxDegree_ (maxDegree_default_),
406 verbosity_ (verbosity_default_),
407 hasOuterSolver_ (false),
408 randomRHS_ (randomRHS_default_),
409 damp_ (dampPoly_default_),
410 addRoots_ (addRoots_default_),
411 polyType_ (polyType_default_),
412 outerSolverType_ (outerSolverType_default_),
413 orthoType_ (orthoType_default_),
415 label_ (label_default_),
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.");
433 template<
class ScalarType,
class MV,
class OP>
437 if (validPL_.is_null ()) {
442 pl->
set(
"Polynomial Type", static_cast<const char *>(polyType_default_),
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.");
446 pl->
set(
"Maximum Degree", static_cast<int>(maxDegree_default_),
447 "The maximum degree allowed for any GMRES polynomial.");
448 pl->
set(
"Outer Solver", static_cast<const char *>(outerSolverType_default_),
449 "The outer solver that this polynomial is used to precondition.");
451 "Parameter list for the outer solver.");
452 pl->
set(
"Verbosity", static_cast<int>(verbosity_default_),
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.");
458 pl->
set(
"Timer Label", static_cast<const char *>(label_default_),
459 "The string to use as a prefix for the timer labels.");
460 pl->
set(
"Orthogonalization", static_cast<const char *>(orthoType_default_),
461 "The type of orthogonalization to use to generate polynomial: DGKS, ICGS, or IMGS.");
462 pl->
set(
"Random RHS", static_cast<bool>(randomRHS_default_),
463 "Add roots to polynomial for stability.");
464 pl->
set(
"Add Roots", static_cast<bool>(addRoots_default_),
465 "Add roots to polynomial for stability.");
466 pl->
set(
"Damp Poly", static_cast<bool>(dampPoly_default_),
467 "Damp polynomial for ill-conditioned problems.");
474 template<
class ScalarType,
class MV,
class OP>
479 if (params_.is_null ()) {
480 params_ = Teuchos::parameterList (*getValidParameters ());
488 polyType_ = params->
get(
"Polynomial Type", polyType_default_);
492 params_->set(
"Polynomial Type", polyType_);
496 outerSolverType_ = params->
get(
"Outer Solver", outerSolverType_default_);
500 params_->set(
"Outer Solver", outerSolverType_);
503 if (params->
isSublist(
"Outer Solver Params")) {
509 maxDegree_ = params->
get(
"Maximum Degree",maxDegree_default_);
513 params_->set(
"Maximum Degree", maxDegree_);
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";
530 params_->set(
"Timer Label", label_);
534 std::string tempOrthoType = params->
get(
"Orthogonalization",orthoType_default_);
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());
545 if (tempOrthoType != orthoType_) {
546 orthoType_ = tempOrthoType;
550 params_->set(
"Orthogonalization", orthoType_);
554 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
555 verbosity_ = params->
get(
"Verbosity", verbosity_default_);
557 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
562 params_->set(
"Verbosity", verbosity_);
566 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
570 params_->set(
"Output Stream", outputStream_);
576 polyTol_ = params->
get (
"Polynomial Tolerance",
585 params_->set(
"Polynomial Tolerance", polyTol_);
589 randomRHS_ = params->
get(
"Random RHS",randomRHS_default_);
593 params_->set(
"Random RHS", randomRHS_);
598 damp_ = params->
get(
"Damped Poly",dampPoly_default_);
601 params_->set(
"Damped Poly", damp_);
605 addRoots_ = params->
get(
"Add Roots",addRoots_default_);
609 params_->set(
"Add Roots", addRoots_);
612 #ifdef BELOS_TEUCHOS_TIME_MONITOR
614 std::string polyLabel = label_ +
": GmresPolyOp creation time";
620 if (outerSolverType_ !=
"") {
621 hasOuterSolver_ =
true;
629 template<
class ScalarType,
class MV,
class OP>
634 using Teuchos::rcp_const_cast;
644 setParameters (Teuchos::parameterList (*getValidParameters ()));
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 "
655 "Belos::GmresPolySolMgr::solve: The linear problem is not ready. Please "
656 "call setProblem() on the LinearProblem object before calling solve().");
660 if (!poly_dim_ && maxDegree_) {
661 #ifdef BELOS_TEUCHOS_TIME_MONITOR
665 poly_dim_ = poly_Op_->polyDegree();
668 "Belos::GmresPolyOp: Failed to generate polynomial that satisfied requirements.");
673 if (hasOuterSolver_ && maxDegree_) {
678 RCP<SolverManager<ScalarType, MultiVec<ScalarType>,
Operator<ScalarType> > > solver = factory.
create( outerSolverType_, outerParams_ );
680 "Belos::GmresPolySolMgr::solve(): Selected solver is not valid.");
685 RCP<gmres_poly_mv_t> new_rhs =
rcp(
new gmres_poly_mv_t( rcp_const_cast<MV>( problem_->getRHS() ) ) );
689 std::string solverLabel = label_ +
": Hybrid Gmres";
690 newProblem->setLabel(solverLabel);
694 newProblem->setLeftPrec( poly_Op_ );
696 newProblem->setRightPrec( poly_Op_ );
700 newProblem->setInitResVec(
rcp(
new gmres_poly_mv_t( rcp_const_cast<MV>( problem_->getInitResVec() ) ) ) );
701 newProblem->setProblem();
703 solver->setProblem( newProblem );
705 ret = solver->solve();
706 numIters_ = solver->getNumIters();
707 loaDetected_ = solver->isLOADetected();
708 achievedTol_ = solver->achievedTol();
711 else if (hasOuterSolver_) {
715 RCP<SolverManager<ScalarType, MV, OP> > solver = factory.create( outerSolverType_, outerParams_ );
717 "Belos::GmresPolySolMgr::solve(): Selected solver is not valid.");
719 solver->setProblem( problem_ );
721 ret = solver->solve();
722 numIters_ = solver->getNumIters();
723 loaDetected_ = solver->isLOADetected();
724 achievedTol_ = solver->achievedTol();
727 else if (maxDegree_) {
730 poly_Op_->ApplyPoly( *problem_->getRHS(), *problem_->getLHS() );
731 achievedTol_ = MTS::one();
739 template<
class ScalarType,
class MV,
class OP>
742 std::ostringstream out;
744 out <<
"\"Belos::GmresPolySolMgr\": {"
746 <<
", Poly Degree: " << poly_dim_
747 <<
", Poly Max Degree: " << maxDegree_
748 <<
", Poly Tol: " << polyTol_;
755 #endif // BELOS_GMRES_POLY_SOLMGR_HPP
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Collection of types and exceptions used within the Belos solvers.
Belos::GmresPolyOp< ScalarType, MV, OP > gmres_poly_t
Teuchos::RCP< gmres_poly_t > poly_Op_
Teuchos::RCP< const Teuchos::ParameterList > validPL_
Cached default (valid) parameters.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
MagnitudeType achievedTol_
virtual ~GmresPolySolMgr()
Destructor.
Defines the GMRES polynomial operator hybrid-GMRES iterative linear solver.
Belos::GmresPolyMv< ScalarType, MV > gmres_poly_mv_t
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve...
static constexpr const char * label_default_
T & get(ParameterList &l, const std::string &name)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
static constexpr int maxDegree_default_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< Teuchos::ParameterList > outerParams_
Teuchos::RCP< Teuchos::ParameterList > params_
static const double polyTol
Relative residual tolerance for matrix polynomial construction.
bool isParameter(const std::string &name) const
ResetType
How to reset the solver.
Alternative run-time polymorphic interface for operators.
GmresPolySolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
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. ...
bool is_null(const RCP< T > &p)
static constexpr bool addRoots_default_
bool isValidName(const std::string &name) const
Whether this factory recognizes the MatOrthoManager with the given name.
bool isSublist(const std::string &name) const
std::ostream & printValidNames(std::ostream &out) const
Print all recognized MatOrthoManager names to the given ostream.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Get current linear problem being solved for in this object.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
The GMRES polynomial can be created in conjunction with any standard preconditioner.
static constexpr const char * orthoType_default_
int getNumIters() const override
Get the iteration count for the most recent call to solve().
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 ...
Belos's class for applying the GMRES polynomial operator that is used by the hybrid-GMRES linear solv...
void reset(const ResetType type) override
Reset the solver.
Teuchos::RCP< Teuchos::Time > timerPoly_
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
std::string description() const override
Method to return description of the hybrid block GMRES solver manager.
static constexpr bool randomRHS_default_
GmresPolySolMgrPolynomialFailure is thrown when their is a problem generating the GMRES polynomial fo...
virtual Teuchos::RCP< solver_base_type > create(const std::string &solverName, const Teuchos::RCP< Teuchos::ParameterList > &solverParams)
Create, configure, and return the specified solver.
GmresPolySolMgrPolynomialFailure(const std::string &what_arg)
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms) override
Set the parameters the solver manager should use to solve the linear problem.
bool isType(const std::string &name) const
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
static constexpr const char * outerSolverType_default_
Interface for multivectors used by Belos' linear solvers.
Teuchos::RCP< std::ostream > outputStream_
Parent class to all Belos exceptions.
Default parameters common to most Belos solvers.
GmresPolySolMgr()
Empty constructor for GmresPolySolMgr. This constructor takes no arguments and sets the default value...
static constexpr bool dampPoly_default_
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
Belos header file which uses auto-configuration information to include necessary C++ headers...
static constexpr int verbosity_default_
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
typename::Belos::Impl::SolverFactorySelector< SC, MV, OP >::type SolverFactory
GmresPolySolMgrLinearProblemFailure(const std::string &what_arg)
static constexpr const char * polyType_default_
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
std::string outerSolverType_
static std::string name()
Teuchos::ScalarTraits< MagnitudeType > MTS