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>
328 registerLinearSolverFactory (
const std::string& packageName,
329 #ifdef HAVE_TEUCHOSCORE_CXX11
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);
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) {
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>
538 registerLinearSolverFactory (
const std::string& packageName,
539 #ifdef HAVE_TEUCHOSCORE_CXX11
540 const std::shared_ptr<LinearSolverFactory<MV, OP, NormType> >& factory)
549 template<
class MV,
class OP,
class NormType>
551 getLinearSolver (
const std::string& packageName,
const std::string& solverName)
555 typedef Impl::LinearSolverFactoryRepository<MV, OP, NormType> repo_type;
556 typedef typename repo_type::factory_pointer_type factory_pointer_type;
557 typedef LinearSolver<MV, OP, NormType> solver_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 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.
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.
bool registeredSomeLinearSolverFactory(const std::string &packageName)
Did the package with the given name register at least one LinearSolverFactory, with any template para...
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.
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.
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.