Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_ContainerFactory_decl.hpp
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK2_CONTAINERFACTORY_DECL_H
44 #define IFPACK2_CONTAINERFACTORY_DECL_H
45 
46 #include "Ifpack2_Container.hpp"
47 #include "Ifpack2_Partitioner.hpp"
48 #ifdef HAVE_IFPACK2_AMESOS2
49 # include "Ifpack2_Details_Amesos2Wrapper.hpp"
50 #endif
51 #include "Tpetra_RowMatrix.hpp"
52 #include "Teuchos_RCP.hpp"
53 #include "Teuchos_Ptr.hpp"
54 #include <string>
55 #include <map>
56 
59 
60 namespace Ifpack2 {
61 namespace Details {
62 
63 //The default container type names:
64 //
65 //Dense
66 //SparseILUT
67 //SparseAmesos, alias SparseAmesos2
68 //TriDi
69 //Banded
70 
71 template<typename MatrixType>
72 struct ContainerFactoryEntryBase
73 {
77  const Teuchos::RCP<const Tpetra::Import<
78  typename MatrixType::local_ordinal_type,
79  typename MatrixType::global_ordinal_type,
80  typename MatrixType::node_type>> importer,
81  int OverlapLevel,
82  typename MatrixType::scalar_type DampingFactor) = 0;
83  virtual ~ContainerFactoryEntryBase<MatrixType>() {}
84 };
85 
86 template<typename MatrixType, typename ContainerType>
87 struct ContainerFactoryEntry : public ContainerFactoryEntryBase<MatrixType>
88 {
92  const Teuchos::RCP<const Tpetra::Import<
93  typename MatrixType::local_ordinal_type,
94  typename MatrixType::global_ordinal_type,
95  typename MatrixType::node_type>> importer,
96  int OverlapLevel,
97  typename MatrixType::scalar_type DampingFactor)
98  {
99  return Teuchos::rcp(new ContainerType(A, localRows, importer, OverlapLevel, DampingFactor));
100  }
101  ~ContainerFactoryEntry<MatrixType, ContainerType>() {}
102 };
103 
104 } // namespace Details
105 
111 
112 template<typename MatrixType>
114 {
116 
117 
119  typedef typename MatrixType::scalar_type scalar_type;
121  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
123  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
125  typedef typename MatrixType::node_type node_type;
126 
128  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
130  typedef Tpetra::Import<local_ordinal_type, global_ordinal_type, node_type> import_type;
133 
134  static_assert (std::is_same<typename std::decay<MatrixType>::type, row_matrix_type>::value,
135  "MatrixType must be a Tpetra::RowMatrix specialization.");
136 
137  // \name Functions
139 
144  template<typename ContainerType>
145  static void registerContainer(std::string containerType);
146 
148 
156  static Teuchos::RCP<BaseContainer> build(std::string containerType, const Teuchos::RCP<const MatrixType>& A,
158  int OverlapLevel, scalar_type DampingFactor);
159 
161 
164  static void deregisterContainer(std::string containerType);
166 
167  private:
168  static std::map<std::string, Teuchos::RCP<Details::ContainerFactoryEntryBase<MatrixType>>> table;
169  static bool registeredDefaults; //this will initially be false
170  static void registerDefaults();
171 };
172 
173 } // namespace Ifpack2
174 
175 #endif // IFPACK2_DETAILS_CONTAINERFACTORY_H
Ifpack2::Container class declaration.
MatrixType::node_type node_type
The node_type from the input MatrixType.
Definition: Ifpack2_ContainerFactory_decl.hpp:125
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Tpetra::RowMatrix specialization (superclass of MatrixType)
Definition: Ifpack2_ContainerFactory_decl.hpp:128
static Teuchos::RCP< BaseContainer > build(std::string containerType, const Teuchos::RCP< const MatrixType > &A, const Teuchos::Array< Teuchos::Array< local_ordinal_type >> &localRows, const Teuchos::RCP< const import_type > importer, int OverlapLevel, scalar_type DampingFactor)
Build a specialization of Ifpack2::Container given a key that has been registered.
Definition: Ifpack2_ContainerFactory_def.hpp:89
MatrixType::global_ordinal_type global_ordinal_type
The global_ordinal_type from the input MatrixType.
Definition: Ifpack2_ContainerFactory_decl.hpp:123
static void registerContainer(std::string containerType)
Registers a specialization of Ifpack2::Container by binding a key (string) to it. ...
Definition: Ifpack2_ContainerFactory_def.hpp:80
A static &quot;factory&quot; that provides a way to register and construct arbitrary Ifpack2::Container subclas...
Definition: Ifpack2_ContainerFactory_decl.hpp:113
Tpetra::Import< local_ordinal_type, global_ordinal_type, node_type > import_type
Tpetra::Importer specialization for use with MatrixType and compatible MultiVectors.
Definition: Ifpack2_ContainerFactory_decl.hpp:130
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MatrixType::local_ordinal_type local_ordinal_type
The local_ordinal_type from the input MatrixType.
Definition: Ifpack2_ContainerFactory_decl.hpp:121
static void deregisterContainer(std::string containerType)
Registers a specialization of Ifpack2::Container by binding a key (string) to it. ...
Definition: Ifpack2_ContainerFactory_def.hpp:126
Interface for creating and solving a local linear problem.
Definition: Ifpack2_Container.hpp:114
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_ContainerFactory_decl.hpp:119