All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Xpetra_StridedEpetraMap.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 // WARNING: This code is experimental. Backwards compatibility should not be expected.
00048 
00049 #ifndef XPETRA_STRIDEDEPETRAMAP_HPP
00050 #define XPETRA_STRIDEDEPETRAMAP_HPP
00051 
00052 #include "Xpetra_EpetraConfigDefs.hpp"
00053 
00054 #include "Xpetra_StridedMap.hpp"
00055 #include "Xpetra_EpetraMap.hpp"
00056 
00057 //#include "Xpetra_Utils.hpp"
00058 
00059 #include "Xpetra_EpetraUtils.hpp"
00060 #include "Xpetra_ConfigDefs.hpp"
00061 
00062 namespace Xpetra {
00063 
00064 
00065   class StridedEpetraMap
00066     : public virtual EpetraMap, public virtual StridedMap<int, int>
00067   {
00068 
00069     typedef int LocalOrdinal;
00070     typedef int GlobalOrdinal;
00071     typedef Kokkos::DefaultNode::DefaultNodeType Node;
00072 
00073   public:
00074 
00076 
00077 
00079     StridedEpetraMap(global_size_t numGlobalElements, GlobalOrdinal indexBase, std::vector<size_t>& stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset = 0, LocalGlobal lg=GloballyDistributed, const Teuchos::RCP< Node > &node=Kokkos::DefaultNode::getDefaultNode());
00080 
00082     StridedEpetraMap(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, std::vector<size_t>& stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset = 0, const Teuchos::RCP< Node > &node=Kokkos::DefaultNode::getDefaultNode());
00083 
00085     StridedEpetraMap(global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase, std::vector<size_t>& stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, const Teuchos::RCP< Node > &node=Kokkos::DefaultNode::getDefaultNode());
00086 
00088     ~StridedEpetraMap() { }
00089 
00091 
00093 
00094 
00096     global_size_t getGlobalNumElements() const { return EpetraMap::getGlobalNumElements(); }
00097 
00099     size_t getNodeNumElements() const { return EpetraMap::getNodeNumElements(); }
00100 
00102     GlobalOrdinal getIndexBase() const { return EpetraMap::getIndexBase(); }
00103 
00105     LocalOrdinal getMinLocalIndex() const { return EpetraMap::getMinLocalIndex(); }
00106 
00108     LocalOrdinal getMaxLocalIndex() const { return EpetraMap::getMaxLocalIndex(); }
00109 
00111     GlobalOrdinal getMinGlobalIndex() const { return EpetraMap::getMinGlobalIndex(); }
00112 
00114     GlobalOrdinal getMaxGlobalIndex() const { return EpetraMap::getMaxGlobalIndex(); }
00115 
00117     GlobalOrdinal getMinAllGlobalIndex() const { return EpetraMap::getMinAllGlobalIndex(); }
00118 
00120     GlobalOrdinal getMaxAllGlobalIndex() const { return EpetraMap::getMaxAllGlobalIndex(); }
00121 
00123     LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const { return EpetraMap::getLocalElement(globalIndex); }
00124 
00126     LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const { return EpetraMap::getRemoteIndexList(GIDList, nodeIDList, LIDList); }
00127 
00129     LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const { return EpetraMap::getRemoteIndexList(GIDList, nodeIDList); }
00130 
00132     Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const { return EpetraMap::getNodeElementList(); }
00133 
00135     bool isNodeLocalElement(LocalOrdinal localIndex) const { return EpetraMap::isNodeLocalElement(localIndex); }
00136 
00138     bool isNodeGlobalElement(GlobalOrdinal globalIndex) const { return EpetraMap::isNodeGlobalElement(globalIndex); }
00139 
00141     bool isContiguous() const { return EpetraMap::isContiguous(); }
00142 
00144     bool isDistributed() const { return EpetraMap::isDistributed(); }
00145 
00147 
00149 
00150 
00152     const Teuchos::RCP< const Teuchos::Comm< int > >  getComm() const { return EpetraMap::getComm(); }
00153 
00155     const Teuchos::RCP< Node >  getNode() const { return EpetraMap::getNode(); }
00156 
00158 
00159 
00161 
00162 
00164     bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { return EpetraMap::isCompatible(map); }
00165 
00167     bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { return EpetraMap::isSameAs(map); }
00168 
00170 
00172 
00173 
00175     std::string description() const;
00176 
00178     void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00179 
00181 
00183     GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const { return EpetraMap::getGlobalElement(localIndex); }
00184 
00186 
00187 
00189     StridedEpetraMap(const Teuchos::RCP<const Epetra_BlockMap> &map, std::vector<size_t>& stridingInfo, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset = 0) 
00190       : EpetraMap(map), StridedMap<int, int>(stridingInfo, stridedBlockId, offset) { 
00191       int nDofsPerNode = Teuchos::as<int>(getFixedBlockSize());
00192       TEUCHOS_TEST_FOR_EXCEPTION(map_->NumMyPoints() % nDofsPerNode != 0, Exceptions::RuntimeError, "StridedEpetraMap::StridedEpetraMap: wrong distribution of dofs among processors.");
00193       TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedEpetraMap::StridedEpetraMap: CheckConsistency() == false");
00194     }
00195 
00197     UnderlyingLib lib() const { return Xpetra::UseEpetra; }
00198     
00199     /*//! Get the underlying Epetra map
00200     //const RCP< const Epetra_Map > & getEpetra_Map() const { return map_; }
00201     const Epetra_BlockMap& getEpetra_BlockMap() const { return *map_; }
00202     const Epetra_Map& getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.*/
00203 
00205 
00206   private:
00207 
00208     bool CheckConsistency() {
00209       if(getStridedBlockId() == -1) {
00210         //if(isContiguous() == false) return false;
00211         if(getNodeNumElements() % getFixedBlockSize() != 0) return false;
00212         if(getGlobalNumElements() % getFixedBlockSize() != 0) return false;
00213       }
00214       else {
00215         Teuchos::ArrayView< const GlobalOrdinal > dofGids = getNodeElementList();
00216         //std::sort(dofGids.begin(),dofGids.end());
00217 
00218         // determine nStridedOffset
00219         size_t nStridedOffset = 0;
00220         for(int j=0; j<stridedBlockId_; j++) {
00221           nStridedOffset += stridingInfo_[j];
00222         }
00223         //size_t nDofsPerNode = stridingInfo_[stridedBlockId_];
00224 
00225         const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
00226         const GlobalOrdinal goZeroOffset = (dofGids[0] - nStridedOffset - offset_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize());
00227         /*printf("goZeroOffset: %i\n",goZeroOffset);
00228         printf("dofGids[0]: %i \n",dofGids[0]);
00229         printf("stridedOffset: %i\n",nStridedOffset);
00230         printf("offset_: %i\n",offset_);
00231         printf("goStridedOffset: %i\n",goStridedOffset);
00232         printf("getFixedBlkSize: %i\n",getFixedBlockSize());*/
00233 
00234         GlobalOrdinal cnt = 0;
00235         for(size_t i = 0; i<Teuchos::as<size_t>(dofGids.size())/stridingInfo_[stridedBlockId_]; i+=stridingInfo_[stridedBlockId_]) {
00236 
00237           for(size_t j=0; j<stridingInfo_[stridedBlockId_]; j++) {
00238             const GlobalOrdinal gid = dofGids[i+j];
00239             if((gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset - offset_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset - cnt != 0) {
00240               //std::cout << "gid: " << gid << " GID: " <<  (gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset - cnt << std::endl;
00241               return false;
00242             }
00243           }
00244           cnt++;
00245         }
00246 
00247       }
00248       
00249       return true;
00250     }
00251 
00252 
00253   }; // StridedEpetraMap class
00254 
00255 } // Xpetra namespace
00256 
00257 #endif // XPETRA_STRIDEDEPETRAMAP_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines