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"
62 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 BlockedMap(
const RCP<const Map>& fullmap,
const std::vector<RCP<const Map>>& maps,
bool bThyraMode)
74 bThyraMode_ = bThyraMode;
76 if(bThyraMode ==
false)
82 size_t numAllElements = 0;
83 for(
size_t v = 0; v < maps.size(); ++v)
85 numAllElements += maps[ v ]->getGlobalNumElements();
87 TEUCHOS_TEST_FOR_EXCEPTION(fullmap->getGlobalNumElements() != numAllElements,
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)
106 TEUCHOS_TEST_FOR_EXCEPTION(maps[ v ]->getMinAllGlobalIndex() != 0,
108 "logic error. When using Thyra-style numbering all sub-block maps must start with zero as GID. Map block "
109 << v <<
" starts with GID " << maps[ v ]->getMinAllGlobalIndex());
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;
125 const GO INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
126 for(
size_t v = 0; v < maps.size(); ++v)
128 size_t myNumElements = maps[ v ]->getNodeNumElements();
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 ]);
139 Teuchos::ArrayView<GlobalOrdinal> subMapGidsView(&subMapGids[ 0 ], subMapGids.size());
142 maps[ v ]->lib(), INVALID, subMapGidsView, maps[ v ]->getIndexBase(), maps[ v ]->getComm());
143 maps_[ v ] = mySubMap;
153 Teuchos::ArrayView<GlobalOrdinal> fullMapGidsView(&fullMapGids[ 0 ], fullMapGids.size());
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();
164 TEUCHOS_TEST_FOR_EXCEPTION(
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!");
171 importers_.resize(maps_.size());
172 for(
unsigned i = 0; i < maps_.size(); ++i)
174 if(maps[ i ] != null)
179 TEUCHOS_TEST_FOR_EXCEPTION(
180 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
184 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
186 BlockedMap(
const std::vector<RCP<const Map>>& maps,
const std::vector<RCP<const Map>>& thyramaps)
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)
194 TEUCHOS_TEST_FOR_EXCEPTION(thyramaps[ v ]->getMinAllGlobalIndex() != 0,
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)");
204 thyraMaps_ = thyramaps;
206 fullmap_ = this->concatenateMaps(maps);
209 size_t numAllElements = 0;
210 for(
size_t v = 0; v < maps_.size(); ++v)
212 numAllElements += maps_[ v ]->getGlobalNumElements();
214 TEUCHOS_TEST_FOR_EXCEPTION(
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!");
220 importers_.resize(maps_.size());
221 for(
unsigned i = 0; i < maps_.size(); ++i)
223 if(maps[ i ] != null)
228 TEUCHOS_TEST_FOR_EXCEPTION(
229 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
233 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
238 fullmap_ = Teuchos::null;
239 maps_.resize(input.
getNumMaps(), Teuchos::null);
240 thyraMaps_.resize(input.
getNumMaps(), Teuchos::null);
245 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
250 for(
size_t v = 0; v < maps_.size(); ++v)
252 maps_[ v ] = Teuchos::null;
253 if(bThyraMode_ ==
true)
254 thyraMaps_[ v ] = Teuchos::null;
255 importers_[ v ] = Teuchos::null;
258 fullmap_ = Teuchos::null;
262 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
267 return fullmap_->getGlobalNumElements();
271 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
275 return fullmap_->getNodeNumElements();
279 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
284 return fullmap_->getIndexBase();
288 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
293 return fullmap_->getMinLocalIndex();
297 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
302 return fullmap_->getMaxLocalIndex();
306 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
311 return fullmap_->getMinGlobalIndex();
315 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
320 return fullmap_->getMaxGlobalIndex();
324 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
329 return fullmap_->getMinAllGlobalIndex();
333 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
338 return fullmap_->getMaxAllGlobalIndex();
342 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
347 return fullmap_->getLocalElement(globalIndex);
351 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
356 return fullmap_->getGlobalElement(localIndex);
360 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
364 const Teuchos::ArrayView<int>& ,
365 const Teuchos::ArrayView<LocalOrdinal>& )
const
372 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
376 const Teuchos::ArrayView<int>& )
const
383 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
384 Teuchos::ArrayView<const GlobalOrdinal>
388 return fullmap_->getNodeElementList();
392 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
397 return fullmap_->isNodeLocalElement(localIndex);
401 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
406 return fullmap_->isNodeGlobalElement(globalIndex);
410 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
416 TEUCHOS_UNREACHABLE_RETURN(
false);
420 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
425 return fullmap_->isDistributed();
429 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
434 RCP<const Map> rcpMap = Teuchos::rcpFromRef(map);
435 RCP<const BlockedMap> rcpBMap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(rcpMap);
436 if(rcpBMap.is_null() ==
true)
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)));
453 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
458 RCP<const Map> rcpMap = Teuchos::rcpFromRef(map);
459 RCP<const BlockedMap> rcpBMap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(rcpMap);
460 if(rcpBMap.is_null() ==
true)
463 if(this->getNumMaps() > 1)
469 bool bSame = getMap(0, bThyraMode_)->
isSameAs(*rcpMap);
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)));
493 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
494 Teuchos::RCP<const Teuchos::Comm<int>>
498 return fullmap_->getComm();
504 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
513 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
521 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
522 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
530 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
531 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
539 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
543 return fullmap_->lib();
547 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
548 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
556 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
565 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
566 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, 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
576 if(bThyraMode_ ==
true && bThyraMode ==
true)
578 return thyraMaps_[ i ];
583 "BlockedMap::getMap: cannot return sub map in Thyra-style numbering if BlockedMap object is not created using "
584 "Thyra-style numbered submaps.");
589 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
590 const RCP<Xpetra::Import<LocalOrdinal,GlobalOrdinal,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
599 return importers_[ i ];
603 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
604 const RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node>>
612 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
617 for(
size_t i = 0; i < getNumMaps(); i++)
618 if(getMap(i)->isNodeGlobalElement(gid) ==
true)
621 TEUCHOS_TEST_FOR_EXCEPTION(
627 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
632 return std::string(
"BlockedMap");
636 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
639 describe(Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const
641 out <<
"------------- Blocked Map -----------" << std::endl;
642 out << description() << std::endl;
643 out <<
"Thyra mode: " << getThyraMode() << std::endl;
644 out <<
"No of submaps: " << getNumMaps() << std::endl;
645 Teuchos::OSTab tab(out);
646 for(
size_t r = 0; r < getNumMaps(); r++)
648 std::cout <<
"MAP " << r <<
"/" << getNumMaps() - 1 << std::endl;
649 getMap(r,
false)->describe(out, verbLevel);
651 if(getThyraMode() ==
true)
653 for(
size_t r = 0; r < getNumMaps(); r++)
655 std::cout <<
"Thyra MAP " << r <<
"/" << getNumMaps() - 1 << std::endl;
656 getMap(r,
true)->describe(out, verbLevel);
659 out <<
"-------------------------------------" << std::endl;
663 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
673 maps_.resize(input.
getNumMaps(), Teuchos::null);
674 if(bThyraMode_ ==
true)
675 thyraMaps_.resize(input.
getNumMaps(), Teuchos::null);
676 for(
size_t i = 0; i < input.
getNumMaps(); ++i)
679 if(bThyraMode_ ==
true)
684 size_t numAllElements = 0;
685 for(
size_t v = 0; v < maps_.size(); ++v)
687 numAllElements += maps_[ v ]->getGlobalNumElements();
689 TEUCHOS_TEST_FOR_EXCEPTION(
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!");
695 importers_.resize(maps_.size());
696 for(
unsigned i = 0; i < maps_.size(); ++i)
697 if(maps_[ i ] != null)
699 TEUCHOS_TEST_FOR_EXCEPTION(
700 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
704 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
705 Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
711 std::vector<GlobalOrdinal> gids;
712 for(
size_t tt = 0; tt < subMaps.size(); ++tt)
714 Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> subMap = subMaps[ tt ];
716 #if 1 // WCMCLEN : IS THIS NECESSARY TO HANG ONTO?
717 Teuchos::ArrayView<const GlobalOrdinal> subMapGids = subMap->getNodeElementList();
718 gids.insert(gids.end(), subMapGids.begin(), subMapGids.end());
720 size_t myNumElements = subMap->getNodeNumElements();
721 for(LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(myNumElements); ++l)
723 GlobalOrdinal gid = subMap->getGlobalElement(l);
729 const GlobalOrdinal INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
732 Teuchos::ArrayView<GlobalOrdinal> gidsView(&gids[ 0 ], gids.size());
735 Build(subMaps[ 0 ]->lib(), INVALID, gidsView, subMaps[ 0 ]->getIndexBase(), subMaps[ 0 ]->getComm());
741 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
746 const RCP<const Map> fullMap = getFullMap();
748 for(
size_t i = 0; i < getNumMaps(); i++)
750 const RCP<const Map> map = getMap(i);
752 ArrayView<const GlobalOrdinal> mapGids = map->getNodeElementList();
753 for(
typename ArrayView<const GlobalOrdinal>::const_iterator it = mapGids.begin(); it != mapGids.end(); it++)
755 if(fullMap->isNodeGlobalElement(*it) ==
false)
virtual GlobalOrdinal getIndexBase() const
The index base for this Map.
virtual Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this process.
virtual std::string description() const
A simple one-line description of this object.
bool CheckConsistency() const
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map's Comm object.
virtual ~BlockedMap()
Destructor.
Exception throws to report errors in the internal logical of the program.
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
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
virtual global_size_t getGlobalNumElements() const
The number of elements in this Map.
virtual size_t getNodeNumElements() const
The number of elements belonging to the calling process.
virtual GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
virtual bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is valid for this Map on this process.
const RCP< Xpetra::Import< LocalOrdinal, GlobalOrdinal, Node > > getImporter(size_t i) const
get the importer between full map and partial map
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 void assign(const BlockedMap &input)
Implementation of the assignment operator (operator=); does a deep copy.
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.
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.
virtual bool isSameAs(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
virtual LocalOrdinal getMinLocalIndex() const
The minimum local index.
size_t getNumMaps() const
number of partial maps
virtual GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
virtual LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
virtual bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on this process.
BlockedMap< LocalOrdinal, GlobalOrdinal, Node > & operator=(const BlockedMap &rhs)
Assignment operator: Does a deep copy.
size_t global_size_t
Global size_t object.
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 UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
virtual GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
virtual GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
virtual bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
virtual bool isContiguous() const
True if this Map is distributed contiguously, else false.
virtual GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
size_t getMapIndexForGID(GlobalOrdinal gid) const
returns map index in map extractor which contains GID
virtual bool getThyraMode() const
Local number of rows on the calling process.
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.
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.