42 #ifndef __Belos_SolverFactory_hpp
43 #define __Belos_SolverFactory_hpp
60 #include <Teuchos_Describable.hpp>
61 #include <Teuchos_StandardCatchMacros.hpp>
213 template<
class Scalar,
class MV,
class OP>
257 create (
const std::string& solverName,
275 bool isSupported (
const std::string& solverName)
const;
305 std::map<std::string, std::string> aliasToCanonicalName_;
320 std::map<std::string, details::EBelosSolverType> canonicalNameToEnum_;
328 reviseParameterListForAlias (
const std::string& aliasName,
359 template<
class SolverManagerBaseType,
class SolverManagerType>
381 template<
class Scalar,
class MV,
class OP>
388 switch (solverType) {
391 return makeSolverManagerTmpl<base_type, impl_type> (params);
396 return makeSolverManagerTmpl<base_type, impl_type> (params);
401 return makeSolverManagerTmpl<base_type, impl_type> (params);
406 return makeSolverManagerTmpl<base_type, impl_type> (params);
411 return makeSolverManagerTmpl<base_type, impl_type> (params);
416 return makeSolverManagerTmpl<base_type, impl_type> (params);
421 return makeSolverManagerTmpl<base_type, impl_type> (params);
426 return makeSolverManagerTmpl<base_type, impl_type> (params);
431 return makeSolverManagerTmpl<base_type, impl_type> (params);
435 "Invalid EBelosSolverType enum value " << solverType
436 <<
". Please report this bug to the Belos developers.");
443 return Teuchos::null;
446 template<
class SolverManagerBaseType,
class SolverManagerType>
451 using Teuchos::parameterList;
454 RCP<SolverManagerType> solver =
rcp (
new SolverManagerType);
458 RCP<ParameterList> pl;
460 pl = parameterList (*solver->getValidParameters());
465 "ParameterList to pass to solver is null. This "
466 "should never happen. Please report this bug to "
467 "the Belos developers.");
468 solver->setParameters (pl);
475 template<
class Scalar,
class MV,
class OP>
478 aliasToCanonicalName_[
"GMRES"] =
"Pseudoblock GMRES";
485 aliasToCanonicalName_[
"Flexible GMRES"] =
"Block GMRES";
486 aliasToCanonicalName_[
"CG"] =
"Pseudoblock CG";
487 aliasToCanonicalName_[
"Stochastic CG"] =
"Pseudoblock Stochastic CG";
488 aliasToCanonicalName_[
"Recycling CG"] =
"RCG";
489 aliasToCanonicalName_[
"Recycling GMRES"] =
"GCRODR";
491 aliasToCanonicalName_[
"Pseudo Block GMRES"] =
"Pseudoblock GMRES";
492 aliasToCanonicalName_[
"Pseudo Block CG"] =
"Pseudoblock CG";
508 template<
class Scalar,
class MV,
class OP>
515 "Belos::SolverFactory::reviseParameterListForAlias: the input "
516 "ParameterList is supposed to be nonnull. Please report this "
517 "bug to the Belos developers.");
518 if (aliasName ==
"Flexible GMRES") {
522 solverParams->
set (
"Flexible Gmres",
true);
527 template<
class Scalar,
class MV,
class OP>
534 std::map<std::string, std::string>::const_iterator aliasIter =
535 aliasToCanonicalName_.find (solverName);
536 const bool isAnAlias = (aliasIter != aliasToCanonicalName_.end());
537 const std::string candidateCanonicalName =
538 isAnAlias ? aliasIter->second : solverName;
541 std::map<std::string, details::EBelosSolverType>::const_iterator canonicalIter =
542 canonicalNameToEnum_.find (candidateCanonicalName);
543 const bool validCanonicalName = (canonicalIter != canonicalNameToEnum_.end());
549 "Valid alias \"" << solverName <<
"\" has candidate canonical name \""
550 << candidateCanonicalName <<
"\", which is not a canonical solver name. "
551 "Please report this bug to the Belos developers.");
553 std::invalid_argument,
"Invalid solver name \"" << solverName <<
"\".");
560 solverParams.
is_null() ? Teuchos::parameterList() : solverParams;
564 reviseParameterListForAlias (solverName, pl);
567 return details::makeSolverManagerFromEnum<Scalar, MV, OP> (canonicalIter->second, pl);
571 template<
class Scalar,
class MV,
class OP>
576 std::ostringstream os;
577 os <<
"Belos::SolverFactory<" << TypeNameTraits<Scalar>::name()
578 <<
", " << TypeNameTraits<Scalar>::name()
579 <<
", " << TypeNameTraits<MV>::name()
580 <<
", " << TypeNameTraits<OP>::name()
585 template<
class Scalar,
class MV,
class OP>
595 out << this->description();
601 out <<
"Number of supported solvers: " << numSupportedSolvers()
603 out <<
"Supported canonical solver names:";
606 for (iter_type iter = names.
begin(); iter != names.
end(); ++iter) {
608 if (iter + 1 != names.
end()) {
613 out <<
"Supported aliases to canonical names:";
616 for (iter_type iter = names.
begin(); iter != names.
end(); ++iter) {
618 if (iter + 1 != names.
end()) {
626 template<
class Scalar,
class MV,
class OP>
630 return static_cast<int> (canonicalNameToEnum_.size());
633 template<
class Scalar,
class MV,
class OP>
638 typedef std::map<std::string, details::EBelosSolverType>::const_iterator iter_type;
639 for (iter_type iter = canonicalNameToEnum_.begin();
640 iter != canonicalNameToEnum_.end(); ++iter) {
643 return canonicalNames;
646 template<
class Scalar,
class MV,
class OP>
648 SolverFactory<Scalar, MV, OP>::solverNameAliases ()
const
652 typedef std::map<std::string, std::string>::const_iterator iter_type;
653 for (iter_type iter = aliasToCanonicalName_.begin();
654 iter != aliasToCanonicalName_.end(); ++iter) {
661 template<
class Scalar,
class MV,
class OP>
667 typedef std::map<std::string, std::string>::const_iterator iter_type;
668 for (iter_type iter = aliasToCanonicalName_.begin();
669 iter != aliasToCanonicalName_.end(); ++iter) {
674 typedef std::map<std::string, details::EBelosSolverType>::const_iterator iter_type;
675 for (iter_type iter = canonicalNameToEnum_.begin();
676 iter != canonicalNameToEnum_.end(); ++iter) {
685 #endif // __Belos_SolverFactory_hpp
Solver manager for the MINRES linear solver.
Class which manages the output and verbosity of the Belos solvers.
The Belos::PseudoBlockCGSolMgr provides a solver manager for the BlockCG linear solver.
bool isSupported(const std::string &solverName) const
Whether the given solver name names a supported solver.
SolverManager< Scalar, MV, OP > solver_base_type
The type returned by create().
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::Array< std::string > supportedSolverNames() const
List of supported solver names.
Teuchos::RCP< SolverManager< Scalar, MV, OP > > makeSolverManagerFromEnum(const EBelosSolverType solverType, const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
The Belos::RCGSolMgr provides a powerful and fully-featured solver manager over the RCG (Recycling Co...
The Belos::BlockCGSolMgr provides a powerful and fully-featured solver manager over the CG and BlockC...
Interface to Block GMRES and Flexible GMRES.
The Belos::PseudoBlockCGSolMgr provides a powerful and fully-featured solver manager over the pseudo-...
int numSupportedSolvers() const
Number of supported solvers.
The Belos::GCRODRSolMgr provides a solver manager for the GCRODR linear solver.
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. ...
The Belos::BlockGmresSolMgr provides a solver manager for the BlockGmres linear solver.
MINRES linear solver solution manager.
Teuchos::RCP< SolverManagerBaseType > makeSolverManagerTmpl(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
The Belos::GCRODRSolMgr provides a powerful and fully-featured solver manager over the GCRODR linear ...
Interface to standard and "pseudoblock" GMRES.
The Belos::PseudoBlockStochasticCGSolMgr provides a solver manager for the stochastic BlockCG linear ...
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
The Belos::BlockCGSolMgr provides a solver manager for the BlockCG linear solver. ...
Teuchos::RCP< solver_base_type > create(const std::string &solverName, const Teuchos::RCP< Teuchos::ParameterList > &solverParams)
Create, configure, and return the specified solver.
std::vector< T >::const_iterator const_iterator
static const EVerbosityLevel verbLevel_default
LSQRSolMgr: interface to the LSQR method.
void push_back(const value_type &x)
EBelosSolverType
1-to-1 enumeration of all supported SolverManager subclasses.
The Belos::PseudoBlockStochasticCGSolMgr provides a powerful and fully-featured solver manager over t...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Describe this SolverFactory object.
LSQR method (for linear systems and linear least-squares problems).
The Belos::RCGSolMgr provides a solver manager for the RCG (Recycling Conjugate Gradient) linear solv...
The Belos::PseudoBlockGmresSolMgr provides a solver manager for the BlockGmres linear solver...
SolverFactory()
Constructor.
Factory for all solvers which Belos supports.
Belos header file which uses auto-configuration information to include necessary C++ headers...
std::string description() const
A string description of this SolverFactory object.