47 #ifndef PACKAGES_XPETRA_SUP_MAP_UTILS_HPP_
48 #define PACKAGES_XPETRA_SUP_MAP_UTILS_HPP_
53 #include "Xpetra_Map.hpp"
54 #include "Xpetra_MapFactory.hpp"
58 #ifndef DOXYGEN_SHOULD_SKIP_THIS
60 template<
class LO,
class GO,
class N>
class BlockedMap;
70 template <
class LocalOrdinal,
74 #undef XPETRA_MAPUTILS_SHORT
98 std::vector<GlobalOrdinal> gids;
99 for(
size_t tt = 0; tt<subMaps.size(); ++tt) {
100 Teuchos::RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > subMap = subMaps[tt];
101 Teuchos::ArrayView< const GlobalOrdinal > subMapGids = subMap->getNodeElementList();
102 gids.insert(gids.end(), subMapGids.begin(), subMapGids.end());
105 const GlobalOrdinal INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
108 Teuchos::ArrayView<GlobalOrdinal> gidsView(&gids[0], gids.size());
128 static Teuchos::RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
134 "Xpetra::MatrixUtils::shrinkMapGIDs: the non-overlapping map must not have more local ids than the overlapping map.")
138 "Xpetra::MatrixUtils::shrinkMapGIDs: the maximum GIDs of the overlapping and non-overlapping maps must be the same.")
140 RCP<
const Teuchos::Comm<int> > comm = input.
getComm();
147 std::vector<int> myGIDs(comm->getSize(),0);
148 std::vector<int> numGIDs(comm->getSize(),0);
150 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,comm->getSize(),&myGIDs[0],&numGIDs[0]);
151 size_t gidOffset = 0;
152 for(
int p = 0; p < comm->getRank(); p++) gidOffset += numGIDs[p];
155 std::map<const GlobalOrdinal, GlobalOrdinal> origGID2newGID;
158 origGID2newGID[nonOvlInput.
getGlobalElement(i)] = Teuchos::as<GlobalOrdinal>(i) + Teuchos::as<GlobalOrdinal>(gidOffset);
161 Teuchos::Array<GlobalOrdinal> ovlUnknownStatusGids;
162 Teuchos::Array<GlobalOrdinal> ovlFoundStatusGids;
167 ovlUnknownStatusGids.push_back(gcid);
172 std::vector<int> myUnknownDofGIDs(comm->getSize(),0);
173 std::vector<int> numUnknownDofGIDs(comm->getSize(),0);
174 myUnknownDofGIDs[comm->getRank()] = ovlUnknownStatusGids.size();
175 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,comm->getSize(),&myUnknownDofGIDs[0],&numUnknownDofGIDs[0]);
178 size_t cntUnknownDofGIDs = 0;
179 for(
int p = 0; p < comm->getSize(); p++) cntUnknownDofGIDs += numUnknownDofGIDs[p];
180 std::vector<GlobalOrdinal> lUnknownDofGIDs(cntUnknownDofGIDs,0);
181 std::vector<GlobalOrdinal> gUnknownDofGIDs(cntUnknownDofGIDs,0);
183 size_t cntUnknownOffset = 0;
184 for(
int p = 0; p < comm->getRank(); p++) cntUnknownOffset += numUnknownDofGIDs[p];
185 for(
size_t k=0; k < Teuchos::as<size_t>(ovlUnknownStatusGids.size()); k++) {
186 lUnknownDofGIDs[k+cntUnknownOffset] = ovlUnknownStatusGids[k];
188 if(cntUnknownDofGIDs > 0)
189 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,Teuchos::as<int>(cntUnknownDofGIDs),&lUnknownDofGIDs[0],&gUnknownDofGIDs[0]);
190 std::vector<GlobalOrdinal> lTranslatedDofGIDs(cntUnknownDofGIDs,0);
191 std::vector<GlobalOrdinal> gTranslatedDofGIDs(cntUnknownDofGIDs,0);
193 for(
size_t k=0; k < gUnknownDofGIDs.size(); k++) {
194 GlobalOrdinal curgid = gUnknownDofGIDs[k];
196 lTranslatedDofGIDs[k] = origGID2newGID[curgid];
199 if(cntUnknownDofGIDs > 0)
200 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,Teuchos::as<int>(cntUnknownDofGIDs),&lTranslatedDofGIDs[0],&gTranslatedDofGIDs[0]);
202 for(
size_t k=0; k < Teuchos::as<size_t>(ovlUnknownStatusGids.size()); k++) {
203 origGID2newGID[ovlUnknownStatusGids[k]] = gTranslatedDofGIDs[k+cntUnknownOffset];
205 Teuchos::Array<GlobalOrdinal> ovlDomainMapArray;
208 ovlDomainMapArray.push_back(origGID2newGID[gcid]);
210 RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > ovlDomainMap =
212 (nonOvlInput.
lib(),Teuchos::OrdinalTraits<GlobalOrdinal>::invalid(),ovlDomainMapArray(),0,comm);
240 RCP< const Teuchos::Comm<int> > comm = input.
getComm();
243 std::map<const GlobalOrdinal, GlobalOrdinal> thyra2xpetraGID;
250 Teuchos::Array<GlobalOrdinal> ovlUnknownStatusGids;
255 ovlUnknownStatusGids.push_back(gcid);
260 std::vector<int> myUnknownDofGIDs(comm->getSize(),0);
261 std::vector<int> numUnknownDofGIDs(comm->getSize(),0);
262 myUnknownDofGIDs[comm->getRank()] = ovlUnknownStatusGids.size();
263 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,comm->getSize(),&myUnknownDofGIDs[0],&numUnknownDofGIDs[0]);
266 size_t cntUnknownDofGIDs = 0;
267 for(
int p = 0; p < comm->getSize(); p++) cntUnknownDofGIDs += numUnknownDofGIDs[p];
268 std::vector<GlobalOrdinal> lUnknownDofGIDs(cntUnknownDofGIDs,0);
269 std::vector<GlobalOrdinal> gUnknownDofGIDs(cntUnknownDofGIDs,0);
271 size_t cntUnknownOffset = 0;
272 for(
int p = 0; p < comm->getRank(); p++) cntUnknownOffset += numUnknownDofGIDs[p];
273 for(
size_t k=0; k < Teuchos::as<size_t>(ovlUnknownStatusGids.size()); k++) {
274 lUnknownDofGIDs[k+cntUnknownOffset] = ovlUnknownStatusGids[k];
276 if(cntUnknownDofGIDs > 0)
277 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,Teuchos::as<int>(cntUnknownDofGIDs),&lUnknownDofGIDs[0],&gUnknownDofGIDs[0]);
278 std::vector<GlobalOrdinal> lTranslatedDofGIDs(cntUnknownDofGIDs,0);
279 std::vector<GlobalOrdinal> gTranslatedDofGIDs(cntUnknownDofGIDs,0);
281 for(
size_t k=0; k < gUnknownDofGIDs.size(); k++) {
282 GlobalOrdinal curgid = gUnknownDofGIDs[k];
284 lTranslatedDofGIDs[k] = thyra2xpetraGID[curgid];
287 if(cntUnknownDofGIDs > 0)
288 Teuchos::reduceAll(*comm,Teuchos::REDUCE_MAX,Teuchos::as<int>(cntUnknownDofGIDs),&lTranslatedDofGIDs[0],&gTranslatedDofGIDs[0]);
290 for(
size_t k=0; k < Teuchos::as<size_t>(ovlUnknownStatusGids.size()); k++) {
291 thyra2xpetraGID[ovlUnknownStatusGids[k]] = gTranslatedDofGIDs[k+cntUnknownOffset];
293 Teuchos::Array<GlobalOrdinal> ovlDomainMapArray;
296 ovlDomainMapArray.push_back(thyra2xpetraGID[gcid]);
298 RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > ovlDomainMap =
300 (nonOvlInput.
lib(),Teuchos::OrdinalTraits<GlobalOrdinal>::invalid(),ovlDomainMapArray(),0,comm);
302 TEUCHOS_TEST_FOR_EXCEPTION(input.
getNodeNumElements() != ovlDomainMap->getNodeNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::transformThyra2XpetraGIDs: the number of local Thyra reference GIDs (overlapping) and local Xpetra GIDs (overlapping) must be the same!");
317 const GO INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
318 RCP< const Teuchos::Comm<int> > comm = input.
getComm();
320 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > rcpInput = Teuchos::rcpFromRef(input);
324 if(rcpBlockedInput.is_null() ==
true) {
327 std::vector<GlobalOrdinal> gids;
328 for(LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(rcpInput->getNodeNumElements()); ++l) {
332 Teuchos::ArrayView<GO> gidsView(&gids[0], gids.size());
333 RCP<Map> fullMap =
MapFactory::Build(rcpInput->lib(), INVALID, gidsView, rcpInput->getIndexBase(), comm);
340 size_t numMaps = rcpBlockedInput->getNumMaps();
344 std::vector<GlobalOrdinal> gidOffsets(numMaps,0);
345 for(
size_t i = 1; i < numMaps; ++i) {
346 gidOffsets[i] = rcpBlockedInput->getMap(i-1,
true)->getMaxAllGlobalIndex() + gidOffsets[i-1] + 1;
349 std::vector<RCP<const Map> > mapsXpetra(rcpBlockedInput->getNumMaps(), Teuchos::null);
350 std::vector<RCP<const Map> > mapsThyra (rcpBlockedInput->getNumMaps(), Teuchos::null);
351 for (
size_t b = 0; b < rcpBlockedInput->getNumMaps(); ++b){
354 RCP<const Map> subMapThyra = rcpBlockedInput->getMap(b,
true);
356 mapsXpetra[b] = subMapXpetra;
357 mapsThyra[b] = subMapThyra;
368 #define XPETRA_MAPUTILS_SHORT
370 #endif // PACKAGES_XPETRA_SUP_MAP_UTILS_HPP_
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const =0
Get this Map's Comm object.
virtual size_t getNodeNumElements() const =0
The number of elements belonging to the calling process.
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 bool isNodeGlobalElement(GlobalOrdinal globalIndex) const =0
Whether the given global index is valid for this Map on this process.
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.
static Teuchos::RCP< Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > transformThyra2XpetraGIDs(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &input, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &nonOvlInput, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &nonOvlReferenceInput)
replace set of global ids by new global ids
virtual GlobalOrdinal getMaxAllGlobalIndex() const =0
The maximum global index over all processes in the communicator.
virtual GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const =0
The global index corresponding to the given local index.
static Teuchos::RCP< Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > shrinkMapGIDs(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &input, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &nonOvlInput)
Helper function to shrink the GIDs and generate a standard map whith GIDs starting at 0...
virtual GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
Exception throws to report incompatible objects (like maps).
static Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > transformThyra2XpetraGIDs(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &input, GlobalOrdinal offset)
replace set of global ids by new global ids
virtual UnderlyingLib lib() const =0
Get the library used by this object (Tpetra or Epetra?)