42 #ifndef TRILINOS_DETAILS_LINEARSOLVER_FACTORY_HPP
43 #define TRILINOS_DETAILS_LINEARSOLVER_FACTORY_HPP
83 #include "TeuchosRemainder_config.h"
85 #ifdef HAVE_TEUCHOSCORE_CXX11
87 #endif // HAVE_TEUCHOSCORE_CXX11
105 #if ! defined(HAVE_TEUCHOS_DYNAMIC_LIBS) && defined(HAVE_TEUCHOS_CXX_ATTRIBUTE_WEAK)
121 #endif // ! defined(HAVE_TEUCHOS_DYNAMIC_LIBS) && defined(HAVE_TEUCHOS_CXX_ATTRIBUTE_WEAK)
136 template<
class MV,
class OP,
class NormType>
165 template<
class MV,
class OP,
class NormType>
167 getLinearSolver (
const std::string& packageName,
const std::string& solverName);
234 template<
class MV,
class OP,
class NormType>
326 template<
class MV,
class OP,
class NormType>
329 #ifdef HAVE_TEUCHOSCORE_CXX11
330 const std::shared_ptr<LinearSolverFactory<MV, OP, NormType> >& factory);
333 #endif // HAVE_TEUCHOSCORE_CXX11
399 template<
class MV,
class OP,
class NormType>
407 #ifdef HAVE_TEUCHOSCORE_CXX11
411 #endif // 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);
467 (factory.
get () == NULL, std::invalid_argument,
"Trilinos::Details::"
468 "LinearSolverFactoryRepository::registerLinearSolverFactory: Input "
469 "'factory' is NULL!");
472 factories_->insert (std::make_pair (packageName, factory));
502 (
factories_ == NULL, std::logic_error,
"Trilinos::Details::"
503 "LinearSolverFactoryRepository::createFactories: "
504 "Should never get here! factories_ is NULL.");
526 template<
class MV,
class OP,
class NormType>
527 typename LinearSolverFactoryRepository<MV, OP, NormType>::map_type*
528 LinearSolverFactoryRepository<MV, OP, NormType>::factories_ = NULL;
536 template<
class MV,
class OP,
class NormType>
539 #ifdef HAVE_TEUCHOSCORE_CXX11
549 template<
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)
573 #endif // ! 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") <<
".");
619 #endif // TRILINOS_DETAILS_LINEARSOLVER_FACTORY_HPP
static void freeFactories()
Free the factories_ singleton.
static factory_pointer_type getFactory(const std::string &packageName)
Get a LinearSolverFactory from the given package.
Teuchos::RCP< LinearSolverFactory< MV, OP, NormType > > factory_pointer_type
Type of a reference-counted pointer to LinearSolverFactory.
Interface for a method for solving linear system(s) AX=B.
Repository of solver factories.
bool rememberRegisteredSomeLinearSolverFactory(const std::string &packageName)
Remember which packages registered at least one LinearSolverFactory, with any template parameters...
static void registerLinearSolverFactory(const std::string &packageName, const factory_pointer_type &factory)
Register the given factory from a package.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
T * get() const
Get the raw C++ pointer to the underlying object.
virtual ~LinearSolverFactory()
void registerLinearSolverFactory(const std::string &packageName, const Teuchos::RCP< LinearSolverFactory< MV, OP, NormType > > &factory)
Called by a package to register its LinearSolverFactory.
bool registeredSomeLinearSolverFactory(const std::string &packageName)
Did the package with the given name register at least one LinearSolverFactory, with any template para...
static void createFactories()
Initialize factories_ if it hasn't been initialized.
virtual Teuchos::RCP< LinearSolver< MV, OP, NormType > > getLinearSolver(const std::string &solverName)=0
Get an instance of a solver from a particular package.
bool haveLinearSolverFactoryRunTimeRegistration()
Whether the CMake run-time registration option is ON.
Teuchos::RCP< LinearSolver< MV, OP, NormType > > getLinearSolver(const std::string &packageName, const std::string &solverName)
Get a LinearSolver instance.
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...
Interface for a "factory" that creates solvers.
static map_type * factories_
Singleton where all packages' factories get stored.
Default traits class that just returns typeid(T).name().
Smart reference counting pointer class for automatic garbage collection.
Reference-counted pointer class and non-member templated function implementations.