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
333 #endif // HAVE_TEUCHOSCORE_CXX11 356 bool rememberRegisteredSomeLinearSolverFactory (
const std::string& packageName);
363 bool registeredSomeLinearSolverFactory (
const std::string& packageName);
371 bool haveLinearSolverFactoryRunTimeRegistration ();
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;
435 static factory_pointer_type
439 typedef typename map_type::iterator iter_type;
440 iter_type it = factories_->find (packageName);
441 if (it == factories_->end ()) {
442 return factory_pointer_type ();
464 const factory_pointer_type& factory)
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));
487 static map_type* factories_;
492 static void createFactories () {
493 if (factories_ == NULL) {
494 factories_ =
new map_type ();
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>
536 template<
class MV,
class OP,
class NormType>
538 registerLinearSolverFactory (
const std::string& packageName,
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 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.
Teuchos::RCP< LinearSolver< MV, OP, NormType > > getLinearSolver(const std::string &packageName, const std::string &solverName)
Get a LinearSolver instance.
T * get() const
Get the raw C++ pointer to the underlying object.
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...
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.
Namespace of things generally useful to many Trilinos packages.
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.
void registerLinearSolverFactory(const std::string &packageName, const Teuchos::RCP< LinearSolverFactory< MV, OP, NormType > > &factory)
Called by a package to register its LinearSolverFactory.
Reference-counted pointer class and non-member templated function implementations.