27 #ifndef EWOMS_GLOBAL_INDICES_HH 28 #define EWOMS_GLOBAL_INDICES_HH 30 #include <dune/grid/common/datahandleif.hh> 31 #include <dune/istl/bcrsmatrix.hh> 32 #include <dune/istl/scalarproducts.hh> 33 #include <dune/istl/operators.hh> 54 template <
class ForeignOverlap>
59 using GlobalToDomesticMap = std::map<Index, Index>;
60 using DomesticToGlobalMap = std::map<Index, Index>;
64 : foreignOverlap_(foreignOverlap)
72 MPI_Comm_rank(MPI_COMM_WORLD, &tmp);
74 MPI_Comm_size(MPI_COMM_WORLD, &tmp);
75 mpiSize_ =
static_cast<size_t>(tmp);
82 buildGlobalIndices_();
90 assert(domesticToGlobal_.find(domesticIdx) != domesticToGlobal_.end());
92 return domesticToGlobal_.find(domesticIdx)->second;
100 const auto& tmp = globalToDomestic_.find(globalIdx);
102 if (tmp == globalToDomestic_.end())
113 {
return foreignOverlap_.numLocal(); }
122 {
return numDomestic_; }
129 domesticToGlobal_[domesticIdx] = globalIdx;
130 globalToDomestic_[globalIdx] = domesticIdx;
131 numDomestic_ = domesticToGlobal_.size();
133 assert(domesticToGlobal_.size() == globalToDomestic_.size());
140 [[maybe_unused]]
Index domesticIdx,
141 [[maybe_unused]]
Index peerLocalIdx)
145 sendBuf.peerIdx = peerLocalIdx;
150 static_cast<int>(peerRank),
167 static_cast<int>(peerRank),
172 Index domesticIdx = foreignOverlap_.nativeToLocal(recvBuf.peerIdx);
173 if (domesticIdx >= 0) {
174 Index globalIdx = recvBuf.globalIdx;
184 {
return globalToDomestic_.find(globalIdx) != globalToDomestic_.end(); }
192 std::cout <<
"(domestic index, global index, domestic->global->domestic)" 193 <<
" list for rank " << myRank_ <<
"\n";
195 for (
size_t domIdx = 0; domIdx < domesticToGlobal_.size(); ++domIdx)
198 std::cout <<
"\n" << std::flush;
204 void buildGlobalIndices_()
209 numDomestic_ = foreignOverlap_.numLocal();
220 MPI_Recv(&domesticOffset_,
223 static_cast<int>(myRank_ - 1),
232 for (
unsigned i = 0; i < foreignOverlap_.numLocal(); ++i) {
233 if (!foreignOverlap_.iAmMasterOf(static_cast<Index>(i)))
237 static_cast<Index>(domesticOffset_ + numMaster));
241 if (myRank_ < mpiSize_ - 1) {
244 int tmp = domesticOffset_ + numMaster;
248 static_cast<int>(myRank_ + 1),
253 typename PeerSet::const_iterator peerIt;
254 typename PeerSet::const_iterator peerEndIt = peerSet_().end();
256 peerIt = peerSet_().begin();
257 for (; peerIt != peerEndIt; ++peerIt) {
258 if (*peerIt < myRank_)
259 receiveBorderFrom_(*peerIt);
263 peerIt = peerSet_().begin();
264 for (; peerIt != peerEndIt; ++peerIt) {
265 if (*peerIt > myRank_)
266 sendBorderTo_(*peerIt);
270 peerIt = peerSet_().begin();
271 for (; peerIt != peerEndIt; ++peerIt) {
272 if (*peerIt > myRank_)
273 receiveBorderFrom_(*peerIt);
277 peerIt = peerSet_().begin();
278 for (; peerIt != peerEndIt; ++peerIt) {
279 if (*peerIt < myRank_)
280 sendBorderTo_(*peerIt);
285 void sendBorderTo_([[maybe_unused]] ProcessRank peerRank)
290 BorderList::const_iterator borderIt = borderList_().begin();
291 BorderList::const_iterator borderEndIt = borderList_().end();
292 for (; borderIt != borderEndIt; ++borderIt) {
295 if (borderPeer != peerRank || borderDistance != 0)
298 Index localIdx = foreignOverlap_.nativeToLocal(borderIt->localIdx);
299 Index peerIdx = borderIt->peerIdx;
300 assert(localIdx >= 0);
301 if (foreignOverlap_.iAmMasterOf(localIdx)) {
308 void receiveBorderFrom_([[maybe_unused]] ProcessRank peerRank)
313 BorderList::const_iterator borderIt = borderList_().begin();
314 BorderList::const_iterator borderEndIt = borderList_().end();
315 for (; borderIt != borderEndIt; ++borderIt) {
318 if (borderPeer != peerRank || borderDistance != 0)
321 Index nativeIdx = borderIt->localIdx;
322 Index localIdx = foreignOverlap_.nativeToLocal(nativeIdx);
323 if (localIdx >= 0 && foreignOverlap_.masterRank(localIdx) == borderPeer)
329 const PeerSet& peerSet_()
const 330 {
return foreignOverlap_.peerSet(); }
333 {
return foreignOverlap_.borderList(); }
340 const ForeignOverlap& foreignOverlap_;
342 GlobalToDomesticMap globalToDomestic_;
343 DomesticToGlobalMap domesticToGlobal_;
unsigned BorderDistance
The type representing the distance of an index to the border.
Definition: overlaptypes.hh:54
This structure stores a local index on a peer process and a global index.
Definition: overlaptypes.hh:69
bool hasGlobalIndex(Index globalIdx) const
Return true iff a given global index already exists.
Definition: globalindices.hh:183
void print() const
Prints the global indices of all domestic indices for debugging purposes.
Definition: globalindices.hh:190
Index domesticToGlobal(Index domesticIdx) const
Converts a domestic index to a global one.
Definition: globalindices.hh:88
void addIndex(Index domesticIdx, Index globalIdx)
Add an index to the domestic<->global mapping.
Definition: globalindices.hh:127
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
size_t numLocal() const
Returns the number of indices which are in the interior or on the border of the current rank...
Definition: globalindices.hh:112
size_t numDomestic() const
Returns the number domestic indices.
Definition: globalindices.hh:121
This class maps domestic row indices to and from "global" indices which is used to construct an algeb...
Definition: globalindices.hh:55
void sendBorderIndex([[maybe_unused]] ProcessRank peerRank, [[maybe_unused]] Index domesticIdx, [[maybe_unused]] Index peerLocalIdx)
Send a border index to a remote process.
Definition: globalindices.hh:139
This files provides several data structures for storing tuples of indices of remote and/or local proc...
unsigned ProcessRank
The type of the rank of a process.
Definition: overlaptypes.hh:49
void receiveBorderIndex([[maybe_unused]] ProcessRank peerRank)
Receive an index on the border from a remote process and add it the translation maps.
Definition: globalindices.hh:160
Index globalToDomestic(Index globalIdx) const
Converts a global index to a domestic one.
Definition: globalindices.hh:98
std::list< BorderIndex > BorderList
This class managages a list of indices which are on the border of a process' partition of the grid...
Definition: overlaptypes.hh:120
int Index
The type of an index of a degree of freedom.
Definition: overlaptypes.hh:44