42 #ifndef __Belos_SolverFactory_hpp 43 #define __Belos_SolverFactory_hpp 59 #include <Teuchos_Array.hpp> 60 #include <Teuchos_Describable.hpp> 61 #include <Teuchos_StandardCatchMacros.hpp> 62 #include <Teuchos_TypeNameTraits.hpp> 213 template<
class Scalar,
class MV,
class OP>
256 Teuchos::RCP<solver_base_type>
257 create (
const std::string& solverName,
258 const Teuchos::RCP<Teuchos::ParameterList>& solverParams);
265 int numSupportedSolvers ()
const;
272 Teuchos::Array<std::string> supportedSolverNames ()
const;
275 bool isSupported (
const std::string& solverName)
const;
281 std::string description()
const;
288 void describe (Teuchos::FancyOStream& out,
289 const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default)
const;
305 std::map<std::string, std::string> aliasToCanonicalName_;
320 std::map<std::string, details::EBelosSolverType> canonicalNameToEnum_;
328 reviseParameterListForAlias (
const std::string& aliasName,
329 const Teuchos::RCP<Teuchos::ParameterList>& solverParams);
332 Teuchos::Array<std::string> canonicalSolverNames ()
const;
335 Teuchos::Array<std::string> solverNameAliases ()
const;
359 template<
class SolverManagerBaseType,
class SolverManagerType>
360 Teuchos::RCP<SolverManagerBaseType>
381 template<
class Scalar,
class MV,
class OP>
382 Teuchos::RCP<SolverManager<Scalar, MV, OP> >
384 const Teuchos::RCP<Teuchos::ParameterList>& params)
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);
434 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
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>
447 Teuchos::RCP<SolverManagerBaseType>
450 using Teuchos::ParameterList;
451 using Teuchos::parameterList;
454 RCP<SolverManagerType> solver = rcp (
new SolverManagerType);
458 RCP<ParameterList> pl;
459 if (params.is_null()) {
460 pl = parameterList (*solver->getValidParameters());
464 TEUCHOS_TEST_FOR_EXCEPTION(pl.is_null(), std::logic_error,
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>
512 const Teuchos::RCP<Teuchos::ParameterList>& solverParams)
514 TEUCHOS_TEST_FOR_EXCEPTION(solverParams.is_null(), std::logic_error,
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>
528 Teuchos::RCP<typename SolverFactory<Scalar, MV, OP>::solver_base_type>
531 const Teuchos::RCP<Teuchos::ParameterList>& solverParams)
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());
548 TEUCHOS_TEST_FOR_EXCEPTION(! validCanonicalName && isAnAlias, std::logic_error,
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.");
552 TEUCHOS_TEST_FOR_EXCEPTION(! validCanonicalName && ! isAnAlias,
553 std::invalid_argument,
"Invalid solver name \"" << solverName <<
"\".");
559 Teuchos::RCP<Teuchos::ParameterList> pl =
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>
575 using Teuchos::TypeNameTraits;
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>
589 const Teuchos::EVerbosityLevel verbLevel)
const 592 typedef Teuchos::Array<std::string>::const_iterator iter_type;
594 Teuchos::OSTab tab1 (out);
595 out << this->description();
598 if (static_cast<int> (verbLevel) > static_cast<int> (Teuchos::VERB_LOW)) {
600 Teuchos::OSTab tab2 (out);
601 out <<
"Number of supported solvers: " << numSupportedSolvers()
603 out <<
"Supported canonical solver names:";
605 Teuchos::Array<std::string> names = canonicalSolverNames();
606 for (iter_type iter = names.begin(); iter != names.end(); ++iter) {
608 if (iter + 1 != names.end()) {
613 out <<
"Supported aliases to canonical names:";
615 Teuchos::Array<std::string> names = solverNameAliases();
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>
634 Teuchos::Array<std::string>
637 Teuchos::Array<std::string> canonicalNames;
638 typedef std::map<std::string, details::EBelosSolverType>::const_iterator iter_type;
639 for (iter_type iter = canonicalNameToEnum_.begin();
640 iter != canonicalNameToEnum_.end(); ++iter) {
641 canonicalNames.push_back (iter->first);
643 return canonicalNames;
646 template<
class Scalar,
class MV,
class OP>
647 Teuchos::Array<std::string>
650 Teuchos::Array<std::string> names;
652 typedef std::map<std::string, std::string>::const_iterator iter_type;
653 for (iter_type iter = aliasToCanonicalName_.begin();
654 iter != aliasToCanonicalName_.end(); ++iter) {
655 names.push_back (iter->first);
661 template<
class Scalar,
class MV,
class OP>
662 Teuchos::Array<std::string>
665 Teuchos::Array<std::string> names;
667 typedef std::map<std::string, std::string>::const_iterator iter_type;
668 for (iter_type iter = aliasToCanonicalName_.begin();
669 iter != aliasToCanonicalName_.end(); ++iter) {
670 names.push_back (iter->first);
674 typedef std::map<std::string, details::EBelosSolverType>::const_iterator iter_type;
675 for (iter_type iter = canonicalNameToEnum_.begin();
676 iter != canonicalNameToEnum_.end(); ++iter) {
677 names.push_back (iter->first);
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.
SolverManager< Scalar, MV, OP > solver_base_type
The type returned by create().
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)
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.
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.
LSQRSolMgr: interface to the LSQR method.
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.