42 #ifndef __Belos_SolverFactory_hpp 43 #define __Belos_SolverFactory_hpp 65 #include <Teuchos_Array.hpp> 66 #include <Teuchos_Describable.hpp> 67 #include <Teuchos_StandardCatchMacros.hpp> 68 #include <Teuchos_TypeNameTraits.hpp> 245 template<
class Scalar,
class MV,
class OP>
281 Teuchos::RCP<solver_base_type>
282 create (
const std::string& solverName,
283 const Teuchos::RCP<Teuchos::ParameterList>& solverParams);
290 int numSupportedSolvers ()
const;
297 Teuchos::Array<std::string> supportedSolverNames ()
const;
300 bool isSupported (
const std::string& solverName)
const;
306 std::string description()
const;
313 void describe (Teuchos::FancyOStream& out,
314 const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default)
const;
330 std::map<std::string, std::string> aliasToCanonicalName_;
345 std::map<std::string, details::EBelosSolverType> canonicalNameToEnum_;
353 reviseParameterListForAlias (
const std::string& aliasName,
354 Teuchos::ParameterList& solverParams);
357 Teuchos::Array<std::string> canonicalSolverNames ()
const;
360 Teuchos::Array<std::string> solverNameAliases ()
const;
364 printStringArray (std::ostream& out,
365 const Teuchos::ArrayView<const std::string>& array)
367 typedef Teuchos::ArrayView<std::string>::const_iterator iter_type;
370 for (iter_type iter = array.begin(); iter != array.end(); ++iter) {
371 out <<
"\"" << *iter <<
"\"";
372 if (iter + 1 != array.end()) {
401 template<
class SolverManagerBaseType,
class SolverManagerType>
402 Teuchos::RCP<SolverManagerBaseType>
423 template<
class Scalar,
class MV,
class OP>
424 Teuchos::RCP<SolverManager<Scalar, MV, OP> >
426 const Teuchos::RCP<Teuchos::ParameterList>& params)
430 switch (solverType) {
433 return makeSolverManagerTmpl<base_type, impl_type> (params);
438 return makeSolverManagerTmpl<base_type, impl_type> (params);
443 return makeSolverManagerTmpl<base_type, impl_type> (params);
448 return makeSolverManagerTmpl<base_type, impl_type> (params);
453 return makeSolverManagerTmpl<base_type, impl_type> (params);
458 return makeSolverManagerTmpl<base_type, impl_type> (params);
463 return makeSolverManagerTmpl<base_type, impl_type> (params);
468 return makeSolverManagerTmpl<base_type, impl_type> (params);
473 return makeSolverManagerTmpl<base_type, impl_type> (params);
477 return makeSolverManagerTmpl<base_type, impl_type> (params);
481 return makeSolverManagerTmpl<base_type, impl_type> (params);
485 return makeSolverManagerTmpl<base_type, impl_type> (params);
489 return makeSolverManagerTmpl<base_type, impl_type> (params);
493 return makeSolverManagerTmpl<base_type, impl_type> (params);
497 return makeSolverManagerTmpl<base_type, impl_type> (params);
500 TEUCHOS_TEST_FOR_EXCEPTION(
501 true, std::logic_error,
"Belos::SolverFactory: Invalid EBelosSolverType " 502 "enum value " << solverType <<
". Please report this bug to the Belos " 510 return Teuchos::null;
513 template<
class SolverManagerBaseType,
class SolverManagerType>
514 Teuchos::RCP<SolverManagerBaseType>
517 using Teuchos::ParameterList;
518 using Teuchos::parameterList;
521 RCP<SolverManagerType> solver = rcp (
new SolverManagerType);
527 RCP<ParameterList> pl;
528 if (params.is_null()) {
529 pl = parameterList (solver->getValidParameters ()->name ());
533 TEUCHOS_TEST_FOR_EXCEPTION(
534 pl.is_null(), std::logic_error,
535 "Belos::SolverFactory: ParameterList to pass to solver is null. This " 536 "should never happen. Please report this bug to the Belos developers.");
537 solver->setParameters (pl);
544 template<
class Scalar,
class MV,
class OP>
547 aliasToCanonicalName_[
"GMRES"] =
"PSEUDOBLOCK GMRES";
556 aliasToCanonicalName_[
"BLOCK GMRES"] =
"BLOCK GMRES";
557 aliasToCanonicalName_[
"FLEXIBLE GMRES"] =
"BLOCK GMRES";
558 aliasToCanonicalName_[
"CG"] =
"PSEUDOBLOCK CG";
559 aliasToCanonicalName_[
"PSEUDOBLOCKCG"] =
"PSEUDOBLOCK CG";
560 aliasToCanonicalName_[
"STOCHASTIC CG"] =
"PSEUDOBLOCK STOCHASTIC CG";
561 aliasToCanonicalName_[
"RECYCLING CG"] =
"RCG";
562 aliasToCanonicalName_[
"RECYCLING GMRES"] =
"GCRODR";
564 aliasToCanonicalName_[
"PSEUDO BLOCK GMRES"] =
"PSEUDOBLOCK GMRES";
565 aliasToCanonicalName_[
"PSEUDOBLOCKGMRES"] =
"PSEUDOBLOCK GMRES";
566 aliasToCanonicalName_[
"PSEUDO BLOCK CG"] =
"PSEUDOBLOCK CG";
567 aliasToCanonicalName_[
"PSEUDOBLOCKCG"] =
"PSEUDOBLOCK CG";
568 aliasToCanonicalName_[
"TRANSPOSE-FREE QMR"] =
"TFQMR";
569 aliasToCanonicalName_[
"PSEUDO BLOCK TFQMR"] =
"PSEUDOBLOCK TFQMR";
570 aliasToCanonicalName_[
"PSEUDO BLOCK TRANSPOSE-FREE QMR"] =
"PSEUDOBLOCK TFQMR";
571 aliasToCanonicalName_[
"GMRESPOLY"] =
"HYBRID BLOCK GMRES";
572 aliasToCanonicalName_[
"SEED GMRES"] =
"HYBRID BLOCK GMRES";
573 aliasToCanonicalName_[
"CGPOLY"] =
"PCPG";
574 aliasToCanonicalName_[
"SEED CG"] =
"PCPG";
575 aliasToCanonicalName_[
"FIXED POINT"] =
"FIXED POINT";
576 aliasToCanonicalName_[
"BICGSTAB"] =
"BICGSTAB";
600 template<
class Scalar,
class MV,
class OP>
604 Teuchos::ParameterList& solverParams)
606 if (aliasName ==
"FLEXIBLE GMRES") {
610 solverParams.set (
"Flexible Gmres",
true);
615 template<
class Scalar,
class MV,
class OP>
616 Teuchos::RCP<typename SolverFactory<Scalar, MV, OP>::solver_base_type>
619 const Teuchos::RCP<Teuchos::ParameterList>& solverParams)
621 const char prefix[] =
"Belos::SolverFactory: ";
624 std::string solverNameUC (solverName);
626 typedef std::string::value_type char_t;
627 typedef std::ctype<char_t> facet_type;
628 const facet_type& facet = std::use_facet<facet_type> (std::locale ());
630 const std::string::size_type len = solverName.size ();
631 for (std::string::size_type k = 0; k < len; ++k) {
632 solverNameUC[k] = facet.toupper (solverName[k]);
637 std::map<std::string, std::string>::const_iterator aliasIter =
638 aliasToCanonicalName_.find (solverNameUC);
639 const bool isAnAlias = (aliasIter != aliasToCanonicalName_.end());
640 const std::string candidateCanonicalName =
641 isAnAlias ? aliasIter->second : solverNameUC;
644 std::map<std::string, details::EBelosSolverType>::const_iterator canonicalIter =
645 canonicalNameToEnum_.find (candidateCanonicalName);
646 const bool validCanonicalName = (canonicalIter != canonicalNameToEnum_.end());
651 TEUCHOS_TEST_FOR_EXCEPTION
652 (! validCanonicalName && isAnAlias, std::logic_error,
653 prefix <<
"Valid alias \"" << solverName <<
"\" has candidate canonical " 654 "name \"" << candidateCanonicalName <<
"\", which is not a canonical " 655 "solver name. Please report this bug to the Belos developers.");
656 TEUCHOS_TEST_FOR_EXCEPTION
657 (! validCanonicalName && ! isAnAlias, std::invalid_argument,
658 prefix <<
"Invalid solver name \"" << solverName <<
"\".");
664 Teuchos::RCP<Teuchos::ParameterList> pl =
665 solverParams.is_null() ? Teuchos::parameterList() : solverParams;
669 reviseParameterListForAlias (solverNameUC, *pl);
672 return details::makeSolverManagerFromEnum<Scalar, MV, OP> (canonicalIter->second, pl);
676 template<
class Scalar,
class MV,
class OP>
680 using Teuchos::TypeNameTraits;
682 std::ostringstream out;
683 out <<
"\"Belos::SolverFactory\": {";
684 if (this->getObjectLabel () !=
"") {
685 out <<
"Label: " << this->getObjectLabel () <<
", ";
687 out <<
"Scalar: " << TypeNameTraits<Scalar>::name ()
688 <<
", MV: " << TypeNameTraits<MV>::name ()
689 <<
", OP: " << TypeNameTraits<OP>::name ()
695 template<
class Scalar,
class MV,
class OP>
699 const Teuchos::EVerbosityLevel verbLevel)
const 701 using Teuchos::TypeNameTraits;
704 const Teuchos::EVerbosityLevel vl =
705 (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
707 if (vl == Teuchos::VERB_NONE) {
712 Teuchos::OSTab tab0 (out);
717 out <<
"\"Belos::SolverFactory\":" << endl;
718 if (this->getObjectLabel () !=
"") {
719 out <<
"Label: " << this->getObjectLabel () << endl;
722 out <<
"Template parameters:" << endl;
723 Teuchos::OSTab tab1 (out);
724 out <<
"Scalar: " << TypeNameTraits<Scalar>::name () << endl
725 <<
"MV: " << TypeNameTraits<MV>::name () << endl
726 <<
"OP: " << TypeNameTraits<OP>::name () << endl;
730 if (vl > Teuchos::VERB_LOW) {
731 Teuchos::OSTab tab1 (out);
732 out <<
"Number of solvers: " << numSupportedSolvers ()
734 out <<
"Canonical solver names: ";
735 printStringArray (out, canonicalSolverNames ());
738 out <<
"Aliases to canonical names: ";
739 printStringArray (out, solverNameAliases ());
744 template<
class Scalar,
class MV,
class OP>
748 return static_cast<int> (canonicalNameToEnum_.size());
751 template<
class Scalar,
class MV,
class OP>
752 Teuchos::Array<std::string>
755 Teuchos::Array<std::string> canonicalNames;
756 typedef std::map<std::string, details::EBelosSolverType>::const_iterator iter_type;
757 for (iter_type iter = canonicalNameToEnum_.begin();
758 iter != canonicalNameToEnum_.end(); ++iter) {
759 canonicalNames.push_back (iter->first);
761 return canonicalNames;
764 template<
class Scalar,
class MV,
class OP>
765 Teuchos::Array<std::string>
768 Teuchos::Array<std::string> names;
770 typedef std::map<std::string, std::string>::const_iterator iter_type;
771 for (iter_type iter = aliasToCanonicalName_.begin();
772 iter != aliasToCanonicalName_.end(); ++iter) {
773 names.push_back (iter->first);
779 template<
class Scalar,
class MV,
class OP>
780 Teuchos::Array<std::string>
783 Teuchos::Array<std::string> names;
785 typedef std::map<std::string, std::string>::const_iterator iter_type;
786 for (iter_type iter = aliasToCanonicalName_.begin();
787 iter != aliasToCanonicalName_.end(); ++iter) {
788 names.push_back (iter->first);
792 typedef std::map<std::string, details::EBelosSolverType>::const_iterator iter_type;
793 for (iter_type iter = canonicalNameToEnum_.begin();
794 iter != canonicalNameToEnum_.end(); ++iter) {
795 names.push_back (iter->first);
803 #endif // __Belos_SolverFactory_hpp Solver manager for the MINRES linear solver.
The Belos::FixedPointSolMgr provides a powerful and fully-featured solver manager over the FixedPoint...
Class which manages the output and verbosity of the Belos solvers.
The Belos::PseudoBlockCGSolMgr provides a solver manager for the BlockCG linear solver.
The Belos::PseudoBlockTFQMRSolMgr provides a solver manager for the pseudo-block TFQMR linear solver...
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)
Implementation of the RCG (Recycling Conjugate Gradient) iterative linear solver. ...
The Belos::BlockCGSolMgr provides a powerful and fully-featured solver manager over the CG and BlockC...
The Belos::FixedPointSolMgr provides a solver manager for the FixedPoint linear solver.
Declaration and definition of Belos::PCPGSolMgr (PCPG iterative linear solver).
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.
Declaration and definition of Belos::GCRODRSolMgr, which implements the GCRODR (recycling GMRES) solv...
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.
Declaration and definition of Belos::GmresPolySolMgr (hybrid block GMRES linear solver).
The Belos::BiCGStabSolMgr provides a solver manager for the BiCGStab linear solver.
Teuchos::RCP< SolverManagerBaseType > makeSolverManagerTmpl(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Implementation of the GCRODR (Recycling GMRES) iterative linear solver.
The Belos::PseudoBlockTFQMRSolMgr provides a powerful and fully-featured solver manager over the pseu...
Interface to standard and "pseudoblock" GMRES.
The Belos::PseudoBlockStochasticCGSolMgr provides a solver manager for the stochastic BlockCG linear ...
Hybrid block GMRES iterative linear solver.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
The Belos::TFQMRSolMgr provides a powerful and fully-featured solver manager over the TFQMR linear so...
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.
The Belos::BiCGStabSolMgr provides a powerful and fully-featured solver manager over the pseudo-block...
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 object.
PCPG iterative linear solver.
SolverManager< Scalar, MV, OP > solver_base_type
The type of the solver returned by create().
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()
Default constructor.
Factory for all solvers which Belos supports.
Belos header file which uses auto-configuration information to include necessary C++ headers...
The Belos::TFQMRSolMgr provides a solver manager for the TFQMR linear solver.
std::string description() const
A string description of this object.