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);
64template<
class Scalar,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int,Scalar>>
66 public Teuchos::Describable
131 virtual Teuchos::RCP<solver_base_type>
133 const Teuchos::RCP<Teuchos::ParameterList>&
solverParams);
145 virtual Teuchos::RCP<solver_base_type>
147 const Teuchos::RCP<Teuchos::ParameterList>&
solverParams);
200 std::invalid_argument,
"Belos::SolverFactoryParent::registerSolver "
201 "was given a null solver to register.");
226 const Teuchos::EVerbosityLevel
verbLevel =
227 Teuchos::Describable::verbLevel_default)
const;
232 static std::vector<Teuchos::RCP<custom_solver_factory_type> > factories_;
234 static std::map<
const std::string, Teuchos::RCP<
typename
236 get_solverManagers() {
237 static std::map<
const std::string, Teuchos::RCP<
typename
243template<
class Scalar,
class MV,
class OP,
class DM>
244std::vector<Teuchos::RCP<typename SolverFactoryParent<Scalar, MV, OP, DM>::custom_solver_factory_type> >
245SolverFactoryParent<Scalar, MV, OP, DM>::factories_;
247template<
class SolverClass,
class Scalar,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int,Scalar>>
263template<
class SC,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int,SC>>
282template<
class SC,
class MV,
class OP,
class DM = DefaultDenseMatrix<
int,SC>>
283using SolverFactory = typename ::Belos::Impl::SolverFactorySelector<SC, MV, OP, DM>::type;
287template<
class Scalar,
class MV,
class OP,
class DM>
288Teuchos::RCP<typename SolverFactoryParent<Scalar, MV, OP, DM>::solver_base_type>
291 const Teuchos::RCP<Teuchos::ParameterList>&
solverParams)
296 (
solver.is_null (), std::invalid_argument,
297 "Invalid or unsupported Belos solver name \"" <<
solverName <<
"\".");
301template<
class Scalar,
class MV,
class OP,
class DM>
302Teuchos::RCP<typename SolverFactoryParent<Scalar, MV, OP, DM>::solver_base_type>
305 const Teuchos::RCP<Teuchos::ParameterList>&
solverParams)
310 for (std::size_t
k = 0;
k < factories_.size (); ++
k) {
315 if (!
solver.is_null ()) {
339 Teuchos::RCP<Teuchos::ParameterList>
pl =
347 typename std::map<
const std::string, Teuchos::RCP<
352 it == get_solverManagers().
end(),
353 std::invalid_argument,
"Belos solver manager " <<
solverNameUC <<
358 it->second == Teuchos::null,
359 std::logic_error,
"Belos::SolverFactoryParent: The registered "
360 "clone source for " <<
solverNameUC <<
" with standardized name "
362 ". Please report this bug to the Belos developers.");
369 std::logic_error,
"Belos::SolverFactoryParent: Failed "
370 "to clone SolverManager with name " <<
solverNameUC <<
" with standardized"
372 ". Please report this bug to the Belos developers.");
379 pl = Teuchos::parameterList (
solver->getValidParameters ()->name ());
383 pl.is_null(), std::logic_error,
384 "Belos::SolverFactory: ParameterList to pass to solver is null. This "
385 "should never happen. Please report this bug to the Belos developers.");
391template<
class Scalar,
class MV,
class OP,
class DM>
396 factories_.push_back (
factory);
400template<
class Scalar,
class MV,
class OP,
class DM>
409template<
class Scalar,
class MV,
class OP,
class DM>
414 using Teuchos::TypeNameTraits;
416 std::ostringstream
out;
417 out <<
"\"Belos::SolverFactory\": {";
430template<
class Scalar,
class MV,
class OP,
class DM>
434 const Teuchos::EVerbosityLevel
verbLevel)
const
436 using Teuchos::TypeNameTraits;
439 const Teuchos::EVerbosityLevel
vl =
442 if (
vl == Teuchos::VERB_NONE) {
452 out <<
"\"Belos::SolverFactory\":" << endl;
457 out <<
"Template parameters:" << endl;
466 if (
vl > Teuchos::VERB_LOW) {
468 out <<
"Number of solvers: " << numSupportedSolvers ()
470 out <<
"Canonical solver names: ";
474 out <<
"Aliases to canonical names: ";
480template<
class Scalar,
class MV,
class OP,
class DM>
488 for (std::size_t
k = 0;
k < factories_.size (); ++
k) {
500template<
class Scalar,
class MV,
class OP,
class DM>
501Teuchos::Array<std::string>
505 typedef std::vector<std::string>::const_iterator
iter_type;
506 Teuchos::Array<std::string>
names;
511 Teuchos::RCP<custom_solver_factory_type>
factory = factories_[
factInd];
514 factory->supportedSolverNames ();
538template<
class Scalar,
class MV,
class OP,
class DM>
Declaration of alias functions for solver names.
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.
Specializations of Belos::SolverFactory may inherit from this class to get basic SolverFactory functi...
virtual int numSupportedSolvers() const
Number of supported solvers.
void clearFactories()
Clear all custom solver factories.
void addFactory(const Teuchos::RCP< custom_solver_factory_type > &factory)
Add a custom solver factory.
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 Teuchos::Array< std::string > supportedSolverNames() const
List of supported solver names.
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...
virtual bool isSupported(const std::string &solverName) const
Whether the given solver name names a supported solver.
CustomSolverFactory< Scalar, MV, OP, DM > custom_solver_factory_type
The type of a solver factory that users may give to addFactory() (which see below)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Describe this object.
static void registerSolver(const std::string &solverName, Teuchos::RCP< SolverFactoryParent< Scalar, MV, OP, DM >::solver_base_type > instance)
register a solver for Inverted Injection (DII).
::Belos::SolverManager< Scalar, MV, OP, DM > solver_base_type
The type of the solver returned by create().
virtual std::string description() const
A string description of this object.
SolverFactoryParent< SC, MV, OP, DM > 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.
void registerSolverSubclassForTypes(const std::string &solverName)
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.
typename ::Belos::Impl::SolverFactorySelector< SC, MV, OP, DM >::type SolverFactory