All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Xpetra_VectorFactory.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 //
00003 // ***********************************************************************
00004 //
00005 //             Xpetra: A linear algebra interface package
00006 //                  Copyright 2012 Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact
00039 //                    Jonathan Hu       (jhu@sandia.gov)
00040 //                    Andrey Prokopenko (aprokop@sandia.gov)
00041 //                    Ray Tuminaro      (rstumin@sandia.gov)
00042 //
00043 // ***********************************************************************
00044 //
00045 // @HEADER
00046 #ifndef XPETRA_VECTORFACTORY_HPP
00047 #define XPETRA_VECTORFACTORY_HPP
00048 
00049 #include "Xpetra_ConfigDefs.hpp"
00050 #include "Xpetra_Vector.hpp"
00051 
00052 #ifdef HAVE_XPETRA_TPETRA
00053 #  include "Xpetra_TpetraVector.hpp"
00054 #endif
00055 #ifdef HAVE_XPETRA_EPETRA
00056 #  include "Xpetra_EpetraVector.hpp"
00057 #  include "Xpetra_EpetraIntVector.hpp"
00058 #endif
00059 
00060 #include "Xpetra_Exceptions.hpp"
00061 
00062 namespace Xpetra {
00063 
00064   template <class Scalar = Vector<>::scalar_type,
00065             class LocalOrdinal = typename Vector<Scalar>::local_ordinal_type,
00066             class GlobalOrdinal = typename Vector<Scalar, LocalOrdinal>::local_ordinal_type,
00067             class Node = typename Vector<Scalar, LocalOrdinal, GlobalOrdinal>::node_type>
00068   class VectorFactory {
00069 #undef XPETRA_VECTORFACTORY_SHORT
00070 #include "Xpetra_UseShortNames.hpp"
00071 
00072   private:
00074     VectorFactory() {}
00075 
00076   public:
00077 
00079     static RCP<Vector> Build(const Teuchos::RCP<const Map> &map, bool zeroOut=true) {
00080       XPETRA_MONITOR("VectorFactory::Build");
00081 
00082 #ifdef HAVE_XPETRA_TPETRA
00083       if (map->lib() == UseTpetra)
00084         return rcp( new TpetraVector(map, zeroOut) );
00085 #endif
00086 
00087       XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
00088       XPETRA_FACTORY_END;
00089     }
00090 
00091   };
00092 #define XPETRA_VECTORFACTORY_SHORT
00093 
00094   template <>
00095   class VectorFactory<double, int, int> {
00096 
00097     typedef double                              Scalar;
00098     typedef int                                 LocalOrdinal;
00099     typedef int                                 GlobalOrdinal;
00100     typedef Vector<double, int, GlobalOrdinal>::node_type Node;
00101 #undef XPETRA_VECTORFACTORY_SHORT
00102 #include "Xpetra_UseShortNames.hpp"
00103 
00104   private:
00106     VectorFactory() {}
00107 
00108   public:
00109 
00110     static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
00111       XPETRA_MONITOR("VectorFactory::Build");
00112 
00113 #ifdef HAVE_XPETRA_TPETRA
00114       if (map->lib() == UseTpetra)
00115         return rcp( new TpetraVector(map, zeroOut) );
00116 #endif
00117 
00118 #ifdef HAVE_XPETRA_EPETRA
00119 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
00120       if (map->lib() == UseEpetra)
00121         return rcp( new EpetraVectorT<int>(map, zeroOut) );
00122 #endif
00123 #endif
00124 
00125       XPETRA_FACTORY_END;
00126     }
00127 
00128   };
00129 
00130 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00131   template <>
00132   class VectorFactory<double, int, long long> {
00133 
00134     typedef double                              Scalar;
00135     typedef int                                 LocalOrdinal;
00136     typedef long long                           GlobalOrdinal;
00137     typedef Vector<double, int, GlobalOrdinal>::node_type Node;
00138 #undef XPETRA_VECTORFACTORY_SHORT
00139 #include "Xpetra_UseShortNames.hpp"
00140 
00141   private:
00143     VectorFactory() {}
00144 
00145   public:
00146 
00147     static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
00148       XPETRA_MONITOR("VectorFactory::Build");
00149 
00150 #ifdef HAVE_XPETRA_TPETRA
00151       if (map->lib() == UseTpetra)
00152         return rcp( new TpetraVector(map, zeroOut) );
00153 #endif
00154 
00155 #ifdef HAVE_XPETRA_EPETRA
00156 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
00157       if (map->lib() == UseEpetra)
00158         return rcp( new EpetraVectorT<long long>(map, zeroOut) );
00159 #endif
00160 #endif
00161 
00162       XPETRA_FACTORY_END;
00163     }
00164 
00165   };
00166 #endif // HAVE_TEUCHOS_LONG_LONG_INT
00167 
00168 #define XPETRA_VECTORFACTORY_SHORT
00169 
00170   template <>
00171   class VectorFactory<int, int, int> {
00172 
00173     typedef int                              Scalar;
00174     typedef int                              LocalOrdinal;
00175     typedef int                              GlobalOrdinal;
00176     typedef Vector<int, int, GlobalOrdinal>::node_type Node;
00177 #undef XPETRA_VECTORFACTORY_SHORT
00178 #include "Xpetra_UseShortNames.hpp"
00179 
00180   private:
00182     VectorFactory() {}
00183 
00184   public:
00185 
00186     static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
00187       XPETRA_MONITOR("VectorFactory::Build");
00188 
00189 #ifdef HAVE_XPETRA_TPETRA
00190       if (map->lib() == UseTpetra)
00191         return rcp( new TpetraVector(map, zeroOut) );
00192 #endif
00193 
00194 #ifdef HAVE_XPETRA_EPETRA
00195 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
00196       if (map->lib() == UseEpetra)
00197         return rcp( new EpetraIntVectorT<int>(map, zeroOut) );
00198 #endif
00199 #endif
00200 
00201       XPETRA_FACTORY_END;
00202     }
00203 
00204   };
00205 
00206 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00207   template <>
00208   class VectorFactory<int, int, long long> {
00209 
00210     typedef int                              Scalar;
00211     typedef int                              LocalOrdinal;
00212     typedef long long                        GlobalOrdinal;
00213     typedef Vector<int, int, GlobalOrdinal>::node_type Node;
00214 #undef XPETRA_VECTORFACTORY_SHORT
00215 #include "Xpetra_UseShortNames.hpp"
00216 
00217   private:
00219     VectorFactory() {}
00220 
00221   public:
00222 
00223     static RCP<Vector> Build(const Teuchos::RCP<const Map>& map, bool zeroOut=true) {
00224       XPETRA_MONITOR("VectorFactory::Build");
00225 
00226 #ifdef HAVE_XPETRA_TPETRA
00227       if (map->lib() == UseTpetra)
00228         return rcp( new TpetraVector(map, zeroOut) );
00229 #endif
00230 
00231 #ifdef HAVE_XPETRA_EPETRA
00232 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
00233       if (map->lib() == UseEpetra)
00234         return rcp( new EpetraIntVectorT<long long>(map, zeroOut) );
00235 #endif
00236 #endif
00237 
00238       XPETRA_FACTORY_END;
00239     }
00240 
00241   };
00242 #endif // HAVE_TEUCHOS_LONG_LONG_INT
00243 
00244 }
00245 
00246 #define XPETRA_VECTORFACTORY_SHORT
00247 #endif
00248 // TODO: one factory for both Vector and MultiVector ?
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines