10#ifndef __Belos_SolverFactory_hpp
11#define __Belos_SolverFactory_hpp
20#include <Teuchos_Describable.hpp>
21#include <Teuchos_StandardCatchMacros.hpp>
22#include <Teuchos_TypeNameTraits.hpp>
35 const Teuchos::ArrayView<const std::string>& array);
40 const std::vector<std::string>& array);
62template<
class Scalar,
class MV,
class OP>
64 public Teuchos::Describable
129 virtual Teuchos::RCP<solver_base_type>
131 const Teuchos::RCP<Teuchos::ParameterList>&
solverParams);
143 virtual Teuchos::RCP<solver_base_type>
145 const Teuchos::RCP<Teuchos::ParameterList>&
solverParams);
198 std::invalid_argument,
"Belos::SolverFactoryParent::registerSolver "
199 "was given a null solver to register.");
224 const Teuchos::EVerbosityLevel
verbLevel =
225 Teuchos::Describable::verbLevel_default)
const;
230 static std::vector<Teuchos::RCP<custom_solver_factory_type> > factories_;
232 static std::map<
const std::string, Teuchos::RCP<
typename
234 get_solverManagers() {
235 static std::map<
const std::string, Teuchos::RCP<
typename
241template<
class Scalar,
class MV,
class OP>
242std::vector<Teuchos::RCP<typename SolverFactoryParent<Scalar, MV, OP>::custom_solver_factory_type> >
243SolverFactoryParent<Scalar, MV, OP>::factories_;
245template<
class SolverClass,
class Scalar,
class MV,
class OP>
261template<
class SC,
class MV,
class OP>
280template<
class SC,
class MV,
class OP>
281using SolverFactory = typename ::Belos::Impl::SolverFactorySelector<SC, MV, OP>::type;
285template<
class Scalar,
class MV,
class OP>
286Teuchos::RCP<typename SolverFactoryParent<Scalar, MV, OP>::solver_base_type>
289 const Teuchos::RCP<Teuchos::ParameterList>&
solverParams)
294 (
solver.is_null (), std::invalid_argument,
295 "Invalid or unsupported Belos solver name \"" <<
solverName <<
"\".");
299template<
class Scalar,
class MV,
class OP>
300Teuchos::RCP<typename SolverFactoryParent<Scalar, MV, OP>::solver_base_type>
303 const Teuchos::RCP<Teuchos::ParameterList>&
solverParams)
308 for (std::size_t
k = 0;
k < factories_.size (); ++
k) {
313 if (!
solver.is_null ()) {
337 Teuchos::RCP<Teuchos::ParameterList>
pl =
345 typename std::map<
const std::string, Teuchos::RCP<
350 it == get_solverManagers().
end(),
351 std::invalid_argument,
"Belos solver manager " <<
solverNameUC <<
356 it->second == Teuchos::null,
357 std::logic_error,
"Belos::SolverFactoryParent: The registered "
358 "clone source for " <<
solverNameUC <<
" with standardized name "
360 ". Please report this bug to the Belos developers.");
367 std::logic_error,
"Belos::SolverFactoryParent: Failed "
368 "to clone SolverManager with name " <<
solverNameUC <<
" with standardized"
370 ". Please report this bug to the Belos developers.");
377 pl = Teuchos::parameterList (
solver->getValidParameters ()->name ());
381 pl.is_null(), std::logic_error,
382 "Belos::SolverFactory: ParameterList to pass to solver is null. This "
383 "should never happen. Please report this bug to the Belos developers.");
389template<
class Scalar,
class MV,
class OP>
394 factories_.push_back (
factory);
398template<
class Scalar,
class MV,
class OP>
407template<
class Scalar,
class MV,
class OP>
412 using Teuchos::TypeNameTraits;
414 std::ostringstream
out;
415 out <<
"\"Belos::SolverFactory\": {";
427template<
class Scalar,
class MV,
class OP>
431 const Teuchos::EVerbosityLevel
verbLevel)
const
433 using Teuchos::TypeNameTraits;
436 const Teuchos::EVerbosityLevel
vl =
439 if (
vl == Teuchos::VERB_NONE) {
449 out <<
"\"Belos::SolverFactory\":" << endl;
454 out <<
"Template parameters:" << endl;
462 if (
vl > Teuchos::VERB_LOW) {
464 out <<
"Number of solvers: " << numSupportedSolvers ()
466 out <<
"Canonical solver names: ";
470 out <<
"Aliases to canonical names: ";
476template<
class Scalar,
class MV,
class OP>
484 for (std::size_t
k = 0;
k < factories_.size (); ++
k) {
496template<
class Scalar,
class MV,
class OP>
497Teuchos::Array<std::string>
501 typedef std::vector<std::string>::const_iterator
iter_type;
502 Teuchos::Array<std::string>
names;
507 Teuchos::RCP<custom_solver_factory_type>
factory = factories_[
factInd];
510 factory->supportedSolverNames ();
534template<
class Scalar,
class MV,
class OP>
Belos header file which uses auto-configuration information to include necessary C++ headers.
Class which manages the output and verbosity of the Belos solvers.
Pure virtual base class which describes the basic interface for a solver manager.
Declaration of alias functions for solver names.
Specializations of Belos::SolverFactory may inherit from this class to get basic SolverFactory functi...
CustomSolverFactory< Scalar, MV, OP > custom_solver_factory_type
The type of a solver factory that users may give to addFactory() (which see below)
static void registerSolver(const std::string &solverName, Teuchos::RCP< SolverFactoryParent< Scalar, MV, OP >::solver_base_type > instance)
register a solver for Inverted Injection (DII).
void addFactory(const Teuchos::RCP< custom_solver_factory_type > &factory)
Add a custom solver factory.
void clearFactories()
Clear all custom solver factories.
virtual int numSupportedSolvers() const
Number of supported solvers.
virtual Teuchos::Array< std::string > supportedSolverNames() const
List of supported solver names.
static bool isSolverRegistered(const std::string &solverName)
is solver registered for Inverted Injection (DII).
virtual Teuchos::RCP< solver_base_type > create(const std::string &solverName, const Teuchos::RCP< Teuchos::ParameterList > &solverParams)
Create, configure, and return the specified solver.
virtual bool isSupported(const std::string &solverName) const
Whether the given solver name names a supported solver.
::Belos::SolverManager< Scalar, MV, OP > solver_base_type
The type of the solver returned by create().
virtual std::string description() const
A string description of this object.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Describe this object.
virtual Teuchos::RCP< solver_base_type > getSolver(const std::string &solverName, const Teuchos::RCP< Teuchos::ParameterList > &solverParams)
Return an instance of the specified solver, or Teuchos::null if this factory does not provide the req...
SolverFactoryParent< SC, MV, OP > type
Alternative run-time polymorphic interface for operators.
std::pair< std::string, bool > getCanonicalNameFromAlias(const std::string &candidateAlias)
Get the candidate canonical name for a given candidate alias.
void reviseParameterListForAlias(const std::string &aliasName, Teuchos::ParameterList &solverParams)
Modify the input ParameterList appropriately for the given solver alias.
std::vector< std::string > solverNameAliases()
List of supported aliases (to canonical solver names).
int numSupportedSolvers()
Number of Belos solvers supported for any linear algebra implementation ("generically").
std::vector< std::string > canonicalSolverNames()
List of canonical solver names.
std::string upperCase(const std::string &s)
Return the upper-case version of s.
void printStringArray(std::ostream &out, const Teuchos::ArrayView< const std::string > &array)
Print the given array of strings, in YAML format, to out.
void registerSolverSubclassForTypes(const std::string &solverName)
typename ::Belos::Impl::SolverFactorySelector< SC, MV, OP >::type SolverFactory