10 #ifndef PACKAGES_XPETRA_SUP_MAP_UTILS_HPP_
11 #define PACKAGES_XPETRA_SUP_MAP_UTILS_HPP_
16 #include "Xpetra_Map.hpp"
17 #include "Xpetra_MapFactory.hpp"
21 #ifndef DOXYGEN_SHOULD_SKIP_THIS
23 template <
class LO,
class GO,
class N>
34 template <
class LocalOrdinal,
36 class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
38 #undef XPETRA_MAPUTILS_SHORT
60 std::vector<GlobalOrdinal> gids;
61 for (
size_t tt = 0; tt < subMaps.size(); ++tt) {
62 Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > subMap = subMaps[tt];
63 Teuchos::ArrayView<const GlobalOrdinal> subMapGids = subMap->getLocalElementList();
64 gids.insert(gids.end(), subMapGids.begin(), subMapGids.end());
67 const GlobalOrdinal INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
70 Teuchos::ArrayView<GlobalOrdinal> gidsView(&gids[0], gids.size());
90 static Teuchos::RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
95 "Xpetra::MatrixUtils::shrinkMapGIDs: the non-overlapping map must not have more local ids than the overlapping map.")
99 "Xpetra::MatrixUtils::shrinkMapGIDs: the maximum GIDs of the overlapping and non-overlapping maps must be the same.")
101 RCP<
const Teuchos::Comm<int> > comm = input.
getComm();
108 std::vector<int> myGIDs(comm->getSize(), 0);
109 std::vector<int> numGIDs(comm->getSize(), 0);
111 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, comm->getSize(), &myGIDs[0], &numGIDs[0]);
112 size_t gidOffset = 0;
113 for (
int p = 0; p < comm->getRank(); p++) gidOffset += numGIDs[p];
116 std::map<const GlobalOrdinal, GlobalOrdinal> origGID2newGID;
118 origGID2newGID[nonOvlInput.
getGlobalElement(i)] = Teuchos::as<GlobalOrdinal>(i) + Teuchos::as<GlobalOrdinal>(gidOffset);
121 Teuchos::Array<GlobalOrdinal> ovlUnknownStatusGids;
122 Teuchos::Array<GlobalOrdinal> ovlFoundStatusGids;
127 ovlUnknownStatusGids.push_back(gcid);
132 std::vector<int> myUnknownDofGIDs(comm->getSize(), 0);
133 std::vector<int> numUnknownDofGIDs(comm->getSize(), 0);
134 myUnknownDofGIDs[comm->getRank()] = ovlUnknownStatusGids.size();
135 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, comm->getSize(), &myUnknownDofGIDs[0], &numUnknownDofGIDs[0]);
138 size_t cntUnknownDofGIDs = 0;
139 for (
int p = 0; p < comm->getSize(); p++) cntUnknownDofGIDs += numUnknownDofGIDs[p];
140 std::vector<GlobalOrdinal> lUnknownDofGIDs(cntUnknownDofGIDs, 0);
141 std::vector<GlobalOrdinal> gUnknownDofGIDs(cntUnknownDofGIDs, 0);
143 size_t cntUnknownOffset = 0;
144 for (
int p = 0; p < comm->getRank(); p++) cntUnknownOffset += numUnknownDofGIDs[p];
145 for (
size_t k = 0; k < Teuchos::as<size_t>(ovlUnknownStatusGids.size()); k++) {
146 lUnknownDofGIDs[k + cntUnknownOffset] = ovlUnknownStatusGids[k];
148 if (cntUnknownDofGIDs > 0)
149 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, Teuchos::as<int>(cntUnknownDofGIDs), &lUnknownDofGIDs[0], &gUnknownDofGIDs[0]);
150 std::vector<GlobalOrdinal> lTranslatedDofGIDs(cntUnknownDofGIDs, 0);
151 std::vector<GlobalOrdinal> gTranslatedDofGIDs(cntUnknownDofGIDs, 0);
153 for (
size_t k = 0; k < gUnknownDofGIDs.size(); k++) {
154 GlobalOrdinal curgid = gUnknownDofGIDs[k];
156 lTranslatedDofGIDs[k] = origGID2newGID[curgid];
159 if (cntUnknownDofGIDs > 0)
160 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, Teuchos::as<int>(cntUnknownDofGIDs), &lTranslatedDofGIDs[0], &gTranslatedDofGIDs[0]);
162 for (
size_t k = 0; k < Teuchos::as<size_t>(ovlUnknownStatusGids.size()); k++) {
163 origGID2newGID[ovlUnknownStatusGids[k]] = gTranslatedDofGIDs[k + cntUnknownOffset];
165 Teuchos::Array<GlobalOrdinal> ovlDomainMapArray;
168 ovlDomainMapArray.push_back(origGID2newGID[gcid]);
170 RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > ovlDomainMap =
199 RCP<const Teuchos::Comm<int> > comm = input.
getComm();
202 std::map<const GlobalOrdinal, GlobalOrdinal> thyra2xpetraGID;
209 Teuchos::Array<GlobalOrdinal> ovlUnknownStatusGids;
214 ovlUnknownStatusGids.push_back(gcid);
219 std::vector<int> myUnknownDofGIDs(comm->getSize(), 0);
220 std::vector<int> numUnknownDofGIDs(comm->getSize(), 0);
221 myUnknownDofGIDs[comm->getRank()] = ovlUnknownStatusGids.size();
222 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, comm->getSize(), &myUnknownDofGIDs[0], &numUnknownDofGIDs[0]);
225 size_t cntUnknownDofGIDs = 0;
226 for (
int p = 0; p < comm->getSize(); p++) cntUnknownDofGIDs += numUnknownDofGIDs[p];
227 std::vector<GlobalOrdinal> lUnknownDofGIDs(cntUnknownDofGIDs, 0);
228 std::vector<GlobalOrdinal> gUnknownDofGIDs(cntUnknownDofGIDs, 0);
230 size_t cntUnknownOffset = 0;
231 for (
int p = 0; p < comm->getRank(); p++) cntUnknownOffset += numUnknownDofGIDs[p];
232 for (
size_t k = 0; k < Teuchos::as<size_t>(ovlUnknownStatusGids.size()); k++) {
233 lUnknownDofGIDs[k + cntUnknownOffset] = ovlUnknownStatusGids[k];
235 if (cntUnknownDofGIDs > 0)
236 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, Teuchos::as<int>(cntUnknownDofGIDs), &lUnknownDofGIDs[0], &gUnknownDofGIDs[0]);
237 std::vector<GlobalOrdinal> lTranslatedDofGIDs(cntUnknownDofGIDs, 0);
238 std::vector<GlobalOrdinal> gTranslatedDofGIDs(cntUnknownDofGIDs, 0);
240 for (
size_t k = 0; k < gUnknownDofGIDs.size(); k++) {
241 GlobalOrdinal curgid = gUnknownDofGIDs[k];
243 lTranslatedDofGIDs[k] = thyra2xpetraGID[curgid];
246 if (cntUnknownDofGIDs > 0)
247 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, Teuchos::as<int>(cntUnknownDofGIDs), &lTranslatedDofGIDs[0], &gTranslatedDofGIDs[0]);
249 for (
size_t k = 0; k < Teuchos::as<size_t>(ovlUnknownStatusGids.size()); k++) {
250 thyra2xpetraGID[ovlUnknownStatusGids[k]] = gTranslatedDofGIDs[k + cntUnknownOffset];
252 Teuchos::Array<GlobalOrdinal> ovlDomainMapArray;
255 ovlDomainMapArray.push_back(thyra2xpetraGID[gcid]);
257 RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > ovlDomainMap =
260 TEUCHOS_TEST_FOR_EXCEPTION(input.
getLocalNumElements() != ovlDomainMap->getLocalNumElements(),
Xpetra::Exceptions::Incompatible,
"Xpetra::MatrixUtils::transformThyra2XpetraGIDs: the number of local Thyra reference GIDs (overlapping) and local Xpetra GIDs (overlapping) must be the same!");
274 const GO INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
275 RCP<const Teuchos::Comm<int> > comm = input.
getComm();
277 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > rcpInput = Teuchos::rcpFromRef(input);
281 if (rcpBlockedInput.is_null() ==
true) {
283 std::vector<GlobalOrdinal> gids;
284 for (LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(rcpInput->getLocalNumElements()); ++l) {
288 Teuchos::ArrayView<GO> gidsView(&gids[0], gids.size());
289 RCP<Map> fullMap =
MapFactory::Build(rcpInput->lib(), INVALID, gidsView, rcpInput->getIndexBase(), comm);
296 size_t numMaps = rcpBlockedInput->getNumMaps();
300 std::vector<GlobalOrdinal> gidOffsets(numMaps, 0);
301 for (
size_t i = 1; i < numMaps; ++i) {
302 gidOffsets[i] = rcpBlockedInput->getMap(i - 1,
true)->getMaxAllGlobalIndex() + gidOffsets[i - 1] + 1;
305 std::vector<RCP<const Map> > mapsXpetra(rcpBlockedInput->getNumMaps(), Teuchos::null);
306 std::vector<RCP<const Map> > mapsThyra(rcpBlockedInput->getNumMaps(), Teuchos::null);
307 for (
size_t b = 0; b < rcpBlockedInput->getNumMaps(); ++b) {
310 RCP<const Map> subMapThyra = rcpBlockedInput->getMap(b,
true);
312 mapsXpetra[b] = subMapXpetra;
313 mapsThyra[b] = subMapThyra;
323 #define XPETRA_MAPUTILS_SHORT
325 #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 getLocalNumElements() 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?)