42#ifndef TRILINOS_DETAILS_LINEARSOLVER_FACTORY_HPP
43#define TRILINOS_DETAILS_LINEARSOLVER_FACTORY_HPP
83#include "TeuchosRemainder_config.h"
85#ifdef HAVE_TEUCHOSCORE_CXX11
105#if ! defined(HAVE_TEUCHOS_DYNAMIC_LIBS) && defined(HAVE_TEUCHOS_CXX_ATTRIBUTE_WEAK)
136template<
class MV,
class OP,
class NormType>
165template<
class MV,
class OP,
class NormType>
167getLinearSolver (
const std::string& packageName,
const std::string& solverName);
234template<
class MV,
class OP,
class NormType>
326template<
class MV,
class OP,
class NormType>
329#ifdef HAVE_TEUCHOSCORE_CXX11
399template<
class MV,
class OP,
class NormType>
407#ifdef HAVE_TEUCHOSCORE_CXX11
420 typedef std::map<std::string, factory_pointer_type>
map_type;
439 typedef typename map_type::iterator iter_type;
440 iter_type it = factories_->find (packageName);
441 if (it == factories_->end ()) {
467 (factory.
get () == NULL, std::invalid_argument,
"Trilinos::Details::"
468 "LinearSolverFactoryRepository::registerLinearSolverFactory: Input "
469 "'factory' is NULL!");
471 if (factories_->find (packageName) == factories_->end ()) {
472 factories_->insert (std::make_pair (packageName, factory));
492 static void createFactories () {
493 if (factories_ == NULL) {
499 (void) atexit (freeFactories);
502 (factories_ == NULL, std::logic_error,
"Trilinos::Details::"
503 "LinearSolverFactoryRepository::createFactories: "
504 "Should never get here! factories_ is NULL.");
515 static void freeFactories () {
516 if (factories_ != NULL) {
526template<
class MV,
class OP,
class NormType>
528LinearSolverFactoryRepository<MV, OP, NormType>::factories_ = NULL;
536template<
class MV,
class OP,
class NormType>
539#ifdef HAVE_TEUCHOSCORE_CXX11
549template<
class MV,
class OP,
class NormType>
556 typedef typename repo_type::factory_pointer_type factory_pointer_type;
558 const char prefix[] =
"Trilinos::Details::getLinearSolver: ";
562#if ! defined(HAVE_TEUCHOS_DYNAMIC_LIBS) && defined(HAVE_TEUCHOS_CXX_ATTRIBUTE_WEAK)
579 const bool haveRunTimeReg =
584 (! pkgExists, std::invalid_argument, prefix <<
"Package \"" << packageName
585 <<
"\" never registered a LinearSolverFactory for _any_ combination of "
586 "template parameters MV, OP, and NormType. This means either that the "
587 "package name is invalid, or that the package is not enabled. "
588 "Trilinos_ENABLE_LINEAR_SOLVER_FACTORY_REGISTRATION = "
589 << (haveRunTimeReg ?
"ON" :
"OFF") <<
".");
591 factory_pointer_type factory = repo_type::getFactory (packageName);
593 (factory.get () == NULL, std::invalid_argument, prefix <<
"Package \"" <<
594 packageName <<
"\" is valid, but it never registered a LinearSolverFactory"
595 " for template parameters "
596 "MV = " << TypeNameTraits<MV>::name () <<
", "
597 "OP = " << TypeNameTraits<OP>::name () <<
", "
598 "NormType = " << TypeNameTraits<NormType>::name () <<
". "
599 "Trilinos_ENABLE_LINEAR_SOLVER_FACTORY_REGISTRATION = "
600 << (haveRunTimeReg ?
"ON" :
"OFF") <<
".");
602 RCP<solver_type> solver = factory->getLinearSolver (solverName);
604 (solver.is_null (), std::invalid_argument, prefix <<
"Invalid solver name "
605 "\"" << solverName <<
"\". However, package \"" << packageName <<
"\" is "
606 "valid, and it did register a LinearSolverFactory for template parameters "
607 "MV = " << TypeNameTraits<MV>::name () <<
", "
608 "OP = " << TypeNameTraits<OP>::name () <<
", "
609 "NormType = " << TypeNameTraits<NormType>::name () <<
". "
610 "Trilinos_ENABLE_LINEAR_SOLVER_FACTORY_REGISTRATION = "
611 << (haveRunTimeReg ?
"ON" :
"OFF") <<
".");
Reference-counted pointer class and non-member templated function implementations.
void registerLinearSolverFactory(const std::string &packageName, const Teuchos::RCP< LinearSolverFactory< MV, OP, NormType > > &factory)
Called by a package to register its LinearSolverFactory.
Teuchos::RCP< LinearSolver< MV, OP, NormType > > getLinearSolver(const std::string &packageName, const std::string &solverName)
Get a LinearSolver instance.
Smart reference counting pointer class for automatic garbage collection.
T * get() const
Get the raw C++ pointer to the underlying object.
Default traits class that just returns typeid(T).name().
Repository of solver factories.
Teuchos::RCP< LinearSolverFactory< MV, OP, NormType > > factory_pointer_type
Type of a reference-counted pointer to LinearSolverFactory.
static factory_pointer_type getFactory(const std::string &packageName)
Get a LinearSolverFactory from the given package.
std::map< std::string, factory_pointer_type > map_type
Type of a data structure that looks up a LinearSolverFactory corresponding to a given package name.
static void registerLinearSolverFactory(const std::string &packageName, const factory_pointer_type &factory)
Register the given factory from a package.
Interface for a "factory" that creates solvers.
virtual Teuchos::RCP< LinearSolver< MV, OP, NormType > > getLinearSolver(const std::string &solverName)=0
Get an instance of a solver from a particular package.
Interface for a method for solving linear system(s) AX=B.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Namespace of implementation details.
bool registeredSomeLinearSolverFactory(const std::string &packageName)
Did the package with the given name register at least one LinearSolverFactory, with any template para...
bool rememberRegisteredSomeLinearSolverFactory(const std::string &packageName)
Remember which packages registered at least one LinearSolverFactory, with any template parameters.
bool haveLinearSolverFactoryRunTimeRegistration()
Whether the CMake run-time registration option is ON.
Namespace of things generally useful to many Trilinos packages.