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>
199 return Teuchos::tuple(timerPoly_);
237 problem_->setProblem ();
238 poly_Op_ = Teuchos::null;
289 static constexpr
int maxDegree_default_ = 25;
291 static constexpr
const char * label_default_ =
"Belos";
292 static constexpr
const char * outerSolverType_default_ =
"";
293 static constexpr
const char * polyType_default_ =
"Arnoldi";
294 static constexpr
const char * orthoType_default_ =
"DGKS";
295 static constexpr std::ostream * outputStream_default_ = &std::cout;
298 MagnitudeType polyTol_;
299 int maxDegree_, numIters_;
301 bool hasOuterSolver_;
303 std::string polyType_;
304 std::string outerSolverType_;
305 std::string orthoType_;
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_);
504 if (params->
isType<MagnitudeType> (
"Polynomial Tolerance")) {
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
526 if (timerPoly_ == Teuchos::null) {
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);
606 if (problem_->getLeftPrec() != Teuchos::null)
607 newProblem->setLeftPrec( poly_Op_ );
609 newProblem->setRightPrec( poly_Op_ );
612 if (problem_->getInitResVec() != Teuchos::null)
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.
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 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.
Hybrid block GMRES iterative linear solver.
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()