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);
300 bool isSupported (
const std::string& solverName)
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);
437 return makeSolverManagerTmpl<base_type, impl_type> (params);
441 return makeSolverManagerTmpl<base_type, impl_type> (params);
445 return makeSolverManagerTmpl<base_type, impl_type> (params);
449 return makeSolverManagerTmpl<base_type, impl_type> (params);
453 return makeSolverManagerTmpl<base_type, impl_type> (params);
457 return makeSolverManagerTmpl<base_type, impl_type> (params);
461 return makeSolverManagerTmpl<base_type, impl_type> (params);
465 return makeSolverManagerTmpl<base_type, impl_type> (params);
469 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);
492 TEUCHOS_TEST_FOR_EXCEPTION(
493 true, std::logic_error,
"Belos::SolverFactory: Invalid EBelosSolverType " 494 "enum value " << solverType <<
". Please report this bug to the Belos " 502 return Teuchos::null;
505 template<
class SolverManagerBaseType,
class SolverManagerType>
506 Teuchos::RCP<SolverManagerBaseType>
509 using Teuchos::ParameterList;
510 using Teuchos::parameterList;
513 RCP<SolverManagerType> solver = rcp (
new SolverManagerType);
519 RCP<ParameterList> pl;
520 if (params.is_null()) {
521 pl = parameterList (solver->getValidParameters ()->name ());
525 TEUCHOS_TEST_FOR_EXCEPTION(
526 pl.is_null(), std::logic_error,
527 "Belos::SolverFactory: ParameterList to pass to solver is null. This " 528 "should never happen. Please report this bug to the Belos developers.");
529 solver->setParameters (pl);
536 template<
class Scalar,
class MV,
class OP>
539 aliasToCanonicalName_[
"GMRES"] =
"PSEUDOBLOCK GMRES";
548 aliasToCanonicalName_[
"BLOCK GMRES"] =
"BLOCK GMRES";
549 aliasToCanonicalName_[
"FLEXIBLE GMRES"] =
"BLOCK GMRES";
550 aliasToCanonicalName_[
"CG"] =
"PSEUDOBLOCK CG";
551 aliasToCanonicalName_[
"PSEUDOBLOCKCG"] =
"PSEUDOBLOCK CG";
552 aliasToCanonicalName_[
"STOCHASTIC CG"] =
"PSEUDOBLOCK STOCHASTIC CG";
553 aliasToCanonicalName_[
"RECYCLING CG"] =
"RCG";
554 aliasToCanonicalName_[
"RECYCLING GMRES"] =
"GCRODR";
556 aliasToCanonicalName_[
"PSEUDO BLOCK GMRES"] =
"PSEUDOBLOCK GMRES";
557 aliasToCanonicalName_[
"PSEUDOBLOCKGMRES"] =
"PSEUDOBLOCK GMRES";
558 aliasToCanonicalName_[
"PSEUDO BLOCK CG"] =
"PSEUDOBLOCK CG";
559 aliasToCanonicalName_[
"PSEUDOBLOCKCG"] =
"PSEUDOBLOCK CG";
560 aliasToCanonicalName_[
"TRANSPOSE-FREE QMR"] =
"TFQMR";
561 aliasToCanonicalName_[
"PSEUDO BLOCK TFQMR"] =
"PSEUDOBLOCK TFQMR";
562 aliasToCanonicalName_[
"PSEUDO BLOCK TRANSPOSE-FREE QMR"] =
"PSEUDOBLOCK TFQMR";
563 aliasToCanonicalName_[
"GMRESPOLY"] =
"HYBRID BLOCK GMRES";
564 aliasToCanonicalName_[
"SEED GMRES"] =
"HYBRID BLOCK GMRES";
565 aliasToCanonicalName_[
"CGPOLY"] =
"PCPG";
566 aliasToCanonicalName_[
"SEED CG"] =
"PCPG";
567 aliasToCanonicalName_[
"FIXED POINT"] =
"FIXED POINT";
568 aliasToCanonicalName_[
"BICGSTAB"] =
"BICGSTAB";
592 template<
class Scalar,
class MV,
class OP>
596 Teuchos::ParameterList& solverParams)
598 if (aliasName ==
"FLEXIBLE GMRES") {
602 solverParams.set (
"Flexible Gmres",
true);
607 template<
class Scalar,
class MV,
class OP>
608 Teuchos::RCP<typename SolverFactory<Scalar, MV, OP>::solver_base_type>
611 const Teuchos::RCP<Teuchos::ParameterList>& solverParams)
613 const char prefix[] =
"Belos::SolverFactory: ";
616 std::string solverNameUC (solverName);
618 typedef std::string::value_type char_t;
619 typedef std::ctype<char_t> facet_type;
620 const facet_type& facet = std::use_facet<facet_type> (std::locale ());
622 const std::string::size_type len = solverName.size ();
623 for (std::string::size_type k = 0; k < len; ++k) {
624 solverNameUC[k] = facet.toupper (solverName[k]);
629 std::map<std::string, std::string>::const_iterator aliasIter =
630 aliasToCanonicalName_.find (solverNameUC);
631 const bool isAnAlias = (aliasIter != aliasToCanonicalName_.end());
632 const std::string candidateCanonicalName =
633 isAnAlias ? aliasIter->second : solverNameUC;
636 std::map<std::string, details::EBelosSolverType>::const_iterator canonicalIter =
637 canonicalNameToEnum_.find (candidateCanonicalName);
638 const bool validCanonicalName = (canonicalIter != canonicalNameToEnum_.end());
643 TEUCHOS_TEST_FOR_EXCEPTION
644 (! validCanonicalName && isAnAlias, std::logic_error,
645 prefix <<
"Valid alias \"" << solverName <<
"\" has candidate canonical " 646 "name \"" << candidateCanonicalName <<
"\", which is not a canonical " 647 "solver name. Please report this bug to the Belos developers.");
648 TEUCHOS_TEST_FOR_EXCEPTION
649 (! validCanonicalName && ! isAnAlias, std::invalid_argument,
650 prefix <<
"Invalid solver name \"" << solverName <<
"\".");
656 Teuchos::RCP<Teuchos::ParameterList> pl =
657 solverParams.is_null() ? Teuchos::parameterList() : solverParams;
661 reviseParameterListForAlias (solverNameUC, *pl);
664 return details::makeSolverManagerFromEnum<Scalar, MV, OP> (canonicalIter->second, pl);
668 template<
class Scalar,
class MV,
class OP>
672 using Teuchos::TypeNameTraits;
674 std::ostringstream out;
675 out <<
"\"Belos::SolverFactory\": {";
676 if (this->getObjectLabel () !=
"") {
677 out <<
"Label: " << this->getObjectLabel () <<
", ";
679 out <<
"Scalar: " << TypeNameTraits<Scalar>::name ()
680 <<
", MV: " << TypeNameTraits<MV>::name ()
681 <<
", OP: " << TypeNameTraits<OP>::name ()
687 template<
class Scalar,
class MV,
class OP>
691 const Teuchos::EVerbosityLevel verbLevel)
const 693 using Teuchos::TypeNameTraits;
696 const Teuchos::EVerbosityLevel vl =
697 (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
699 if (vl == Teuchos::VERB_NONE) {
704 Teuchos::OSTab tab0 (out);
709 out <<
"\"Belos::SolverFactory\":" << endl;
710 if (this->getObjectLabel () !=
"") {
711 out <<
"Label: " << this->getObjectLabel () << endl;
714 out <<
"Template parameters:" << endl;
715 Teuchos::OSTab tab1 (out);
716 out <<
"Scalar: " << TypeNameTraits<Scalar>::name () << endl
717 <<
"MV: " << TypeNameTraits<MV>::name () << endl
718 <<
"OP: " << TypeNameTraits<OP>::name () << endl;
722 if (vl > Teuchos::VERB_LOW) {
723 Teuchos::OSTab tab1 (out);
724 out <<
"Number of solvers: " << numSupportedSolvers ()
726 out <<
"Canonical solver names: ";
727 printStringArray (out, canonicalSolverNames ());
730 out <<
"Aliases to canonical names: ";
731 printStringArray (out, solverNameAliases ());
736 template<
class Scalar,
class MV,
class OP>
740 return static_cast<int> (canonicalNameToEnum_.size());
743 template<
class Scalar,
class MV,
class OP>
744 Teuchos::Array<std::string>
747 Teuchos::Array<std::string> canonicalNames;
748 typedef std::map<std::string, details::EBelosSolverType>::const_iterator iter_type;
749 for (iter_type iter = canonicalNameToEnum_.begin();
750 iter != canonicalNameToEnum_.end(); ++iter) {
751 canonicalNames.push_back (iter->first);
753 return canonicalNames;
756 template<
class Scalar,
class MV,
class OP>
757 Teuchos::Array<std::string>
758 SolverFactory<Scalar, MV, OP>::solverNameAliases ()
const 760 Teuchos::Array<std::string> names;
762 typedef std::map<std::string, std::string>::const_iterator iter_type;
763 for (iter_type iter = aliasToCanonicalName_.begin();
764 iter != aliasToCanonicalName_.end(); ++iter) {
765 names.push_back (iter->first);
771 template<
class Scalar,
class MV,
class OP>
772 Teuchos::Array<std::string>
775 Teuchos::Array<std::string> names;
777 typedef std::map<std::string, std::string>::const_iterator iter_type;
778 for (iter_type iter = aliasToCanonicalName_.begin();
779 iter != aliasToCanonicalName_.end(); ++iter) {
780 names.push_back (iter->first);
784 typedef std::map<std::string, details::EBelosSolverType>::const_iterator iter_type;
785 for (iter_type iter = canonicalNameToEnum_.begin();
786 iter != canonicalNameToEnum_.end(); ++iter) {
787 names.push_back (iter->first);
795 #endif // __Belos_SolverFactory_hpp Solver manager for the MINRES linear solver.
std::string description() const
A string description of this object.
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::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-...
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.
Namespace containing implementation details of Belos solvers.
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.
int numSupportedSolvers() const
Number of supported solvers.
Teuchos::Array< std::string > supportedSolverNames() const
List of supported solver names.
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.
bool isSupported(const std::string &solverName) const
Whether the given solver name names a supported 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...
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...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Describe this object.
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.