All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Xpetra_MultiVectorFactory.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_MULTIVECTORFACTORY_HPP
00047 #define XPETRA_MULTIVECTORFACTORY_HPP
00048 
00049 #include "Xpetra_ConfigDefs.hpp"
00050 
00051 #include "Xpetra_MultiVector.hpp"
00052 
00053 #ifdef HAVE_XPETRA_TPETRA
00054 #include "Xpetra_TpetraMultiVector.hpp"
00055 #endif
00056 
00057 #ifdef HAVE_XPETRA_EPETRA
00058 #include "Xpetra_EpetraMultiVector.hpp"
00059 #endif
00060 
00061 #include "Xpetra_Exceptions.hpp"
00062 
00063 namespace Xpetra {
00064 
00065   template <class Scalar = MultiVector<>::scalar_type,
00066             class LocalOrdinal =
00067               typename MultiVector<Scalar>::local_ordinal_type,
00068             class GlobalOrdinal =
00069               typename MultiVector<Scalar, LocalOrdinal>::global_ordinal_type,
00070             class Node =
00071               typename MultiVector<Scalar, LocalOrdinal, GlobalOrdinal>::node_type>
00072   class MultiVectorFactory {
00073   private:
00075     MultiVectorFactory() {}
00076 
00077   public:
00078 
00080     static Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
00081     Build (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map,
00082            size_t NumVectors,
00083            bool zeroOut=true)
00084     {
00085       XPETRA_MONITOR("MultiVectorFactory::Build");
00086 
00087 #ifdef HAVE_XPETRA_TPETRA
00088       if (map->lib() == UseTpetra)
00089         return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
00090 #endif
00091 
00092       XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
00093       XPETRA_FACTORY_END;
00094     }
00095 
00097     static Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
00098       XPETRA_MONITOR("MultiVectorFactory::Build");
00099 
00100 #ifdef HAVE_XPETRA_TPETRA
00101       if (map->lib() == UseTpetra)
00102         return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
00103 #endif
00104 
00105       XPETRA_FACTORY_ERROR_IF_EPETRA(map->lib());
00106       XPETRA_FACTORY_END;
00107     }
00108 
00109   };
00110 
00111   template <>
00112   class MultiVectorFactory<double, int, int> {
00113 
00114     typedef double Scalar;
00115     typedef int LocalOrdinal;
00116     typedef int GlobalOrdinal;
00117     typedef MultiVector<double, int, GlobalOrdinal>::node_type Node;
00118 
00119   private:
00121     MultiVectorFactory() {}
00122 
00123   public:
00124 
00125     static RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, bool zeroOut=true) {
00126       XPETRA_MONITOR("MultiVectorFactory::Build");
00127 
00128 #ifdef HAVE_XPETRA_TPETRA
00129       if (map->lib() == UseTpetra)
00130         return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
00131 #endif
00132 
00133 #ifdef HAVE_XPETRA_EPETRA
00134 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
00135       if (map->lib() == UseEpetra)
00136         return rcp( new EpetraMultiVectorT<int>(map, NumVectors, zeroOut) );
00137 #endif
00138 #endif
00139 
00140       XPETRA_FACTORY_END;
00141     }
00142 
00144     static Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
00145       XPETRA_MONITOR("MultiVectorFactory::Build");
00146 
00147 #ifdef HAVE_XPETRA_TPETRA
00148       if (map->lib() == UseTpetra)
00149         return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
00150 #endif
00151 
00152 #ifdef HAVE_XPETRA_EPETRA
00153 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
00154       if (map->lib() == UseEpetra)
00155         return rcp( new EpetraMultiVectorT<int>(map, ArrayOfPtrs, NumVectors) );
00156 #endif
00157 #endif
00158 
00159       XPETRA_FACTORY_END;
00160     }
00161 
00162   };
00163 
00164 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
00165   template <>
00166   class MultiVectorFactory<double, int, long long> {
00167 
00168     typedef double Scalar;
00169     typedef int LocalOrdinal;
00170     typedef long long GlobalOrdinal;
00171     typedef MultiVector<double, int, GlobalOrdinal>::node_type Node;
00172 
00173   private:
00175     MultiVectorFactory() {}
00176 
00177   public:
00178 
00179     static RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, bool zeroOut=true) {
00180       XPETRA_MONITOR("MultiVectorFactory::Build");
00181 
00182 #ifdef HAVE_XPETRA_TPETRA
00183       if (map->lib() == UseTpetra)
00184         return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, zeroOut) );
00185 #endif
00186 
00187 #ifdef HAVE_XPETRA_EPETRA
00188 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
00189       if (map->lib() == UseEpetra)
00190         return rcp( new EpetraMultiVectorT<long long>(map, NumVectors, zeroOut) );
00191 #endif
00192 #endif
00193 
00194       XPETRA_FACTORY_END;
00195     }
00196 
00198     static Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
00199       XPETRA_MONITOR("MultiVectorFactory::Build");
00200 
00201 #ifdef HAVE_XPETRA_TPETRA
00202       if (map->lib() == UseTpetra)
00203         return rcp( new TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> (map, ArrayOfPtrs, NumVectors) );
00204 #endif
00205 
00206 #ifdef HAVE_XPETRA_EPETRA
00207 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
00208       if (map->lib() == UseEpetra)
00209         return rcp( new EpetraMultiVectorT<long long>(map, ArrayOfPtrs, NumVectors) );
00210 #endif
00211 #endif
00212 
00213       XPETRA_FACTORY_END;
00214     }
00215 
00216   };
00217 #endif // HAVE_TEUCHOS_LONG_LONG_INT
00218 
00219 }
00220 
00221 #define XPETRA_MULTIVECTORFACTORY_SHORT
00222 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines