47#ifndef PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DEF_HPP_
48#define PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DEF_HPP_
54#include "Xpetra_MapFactory.hpp"
62template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 if(bThyraMode ==
false)
82 size_t numAllElements = 0;
83 for(
size_t v = 0; v < maps.size(); ++v)
85 numAllElements += maps[ v ]->getGlobalNumElements();
89 "logic error. full map and sub maps have not same number of elements ("
90 << fullmap->getGlobalNumElements() <<
" versus " << numAllElements
91 <<
"). We cannot build MapExtractor with Xpetra-style numbering. Please make sure that you want "
92 "Xpetra-style numbering instead of Thyra-style numbering.");
104 for(
size_t v = 0; v < maps.size(); ++v)
108 "logic error. When using Thyra-style numbering all sub-block maps must start with zero as GID. Map block "
116 std::vector<GlobalOrdinal> gidOffsets(maps.size(), 0);
117 for(
size_t v = 1; v < maps.size(); ++v)
119 gidOffsets[ v ] = maps[ v - 1 ]->getMaxAllGlobalIndex() + gidOffsets[ v - 1 ] + 1;
123 maps_.resize(maps.size());
124 std::vector<GlobalOrdinal> fullMapGids;
126 for(
size_t v = 0; v < maps.size(); ++v)
128 size_t myNumElements = maps[ v ]->getLocalNumElements();
129 std::vector<GlobalOrdinal> subMapGids(myNumElements, 0);
130 for(LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(myNumElements); ++l)
132 GlobalOrdinal myGid = maps[ v ]->getGlobalElement(l);
133 subMapGids[ l ] = myGid + gidOffsets[ v ];
134 fullMapGids.push_back(myGid + gidOffsets[ v ]);
143 maps_[ v ] = mySubMap;
156 fullmap->lib(), INVALID, fullMapGidsView, fullmap->getIndexBase(), fullmap->getComm());
159 size_t numAllElements = 0;
160 for(
size_t v = 0; v <
maps_.size(); ++v)
162 numAllElements +=
maps_[ v ]->getGlobalNumElements();
165 fullmap_->getGlobalNumElements() != numAllElements,
167 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
172 for(
unsigned i = 0; i <
maps_.size(); ++i)
174 if(maps[ i ] != null)
180 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
184template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
191 TEUCHOS_TEST_FOR_EXCEPTION(thyramaps.size() != maps.size(), std::logic_error,
"logic error. The number of submaps must be identical!");
192 for(
size_t v = 0; v < thyramaps.size(); ++v)
196 "logic error. When using Thyra-style numbering all sub-block maps must start with zero as GID.");
200 "logic error. The size of the submaps must be identical (same distribution, just different GIDs)");
209 size_t numAllElements = 0;
210 for(
size_t v = 0; v <
maps_.size(); ++v)
212 numAllElements +=
maps_[ v ]->getGlobalNumElements();
215 fullmap_->getGlobalNumElements() != numAllElements,
217 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
221 for(
unsigned i = 0; i <
maps_.size(); ++i)
223 if(maps[ i ] != null)
229 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
233template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
245template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
250 for(
size_t v = 0; v <
maps_.size(); ++v)
252 maps_[ v ] = Teuchos::null;
262template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
267 return fullmap_->getGlobalNumElements();
271template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
275 return fullmap_->getLocalNumElements();
279template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
288template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
293 return fullmap_->getMinLocalIndex();
297template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
302 return fullmap_->getMaxLocalIndex();
306template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
311 return fullmap_->getMinGlobalIndex();
315template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
320 return fullmap_->getMaxGlobalIndex();
324template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
329 return fullmap_->getMinAllGlobalIndex();
333template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
338 return fullmap_->getMaxAllGlobalIndex();
342template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
347 return fullmap_->getLocalElement(globalIndex);
351template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
356 return fullmap_->getGlobalElement(localIndex);
360template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
372template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
383template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
388 return fullmap_->getLocalElementList();
392template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
397 return fullmap_->isNodeLocalElement(localIndex);
401template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
406 return fullmap_->isNodeGlobalElement(globalIndex);
410template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
420template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
429template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
439 for(
size_t v = 0; v <
maps_.size(); ++v)
441 bool bSame =
getMap(v,
false)->isCompatible(*(rcpBMap->getMap(v,
false)));
446 bSame =
getMap(v,
true)->isCompatible(*(rcpBMap->getMap(v,
true)));
453template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
473 for(
size_t v = 0; v <
maps_.size(); ++v)
475 bool bSame =
getMap(v,
false)->isSameAs(*(rcpBMap->getMap(v,
false)));
482 bSame =
getMap(v,
true)->isSameAs(*(rcpBMap->getMap(v,
true)));
493template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
504template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
513template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
521template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
530template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
539template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
547template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
556template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
565template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
569 bool bThyraMode)
const
573 "BlockedMap::getMap: tried to access block " << i <<
", but BlockedMap has only " <<
getNumMaps()
574 <<
" blocks! Block indices must be between 0 and " <<
getNumMaps() - 1
583 "BlockedMap::getMap: cannot return sub map in Thyra-style numbering if BlockedMap object is not created using "
584 "Thyra-style numbered submaps.");
589template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
596 "BlockedMap::getImporter: tried to access block " << i <<
", but BlockedMap has only " <<
getNumMaps()
597 <<
" blocks! Block indices must be between 0 and " <<
getNumMaps() - 1
603template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
612template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
627template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
632 return std::string(
"BlockedMap");
636template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
641 out <<
"------------- Blocked Map -----------" << std::endl;
644 out <<
"No of submaps: " <<
getNumMaps() << std::endl;
648 std::cout <<
"MAP " << r <<
"/" <<
getNumMaps() - 1 << std::endl;
649 getMap(r,
false)->describe(out, verbLevel);
655 std::cout <<
"Thyra MAP " << r <<
"/" <<
getNumMaps() - 1 << std::endl;
656 getMap(r,
true)->describe(out, verbLevel);
659 out <<
"-------------------------------------" << std::endl;
663template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
676 for(
size_t i = 0; i < input.
getNumMaps(); ++i)
684 size_t numAllElements = 0;
685 for(
size_t v = 0; v <
maps_.size(); ++v)
687 numAllElements +=
maps_[ v ]->getGlobalNumElements();
690 fullmap_->getGlobalNumElements() != numAllElements,
692 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
696 for(
unsigned i = 0; i <
maps_.size(); ++i)
697 if(
maps_[ i ] != null)
700 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
704template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
711 std::vector<GlobalOrdinal> gids;
712 for(
size_t tt = 0; tt < subMaps.size(); ++tt)
718 gids.insert(gids.end(), subMapGids.
begin(), subMapGids.
end());
720 size_t myNumElements = subMap->getLocalNumElements();
721 for(LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(myNumElements); ++l)
723 GlobalOrdinal gid = subMap->getGlobalElement(l);
741template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
755 if(fullMap->isNodeGlobalElement(*it) ==
false)
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const_pointer const_iterator
virtual GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
virtual global_size_t getGlobalNumElements() const
The number of elements in this Map.
virtual GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
BlockedMap< LocalOrdinal, GlobalOrdinal, Node > & operator=(const BlockedMap &rhs)
Assignment operator: Does a deep copy.
virtual GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
virtual GlobalOrdinal getIndexBase() const
The index base for this Map.
virtual bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is valid for this Map on this process.
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
const RCP< Xpetra::Import< LocalOrdinal, GlobalOrdinal, Node > > getImporter(size_t i) const
get the importer between full map and partial map
static Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > concatenateMaps(const std::vector< Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > > &subMaps)
Helper function to concatenate several maps.
RCP< const Map > fullmap_
virtual Teuchos::ArrayView< const GlobalOrdinal > getLocalElementList() const
Return a view of the global indices owned by this process.
virtual GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
virtual bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
size_t getMapIndexForGID(GlobalOrdinal gid) const
returns map index in map extractor which contains GID
virtual bool isSameAs(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
virtual bool isCompatible(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getFullMap() const
the full map
bool CheckConsistency() const
std::vector< RCP< const Map > > thyraMaps_
size_t getNumMaps() const
number of partial maps
virtual GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
virtual LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
std::vector< RCP< const Map > > maps_
virtual bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on this process.
std::vector< RCP< Import > > importers_
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map's Comm object.
virtual ~BlockedMap()
Destructor.
virtual bool getThyraMode() const
Local number of rows on the calling process.
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &) const
Replace this Map's communicator with a subset communicator.
virtual bool isContiguous() const
True if this Map is distributed contiguously, else false.
virtual UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
virtual LocalOrdinal getMinLocalIndex() const
The minimum local index.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
virtual LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
virtual std::string description() const
A simple one-line description of this object.
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
virtual size_t getLocalNumElements() const
The number of elements belonging to the calling process.
virtual void assign(const BlockedMap &input)
Implementation of the assignment operator (operator=); does a deep copy.
virtual LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &, const Teuchos::ArrayView< int > &, const Teuchos::ArrayView< LocalOrdinal > &) const
Return the process ranks and corresponding local indices for the given global indices.
Exception throws to report errors in the internal logical of the program.
static RCP< Import< LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &source, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &target, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying the number of non-zeros for all rows.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=Xpetra::GloballyDistributed)
Map constructor with Xpetra-defined contiguous uniform distribution.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
basic_FancyOStream< char > FancyOStream
basic_OSTab< char > OSTab
size_t global_size_t
Global size_t object.