11 #ifndef BELOS_GMRES_POLY_SOLMGR_HPP
12 #define BELOS_GMRES_POLY_SOLMGR_HPP
27 #ifdef BELOS_TEUCHOS_TIME_MONITOR
121 template<
class ScalarType,
class MV,
class OP>
216 return Teuchos::tuple(timerPoly_);
254 problem_->setProblem ();
255 poly_Op_ = Teuchos::null;
306 static constexpr
int maxDegree_default_ = 25;
308 static constexpr
const char * label_default_ =
"Belos";
309 static constexpr
const char * outerSolverType_default_ =
"";
310 static constexpr
const char * polyType_default_ =
"Arnoldi";
311 static constexpr
const char * orthoType_default_ =
"ICGS";
312 static constexpr
bool addRoots_default_ =
true;
313 static constexpr
bool dampPoly_default_ =
false;
314 static constexpr
bool randomRHS_default_ =
true;
317 MagnitudeType polyTol_, achievedTol_;
318 int maxDegree_, numIters_;
320 bool hasOuterSolver_;
324 std::string polyType_;
325 std::string outerSolverType_;
326 std::string orthoType_;
345 template<
class ScalarType,
class MV,
class OP>
347 outputStream_ (Teuchos::rcpFromRef(std::cout)),
349 achievedTol_(
MTS::zero()),
350 maxDegree_ (maxDegree_default_),
352 verbosity_ (verbosity_default_),
353 hasOuterSolver_ (false),
354 randomRHS_ (randomRHS_default_),
355 damp_ (dampPoly_default_),
356 addRoots_ (addRoots_default_),
357 polyType_ (polyType_default_),
358 outerSolverType_ (outerSolverType_default_),
359 orthoType_ (orthoType_default_),
361 label_ (label_default_),
367 template<
class ScalarType,
class MV,
class OP>
372 outputStream_ (Teuchos::rcpFromRef(std::cout)),
374 maxDegree_ (maxDegree_default_),
376 verbosity_ (verbosity_default_),
377 hasOuterSolver_ (false),
378 randomRHS_ (randomRHS_default_),
379 damp_ (dampPoly_default_),
380 addRoots_ (addRoots_default_),
381 polyType_ (polyType_default_),
382 outerSolverType_ (outerSolverType_default_),
383 orthoType_ (orthoType_default_),
385 label_ (label_default_),
390 problem_.is_null (), std::invalid_argument,
391 "Belos::GmresPolySolMgr: The given linear problem is null. "
392 "Please call this constructor with a nonnull LinearProblem argument, "
393 "or call the constructor that does not take a LinearProblem.");
403 template<
class ScalarType,
class MV,
class OP>
407 if (validPL_.is_null ()) {
412 pl->
set(
"Polynomial Type", static_cast<const char *>(polyType_default_),
413 "The type of GMRES polynomial that is used as a preconditioner: Roots, Arnoldi, or Gmres.");
415 "The relative residual tolerance that used to construct the GMRES polynomial.");
416 pl->
set(
"Maximum Degree", static_cast<int>(maxDegree_default_),
417 "The maximum degree allowed for any GMRES polynomial.");
418 pl->
set(
"Outer Solver", static_cast<const char *>(outerSolverType_default_),
419 "The outer solver that this polynomial is used to precondition.");
421 "Parameter list for the outer solver.");
422 pl->
set(
"Verbosity", static_cast<int>(verbosity_default_),
423 "What type(s) of solver information should be outputted\n"
424 "to the output stream.");
425 pl->
set(
"Output Stream", Teuchos::rcpFromRef(std::cout),
426 "A reference-counted pointer to the output stream where all\n"
427 "solver output is sent.");
428 pl->
set(
"Timer Label", static_cast<const char *>(label_default_),
429 "The string to use as a prefix for the timer labels.");
430 pl->
set(
"Orthogonalization", static_cast<const char *>(orthoType_default_),
431 "The type of orthogonalization to use to generate polynomial: DGKS, ICGS, or IMGS.");
432 pl->
set(
"Random RHS", static_cast<bool>(randomRHS_default_),
433 "Add roots to polynomial for stability.");
434 pl->
set(
"Add Roots", static_cast<bool>(addRoots_default_),
435 "Add roots to polynomial for stability.");
436 pl->
set(
"Damp Poly", static_cast<bool>(dampPoly_default_),
437 "Damp polynomial for ill-conditioned problems.");
444 template<
class ScalarType,
class MV,
class OP>
449 if (params_.is_null ()) {
450 params_ = Teuchos::parameterList (*getValidParameters ());
458 polyType_ = params->
get(
"Polynomial Type", polyType_default_);
462 params_->set(
"Polynomial Type", polyType_);
466 outerSolverType_ = params->
get(
"Outer Solver", outerSolverType_default_);
470 params_->set(
"Outer Solver", outerSolverType_);
473 if (params->
isSublist(
"Outer Solver Params")) {
479 maxDegree_ = params->
get(
"Maximum Degree",maxDegree_default_);
483 params_->set(
"Maximum Degree", maxDegree_);
487 std::string tempLabel = params->
get(
"Timer Label", label_default_);
490 if (tempLabel != label_) {
492 #ifdef BELOS_TEUCHOS_TIME_MONITOR
493 std::string polyLabel = label_ +
": GmresPolyOp creation time";
500 params_->set(
"Timer Label", label_);
504 std::string tempOrthoType = params->
get(
"Orthogonalization",orthoType_default_);
508 std::ostringstream os;
509 os <<
"Belos::GCRODRSolMgr: Invalid orthogonalization name \""
510 << tempOrthoType <<
"\". The following are valid options "
511 <<
"for the \"Orthogonalization\" name parameter: ";
513 throw std::invalid_argument (os.str());
515 if (tempOrthoType != orthoType_) {
516 orthoType_ = tempOrthoType;
520 params_->set(
"Orthogonalization", orthoType_);
524 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
525 verbosity_ = params->
get(
"Verbosity", verbosity_default_);
527 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
532 params_->set(
"Verbosity", verbosity_);
536 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
540 params_->set(
"Output Stream", outputStream_);
545 if (params->
isType<MagnitudeType> (
"Polynomial Tolerance")) {
546 polyTol_ = params->
get (
"Polynomial Tolerance",
555 params_->set(
"Polynomial Tolerance", polyTol_);
559 randomRHS_ = params->
get(
"Random RHS",randomRHS_default_);
563 params_->set(
"Random RHS", randomRHS_);
568 damp_ = params->
get(
"Damped Poly",dampPoly_default_);
571 params_->set(
"Damped Poly", damp_);
575 addRoots_ = params->
get(
"Add Roots",addRoots_default_);
579 params_->set(
"Add Roots", addRoots_);
582 #ifdef BELOS_TEUCHOS_TIME_MONITOR
583 if (timerPoly_ == Teuchos::null) {
584 std::string polyLabel = label_ +
": GmresPolyOp creation time";
590 if (outerSolverType_ !=
"") {
591 hasOuterSolver_ =
true;
599 template<
class ScalarType,
class MV,
class OP>
604 using Teuchos::rcp_const_cast;
614 setParameters (Teuchos::parameterList (*getValidParameters ()));
619 "Belos::GmresPolySolMgr::solve: The linear problem has not been set yet, "
620 "or was set to null. Please call setProblem() with a nonnull input before "
625 "Belos::GmresPolySolMgr::solve: The linear problem is not ready. Please "
626 "call setProblem() on the LinearProblem object before calling solve().");
630 if (!poly_dim_ && maxDegree_) {
631 #ifdef BELOS_TEUCHOS_TIME_MONITOR
635 poly_dim_ = poly_Op_->polyDegree();
638 "Belos::GmresPolyOp: Failed to generate polynomial that satisfied requirements.");
643 if (hasOuterSolver_ && maxDegree_) {
648 RCP<SolverManager<ScalarType, MultiVec<ScalarType>,
Operator<ScalarType> > > solver = factory.
create( outerSolverType_, outerParams_ );
650 "Belos::GmresPolySolMgr::solve(): Selected solver is not valid.");
655 RCP<gmres_poly_mv_t> new_rhs =
rcp(
new gmres_poly_mv_t( rcp_const_cast<MV>( problem_->getRHS() ) ) );
659 std::string solverLabel = label_ +
": Hybrid Gmres";
660 newProblem->setLabel(solverLabel);
663 if (problem_->getLeftPrec() != Teuchos::null)
664 newProblem->setLeftPrec( poly_Op_ );
666 newProblem->setRightPrec( poly_Op_ );
669 if (problem_->getInitResVec() != Teuchos::null)
670 newProblem->setInitResVec(
rcp(
new gmres_poly_mv_t( rcp_const_cast<MV>( problem_->getInitResVec() ) ) ) );
671 newProblem->setProblem();
673 solver->setProblem( newProblem );
675 ret = solver->solve();
676 numIters_ = solver->getNumIters();
677 loaDetected_ = solver->isLOADetected();
678 achievedTol_ = solver->achievedTol();
681 else if (hasOuterSolver_) {
685 RCP<SolverManager<ScalarType, MV, OP> > solver = factory.create( outerSolverType_, outerParams_ );
687 "Belos::GmresPolySolMgr::solve(): Selected solver is not valid.");
689 solver->setProblem( problem_ );
691 ret = solver->solve();
692 numIters_ = solver->getNumIters();
693 loaDetected_ = solver->isLOADetected();
694 achievedTol_ = solver->achievedTol();
697 else if (maxDegree_) {
700 poly_Op_->ApplyPoly( *problem_->getRHS(), *problem_->getLHS() );
701 achievedTol_ = MTS::one();
709 template<
class ScalarType,
class MV,
class OP>
712 std::ostringstream out;
714 out <<
"\"Belos::GmresPolySolMgr\": {"
716 <<
", Poly Degree: " << poly_dim_
717 <<
", Poly Max Degree: " << maxDegree_
718 <<
", Poly Tol: " << polyTol_;
725 #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)
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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 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...
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
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()