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  bool pointIndexed) = 0;
82  virtual ~ContainerFactoryEntryBase() {}
83 };
84 
85 template<typename MatrixType, typename ContainerType>
86 struct ContainerFactoryEntry : public ContainerFactoryEntryBase<MatrixType>
87 {
91  const Teuchos::RCP<const Tpetra::Import<
92  typename MatrixType::local_ordinal_type,
93  typename MatrixType::global_ordinal_type,
94  typename MatrixType::node_type>> importer,
95  bool pointIndexed)
96  {
97  return Teuchos::rcp(new ContainerType(A, partitions, importer, pointIndexed));
98  }
99  ~ContainerFactoryEntry() {}
100 };
101 
102 } // namespace Details
103 
109 
110 template<typename MatrixType>
112 {
114 
115 
117  typedef typename MatrixType::scalar_type scalar_type;
119  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
121  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
123  typedef typename MatrixType::node_type node_type;
124 
126  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
128  typedef Tpetra::Import<local_ordinal_type, global_ordinal_type, node_type> import_type;
131 
132  static_assert (std::is_same<typename std::decay<MatrixType>::type, row_matrix_type>::value,
133  "MatrixType must be a Tpetra::RowMatrix specialization.");
134 
135  // \name Functions
137 
142  template<typename ContainerType>
143  static void registerContainer(std::string containerType);
144 
146 
153  static Teuchos::RCP<BaseContainer> build(std::string containerType, const Teuchos::RCP<const MatrixType>& A,
154  const Teuchos::Array<Teuchos::Array<local_ordinal_type>>& partitions, const Teuchos::RCP<const import_type> importer, bool pointIndexed);
155 
157 
160  static void deregisterContainer(std::string containerType);
162 
163  private:
164  static std::map<std::string, Teuchos::RCP<Details::ContainerFactoryEntryBase<MatrixType>>> table;
165  static bool registeredDefaults; //this will initially be false
166  static void registerDefaults();
167 };
168 
169 } // namespace Ifpack2
170 
171 #endif // IFPACK2_DETAILS_CONTAINERFACTORY_H
MatrixType::node_type node_type
The node_type from the input MatrixType.
Definition: Ifpack2_ContainerFactory_decl.hpp:123
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:126
MatrixType::global_ordinal_type global_ordinal_type
The global_ordinal_type from the input MatrixType.
Definition: Ifpack2_ContainerFactory_decl.hpp:121
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:111
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:128
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:119
static void deregisterContainer(std::string containerType)
Registers a specialization of Ifpack2::Container by binding a key (string) to it. ...
Definition: Ifpack2_ContainerFactory_def.hpp:132
Interface for creating and solving a set of local linear problems.
Definition: Ifpack2_Container_decl.hpp:112
static Teuchos::RCP< BaseContainer > build(std::string containerType, const Teuchos::RCP< const MatrixType > &A, const Teuchos::Array< Teuchos::Array< local_ordinal_type >> &partitions, const Teuchos::RCP< const import_type > importer, bool pointIndexed)
Build a specialization of Ifpack2::Container given a key that has been registered.
Definition: Ifpack2_ContainerFactory_def.hpp:89
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_ContainerFactory_decl.hpp:117