42 #ifndef BELOS_GMRES_POLY_SOLMGR_HPP
43 #define BELOS_GMRES_POLY_SOLMGR_HPP
57 #ifdef BELOS_TEUCHOS_TIME_MONITOR
133 template<
class ScalarType,
class MV,
class OP>
324 template<
class ScalarType,
class MV,
class OP>
326 outputStream_ (Teuchos::
rcp(outputStream_default_,false)),
328 maxDegree_ (maxDegree_default_),
330 verbosity_ (verbosity_default_),
331 hasOuterSolver_ (false),
333 polyType_ (polyType_default_),
334 outerSolverType_ (outerSolverType_default_),
335 orthoType_ (orthoType_default_),
337 label_ (label_default_),
343 template<
class ScalarType,
class MV,
class OP>
348 outputStream_ (Teuchos::
rcp(outputStream_default_,false)),
350 maxDegree_ (maxDegree_default_),
352 verbosity_ (verbosity_default_),
353 hasOuterSolver_ (false),
355 polyType_ (polyType_default_),
356 outerSolverType_ (outerSolverType_default_),
357 orthoType_ (orthoType_default_),
359 label_ (label_default_),
364 problem_.is_null (), std::invalid_argument,
365 "Belos::GmresPolySolMgr: The given linear problem is null. "
366 "Please call this constructor with a nonnull LinearProblem argument, "
367 "or call the constructor that does not take a LinearProblem.");
377 template<
class ScalarType,
class MV,
class OP>
381 if (validPL_.is_null ()) {
386 pl->
set(
"Polynomial Type", static_cast<const char *>(polyType_default_),
387 "The type of GMRES polynomial that is used as a preconditioner.");
389 "The relative residual tolerance that used to construct the GMRES polynomial.");
390 pl->
set(
"Maximum Degree", static_cast<int>(maxDegree_default_),
391 "The maximum degree allowed for any GMRES polynomial.");
392 pl->
set(
"Outer Solver", static_cast<const char *>(outerSolverType_default_),
393 "The outer solver that this polynomial is used to precondition.");
394 pl->
set(
"Verbosity", static_cast<int>(verbosity_default_),
395 "What type(s) of solver information should be outputted\n"
396 "to the output stream.");
398 "A reference-counted pointer to the output stream where all\n"
399 "solver output is sent.");
400 pl->
set(
"Timer Label", static_cast<const char *>(label_default_),
401 "The string to use as a prefix for the timer labels.");
402 pl->
set(
"Orthogonalization", static_cast<const char *>(orthoType_default_),
403 "The type of orthogonalization to use to generate polynomial: DGKS, ICGS, or IMGS.");
410 template<
class ScalarType,
class MV,
class OP>
415 if (params_.is_null ()) {
416 params_ = Teuchos::parameterList (*getValidParameters ());
424 polyType_ = params->
get(
"Polynomial Type", polyType_default_);
428 params_->set(
"Polynomial Type", polyType_);
432 outerSolverType_ = params->
get(
"Outer Solver", outerSolverType_default_);
436 params_->set(
"Outer Solver", outerSolverType_);
439 if (params->
isSublist(
"Outer Solver Params")) {
445 maxDegree_ = params->
get(
"Maximum Degree",maxDegree_default_);
449 params_->set(
"Maximum Degree", maxDegree_);
453 std::string tempLabel = params->
get(
"Timer Label", label_default_);
456 if (tempLabel != label_) {
458 #ifdef BELOS_TEUCHOS_TIME_MONITOR
459 std::string polyLabel = label_ +
": GmresPolyOp creation time";
466 params_->set(
"Timer Label", label_);
470 std::string tempOrthoType = params->
get(
"Orthogonalization",orthoType_default_);
472 std::invalid_argument,
473 "Belos::GmresPolySolMgr: \"Orthogonalization\" must be either \"DGKS\", \"ICGS\", or \"IMGS\".");
474 if (tempOrthoType != orthoType_) {
475 orthoType_ = tempOrthoType;
479 params_->set(
"Orthogonalization", orthoType_);
483 if (Teuchos::isParameterType<int>(*params,
"Verbosity")) {
484 verbosity_ = params->
get(
"Verbosity", verbosity_default_);
486 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,
"Verbosity");
491 params_->set(
"Verbosity", verbosity_);
495 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,
"Output Stream");
499 params_->set(
"Output Stream", outputStream_);
505 polyTol_ = params->
get (
"Polynomial Tolerance",
514 params_->set(
"Polynomial Tolerance", polyTol_);
518 randomRHS_ = params->
get(
"Random RHS",
true);
522 params_->set(
"Random RHS", randomRHS_);
525 #ifdef BELOS_TEUCHOS_TIME_MONITOR
527 std::string polyLabel = label_ +
": GmresPolyOp creation time";
533 if (outerSolverType_ !=
"") {
534 hasOuterSolver_ =
true;
542 template<
class ScalarType,
class MV,
class OP>
547 using Teuchos::rcp_const_cast;
557 setParameters (Teuchos::parameterList (*getValidParameters ()));
562 "Belos::GmresPolySolMgr::solve: The linear problem has not been set yet, "
563 "or was set to null. Please call setProblem() with a nonnull input before "
568 "Belos::GmresPolySolMgr::solve: The linear problem is not ready. Please "
569 "call setProblem() on the LinearProblem object before calling solve().");
573 if (!poly_dim_ && maxDegree_) {
574 #ifdef BELOS_TEUCHOS_TIME_MONITOR
578 poly_dim_ = poly_Op_->polyDegree();
581 "Belos::GmresPolyOp: Failed to generate polynomial that satisfied requirements.");
586 if (hasOuterSolver_ && maxDegree_) {
591 RCP<SolverManager<ScalarType, MultiVec<ScalarType>,
Operator<ScalarType> > > solver = factory.
create( outerSolverType_, outerParams_ );
593 "Belos::GmresPolySolMgr::solve(): Selected solver is not valid.");
598 RCP<gmres_poly_mv_t> new_rhs =
rcp(
new gmres_poly_mv_t( rcp_const_cast<MV>( problem_->getRHS() ) ) );
602 std::string solverLabel = label_ +
": Hybrid Gmres";
603 newProblem->setLabel(solverLabel);
607 newProblem->setLeftPrec( poly_Op_ );
609 newProblem->setRightPrec( poly_Op_ );
613 newProblem->setInitResVec(
rcp(
new gmres_poly_mv_t( rcp_const_cast<MV>( problem_->getInitResVec() ) ) ) );
614 newProblem->setProblem();
616 solver->setProblem( newProblem );
618 ret = solver->solve();
619 numIters_ = solver->getNumIters();
620 loaDetected_ = solver->isLOADetected();
623 else if (hasOuterSolver_) {
627 RCP<SolverManager<ScalarType, MV, OP> > solver = factory.create( outerSolverType_, outerParams_ );
629 "Belos::GmresPolySolMgr::solve(): Selected solver is not valid.");
631 solver->setProblem( problem_ );
633 ret = solver->solve();
634 numIters_ = solver->getNumIters();
635 loaDetected_ = solver->isLOADetected();
638 else if (maxDegree_) {
641 poly_Op_->ApplyPoly( *problem_->getRHS(), *problem_->getLHS() );
649 template<
class ScalarType,
class MV,
class OP>
652 std::ostringstream out;
654 out <<
"\"Belos::GmresPolySolMgr\": {"
656 <<
", Poly Degree: " << poly_dim_
657 <<
", Poly Max Degree: " << maxDegree_
658 <<
", Poly Tol: " << polyTol_;
665 #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...
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.
Traits class which defines basic operations on multivectors.
bool isParameter(const std::string &name) const
static constexpr std::ostream * outputStream_default_
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)
Teuchos::ScalarTraits< ScalarType > STS
bool isSublist(const std::string &name) const
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.
MultiVecTraits< ScalarType, MV > MVT
Hybrid block GMRES iterative linear solver.
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.
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...
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()