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> 229 template<
class Scalar,
class MV,
class OP>
265 Teuchos::RCP<solver_base_type>
266 create (
const std::string& solverName,
267 const Teuchos::RCP<Teuchos::ParameterList>& solverParams);
274 int numSupportedSolvers ()
const;
281 Teuchos::Array<std::string> supportedSolverNames ()
const;
284 bool isSupported (
const std::string& solverName)
const;
290 std::string description()
const;
297 void describe (Teuchos::FancyOStream& out,
298 const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default)
const;
314 std::map<std::string, std::string> aliasToCanonicalName_;
329 std::map<std::string, details::EBelosSolverType> canonicalNameToEnum_;
337 reviseParameterListForAlias (
const std::string& aliasName,
338 Teuchos::ParameterList& solverParams);
341 Teuchos::Array<std::string> canonicalSolverNames ()
const;
344 Teuchos::Array<std::string> solverNameAliases ()
const;
348 printStringArray (std::ostream& out,
349 const Teuchos::ArrayView<const std::string>& array)
351 typedef Teuchos::ArrayView<std::string>::const_iterator iter_type;
354 for (iter_type iter = array.begin(); iter != array.end(); ++iter) {
355 out <<
"\"" << *iter <<
"\"";
356 if (iter + 1 != array.end()) {
385 template<
class SolverManagerBaseType,
class SolverManagerType>
386 Teuchos::RCP<SolverManagerBaseType>
407 template<
class Scalar,
class MV,
class OP>
408 Teuchos::RCP<SolverManager<Scalar, MV, OP> >
410 const Teuchos::RCP<Teuchos::ParameterList>& params)
414 switch (solverType) {
417 return makeSolverManagerTmpl<base_type, impl_type> (params);
422 return makeSolverManagerTmpl<base_type, impl_type> (params);
427 return makeSolverManagerTmpl<base_type, impl_type> (params);
432 return makeSolverManagerTmpl<base_type, impl_type> (params);
437 return makeSolverManagerTmpl<base_type, impl_type> (params);
442 return makeSolverManagerTmpl<base_type, impl_type> (params);
447 return makeSolverManagerTmpl<base_type, impl_type> (params);
452 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);
484 TEUCHOS_TEST_FOR_EXCEPTION(
485 true, std::logic_error,
"Belos::SolverFactory: Invalid EBelosSolverType " 486 "enum value " << solverType <<
". Please report this bug to the Belos " 494 return Teuchos::null;
497 template<
class SolverManagerBaseType,
class SolverManagerType>
498 Teuchos::RCP<SolverManagerBaseType>
501 using Teuchos::ParameterList;
502 using Teuchos::parameterList;
505 RCP<SolverManagerType> solver = rcp (
new SolverManagerType);
511 RCP<ParameterList> pl;
512 if (params.is_null()) {
513 pl = parameterList (solver->getValidParameters ()->name ());
517 TEUCHOS_TEST_FOR_EXCEPTION(
518 pl.is_null(), std::logic_error,
519 "Belos::SolverFactory: ParameterList to pass to solver is null. This " 520 "should never happen. Please report this bug to the Belos developers.");
521 solver->setParameters (pl);
528 template<
class Scalar,
class MV,
class OP>
531 aliasToCanonicalName_[
"GMRES"] =
"PSEUDOBLOCK GMRES";
540 aliasToCanonicalName_[
"BLOCK GMRES"] =
"BLOCK GMRES";
541 aliasToCanonicalName_[
"FLEXIBLE GMRES"] =
"BLOCK GMRES";
542 aliasToCanonicalName_[
"CG"] =
"PSEUDOBLOCK CG";
543 aliasToCanonicalName_[
"PSEUDOBLOCKCG"] =
"PSEUDOBLOCK CG";
544 aliasToCanonicalName_[
"STOCHASTIC CG"] =
"PSEUDOBLOCK STOCHASTIC CG";
545 aliasToCanonicalName_[
"RECYCLING CG"] =
"RCG";
546 aliasToCanonicalName_[
"RECYCLING GMRES"] =
"GCRODR";
548 aliasToCanonicalName_[
"PSEUDO BLOCK GMRES"] =
"PSEUDOBLOCK GMRES";
549 aliasToCanonicalName_[
"PSEUDOBLOCKGMRES"] =
"PSEUDOBLOCK GMRES";
550 aliasToCanonicalName_[
"PSEUDO BLOCK CG"] =
"PSEUDOBLOCK CG";
551 aliasToCanonicalName_[
"PSEUDOBLOCKCG"] =
"PSEUDOBLOCK CG";
552 aliasToCanonicalName_[
"TRANSPOSE-FREE QMR"] =
"TFQMR";
553 aliasToCanonicalName_[
"PSEUDO BLOCK TFQMR"] =
"PSEUDOBLOCK TFQMR";
554 aliasToCanonicalName_[
"PSEUDO BLOCK TRANSPOSE-FREE QMR"] =
"PSEUDOBLOCK TFQMR";
555 aliasToCanonicalName_[
"GMRESPOLY"] =
"HYBRID BLOCK GMRES";
556 aliasToCanonicalName_[
"SEED GMRES"] =
"HYBRID BLOCK GMRES";
557 aliasToCanonicalName_[
"CGPOLY"] =
"PCPG";
558 aliasToCanonicalName_[
"SEED CG"] =
"PCPG";
559 aliasToCanonicalName_[
"FIXED POINT"] =
"FIXED POINT";
560 aliasToCanonicalName_[
"BICGSTAB"] =
"BICGSTAB";
584 template<
class Scalar,
class MV,
class OP>
588 Teuchos::ParameterList& solverParams)
590 if (aliasName ==
"FLEXIBLE GMRES") {
594 solverParams.set (
"Flexible Gmres",
true);
599 template<
class Scalar,
class MV,
class OP>
600 Teuchos::RCP<typename SolverFactory<Scalar, MV, OP>::solver_base_type>
603 const Teuchos::RCP<Teuchos::ParameterList>& solverParams)
605 const char prefix[] =
"Belos::SolverFactory: ";
608 std::string solverNameUC (solverName);
610 typedef std::string::value_type char_t;
611 typedef std::ctype<char_t> facet_type;
612 const facet_type& facet = std::use_facet<facet_type> (std::locale ());
614 const std::string::size_type len = solverName.size ();
615 for (std::string::size_type k = 0; k < len; ++k) {
616 solverNameUC[k] = facet.toupper (solverName[k]);
621 std::map<std::string, std::string>::const_iterator aliasIter =
622 aliasToCanonicalName_.find (solverNameUC);
623 const bool isAnAlias = (aliasIter != aliasToCanonicalName_.end());
624 const std::string candidateCanonicalName =
625 isAnAlias ? aliasIter->second : solverNameUC;
628 std::map<std::string, details::EBelosSolverType>::const_iterator canonicalIter =
629 canonicalNameToEnum_.find (candidateCanonicalName);
630 const bool validCanonicalName = (canonicalIter != canonicalNameToEnum_.end());
635 TEUCHOS_TEST_FOR_EXCEPTION
636 (! validCanonicalName && isAnAlias, std::logic_error,
637 prefix <<
"Valid alias \"" << solverName <<
"\" has candidate canonical " 638 "name \"" << candidateCanonicalName <<
"\", which is not a canonical " 639 "solver name. Please report this bug to the Belos developers.");
640 TEUCHOS_TEST_FOR_EXCEPTION
641 (! validCanonicalName && ! isAnAlias, std::invalid_argument,
642 prefix <<
"Invalid solver name \"" << solverName <<
"\".");
648 Teuchos::RCP<Teuchos::ParameterList> pl =
649 solverParams.is_null() ? Teuchos::parameterList() : solverParams;
653 reviseParameterListForAlias (solverNameUC, *pl);
656 return details::makeSolverManagerFromEnum<Scalar, MV, OP> (canonicalIter->second, pl);
660 template<
class Scalar,
class MV,
class OP>
664 using Teuchos::TypeNameTraits;
666 std::ostringstream out;
667 out <<
"\"Belos::SolverFactory\": {";
668 if (this->getObjectLabel () !=
"") {
669 out <<
"Label: " << this->getObjectLabel () <<
", ";
671 out <<
"Scalar: " << TypeNameTraits<Scalar>::name ()
672 <<
", MV: " << TypeNameTraits<MV>::name ()
673 <<
", OP: " << TypeNameTraits<OP>::name ()
679 template<
class Scalar,
class MV,
class OP>
683 const Teuchos::EVerbosityLevel verbLevel)
const 685 using Teuchos::TypeNameTraits;
688 const Teuchos::EVerbosityLevel vl =
689 (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
691 if (vl == Teuchos::VERB_NONE) {
696 Teuchos::OSTab tab0 (out);
701 out <<
"\"Belos::SolverFactory\":" << endl;
702 if (this->getObjectLabel () !=
"") {
703 out <<
"Label: " << this->getObjectLabel () << endl;
706 out <<
"Template parameters:" << endl;
707 Teuchos::OSTab tab1 (out);
708 out <<
"Scalar: " << TypeNameTraits<Scalar>::name () << endl
709 <<
"MV: " << TypeNameTraits<MV>::name () << endl
710 <<
"OP: " << TypeNameTraits<OP>::name () << endl;
714 if (vl > Teuchos::VERB_LOW) {
715 Teuchos::OSTab tab1 (out);
716 out <<
"Number of solvers: " << numSupportedSolvers ()
718 out <<
"Canonical solver names: ";
719 printStringArray (out, canonicalSolverNames ());
722 out <<
"Aliases to canonical names: ";
723 printStringArray (out, solverNameAliases ());
728 template<
class Scalar,
class MV,
class OP>
732 return static_cast<int> (canonicalNameToEnum_.size());
735 template<
class Scalar,
class MV,
class OP>
736 Teuchos::Array<std::string>
739 Teuchos::Array<std::string> canonicalNames;
740 typedef std::map<std::string, details::EBelosSolverType>::const_iterator iter_type;
741 for (iter_type iter = canonicalNameToEnum_.begin();
742 iter != canonicalNameToEnum_.end(); ++iter) {
743 canonicalNames.push_back (iter->first);
745 return canonicalNames;
748 template<
class Scalar,
class MV,
class OP>
749 Teuchos::Array<std::string>
752 Teuchos::Array<std::string> names;
754 typedef std::map<std::string, std::string>::const_iterator iter_type;
755 for (iter_type iter = aliasToCanonicalName_.begin();
756 iter != aliasToCanonicalName_.end(); ++iter) {
757 names.push_back (iter->first);
763 template<
class Scalar,
class MV,
class OP>
764 Teuchos::Array<std::string>
767 Teuchos::Array<std::string> names;
769 typedef std::map<std::string, std::string>::const_iterator iter_type;
770 for (iter_type iter = aliasToCanonicalName_.begin();
771 iter != aliasToCanonicalName_.end(); ++iter) {
772 names.push_back (iter->first);
776 typedef std::map<std::string, details::EBelosSolverType>::const_iterator iter_type;
777 for (iter_type iter = canonicalNameToEnum_.begin();
778 iter != canonicalNameToEnum_.end(); ++iter) {
779 names.push_back (iter->first);
787 #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.