43 #ifndef BELOS_GMRES_POLY_SOLMGR_HPP
44 #define BELOS_GMRES_POLY_SOLMGR_HPP
59 #ifdef BELOS_TEUCHOS_TIME_MONITOR
149 template<
class ScalarType,
class MV,
class OP>
224 return Teuchos::tuple(timerPoly_);
262 problem_->setProblem ();
263 poly_Op_ = Teuchos::null;
314 static constexpr
int maxDegree_default_ = 25;
316 static constexpr
const char * label_default_ =
"Belos";
317 static constexpr
const char * outerSolverType_default_ =
"";
318 static constexpr
const char * polyType_default_ =
"Arnoldi";
319 static constexpr
const char * orthoType_default_ =
"ICGS";
320 static constexpr
bool addRoots_default_ =
true;
321 static constexpr
bool dampPoly_default_ =
false;
322 static constexpr
bool randomRHS_default_ =
true;
323 static constexpr std::ostream * outputStream_default_ = &std::cout;
326 MagnitudeType polyTol_;
327 int maxDegree_, numIters_;
329 bool hasOuterSolver_;
333 std::string polyType_;
334 std::string outerSolverType_;
335 std::string orthoType_;
354 template<
class ScalarType,
class MV,
class OP>
356 outputStream_ (Teuchos::
rcp(outputStream_default_,false)),
358 maxDegree_ (maxDegree_default_),
360 verbosity_ (verbosity_default_),
361 hasOuterSolver_ (false),
362 randomRHS_ (randomRHS_default_),
363 damp_ (dampPoly_default_),
364 addRoots_ (addRoots_default_),
365 polyType_ (polyType_default_),
366 outerSolverType_ (outerSolverType_default_),
367 orthoType_ (orthoType_default_),
369 label_ (label_default_),
375 template<
class ScalarType,
class MV,
class OP>
380 outputStream_ (Teuchos::
rcp(outputStream_default_,false)),
382 maxDegree_ (maxDegree_default_),
384 verbosity_ (verbosity_default_),
385 hasOuterSolver_ (false),
386 randomRHS_ (randomRHS_default_),
387 damp_ (dampPoly_default_),
388 addRoots_ (addRoots_default_),
389 polyType_ (polyType_default_),
390 outerSolverType_ (outerSolverType_default_),
391 orthoType_ (orthoType_default_),
393 label_ (label_default_),
398 problem_.is_null (), std::invalid_argument,
399 "Belos::GmresPolySolMgr: The given linear problem is null. "
400 "Please call this constructor with a nonnull LinearProblem argument, "
401 "or call the constructor that does not take a LinearProblem.");
411 template<
class ScalarType,
class MV,
class OP>
415 if (validPL_.is_null ()) {
420 pl->
set(
"Polynomial Type", static_cast<const char *>(polyType_default_),
421 "The type of GMRES polynomial that is used as a preconditioner: Roots, Arnoldi, or Gmres.");
423 "The relative residual tolerance that used to construct the GMRES polynomial.");
424 pl->
set(
"Maximum Degree", static_cast<int>(maxDegree_default_),
425 "The maximum degree allowed for any GMRES polynomial.");
426 pl->
set(
"Outer Solver", static_cast<const char *>(outerSolverType_default_),
427 "The outer solver that this polynomial is used to precondition.");
428 pl->
set(
"Verbosity", static_cast<int>(verbosity_default_),
429 "What type(s) of solver information should be outputted\n"
430 "to the output stream.");
432 "A reference-counted pointer to the output stream where all\n"
433 "solver output is sent.");
434 pl->
set(
"Timer Label", static_cast<const char *>(label_default_),
435 "The string to use as a prefix for the timer labels.");
436 pl->
set(
"Orthogonalization", static_cast<const char *>(orthoType_default_),
437 "The type of orthogonalization to use to generate polynomial: DGKS, ICGS, or IMGS.");
438 pl->
set(
"Random RHS", static_cast<bool>(randomRHS_default_),
439 "Add roots to polynomial for stability.");
440 pl->
set(
"Add Roots", static_cast<bool>(addRoots_default_),
441 "Add roots to polynomial for stability.");
442 pl->
set(
"Damp Poly", static_cast<bool>(dampPoly_default_),
443 "Damp polynomial for ill-conditioned problems.");
450 template<
class ScalarType,
class MV,
class OP>
455 if (params_.is_null ()) {
456 params_ = Teuchos::parameterList (*getValidParameters ());
464 polyType_ = params->
get(
"Polynomial Type", polyType_default_);
468 params_->set(
"Polynomial Type", polyType_);
472 outerSolverType_ = params->
get(
"Outer Solver", outerSolverType_default_);
476 params_->set(
"Outer Solver", outerSolverType_);
479 if (params->
isSublist(
"Outer Solver Params")) {
485 maxDegree_ = params->
get(
"Maximum Degree",maxDegree_default_);
489 params_->set(
"Maximum Degree", maxDegree_);
493 std::string tempLabel = params->
get(
"Timer Label", label_default_);
496 if (tempLabel != label_) {
498 #ifdef BELOS_TEUCHOS_TIME_MONITOR
499 std::string polyLabel = label_ +
": GmresPolyOp creation time";
506 params_->set(
"Timer Label", label_);
510 std::string tempOrthoType = params->
get(
"Orthogonalization",orthoType_default_);
514 std::ostringstream os;
515 os <<
"Belos::GCRODRSolMgr: Invalid orthogonalization name \""
516 << tempOrthoType <<
"\". The following are valid options "
517 <<
"for the \"Orthogonalization\" name parameter: ";
519 throw std::invalid_argument (os.str());
521 if (tempOrthoType != orthoType_) {
522 orthoType_ = tempOrthoType;
526 params_->set(
"Orthogonalization", orthoType_);
530 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
531 verbosity_ = params->
get(
"Verbosity", verbosity_default_);
533 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
538 params_->set(
"Verbosity", verbosity_);
542 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
546 params_->set(
"Output Stream", outputStream_);
551 if (params->
isType<MagnitudeType> (
"Polynomial Tolerance")) {
552 polyTol_ = params->
get (
"Polynomial Tolerance",
561 params_->set(
"Polynomial Tolerance", polyTol_);
565 randomRHS_ = params->
get(
"Random RHS",randomRHS_default_);
569 params_->set(
"Random RHS", randomRHS_);
574 damp_ = params->
get(
"Damped Poly",dampPoly_default_);
577 params_->set(
"Damped Poly", damp_);
581 addRoots_ = params->
get(
"Add Roots",addRoots_default_);
585 params_->set(
"Add Roots", addRoots_);
588 #ifdef BELOS_TEUCHOS_TIME_MONITOR
589 if (timerPoly_ == Teuchos::null) {
590 std::string polyLabel = label_ +
": GmresPolyOp creation time";
596 if (outerSolverType_ !=
"") {
597 hasOuterSolver_ =
true;
605 template<
class ScalarType,
class MV,
class OP>
610 using Teuchos::rcp_const_cast;
620 setParameters (Teuchos::parameterList (*getValidParameters ()));
625 "Belos::GmresPolySolMgr::solve: The linear problem has not been set yet, "
626 "or was set to null. Please call setProblem() with a nonnull input before "
631 "Belos::GmresPolySolMgr::solve: The linear problem is not ready. Please "
632 "call setProblem() on the LinearProblem object before calling solve().");
636 if (!poly_dim_ && maxDegree_) {
637 #ifdef BELOS_TEUCHOS_TIME_MONITOR
641 poly_dim_ = poly_Op_->polyDegree();
644 "Belos::GmresPolyOp: Failed to generate polynomial that satisfied requirements.");
649 if (hasOuterSolver_ && maxDegree_) {
654 RCP<SolverManager<ScalarType, MultiVec<ScalarType>,
Operator<ScalarType> > > solver = factory.
create( outerSolverType_, outerParams_ );
656 "Belos::GmresPolySolMgr::solve(): Selected solver is not valid.");
661 RCP<gmres_poly_mv_t> new_rhs =
rcp(
new gmres_poly_mv_t( rcp_const_cast<MV>( problem_->getRHS() ) ) );
665 std::string solverLabel = label_ +
": Hybrid Gmres";
666 newProblem->setLabel(solverLabel);
669 if (problem_->getLeftPrec() != Teuchos::null)
670 newProblem->setLeftPrec( poly_Op_ );
672 newProblem->setRightPrec( poly_Op_ );
675 if (problem_->getInitResVec() != Teuchos::null)
676 newProblem->setInitResVec(
rcp(
new gmres_poly_mv_t( rcp_const_cast<MV>( problem_->getInitResVec() ) ) ) );
677 newProblem->setProblem();
679 solver->setProblem( newProblem );
681 ret = solver->solve();
682 numIters_ = solver->getNumIters();
683 loaDetected_ = solver->isLOADetected();
686 else if (hasOuterSolver_) {
690 RCP<SolverManager<ScalarType, MV, OP> > solver = factory.create( outerSolverType_, outerParams_ );
692 "Belos::GmresPolySolMgr::solve(): Selected solver is not valid.");
694 solver->setProblem( problem_ );
696 ret = solver->solve();
697 numIters_ = solver->getNumIters();
698 loaDetected_ = solver->isLOADetected();
701 else if (maxDegree_) {
704 poly_Op_->ApplyPoly( *problem_->getRHS(), *problem_->getLHS() );
712 template<
class ScalarType,
class MV,
class OP>
715 std::ostringstream out;
717 out <<
"\"Belos::GmresPolySolMgr\": {"
719 <<
", Poly Degree: " << poly_dim_
720 <<
", Poly Max Degree: " << maxDegree_
721 <<
", Poly Tol: " << polyTol_;
728 #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.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
virtual ~GmresPolySolMgr()
Destructor.
Defines the GMRES polynomial operator hybrid-GMRES iterative linear solver.
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve...
T & get(const std::string &name, T def_value)
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static const double polyTol
Relative residual tolerance for matrix polynomial construction.
Traits class which defines basic operations on multivectors.
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 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.
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.
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.
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::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Interface for multivectors used by Belos' linear solvers.
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...
Belos header file which uses auto-configuration information to include necessary C++ headers...
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 std::string name()