42 #ifndef __Belos_SolverFactory_hpp 43 #define __Belos_SolverFactory_hpp 67 #include <Teuchos_Describable.hpp> 68 #include <Teuchos_StandardCatchMacros.hpp> 69 #include <Teuchos_TypeNameTraits.hpp> 208 template<
class Scalar,
class MV,
class OP>
244 Teuchos::RCP<solver_base_type>
245 create (
const std::string& solverName,
246 const Teuchos::RCP<Teuchos::ParameterList>& solverParams);
263 bool isSupported (
const std::string& solverName)
const;
276 void describe (Teuchos::FancyOStream& out,
277 const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default)
const;
283 printStringArray (std::ostream& out,
284 const Teuchos::ArrayView<const std::string>& array)
286 typedef Teuchos::ArrayView<std::string>::const_iterator iter_type;
289 for (iter_type iter = array.begin(); iter != array.end(); ++iter) {
290 out <<
"\"" << *iter <<
"\"";
291 if (iter + 1 != array.end()) {
300 printStringArray (std::ostream& out,
301 const std::vector<std::string>& array)
303 typedef std::vector<std::string>::const_iterator iter_type;
306 for (iter_type iter = array.begin(); iter != array.end(); ++iter) {
307 out <<
"\"" << *iter <<
"\"";
308 if (iter + 1 != array.end()) {
337 template<
class SolverManagerBaseType,
class SolverManagerType>
338 Teuchos::RCP<SolverManagerBaseType>
359 template<
class Scalar,
class MV,
class OP>
360 Teuchos::RCP<SolverManager<Scalar, MV, OP> >
362 const Teuchos::RCP<Teuchos::ParameterList>& params)
366 switch (solverType) {
369 return makeSolverManagerTmpl<base_type, impl_type> (params);
373 return makeSolverManagerTmpl<base_type, impl_type> (params);
377 return makeSolverManagerTmpl<base_type, impl_type> (params);
381 return makeSolverManagerTmpl<base_type, impl_type> (params);
385 return makeSolverManagerTmpl<base_type, impl_type> (params);
389 return makeSolverManagerTmpl<base_type, impl_type> (params);
393 return makeSolverManagerTmpl<base_type, impl_type> (params);
397 return makeSolverManagerTmpl<base_type, impl_type> (params);
401 return makeSolverManagerTmpl<base_type, impl_type> (params);
405 return makeSolverManagerTmpl<base_type, impl_type> (params);
409 return makeSolverManagerTmpl<base_type, impl_type> (params);
413 return makeSolverManagerTmpl<base_type, impl_type> (params);
417 return makeSolverManagerTmpl<base_type, impl_type> (params);
421 return makeSolverManagerTmpl<base_type, impl_type> (params);
425 return makeSolverManagerTmpl<base_type, impl_type> (params);
428 TEUCHOS_TEST_FOR_EXCEPTION(
429 true, std::logic_error,
"Belos::SolverFactory: Invalid EBelosSolverType " 430 "enum value " << solverType <<
". Please report this bug to the Belos " 438 return Teuchos::null;
441 template<
class SolverManagerBaseType,
class SolverManagerType>
442 Teuchos::RCP<SolverManagerBaseType>
445 using Teuchos::ParameterList;
446 using Teuchos::parameterList;
449 RCP<SolverManagerType> solver = rcp (
new SolverManagerType);
455 RCP<ParameterList> pl;
456 if (params.is_null()) {
457 pl = parameterList (solver->getValidParameters ()->name ());
461 TEUCHOS_TEST_FOR_EXCEPTION(
462 pl.is_null(), std::logic_error,
463 "Belos::SolverFactory: ParameterList to pass to solver is null. This " 464 "should never happen. Please report this bug to the Belos developers.");
465 solver->setParameters (pl);
472 template<
class Scalar,
class MV,
class OP>
476 template<
class Scalar,
class MV,
class OP>
477 Teuchos::RCP<typename SolverFactory<Scalar, MV, OP>::solver_base_type>
480 const Teuchos::RCP<Teuchos::ParameterList>& solverParams)
482 const char prefix[] =
"Belos::SolverFactory: ";
485 std::string solverNameUC (solverName);
487 typedef std::string::value_type char_t;
488 typedef std::ctype<char_t> facet_type;
489 const facet_type& facet = std::use_facet<facet_type> (std::locale ());
491 const std::string::size_type len = solverName.size ();
492 for (std::string::size_type k = 0; k < len; ++k) {
493 solverNameUC[k] = facet.toupper (solverName[k]);
498 std::pair<std::string, bool> aliasResult =
500 const std::string candidateCanonicalName = aliasResult.first;
501 const bool isAnAlias = aliasResult.second;
506 candidateCanonicalName :
508 const bool validCanonicalName =
514 TEUCHOS_TEST_FOR_EXCEPTION
515 (! validCanonicalName && isAnAlias, std::logic_error,
516 prefix <<
"Valid alias \"" << solverName <<
"\" has candidate canonical " 517 "name \"" << candidateCanonicalName <<
"\", which is not a canonical " 518 "solver name. Please report this bug to the Belos developers.");
519 TEUCHOS_TEST_FOR_EXCEPTION
520 (! validCanonicalName && ! isAnAlias, std::invalid_argument,
521 prefix <<
"Invalid solver name \"" << solverName <<
"\".");
527 Teuchos::RCP<Teuchos::ParameterList> pl =
528 solverParams.is_null() ? Teuchos::parameterList() : solverParams;
535 return Details::makeSolverManagerFromEnum<Scalar, MV, OP> (solverEnum, pl);
539 template<
class Scalar,
class MV,
class OP>
543 using Teuchos::TypeNameTraits;
545 std::ostringstream out;
546 out <<
"\"Belos::SolverFactory\": {";
547 if (this->getObjectLabel () !=
"") {
548 out <<
"Label: " << this->getObjectLabel () <<
", ";
550 out <<
"Scalar: " << TypeNameTraits<Scalar>::name ()
551 <<
", MV: " << TypeNameTraits<MV>::name ()
552 <<
", OP: " << TypeNameTraits<OP>::name ()
558 template<
class Scalar,
class MV,
class OP>
562 const Teuchos::EVerbosityLevel verbLevel)
const 564 using Teuchos::TypeNameTraits;
567 const Teuchos::EVerbosityLevel vl =
568 (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
570 if (vl == Teuchos::VERB_NONE) {
575 Teuchos::OSTab tab0 (out);
580 out <<
"\"Belos::SolverFactory\":" << endl;
581 if (this->getObjectLabel () !=
"") {
582 out <<
"Label: " << this->getObjectLabel () << endl;
585 out <<
"Template parameters:" << endl;
586 Teuchos::OSTab tab1 (out);
587 out <<
"Scalar: " << TypeNameTraits<Scalar>::name () << endl
588 <<
"MV: " << TypeNameTraits<MV>::name () << endl
589 <<
"OP: " << TypeNameTraits<OP>::name () << endl;
593 if (vl > Teuchos::VERB_LOW) {
594 Teuchos::OSTab tab1 (out);
597 out <<
"Canonical solver names: ";
601 out <<
"Aliases to canonical names: ";
607 template<
class Scalar,
class MV,
class OP>
614 template<
class Scalar,
class MV,
class OP>
615 Teuchos::Array<std::string>
618 typedef std::vector<std::string>::const_iterator iter_type;
619 Teuchos::Array<std::string> names;
623 for (iter_type iter = aliases.begin (); iter != aliases.end (); ++iter) {
624 names.push_back (*iter);
629 for (iter_type iter = canonicalNames.begin (); iter != canonicalNames.end (); ++iter) {
630 names.push_back (*iter);
638 #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.
Teuchos::RCP< SolverManagerBaseType > makeSolverManagerTmpl(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
The Belos::PseudoBlockTFQMRSolMgr provides a solver manager for the pseudo-block TFQMR linear solver...
Implementation of the RCG (Recycling Conjugate Gradient) iterative linear solver. ...
EBelosSolverType getEnumFromCanonicalName(const std::string &canonicalName)
Map from canonical solver name to solver enum value.
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.
Declaration of Belos::Details::EBelosSolverType enum, and associated functions.
The Belos::PseudoBlockCGSolMgr provides a powerful and fully-featured solver manager over the pseudo-...
Teuchos::RCP< SolverManager< Scalar, MV, OP > > makeSolverManagerFromEnum(const EBelosSolverType solverType, const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
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.
std::vector< std::string > solverNameAliases()
List of supported aliases (to canonical solver names).
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.
EBelosSolverType
1-to-1 enumeration of all supported SolverManager subclasses.
Implementation of the GCRODR (Recycling GMRES) iterative linear solver.
int numSupportedSolvers()
Number of Belos solvers supported for any linear algebra implementation ("generically").
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...
std::pair< std::string, bool > getCanonicalNameFromAlias(const std::string &candidateAlias)
Get the candidate canonical name for a given candidate alias.
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.
void reviseParameterListForAlias(const std::string &aliasName, Teuchos::ParameterList &solverParams)
Modify the input ParameterList appropriately for the given solver alias.
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::vector< std::string > canonicalSolverNames()
List of canonical solver names.