47 #ifndef PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_HPP_
48 #define PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_HPP_
58 #ifndef DOXYGEN_SHOULD_SKIP_THIS
61 template<
class LO,
class GO,
class N>
class MapFactory;
64 template <class LocalOrdinal = Map<>::local_ordinal_type,
68 :
public Map< LocalOrdinal, GlobalOrdinal, Node >
76 #undef XPETRA_BLOCKEDMAP_SHORT
102 BlockedMap(
const RCP<const Map>& fullmap,
const std::vector<RCP<const Map> >& maps,
bool bThyraMode =
false) {
105 if(bThyraMode ==
false) {
110 size_t numAllElements = 0;
111 for(
size_t v = 0; v < maps.size(); ++v) {
112 numAllElements += maps[v]->getGlobalNumElements();
114 TEUCHOS_TEST_FOR_EXCEPTION(fullmap->getGlobalNumElements() != numAllElements, std::logic_error,
115 "logic error. full map and sub maps have not same number of elements (" << fullmap->getGlobalNumElements() <<
" versus " << numAllElements <<
"). We cannot build MapExtractor with Xpetra-style numbering. Please make sure that you want Xpetra-style numbering instead of Thyra-style numbering.");
125 for(
size_t v = 0; v < maps.size(); ++v) {
127 "logic error. When using Thyra-style numbering all sub-block maps must start with zero as GID. Map block " << v <<
" starts with GID " << maps[v]->
getMinAllGlobalIndex());
134 std::vector<GlobalOrdinal> gidOffsets(maps.size(),0);
135 for(
size_t v = 1; v < maps.size(); ++v) {
136 gidOffsets[v] = maps[v-1]->getMaxAllGlobalIndex() + gidOffsets[v-1] + 1;
140 maps_.resize(maps.size());
141 std::vector<GlobalOrdinal> fullMapGids;
142 const GO INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
143 for(
size_t v = 0; v < maps.size(); ++v) {
144 size_t myNumElements = maps[v]->getNodeNumElements();
145 std::vector<GlobalOrdinal> subMapGids(myNumElements,0);
146 for (LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(myNumElements); ++l) {
147 GlobalOrdinal myGid = maps[v]->getGlobalElement(l);
148 subMapGids[l] = myGid + gidOffsets[v];
149 fullMapGids.push_back(myGid + gidOffsets[v]);
154 Teuchos::ArrayView<GlobalOrdinal> subMapGidsView(&subMapGids[0], subMapGids.size());
166 Teuchos::ArrayView<GlobalOrdinal> fullMapGidsView(&fullMapGids[0], fullMapGids.size());
170 size_t numAllElements = 0;
171 for(
size_t v = 0; v <
maps_.size(); ++v) {
172 numAllElements +=
maps_[v]->getGlobalNumElements();
174 TEUCHOS_TEST_FOR_EXCEPTION(
fullmap_->getGlobalNumElements() != numAllElements, std::logic_error,
175 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
180 for (
unsigned i = 0; i <
maps_.size(); ++i)
184 "logic error. full map and sub maps are inconsistently distributed over the processors.");
189 BlockedMap(
const std::vector<RCP<const Map> >& maps,
const std::vector<RCP<const Map> >& thyramaps) {
193 TEUCHOS_TEST_FOR_EXCEPTION(thyramaps.size() != maps.size(), std::logic_error,
"logic error. The number of submaps must be identical!");
194 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.");
198 "logic error. The size of the submaps must be identical (same distribution, just different GIDs)");
208 size_t numAllElements = 0;
209 for(
size_t v = 0; v <
maps_.size(); ++v) {
210 numAllElements +=
maps_[v]->getGlobalNumElements();
212 TEUCHOS_TEST_FOR_EXCEPTION(
fullmap_->getGlobalNumElements() != numAllElements, std::logic_error,
213 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
217 for (
unsigned i = 0; i <
maps_.size(); ++i)
221 "logic error. full map and sub maps are inconsistently distributed over the processors.");
237 for(
size_t v = 0; v <
maps_.size(); ++v) {
238 maps_[v] = Teuchos::null;
284 virtual LookupStatus getRemoteIndexList(
const Teuchos::ArrayView< const GlobalOrdinal > &GIDList,
const Teuchos::ArrayView< int > &nodeIDList,
const Teuchos::ArrayView< LocalOrdinal > &LIDList)
const {
297 return fullmap_->getNodeElementList();
314 TEUCHOS_UNREACHABLE_RETURN(
false);
322 RCP<const Map> rcpMap = Teuchos::rcpFromRef(map);
323 RCP<const BlockedMap> rcpBMap = Teuchos::rcp_dynamic_cast<const BlockedMap>(rcpMap);
324 if(rcpBMap.is_null() ==
true)
return false;
326 for(
size_t v = 0; v <
maps_.size(); ++v) {
327 bool bSame =
getMap(v,
false)->isCompatible(*(rcpBMap->getMap(v,
false)));
328 if (bSame ==
false)
return false;
330 bSame =
getMap(v,
true)->isCompatible(*(rcpBMap->getMap(v,
true)));
338 RCP<const Map> rcpMap = Teuchos::rcpFromRef(map);
339 RCP<const BlockedMap> rcpBMap = Teuchos::rcp_dynamic_cast<const BlockedMap>(rcpMap);
340 if(rcpBMap.is_null() ==
true) {
349 for(
size_t v = 0; v <
maps_.size(); ++v) {
350 bool bSame =
getMap(v,
false)->isSameAs(*(rcpBMap->getMap(v,
false)));
351 if (bSame ==
false)
return false;
353 bSame =
getMap(v,
true)->isSameAs(*(rcpBMap->getMap(v,
true)));
354 if (bSame ==
false)
return false;
366 virtual Teuchos::RCP< const Teuchos::Comm< int > >
getComm()
const {
return fullmap_->getComm(); } ;
418 virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > >
replaceCommWithSubset(
const Teuchos::RCP<
const Teuchos::Comm< int > > &newComm)
const {
435 virtual RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
getMap()
const {
return getFullMap(); }
447 const RCP<const Map>
getMap(
size_t i,
bool bThyraMode =
false)
const {
452 "BlockedMap::getMap: cannot return sub map in Thyra-style numbering if BlockedMap object is not created using Thyra-style numbered submaps.");
468 if (
getMap(i)->isNodeGlobalElement(gid) ==
true)
472 "getMapIndexForGID: GID " << gid <<
" is not contained by a map in mapextractor." );
476 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
477 #ifdef HAVE_XPETRA_TPETRA
480 local_map_type getLocalMap ()
const {
485 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
497 return std::string(
"BlockedMap");
501 virtual void describe(Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default)
const {
502 out <<
"------------- Blocked Map -----------" << std::endl;
505 out <<
"No of submaps: " <<
getNumMaps() << std::endl;
506 Teuchos::OSTab tab(out);
508 std::cout <<
"MAP " << r <<
"/" <<
getNumMaps() - 1 << std::endl;
509 getMap(r,
false)->describe(out, verbLevel);
513 std::cout <<
"Thyra MAP " << r <<
"/" <<
getNumMaps() - 1 << std::endl;
514 getMap(r,
true)->describe(out, verbLevel);
517 out <<
"-------------------------------------" << std::endl;
536 for(
size_t i = 0; i < input.
getNumMaps(); ++i) {
543 size_t numAllElements = 0;
544 for(
size_t v = 0; v <
maps_.size(); ++v) {
545 numAllElements +=
maps_[v]->getGlobalNumElements();
547 TEUCHOS_TEST_FOR_EXCEPTION(
fullmap_->getGlobalNumElements() != numAllElements, std::logic_error,
548 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
552 for (
unsigned i = 0; i <
maps_.size(); ++i)
553 if (
maps_[i] !=
null)
556 "logic error. full map and sub maps are inconsistently distributed over the processors.");
576 std::vector<GlobalOrdinal> gids;
577 for(
size_t tt = 0; tt<subMaps.size(); ++tt) {
578 Teuchos::RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > subMap = subMaps[tt];
580 Teuchos::ArrayView< const GlobalOrdinal > subMapGids = subMap->getNodeElementList();
581 gids.insert(gids.end(), subMapGids.begin(), subMapGids.end());
583 size_t myNumElements = subMap->getNodeNumElements();
584 for(LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(myNumElements); ++l) {
585 GlobalOrdinal gid = subMap->getGlobalElement(l);
591 const GlobalOrdinal INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
594 Teuchos::ArrayView<GlobalOrdinal> gidsView(&gids[0], gids.size());
604 const RCP<const Map> map =
getMap(i);
606 ArrayView<const GlobalOrdinal> mapGids = map->getNodeElementList();
607 for (
typename ArrayView< const GlobalOrdinal >::const_iterator it = mapGids.begin(); it != mapGids.end(); it++)
608 if (fullMap->isNodeGlobalElement(*it) ==
false)
624 #define XPETRA_BLOCKEDMAP_SHORT