Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Details_LinearSolverFactory_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4 //
5 // Copyright 2009 NTESS and the Ifpack2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
13 
14 #ifndef IFPACK2_DETAILS_LINEARSOLVERFACTORY_DEF_HPP
15 #define IFPACK2_DETAILS_LINEARSOLVERFACTORY_DEF_HPP
16 
19 #include "Ifpack2_Details_LinearSolver.hpp"
20 #include "Ifpack2_Factory.hpp"
21 #include "Tpetra_RowMatrix.hpp"
22 #include <type_traits> // std::is_same
23 
24 namespace Ifpack2 {
25 namespace Details {
26 
27 template<class SC, class LO, class GO, class NT>
30 getLinearSolver (const std::string& solverName)
31 {
32  using Teuchos::null;
33  using Teuchos::RCP;
34  using Teuchos::rcp_dynamic_cast;
37  typedef Tpetra::RowMatrix<SC, LO, GO, NT> ROW;
38  const char prefix[] = "Ifpack2::Details::LinearSolverFactory::getLinearSolver: ";
39 
40  RCP<prec_type> solver;
41  try {
42  // The solver to create must be a subclass of
43  // Ifpack2::Details::CanChangeMatrix (see documentation of
44  // Ifpack2::Details::LinearSolver). As a result, it should be
45  // possible to create the solver with a null matrix.
46  solver = Ifpack2::Factory::template create<ROW> (solverName, null);
47  }
48  catch (std::exception& e) {
50  (true, std::invalid_argument, prefix << "Failed to create Ifpack2 "
51  "preconditioner named \"" << solverName << "\", for the following "
52  "template parameters: "
53  << "SC = " << TypeNameTraits<SC>::name ()
54  << ", LO = " << TypeNameTraits<LO>::name ()
55  << ", GO = " << TypeNameTraits<GO>::name ()
56  << ", NT = " << TypeNameTraits<NT>::name ()
57  << ". Ifpack2::Factory::create threw an exception: " << e.what ());
58  }
60  (solver.is_null (), std::invalid_argument, prefix << "Failed to create "
61  "Ifpack2 preconditioner named \"" << solverName << "\", for the "
62  "following template parameters: "
63  << "SC = " << TypeNameTraits<SC>::name ()
64  << ", LO = " << TypeNameTraits<LO>::name ()
65  << ", GO = " << TypeNameTraits<GO>::name ()
66  << ", NT = " << TypeNameTraits<NT>::name ()
67  << ". Ifpack2::Factory::create returned null.");
68 
70  return Teuchos::rcp (new impl_type (solver, solverName));
71 }
72 
73 template<class SC, class LO, class GO, class NT>
74 void
77 {
78  typedef Tpetra::MultiVector<SC, LO, GO, NT> MV;
79  typedef Tpetra::Operator<SC, LO, GO, NT> OP;
80  typedef typename MV::mag_type mag_type;
83 
84 #ifdef HAVE_TEUCHOSCORE_CXX11
85  typedef std::shared_ptr<factory_base_type> base_ptr_type;
86  typedef std::shared_ptr<factory_impl_type> impl_ptr_type;
87 #else
88  typedef Teuchos::RCP<factory_base_type> base_ptr_type;
89  typedef Teuchos::RCP<factory_impl_type> impl_ptr_type;
90 #endif // HAVE_TEUCHOSCORE_CXX11
91 
92  impl_ptr_type factory (new factory_impl_type ());
93  base_ptr_type factoryBase = factory; // implicit cast to base class
94 
96  (factoryBase.get () == NULL, std::logic_error, "Factory is null! This "
97  "should never happen! Please report this bug to the Ifpack2 developers.");
98 
99 // #ifdef HAVE_IFPACK2_DEBUG
100 // {
101 // using std::cerr;
102 // using std::endl;
103 // using Teuchos::TypeNameTraits;
104 // cerr << "Registering Ifpack2 LinearSolverFactory for"
105 // << " SC = " << TypeNameTraits<SC>::name ()
106 // << ", LO = " << TypeNameTraits<LO>::name ()
107 // << ", GO = " << TypeNameTraits<GO>::name ()
108 // << ", NT = " << TypeNameTraits<NT>::name ()
109 // << ", and mag_type = " << TypeNameTraits<mag_type>::name ()
110 // << endl;
111 // }
112 // #endif // HAVE_IFPACK2_DEBUG
113  Trilinos::Details::registerLinearSolverFactory<MV, OP, mag_type> ("Ifpack2", factoryBase);
114 }
115 
116 } // namespace Details
117 } // namespace Ifpack2
118 
119 // Do explicit instantiation of Ifpack2::Details::LinearSolverFactory,
120 // for Tpetra objects, with the given Tpetra template parameters.
121 #define IFPACK2_DETAILS_LINEARSOLVERFACTORY_INSTANT( SC, LO, GO, NT ) \
122  template class Ifpack2::Details::LinearSolverFactory<SC, LO, GO, NT>;
123 
124 #endif // IFPACK2_DETAILS_LINEARSOLVERFACTORY_DEF_HPP
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static void registerLinearSolverFactory()
Register this LinearSolverFactory with the central registry.
Definition: Ifpack2_Details_LinearSolverFactory_def.hpp:76
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Interface for a &quot;factory&quot; that creates Ifpack2 solvers.
Definition: Ifpack2_Details_LinearSolverFactory_decl.hpp:31
Ifpack2&#39;s implementation of Trilinos::Details::LinearSolver interface.
Definition: Ifpack2_Details_LinearSolver_decl.hpp:72
virtual Teuchos::RCP< solver_type > getLinearSolver(const std::string &solverName)
Get an instance of a Ifpack2 solver.
Definition: Ifpack2_Details_LinearSolverFactory_def.hpp:30
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:74
Declaration of interface for preconditioners that can change their matrix after construction.