All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Xpetra_MapExtractorFactory.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 //                    Jeremie Gaidamour (jngaida@sandia.gov)
00040 //                    Jonathan Hu       (jhu@sandia.gov)
00041 //                    Ray Tuminaro      (rstumin@sandia.gov)
00042 //
00043 // ***********************************************************************
00044 //
00045 // @HEADER
00046 /*
00047  * Xpetra_MapExtractorFactory.hpp
00048  *
00049  *  Created on: Aug 22, 2011
00050  *      Author: wiesner
00051  */
00052 
00053 // WARNING: This code is experimental. Backwards compatibility should not be expected.
00054 
00055 #ifndef XPETRA_MAPEXTRACTORFACTORY_HPP_
00056 #define XPETRA_MAPEXTRACTORFACTORY_HPP_
00057 
00058 #include <Kokkos_DefaultNode.hpp>
00059 
00060 #include <Xpetra_MapExtractor.hpp>
00061 
00062 #ifdef HAVE_XPETRA_TPETRA
00063 #include <Xpetra_TpetraMapExtractor.hpp>
00064 #endif
00065 #ifdef HAVE_XPETRA_EPETRA
00066 #include <Xpetra_EpetraMapExtractor.hpp>
00067 #endif
00068 
00069 namespace Xpetra
00070 {
00071   // factory class
00072   template <class Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = Kokkos::DefaultNode::DefaultNodeType>
00073   class MapExtractorFactory {
00074     typedef Xpetra::MapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node> MapExtractorClass;
00075     typedef Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> MapClass;
00076 #ifdef HAVE_XPETRA_TPETRA
00077     typedef TpetraMap<LocalOrdinal, GlobalOrdinal, Node> TpetraMapClass;
00078     typedef TpetraMapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node> TpetraMapExtractorClass;
00079 #endif
00080   private:
00082     MapExtractorFactory() {}
00083 
00084   public:
00086     static Teuchos::RCP<MapExtractorClass> Build(const Teuchos::RCP<const MapClass>& fullmap, const std::vector<Teuchos::RCP<const MapClass> >& maps)
00087     {
00088 #ifdef HAVE_XPETRA_TPETRA
00089       const Teuchos::RCP<const TpetraMapClass> &tMap = Teuchos::rcp_dynamic_cast<const TpetraMapClass>(fullmap);
00090       if (tMap != null)
00091       {
00092         Teuchos::RCP<TpetraMapExtractorClass> tMapExtractor = Teuchos::rcp(new TpetraMapExtractorClass(tMap,maps));
00093         return Teuchos::rcp_dynamic_cast<MapExtractorClass>(tMapExtractor);
00094       }
00095 #endif
00096 
00097       XPETRA_FACTORY_ERROR_IF_EPETRA(fullmap->lib());
00098 
00099       XPETRA_FACTORY_END;
00100     }
00101 
00103 #ifdef HAVE_XPETRA_TPETRA
00104     static Teuchos::RCP<TpetraMapExtractorClass> Build(const Teuchos::RCP<const TpetraMapClass>& fullmap, const std::vector<Teuchos::RCP<const TpetraMapClass> >& maps)
00105     {
00106       const Teuchos::RCP<const TpetraMapClass> &tMap = Teuchos::rcp_dynamic_cast<const TpetraMapClass>(fullmap);
00107       if (tMap != null)
00108         //return Teuchos::rcp( new TpetraMultiVectorClass(map, NumVectors, zeroOut) );
00109         return Teuchos::rcp(new TpetraMapExtractorClass(tMap,maps));
00110 
00111       XPETRA_FACTORY_END;
00112     }
00113 #endif
00114 
00115   };
00116 
00117 
00118   // factory class
00119   template <>
00120   class MapExtractorFactory<double,int,int> {
00121       typedef int LocalOrdinal;
00122       typedef int GlobalOrdinal;
00123       typedef double Scalar;
00124       typedef Kokkos::DefaultNode::DefaultNodeType Node;
00125     typedef Xpetra::MapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node> MapExtractorClass;
00126     typedef Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> MapClass;
00127 #ifdef HAVE_XPETRA_TPETRA
00128     typedef TpetraMap<LocalOrdinal, GlobalOrdinal, Node> TpetraMapClass;
00129     typedef TpetraMapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node> TpetraMapExtractorClass;
00130 #endif
00131   private:
00133     MapExtractorFactory() {}
00134 
00135   public:
00137     static Teuchos::RCP<MapExtractorClass> Build(const Teuchos::RCP<const MapClass>& fullmap, const std::vector<Teuchos::RCP<const MapClass> >& maps)
00138     {
00139 #ifdef HAVE_XPETRA_EPETRA
00140       const RCP<const EpetraMap> &eMap = Teuchos::rcp_dynamic_cast<const EpetraMap>(fullmap);
00141       if (eMap != null)
00142         return Teuchos::rcp(new Xpetra::EpetraMapExtractor(eMap,maps));
00143 #endif
00144 #ifdef HAVE_XPETRA_TPETRA
00145       const Teuchos::RCP<const TpetraMapClass> &tMap = Teuchos::rcp_dynamic_cast<const TpetraMapClass>(fullmap);
00146       if (tMap != null)
00147       {
00148         Teuchos::RCP<TpetraMapExtractorClass> tMapExtractor = Teuchos::rcp(new TpetraMapExtractorClass(tMap,maps));
00149         return Teuchos::rcp_dynamic_cast<MapExtractorClass>(tMapExtractor);
00150       }
00151 #endif
00152 
00153       XPETRA_FACTORY_END;
00154     }
00155 
00157 #ifdef HAVE_XPETRA_TPETRA
00158     static Teuchos::RCP<TpetraMapExtractorClass> Build(const Teuchos::RCP<const TpetraMapClass>& fullmap, const std::vector<Teuchos::RCP<const TpetraMapClass> >& maps)
00159     {
00160       const Teuchos::RCP<const TpetraMapClass> &tMap = Teuchos::rcp_dynamic_cast<const TpetraMapClass>(fullmap);
00161       if (tMap != null)
00162         //return Teuchos::rcp( new TpetraMultiVectorClass(map, NumVectors, zeroOut) );
00163         return Teuchos::rcp(new TpetraMapExtractorClass(tMap,maps));
00164 
00165       XPETRA_FACTORY_END;
00166     }
00167 #endif
00168 
00170 #ifdef HAVE_XPETRA_EPETRA
00171     static Teuchos::RCP<Xpetra::EpetraMapExtractor> Build(const Teuchos::RCP<const Xpetra::EpetraMap>& fullmap, const std::vector<Teuchos::RCP<const Xpetra::EpetraMap> >& maps)
00172     {
00173       const RCP<const EpetraMap> &eMap = Teuchos::rcp_dynamic_cast<const EpetraMap>(fullmap);
00174       if (eMap != null)
00175         return Teuchos::rcp(new Xpetra::EpetraMapExtractor(eMap,maps));
00176 
00177       XPETRA_FACTORY_END;
00178     }
00179 #endif
00180   };
00181 }
00182 
00183 
00184 #endif /* XPETRA_MAPEXTRACTORFACTORY_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines