All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Xpetra_TpetraMap.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_TPETRAMAP_HPP
00047 #define XPETRA_TPETRAMAP_HPP
00048 
00049 /* this file is automatically generated - do not edit (see script/tpetra.py) */
00050 
00051 #include "Xpetra_TpetraConfigDefs.hpp"
00052 
00053 #include <Tpetra_Map.hpp>
00054 
00055 #include "Xpetra_Map.hpp"
00056 #include "Xpetra_Utils.hpp"
00057 
00058 #include "Xpetra_Exceptions.hpp"
00059 
00060 namespace Xpetra {
00061 
00062   // TODO: move that elsewhere
00063   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00064   const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node>&             toTpetra(const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node>&);
00065 
00066   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00067   const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node > > toTpetra(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >&);
00068 
00069   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00070   const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node > >         toXpetra(const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >&);
00071 
00072   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00073   const RCP<Map<LocalOrdinal,GlobalOrdinal,Node > >               toXpetraNonConst(const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >&);
00074   //
00075 
00076   template <class LocalOrdinal = Map<>::local_ordinal_type,
00077             class GlobalOrdinal = typename Map<LocalOrdinal>::global_ordinal_type,
00078             class Node = typename Map<LocalOrdinal, GlobalOrdinal>::node_type>
00079   class TpetraMap
00080     : public virtual Map<LocalOrdinal,GlobalOrdinal,Node> {
00081 
00082   public:
00083 
00084     static Teuchos::RCP<Node> defaultArgNode() {
00085         // Workaround function for a deferred visual studio bug
00086         // http://connect.microsoft.com/VisualStudio/feedback/details/719847/erroneous-error-c2783-could-not-deduce-template-argument
00087         // Use this function for default arguments rather than calling
00088         // what is the return value below.  Also helps in reducing
00089         // duplication in various constructors.
00090         return KokkosClassic::Details::getNode<Node>();
00091     }
00092 
00094 
00095 
00097     TpetraMap (global_size_t numGlobalElements,
00098                GlobalOrdinal indexBase,
00099                const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
00100                LocalGlobal lg=GloballyDistributed,
00101                const Teuchos::RCP< Node > &node = defaultArgNode())
00102       : map_ (Teuchos::rcp (new Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > (numGlobalElements,
00103                                                                                   indexBase, comm,
00104                                                                                   toTpetra(lg), node)))
00105     {}
00106 
00108     TpetraMap (global_size_t numGlobalElements,
00109                size_t numLocalElements,
00110                GlobalOrdinal indexBase,
00111                const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
00112                const Teuchos::RCP< Node > &node = defaultArgNode())
00113       : map_ (Teuchos::rcp (new Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > (numGlobalElements,
00114                                                                                   numLocalElements,
00115                                                                                   indexBase, comm,
00116                                                                                   node)))
00117     {}
00118 
00120     TpetraMap (global_size_t numGlobalElements,
00121                const Teuchos::ArrayView< const GlobalOrdinal > &elementList,
00122                GlobalOrdinal indexBase,
00123                const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
00124                const Teuchos::RCP< Node > &node = defaultArgNode())
00125       : map_(Teuchos::rcp(new Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node >(numGlobalElements,
00126                                                                                elementList, indexBase,
00127                                                                                comm, node)))
00128     {}
00129 
00131     ~TpetraMap() {  }
00132 
00134 
00136 
00137 
00139     global_size_t getGlobalNumElements() const { XPETRA_MONITOR("TpetraMap::getGlobalNumElements"); return map_->getGlobalNumElements(); }
00140 
00142     size_t getNodeNumElements() const { XPETRA_MONITOR("TpetraMap::getNodeNumElements"); return map_->getNodeNumElements(); }
00143 
00145     GlobalOrdinal getIndexBase() const { XPETRA_MONITOR("TpetraMap::getIndexBase"); return map_->getIndexBase(); }
00146 
00148     LocalOrdinal getMinLocalIndex() const { XPETRA_MONITOR("TpetraMap::getMinLocalIndex"); return map_->getMinLocalIndex(); }
00149 
00151     LocalOrdinal getMaxLocalIndex() const { XPETRA_MONITOR("TpetraMap::getMaxLocalIndex"); return map_->getMaxLocalIndex(); }
00152 
00154     GlobalOrdinal getMinGlobalIndex() const { XPETRA_MONITOR("TpetraMap::getMinGlobalIndex"); return map_->getMinGlobalIndex(); }
00155 
00157     GlobalOrdinal getMaxGlobalIndex() const { XPETRA_MONITOR("TpetraMap::getMaxGlobalIndex"); return map_->getMaxGlobalIndex(); }
00158 
00160     GlobalOrdinal getMinAllGlobalIndex() const { XPETRA_MONITOR("TpetraMap::getMinAllGlobalIndex"); return map_->getMinAllGlobalIndex(); }
00161 
00163     GlobalOrdinal getMaxAllGlobalIndex() const { XPETRA_MONITOR("TpetraMap::getMaxAllGlobalIndex"); return map_->getMaxAllGlobalIndex(); }
00164 
00166     LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("TpetraMap::getLocalElement"); return map_->getLocalElement(globalIndex); }
00167 
00169     GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const { XPETRA_MONITOR("TpetraMap::getGlobalElement"); return map_->getGlobalElement(localIndex); }
00170 
00172     LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const { XPETRA_MONITOR("TpetraMap::getRemoteIndexList"); return toXpetra(map_->getRemoteIndexList(GIDList, nodeIDList, LIDList)); }
00173 
00175     LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const { XPETRA_MONITOR("TpetraMap::getRemoteIndexList"); return toXpetra(map_->getRemoteIndexList(GIDList, nodeIDList)); }
00176 
00178     Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const { XPETRA_MONITOR("TpetraMap::getNodeElementList"); return map_->getNodeElementList(); }
00179 
00181 
00183 
00184 
00186     bool isNodeLocalElement(LocalOrdinal localIndex) const { XPETRA_MONITOR("TpetraMap::isNodeLocalElement"); return map_->isNodeLocalElement(localIndex); }
00187 
00189     bool isNodeGlobalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("TpetraMap::isNodeGlobalElement"); return map_->isNodeGlobalElement(globalIndex); }
00190 
00192     bool isContiguous() const { XPETRA_MONITOR("TpetraMap::isContiguous"); return map_->isContiguous(); }
00193 
00195     bool isDistributed() const { XPETRA_MONITOR("TpetraMap::isDistributed"); return map_->isDistributed(); }
00196 
00198     bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("TpetraMap::isCompatible"); return map_->isCompatible(toTpetra(map)); }
00199 
00201     bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("TpetraMap::isSameAs"); return map_->isSameAs(toTpetra(map)); }
00202 
00204 
00206 
00207 
00209     Teuchos::RCP< const Teuchos::Comm< int > >  getComm() const { XPETRA_MONITOR("TpetraMap::getComm"); return map_->getComm(); }
00210 
00212     Teuchos::RCP< Node >  getNode() const { XPETRA_MONITOR("TpetraMap::getNode"); return map_->getNode(); }
00213 
00215 
00217 
00218 
00220     std::string description() const { XPETRA_MONITOR("TpetraMap::description"); return map_->description(); }
00221 
00223     void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const { XPETRA_MONITOR("TpetraMap::describe"); map_->describe(out, verbLevel); }
00224 
00225     RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > removeEmptyProcesses () const {
00226       return toXpetra(map_->removeEmptyProcesses());
00227     }
00228     RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > replaceCommWithSubset (const Teuchos::RCP<const Teuchos::Comm<int> >& newComm) const {
00229       return toXpetra(map_->replaceCommWithSubset(newComm));
00230     }
00231 
00232     template<class Node2>
00233     RCP<Map<LocalOrdinal, GlobalOrdinal, Node2> > clone(const RCP<Node2> &node2) const {
00234       return toXpetraNonConst(map_->clone(node2));
00235     }
00236 
00238 
00240 
00241 
00243     TpetraMap(const Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node > > &map)
00244       : map_(map) { }
00245 
00247     UnderlyingLib lib() const { return UseTpetra; }
00248 
00250     const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getTpetra_Map() const { return map_; }
00251 
00253 
00254   protected:
00255 
00256     RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_;
00257 
00258   }; // TpetraMap class
00259 
00260   // TODO: move that elsewhere
00261   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00262   const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> & toTpetra(const Map<LocalOrdinal,GlobalOrdinal,Node> &map) {
00263     // TODO: throw exception
00264     const TpetraMap<LocalOrdinal,GlobalOrdinal,Node> & tpetraMap = dynamic_cast<const TpetraMap<LocalOrdinal,GlobalOrdinal,Node> &>(*map.getMap());
00265     return *tpetraMap.getTpetra_Map();
00266   }
00267 
00268   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00269   const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map) {
00270     typedef TpetraMap<LocalOrdinal, GlobalOrdinal, Node> TpetraMapClass;
00271     if (map != Teuchos::null) {
00272       XPETRA_RCP_DYNAMIC_CAST(const TpetraMapClass, map->getMap(), tpetraMap, "toTpetra");
00273       return tpetraMap->getTpetra_Map();
00274     }
00275     return Teuchos::null;
00276   }
00277 
00278   // In some cases (for instance, in MueLu adapter to Tpetra operator), we need to return a reference. This is only possible if
00279   // we assume that the map argument is nonzero
00280   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00281   const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > >& toTpetraNonZero(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map) {
00282     TEUCHOS_TEST_FOR_EXCEPTION(map.is_null(), std::invalid_argument, "map must be nonzero");
00283     typedef TpetraMap<LocalOrdinal, GlobalOrdinal, Node> TpetraMapClass;
00284     XPETRA_RCP_DYNAMIC_CAST(const TpetraMapClass, map, tpetraMap, "toTpetra");
00285     return tpetraMap->getTpetra_Map();
00286   }
00287 
00288   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00289   const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > toXpetra(const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& map) {
00290     if (!map.is_null())
00291       return rcp(new TpetraMap<LocalOrdinal, GlobalOrdinal, Node>(map));
00292 
00293     return Teuchos::null;
00294   }
00295 
00296   template <class LocalOrdinal, class GlobalOrdinal, class Node>
00297   const RCP<Map<LocalOrdinal,GlobalOrdinal,Node> > toXpetraNonConst(const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& map) {
00298     if (!map.is_null())
00299       return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(map));
00300 
00301     return Teuchos::null;
00302   }
00303 
00304   // TODO: removed (but currently used in unit test)
00305   namespace useTpetra {
00306 
00308     template <class LocalOrdinal, class GlobalOrdinal, class Node>
00309     Teuchos::RCP< const TpetraMap<LocalOrdinal,GlobalOrdinal,Node> >
00310     createLocalMapWithNode(size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node) {
00311       XPETRA_MONITOR("useTpetra::createLocalMapWithNode");
00312 
00313       return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm, node)));
00314     }
00315 
00317     template <class LocalOrdinal, class GlobalOrdinal>
00318     Teuchos::RCP< const TpetraMap<LocalOrdinal,GlobalOrdinal> >
00319     createContigMap(global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
00320       XPETRA_MONITOR("useTpetra::createContigMap");
00321 
00322       return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal>(Tpetra::createContigMap<LocalOrdinal,GlobalOrdinal>(numElements, localNumElements, comm)));
00323     }
00324 
00326     template <class LocalOrdinal, class GlobalOrdinal, class Node>
00327     Teuchos::RCP< const TpetraMap<LocalOrdinal,GlobalOrdinal,Node> >
00328     createContigMapWithNode(global_size_t numElements, size_t localNumElements,
00329                             const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node) {
00330       XPETRA_MONITOR("useTpetra::createContigMap");
00331       return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, localNumElements, comm, node)));
00332     }
00333   } // useTpetra namespace
00334 
00335 } // Xpetra namespace
00336 
00337 // TODO: remove?
00339 template <class LocalOrdinal, class GlobalOrdinal, class Node>
00340 bool operator== (const Xpetra::TpetraMap<LocalOrdinal,GlobalOrdinal,Node> &map1, const Xpetra::TpetraMap<LocalOrdinal,GlobalOrdinal,Node> &map2) {
00341   XPETRA_MONITOR("TpetraMap==TpetraMap");
00342   return map1.isSameAs(map2);
00343 }
00344 
00346 template <class LocalOrdinal, class GlobalOrdinal, class Node>
00347 bool operator!= (const Xpetra::TpetraMap<LocalOrdinal,GlobalOrdinal,Node> &map1, const Xpetra::TpetraMap<LocalOrdinal,GlobalOrdinal,Node> &map2) {
00348   XPETRA_MONITOR("TpetraMap!=TpetraMap");
00349   return !map1.isSameAs(map2);
00350 }
00351 
00352 #define XPETRA_TPETRAMAP_SHORT
00353 #endif // XPETRA_TPETRAMAP_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines