47 #ifndef PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DEF_HPP_
48 #define PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DEF_HPP_
62 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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();
89 "logic error. full map and sub maps have not same number of elements ("
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 "
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;
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 ]);
142 maps[ v ]->lib(), INVALID, subMapGidsView, maps[ v ]->getIndexBase(), maps[ v ]->getComm());
143 maps_[ v ] = mySubMap;
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!");
171 importers_.resize(maps_.size());
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.");
184 template<
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)");
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();
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)
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>
372 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
383 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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>
420 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
425 return fullmap_->isDistributed();
429 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
439 for(
size_t v = 0; v < maps_.size(); ++v)
446 bSame = getMap(v,
true)->isCompatible(*(rcpBMap->
getMap(v,
true)));
453 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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>
498 return fullmap_->getComm();
502 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
503 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
509 return fullmap_->getNode();
511 #endif // TPETRA_ENABLE_DEPRECATED_CODE
514 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
515 BlockedMap<LocalOrdinal, GlobalOrdinal, Node>&
523 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
531 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
540 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
549 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
553 return fullmap_->lib();
557 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
566 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
575 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
579 bool bThyraMode)
const
583 "BlockedMap::getMap: tried to access block " << i <<
", but BlockedMap has only " << getNumMaps()
584 <<
" blocks! Block indices must be between 0 and " << getNumMaps() - 1
586 if(bThyraMode_ ==
true && bThyraMode ==
true)
588 return thyraMaps_[ i ];
593 "BlockedMap::getMap: cannot return sub map in Thyra-style numbering if BlockedMap object is not created using "
594 "Thyra-style numbered submaps.");
599 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
606 "BlockedMap::getImporter: tried to access block " << i <<
", but BlockedMap has only " << getNumMaps()
607 <<
" blocks! Block indices must be between 0 and " << getNumMaps() - 1
609 return importers_[ i ];
613 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
622 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
627 for(
size_t i = 0; i < getNumMaps(); i++)
628 if(getMap(i)->isNodeGlobalElement(gid) ==
true)
637 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
642 return std::string(
"BlockedMap");
646 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
651 out <<
"------------- Blocked Map -----------" << std::endl;
652 out << description() << std::endl;
653 out <<
"Thyra mode: " << getThyraMode() << std::endl;
654 out <<
"No of submaps: " << getNumMaps() << std::endl;
656 for(
size_t r = 0; r < getNumMaps(); r++)
658 std::cout <<
"MAP " << r <<
"/" << getNumMaps() - 1 << std::endl;
659 getMap(r,
false)->describe(out, verbLevel);
661 if(getThyraMode() ==
true)
663 for(
size_t r = 0; r < getNumMaps(); r++)
665 std::cout <<
"Thyra MAP " << r <<
"/" << getNumMaps() - 1 << std::endl;
666 getMap(r,
true)->describe(out, verbLevel);
669 out <<
"-------------------------------------" << std::endl;
673 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
683 maps_.resize(input.
getNumMaps(), Teuchos::null);
684 if(bThyraMode_ ==
true)
685 thyraMaps_.resize(input.
getNumMaps(), Teuchos::null);
686 for(
size_t i = 0; i < input.
getNumMaps(); ++i)
689 if(bThyraMode_ ==
true)
694 size_t numAllElements = 0;
695 for(
size_t v = 0; v < maps_.size(); ++v)
697 numAllElements += maps_[ v ]->getGlobalNumElements();
700 fullmap_->getGlobalNumElements() != numAllElements,
702 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
705 importers_.resize(maps_.size());
706 for(
unsigned i = 0; i < maps_.size(); ++i)
707 if(maps_[ i ] != null)
710 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
714 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
721 std::vector<GlobalOrdinal> gids;
722 for(
size_t tt = 0; tt < subMaps.size(); ++tt)
726 #if 1 // WCMCLEN : IS THIS NECESSARY TO HANG ONTO?
728 gids.insert(gids.end(), subMapGids.
begin(), subMapGids.
end());
730 size_t myNumElements = subMap->getNodeNumElements();
731 for(LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(myNumElements); ++l)
733 GlobalOrdinal gid = subMap->getGlobalElement(l);
745 Build(subMaps[ 0 ]->lib(), INVALID, gidsView, subMaps[ 0 ]->getIndexBase(), subMaps[ 0 ]->getComm());
751 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
758 for(
size_t i = 0; i < getNumMaps(); i++)
virtual GlobalOrdinal getIndexBase() const
The index base for this Map.
virtual Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const =0
Return a view of the global indices owned by this process.
virtual Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this process.
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const =0
Get this Map's Comm object.
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const_pointer const_iterator
virtual ~BlockedMap()
Destructor.
Exception throws to report errors in the internal logical of the program.
virtual GlobalOrdinal getIndexBase() const =0
The index base for 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
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.
virtual bool isNodeGlobalElement(GlobalOrdinal globalIndex) const =0
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.
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
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 global_size_t getGlobalNumElements() const =0
The number of elements in this Map.
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 UnderlyingLib lib() const =0
Get the library used by this object (Tpetra or Epetra?)
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.