10#ifndef PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DEF_HPP_
11#define PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DEF_HPP_
17#include "Xpetra_MapFactory.hpp"
21template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
27template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
30 bThyraMode_ = bThyraMode;
32 if (bThyraMode ==
false) {
37 size_t numAllElements = 0;
38 for (
size_t v = 0; v < maps.size(); ++v) {
39 numAllElements += maps[v]->getGlobalNumElements();
43 "logic error. full map and sub maps have not same number of elements ("
44 << fullmap->getGlobalNumElements() <<
" versus " << numAllElements
45 <<
"). We cannot build MapExtractor with Xpetra-style numbering. Please make sure that you want "
46 "Xpetra-style numbering instead of Thyra-style numbering.");
56 for (
size_t v = 0; v < maps.size(); ++v) {
59 "logic error. When using Thyra-style numbering all sub-block maps must start with zero as GID. Map block "
60 << v <<
" starts with GID " << maps[v]->getMinAllGlobalIndex());
67 std::vector<GlobalOrdinal> gidOffsets(maps.size(), 0);
68 for (
size_t v = 1; v < maps.size(); ++v) {
69 gidOffsets[v] = maps[v - 1]->getMaxAllGlobalIndex() + gidOffsets[v - 1] + 1;
73 maps_.resize(maps.size());
74 std::vector<GlobalOrdinal> fullMapGids;
76 for (
size_t v = 0; v < maps.size(); ++v) {
77 size_t myNumElements = maps[v]->getLocalNumElements();
78 std::vector<GlobalOrdinal> subMapGids(myNumElements, 0);
79 for (LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(myNumElements); ++l) {
80 GlobalOrdinal myGid = maps[v]->getGlobalElement(l);
81 subMapGids[l] = myGid + gidOffsets[v];
82 fullMapGids.push_back(myGid + gidOffsets[v]);
90 maps[v]->lib(), INVALID, subMapGidsView, maps[v]->getIndexBase(), maps[v]->getComm());
104 fullmap->lib(), INVALID, fullMapGidsView, fullmap->getIndexBase(), fullmap->getComm());
107 size_t numAllElements = 0;
108 for (
size_t v = 0; v < maps_.size(); ++v) {
109 numAllElements += maps_[v]->getGlobalNumElements();
112 fullmap_->getGlobalNumElements() != numAllElements,
114 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
118 importers_.resize(maps_.size());
119 for (
unsigned i = 0; i < maps_.size(); ++i) {
120 if (maps[i] != null) {
125 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
128template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
134 TEUCHOS_TEST_FOR_EXCEPTION(thyramaps.size() != maps.size(), std::logic_error,
"logic error. The number of submaps must be identical!");
135 for (
size_t v = 0; v < thyramaps.size(); ++v) {
138 "logic error. When using Thyra-style numbering all sub-block maps must start with zero as GID.");
142 "logic error. The size of the submaps must be identical (same distribution, just different GIDs)");
146 thyraMaps_ = thyramaps;
148 fullmap_ = this->concatenateMaps(maps);
151 size_t numAllElements = 0;
152 for (
size_t v = 0; v < maps_.size(); ++v) {
153 numAllElements += maps_[v]->getGlobalNumElements();
156 fullmap_->getGlobalNumElements() != numAllElements,
158 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
161 importers_.resize(maps_.size());
162 for (
unsigned i = 0; i < maps_.size(); ++i) {
163 if (maps[i] != null) {
168 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
171template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
175 fullmap_ = Teuchos::null;
176 maps_.resize(input.
getNumMaps(), Teuchos::null);
177 thyraMaps_.resize(input.
getNumMaps(), Teuchos::null);
181template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
185 for (
size_t v = 0; v < maps_.size(); ++v) {
186 maps_[v] = Teuchos::null;
187 if (bThyraMode_ ==
true)
188 thyraMaps_[v] = Teuchos::null;
189 importers_[v] = Teuchos::null;
192 fullmap_ = Teuchos::null;
195template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
199 return fullmap_->getGlobalNumElements();
202template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
205 return fullmap_->getLocalNumElements();
208template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
212 return fullmap_->getIndexBase();
215template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
219 return fullmap_->getMinLocalIndex();
222template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
226 return fullmap_->getMaxLocalIndex();
229template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
233 return fullmap_->getMinGlobalIndex();
236template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
240 return fullmap_->getMaxGlobalIndex();
243template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
247 return fullmap_->getMinAllGlobalIndex();
250template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
254 return fullmap_->getMaxAllGlobalIndex();
257template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
261 return fullmap_->getLocalElement(globalIndex);
264template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
268 return fullmap_->getGlobalElement(localIndex);
271template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
281template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
290template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
294 return fullmap_->getLocalElementList();
297template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
301 return fullmap_->getMyGlobalIndicesDevice();
304template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
307 return fullmap_->isNodeLocalElement(localIndex);
310template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
313 return fullmap_->isNodeGlobalElement(globalIndex);
316template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
323template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
326 return fullmap_->isDistributed();
329template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
337 for (
size_t v = 0; v < maps_.size(); ++v) {
338 bool bSame = getMap(v,
false)->isCompatible(*(rcpBMap->getMap(v,
false)));
342 bSame = getMap(v,
true)->isCompatible(*(rcpBMap->getMap(v,
true)));
348template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
353 if (rcpBMap.
is_null() ==
true) {
355 if (this->getNumMaps() > 1) {
360 bool bSame = getMap(0, bThyraMode_)->isSameAs(*rcpMap);
364 for (
size_t v = 0; v < maps_.size(); ++v) {
365 bool bSame = getMap(v,
false)->isSameAs(*(rcpBMap->getMap(v,
false)));
366 if (bSame ==
false) {
370 bSame = getMap(v,
true)->isSameAs(*(rcpBMap->getMap(v,
true)));
371 if (bSame ==
false) {
379template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
383 return fullmap_->getComm();
386template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
394template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
399template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
406template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
413template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
416 return fullmap_->lib();
419template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
426template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
433template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
437 bool bThyraMode)
const {
440 "BlockedMap::getMap: tried to access block " << i <<
", but BlockedMap has only " << getNumMaps()
441 <<
" blocks! Block indices must be between 0 and " << getNumMaps() - 1
443 if (bThyraMode_ ==
true && bThyraMode ==
true) {
444 return thyraMaps_[i];
449 "BlockedMap::getMap: cannot return sub map in Thyra-style numbering if BlockedMap object is not created using "
450 "Thyra-style numbered submaps.");
454template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
460 "BlockedMap::getImporter: tried to access block " << i <<
", but BlockedMap has only " << getNumMaps()
461 <<
" blocks! Block indices must be between 0 and " << getNumMaps() - 1
463 return importers_[i];
466template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
473template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
477 for (
size_t i = 0; i < getNumMaps(); i++)
478 if (getMap(i)->isNodeGlobalElement(gid) ==
true)
486template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
490 return std::string(
"BlockedMap");
493template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
496 out <<
"------------- Blocked Map -----------" << std::endl;
497 out << description() << std::endl;
498 out <<
"Thyra mode: " << getThyraMode() << std::endl;
499 out <<
"No of submaps: " << getNumMaps() << std::endl;
501 for (
size_t r = 0; r < getNumMaps(); r++) {
502 std::cout <<
"MAP " << r <<
"/" << getNumMaps() - 1 << std::endl;
503 getMap(r,
false)->describe(out, verbLevel);
505 if (getThyraMode() ==
true) {
506 for (
size_t r = 0; r < getNumMaps(); r++) {
507 std::cout <<
"Thyra MAP " << r <<
"/" << getNumMaps() - 1 << std::endl;
508 getMap(r,
true)->describe(out, verbLevel);
511 out <<
"-------------------------------------" << std::endl;
514template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
522 maps_.resize(input.
getNumMaps(), Teuchos::null);
523 if (bThyraMode_ ==
true)
524 thyraMaps_.resize(input.
getNumMaps(), Teuchos::null);
525 for (
size_t i = 0; i < input.
getNumMaps(); ++i) {
527 if (bThyraMode_ ==
true)
532 size_t numAllElements = 0;
533 for (
size_t v = 0; v < maps_.size(); ++v) {
534 numAllElements += maps_[v]->getGlobalNumElements();
537 fullmap_->getGlobalNumElements() != numAllElements,
539 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
542 importers_.resize(maps_.size());
543 for (
unsigned i = 0; i < maps_.size(); ++i)
544 if (maps_[i] != null)
547 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
550template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
555 std::vector<GlobalOrdinal> gids;
556 for (
size_t tt = 0; tt < subMaps.size(); ++tt) {
561 gids.insert(gids.end(), subMapGids.
begin(), subMapGids.
end());
563 size_t myNumElements = subMap->getLocalNumElements();
564 for (LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(myNumElements); ++l) {
565 GlobalOrdinal gid = subMap->getGlobalElement(l);
577 Build(subMaps[0]->lib(), INVALID, gidsView, subMaps[0]->getIndexBase(), subMaps[0]->getComm());
582template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
587 for (
size_t i = 0; i < getNumMaps(); i++) {
592 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.
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
virtual global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process.
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.
virtual bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on this process.
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.
Kokkos::View< const global_ordinal_type *, typename Node::device_type > global_indices_array_device_type
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
size_t global_size_t
Global size_t object.