Xpetra_VectorFactory.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_VECTORFACTORY_HPP
47 #define XPETRA_VECTORFACTORY_HPP
48 
49 #include "Xpetra_ConfigDefs.hpp"
50 #include "Xpetra_Vector.hpp"
51 
52 #ifdef HAVE_XPETRA_TPETRA
53 # include "Xpetra_TpetraVector.hpp"
54 #endif
55 #ifdef HAVE_XPETRA_EPETRA
56 # include "Xpetra_EpetraVector.hpp"
58 #endif
59 
60 #include "Xpetra_Exceptions.hpp"
61 
62 namespace Xpetra {
63 
64  template <class Scalar = Vector<>::scalar_type,
65  class LocalOrdinal = typename Vector<Scalar>::local_ordinal_type,
66  class GlobalOrdinal = typename Vector<Scalar, LocalOrdinal>::local_ordinal_type,
68  class VectorFactory {
69 #undef XPETRA_VECTORFACTORY_SHORT
70 #include "Xpetra_UseShortNames.hpp"
71 
72  private:
75 
76  public:
77 
79  static RCP<Vector> Build(const Teuchos::RCP<const Map> &map, bool zeroOut=true) {
80  XPETRA_MONITOR("VectorFactory::Build");
81 
82 #ifdef HAVE_XPETRA_TPETRA
83  if (map->lib() == UseTpetra)
84  return rcp( new TpetraVector(map, zeroOut) );
85 #endif
86 
89  }
90 
91  };
92 #define XPETRA_VECTORFACTORY_SHORT
93 
94  template <>
95  class VectorFactory<double, int, int> {
96 
97  typedef double Scalar;
98  typedef int LocalOrdinal;
99  typedef int GlobalOrdinal;
101 #undef XPETRA_VECTORFACTORY_SHORT
102 #include "Xpetra_UseShortNames.hpp"
103 
104  private:
107 
108  public:
109 
110  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
111  XPETRA_MONITOR("VectorFactory::Build");
112 
113 #ifdef HAVE_XPETRA_TPETRA
114  if (map->lib() == UseTpetra)
115  return rcp( new TpetraVector(map, zeroOut) );
116 #endif
117 
118 #ifdef HAVE_XPETRA_EPETRA
119 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
120  if (map->lib() == UseEpetra)
121  return rcp( new EpetraVectorT<int>(map, zeroOut) );
122 #endif
123 #endif
124 
126  }
127 
128  };
129 
130 #ifdef HAVE_XPETRA_INT_LONG_LONG
131  template <>
132  class VectorFactory<double, int, long long> {
133 
134  typedef double Scalar;
135  typedef int LocalOrdinal;
136  typedef long long GlobalOrdinal;
138 #undef XPETRA_VECTORFACTORY_SHORT
139 #include "Xpetra_UseShortNames.hpp"
140 
141  private:
143  VectorFactory() {}
144 
145  public:
146 
147  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
148  XPETRA_MONITOR("VectorFactory::Build");
149 
150 #ifdef HAVE_XPETRA_TPETRA
151  if (map->lib() == UseTpetra)
152  return rcp( new TpetraVector(map, zeroOut) );
153 #endif
154 
155 #if defined(HAVE_XPETRA_EPETRA) && ! defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
156  if (map->lib() == UseEpetra)
157  return rcp( new EpetraVectorT<long long>(map, zeroOut) );
158 #endif
159 
161  }
162 
163  };
164 #endif // HAVE_XPETRA_INT_LONG_LONG
165 
166 #define XPETRA_VECTORFACTORY_SHORT
167 
168  template <>
169  class VectorFactory<int, int, int> {
170 
171  typedef int Scalar;
172  typedef int LocalOrdinal;
173  typedef int GlobalOrdinal;
175 #undef XPETRA_VECTORFACTORY_SHORT
176 #include "Xpetra_UseShortNames.hpp"
177 
178  private:
181 
182  public:
183 
184  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
185  XPETRA_MONITOR("VectorFactory::Build");
186 
187 #ifdef HAVE_XPETRA_TPETRA
188  if (map->lib() == UseTpetra)
189  return rcp( new TpetraVector(map, zeroOut) );
190 #endif
191 
192 #ifdef HAVE_XPETRA_EPETRA
193 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
194  if (map->lib() == UseEpetra)
195  return rcp( new EpetraIntVectorT<int>(map, zeroOut) );
196 #endif
197 #endif
198 
200  }
201 
202  };
203 
204 #ifdef HAVE_XPETRA_INT_LONG_LONG
205  template <>
206  class VectorFactory<int, int, long long> {
207 
208  typedef int Scalar;
209  typedef int LocalOrdinal;
210  typedef long long GlobalOrdinal;
212 #undef XPETRA_VECTORFACTORY_SHORT
213 #include "Xpetra_UseShortNames.hpp"
214 
215  private:
217  VectorFactory() {}
218 
219  public:
220 
221  static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
222  XPETRA_MONITOR("VectorFactory::Build");
223 
224 #ifdef HAVE_XPETRA_TPETRA
225  if (map->lib() == UseTpetra)
226  return rcp( new TpetraVector(map, zeroOut) );
227 #endif
228 
229 #if defined(HAVE_XPETRA_EPETRA) && ! defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES)
230  if (map->lib() == UseEpetra)
231  return rcp( new EpetraIntVectorT<long long>(map, zeroOut) );
232 #endif
233 
235  }
236 
237  };
238 #endif // HAVE_XPETRA_INT_LONG_LONG
239 
240 }
241 
242 #define XPETRA_VECTORFACTORY_SHORT
243 #endif
244 // TODO: one factory for both Vector and MultiVector ?
LocalOrdinal local_ordinal_type
VectorFactory()
Private constructor. This is a static class.
Xpetra namespace
#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
VectorFactory()
Private constructor. This is a static class.
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Vector< int, int, GlobalOrdinal >::node_type Node
Vector< double, int, GlobalOrdinal >::node_type Node
#define XPETRA_FACTORY_END
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
VectorFactory()
Private constructor. This is a static class.
#define XPETRA_MONITOR(funcName)