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>
325 template<
class MV,
class OP,
class NormType>
328 #ifdef HAVE_TEUCHOSCORE_CXX11
332 #endif // HAVE_TEUCHOSCORE_CXX11 398 template<
class MV,
class OP,
class NormType>
406 #ifdef HAVE_TEUCHOSCORE_CXX11 410 #endif // HAVE_TEUCHOSCORE_CXX11 419 typedef std::map<std::string, factory_pointer_type>
map_type;
438 typedef typename map_type::iterator iter_type;
439 iter_type it =
factories_->find (packageName);
466 (factory.
get () == NULL, std::invalid_argument,
"Trilinos::Details::" 467 "LinearSolverFactoryRepository::registerLinearSolverFactory: Input " 468 "'factory' is NULL!");
471 factories_->insert (std::make_pair (packageName, factory));
501 (
factories_ == NULL, std::logic_error,
"Trilinos::Details::" 502 "LinearSolverFactoryRepository::createFactories: " 503 "Should never get here! factories_ is NULL.");
525 template<
class MV,
class OP,
class NormType>
535 template<
class MV,
class OP,
class NormType>
538 #ifdef HAVE_TEUCHOSCORE_CXX11
548 template<
class MV,
class OP,
class NormType>
555 typedef typename repo_type::factory_pointer_type factory_pointer_type;
557 const char prefix[] =
"Trilinos::Details::getLinearSolver: ";
561 #if ! defined(HAVE_TEUCHOS_DYNAMIC_LIBS) && defined(HAVE_TEUCHOS_CXX_ATTRIBUTE_WEAK) 572 #endif // ! defined(HAVE_TEUCHOS_DYNAMIC_LIBS) && defined(HAVE_TEUCHOS_CXX_ATTRIBUTE_WEAK) 578 const bool haveRunTimeReg =
583 (! pkgExists, std::invalid_argument, prefix <<
"Package \"" << packageName
584 <<
"\" never registered a LinearSolverFactory for _any_ combination of " 585 "template parameters MV, OP, and NormType. This means either that the " 586 "package name is invalid, or that the package is not enabled. " 587 "Trilinos_ENABLE_LINEAR_SOLVER_FACTORY_REGISTRATION = " 588 << (haveRunTimeReg ?
"ON" :
"OFF") <<
".");
590 factory_pointer_type factory = repo_type::getFactory (packageName);
592 (factory.get () == NULL, std::invalid_argument, prefix <<
"Package \"" <<
593 packageName <<
"\" is valid, but it never registered a LinearSolverFactory" 594 " for template parameters " 595 "MV = " << TypeNameTraits<MV>::name () <<
", " 596 "OP = " << TypeNameTraits<OP>::name () <<
", " 597 "NormType = " << TypeNameTraits<NormType>::name () <<
". " 598 "Trilinos_ENABLE_LINEAR_SOLVER_FACTORY_REGISTRATION = " 599 << (haveRunTimeReg ?
"ON" :
"OFF") <<
".");
601 RCP<solver_type> solver = factory->getLinearSolver (solverName);
603 (solver.is_null (), std::invalid_argument, prefix <<
"Invalid solver name " 604 "\"" << solverName <<
"\". However, package \"" << packageName <<
"\" is " 605 "valid, and it did register a LinearSolverFactory for template parameters " 606 "MV = " << TypeNameTraits<MV>::name () <<
", " 607 "OP = " << TypeNameTraits<OP>::name () <<
", " 608 "NormType = " << TypeNameTraits<NormType>::name () <<
". " 609 "Trilinos_ENABLE_LINEAR_SOLVER_FACTORY_REGISTRATION = " 610 << (haveRunTimeReg ?
"ON" :
"OFF") <<
".");
618 #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.
Namespace of implementation details.
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.
Namespace of things generally useful to many Trilinos packages.
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.