MueLu  Version of the Day
MueLu_UncoupledIndexManager_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Ray Tuminaro (rstumin@sandia.gov)
41 // Luc Berger-Vergoat (lberge@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef MUELU_UNCOUPLEDINDEXMANAGER_DEF_HPP_
47 #define MUELU_UNCOUPLEDINDEXMANAGER_DEF_HPP_
48 
49 #include <Xpetra_MapFactory.hpp>
50 #include <Teuchos_OrdinalTraits.hpp>
52 
53 namespace MueLu {
54 
55  template <class LocalOrdinal, class GlobalOrdinal, class Node>
57  UncoupledIndexManager(const RCP<const Teuchos::Comm<int> > comm, const bool coupled,
58  const int NumDimensions, const int interpolationOrder,
59  const int MyRank, const int NumRanks,
60  const Array<GO> GFineNodesPerDir, const Array<LO> LFineNodesPerDir,
61  const Array<LO> CoarseRate, const bool singleCoarsePoint) :
62  IndexManager(comm, coupled, singleCoarsePoint, NumDimensions, interpolationOrder,
63  Array<GO>(3, -1), LFineNodesPerDir),
64  myRank(MyRank), numRanks(NumRanks)
65  {
66 
67  // Load coarse rate, being careful about formating
68  for(int dim = 0; dim < 3; ++dim) {
69  if(dim < this->numDimensions) {
70  if(CoarseRate.size() == 1) {
71  this->coarseRate[dim] = CoarseRate[0];
72  } else if(CoarseRate.size() == this->numDimensions) {
73  this->coarseRate[dim] = CoarseRate[dim];
74  }
75  } else {
76  this->coarseRate[dim] = 1;
77  }
78  }
79 
80  this->computeMeshParameters();
81  this->gNumCoarseNodes10 = Teuchos::OrdinalTraits<GO>::invalid();
82  this->gNumCoarseNodes = Teuchos::OrdinalTraits<GO>::invalid();
83  } // Constructor
84 
85  template <class LocalOrdinal, class GlobalOrdinal, class Node>
88  GO input[1] = {as<GO>(this->lNumCoarseNodes)}, output[1] = {0};
89  Teuchos::reduceAll(*(this->comm_), Teuchos::REDUCE_SUM, 1, input, output);
90  this->gNumCoarseNodes = output[0];
91  } // computeGlobalCoarseParameters
92 
93  template <class LocalOrdinal, class GlobalOrdinal, class Node>
95  getGhostedNodesData(const RCP<const Map>/* fineMap */,
96  Array<LO>& ghostedNodeCoarseLIDs,
97  Array<int>& ghostedNodeCoarsePIDs,
98  Array<GO>& /* ghostedNodeCoarseGIDs */) const {
99 
100  // First we allocate memory for the outputs
101  ghostedNodeCoarseLIDs.resize(this->getNumLocalGhostedNodes());
102  ghostedNodeCoarsePIDs.resize(this->getNumLocalGhostedNodes());
103  // In the uncoupled case the data required is trivial to provide!
104  for(LO idx = 0; idx < this->getNumLocalGhostedNodes(); ++idx) {
105  ghostedNodeCoarseLIDs[idx] = idx;
106  ghostedNodeCoarsePIDs[idx] = myRank;
107  }
108  } // getGhostedNodesData
109 
110  template <class LocalOrdinal, class GlobalOrdinal, class Node>
112  getCoarseNodesData(const RCP<const Map> fineCoordinatesMap,
113  Array<GO>& coarseNodeCoarseGIDs,
114  Array<GO>& coarseNodeFineGIDs) const {
115 
116  // Allocate sufficient amount of storage in output arrays
117  coarseNodeCoarseGIDs.resize(this->getNumLocalCoarseNodes());
118  coarseNodeFineGIDs.resize(this->getNumLocalCoarseNodes());
119 
120  // Load all the GIDs on the fine mesh
121  ArrayView<const GO> fineNodeGIDs = fineCoordinatesMap->getNodeElementList();
122 
123  // Extract the fine LIDs of the coarse nodes and store the corresponding GIDs
124  LO fineLID;
125  for(LO coarseLID = 0; coarseLID < this->getNumLocalCoarseNodes(); ++coarseLID) {
126  Array<LO> coarseIndices(3), fineIndices(3);
127  this->getCoarseNodeLocalTuple(coarseLID,
128  coarseIndices[0],
129  coarseIndices[1],
130  coarseIndices[2]);
131  for(int dim = 0; dim < 3; ++dim) {
132  if(coarseIndices[dim] == this->lCoarseNodesPerDir[dim] - 1) {
133  if(this->lCoarseNodesPerDir[dim] == 1) {
134  fineIndices[dim] = 0;
135  } else {
136  fineIndices[dim] = this->lFineNodesPerDir[dim] - 1;
137  }
138  } else {
139  fineIndices[dim] = coarseIndices[dim]*this->coarseRate[dim];
140  }
141  }
142 
143  fineLID = fineIndices[2]*this->lNumFineNodes10
144  + fineIndices[1]*this->lFineNodesPerDir[0]
145  + fineIndices[0];
146  coarseNodeFineGIDs[coarseLID] = fineNodeGIDs[fineLID];
147 
148  }
149  } // getCoarseNodesData
150 
151  template <class LocalOrdinal, class GlobalOrdinal, class Node>
152  std::vector<std::vector<GlobalOrdinal> > UncoupledIndexManager<LocalOrdinal, GlobalOrdinal, Node>::
154  std::vector<std::vector<GO> > coarseMeshData;
155  return coarseMeshData;
156  }
157 
158  template <class LocalOrdinal, class GlobalOrdinal, class Node>
160  getFineNodeGlobalTuple(const GO /* myGID */, GO& /* i */, GO& /* j */, GO& /* k */) const {
161  }
162 
163  template <class LocalOrdinal, class GlobalOrdinal, class Node>
165  getFineNodeLocalTuple(const LO myLID, LO& i, LO& j, LO& k) const {
166  LO tmp;
167  k = myLID / this->lNumFineNodes10;
168  tmp = myLID % this->lNumFineNodes10;
169  j = tmp / this->lFineNodesPerDir[0];
170  i = tmp % this->lFineNodesPerDir[0];
171  } // getFineNodeLocalTuple
172 
173  template <class LocalOrdinal, class GlobalOrdinal, class Node>
175  getFineNodeGhostedTuple(const LO myLID, LO& i, LO& j, LO& k) const {
176  LO tmp;
177  k = myLID / this->lNumFineNodes10;
178  tmp = myLID % this->lNumFineNodes10;
179  j = tmp / this->lFineNodesPerDir[0];
180  i = tmp % this->lFineNodesPerDir[0];
181 
182  k += this->offsets[2];
183  j += this->offsets[1];
184  i += this->offsets[0];
185  } // getFineNodeGhostedTuple
186 
187  template <class LocalOrdinal, class GlobalOrdinal, class Node>
189  getFineNodeGID(const GO /* i */, const GO /* j */, const GO /* k */, GO& /* myGID */) const {
190  }
191 
192  template <class LocalOrdinal, class GlobalOrdinal, class Node>
194  getFineNodeLID(const LO /* i */, const LO /* j */, const LO /* k */, LO& /* myLID */) const {
195  }
196 
197  template <class LocalOrdinal, class GlobalOrdinal, class Node>
199  getCoarseNodeGlobalTuple(const GO /* myGID */, GO& /* i */, GO& /* j */, GO& /* k */) const {
200  }
201 
202  template <class LocalOrdinal, class GlobalOrdinal, class Node>
204  getCoarseNodeLocalTuple(const LO myLID, LO& i, LO& j, LO& k) const {
205  LO tmp;
206  k = myLID / this->lNumCoarseNodes10;
207  tmp = myLID % this->lNumCoarseNodes10;
208  j = tmp / this->lCoarseNodesPerDir[0];
209  i = tmp % this->lCoarseNodesPerDir[0];
210  } // getCoarseNodeLocalTuple
211 
212  template <class LocalOrdinal, class GlobalOrdinal, class Node>
214  getCoarseNodeGID(const GO /* i */, const GO /* j */, const GO /* k */, GO& /* myGID */) const {
215  }
216 
217  template <class LocalOrdinal, class GlobalOrdinal, class Node>
219  getCoarseNodeLID(const LO /* i */, const LO /* j */, const LO /* k */, LO& /* myLID */) const {
220  }
221 
222  template <class LocalOrdinal, class GlobalOrdinal, class Node>
224  getCoarseNodeGhostedLID(const LO i, const LO j, const LO k, LO& myLID) const {
225  myLID = k*this->numGhostedNodes10 + j*this->ghostedNodesPerDir[0] + i;
226  } // getCoarseNodeGhostedLID
227 
228  template <class LocalOrdinal, class GlobalOrdinal, class Node>
230  getCoarseNodeFineLID(const LO /* i */, const LO /* j */, const LO /* k */, LO& /* myLID */) const {
231  }
232 
233  template <class LocalOrdinal, class GlobalOrdinal, class Node>
235  getGhostedNodeFineLID(const LO /* i */, const LO /* j */, const LO /* k */, LO& /* myLID */) const {
236  }
237 
238  template <class LocalOrdinal, class GlobalOrdinal, class Node>
240  getGhostedNodeCoarseLID(const LO /* i */, const LO /* j */, const LO /* k */, LO& /* myLID */) const {
241  }
242 
243 } //namespace MueLu
244 
245 #endif /* MUELU_UNCOUPLEDINDEXMANAGER_DEF_HPP_ */
void getCoarseNodeLocalTuple(const LO myLID, LO &i, LO &j, LO &k) const
void getGhostedNodeCoarseLID(const LO i, const LO j, const LO k, LO &myLID) const
Namespace for MueLu classes and methods.
void getFineNodeGlobalTuple(const GO myGID, GO &i, GO &j, GO &k) const
Array< int > coarseRate
coarsening rate in each direction
void getCoarseNodeFineLID(const LO i, const LO j, const LO k, LO &myLID) const
void getCoarseNodeGhostedLID(const LO i, const LO j, const LO k, LO &myLID) const
const int numDimensions
Number of spacial dimensions in the problem.
void getFineNodeLocalTuple(const LO myLID, LO &i, LO &j, LO &k) const
void getFineNodeLID(const LO i, const LO j, const LO k, LO &myLID) const
void getCoarseNodeGID(const GO i, const GO j, const GO k, GO &myGID) const
void getCoarseNodeLID(const LO i, const LO j, const LO k, LO &myLID) const
void getCoarseNodeGlobalTuple(const GO myGID, GO &i, GO &j, GO &k) const
GO gNumCoarseNodes10
global number of nodes per 0-1 slice remaining after coarsening.
void getFineNodeGID(const GO i, const GO j, const GO k, GO &myGID) const
void getCoarseNodesData(const RCP< const Map > fineCoordinatesMap, Array< GO > &coarseNodeCoarseGIDs, Array< GO > &coarseNodeFineGIDs) const
void getGhostedNodeFineLID(const LO i, const LO j, const LO k, LO &myLID) const
GO gNumCoarseNodes
global number of nodes remaining after coarsening.
Container class for mesh layout and indices calculation.
void getGhostedNodesData(const RCP< const Map > fineMap, Array< LO > &ghostedNodeCoarseLIDs, Array< int > &ghostedNodeCoarsePIDs, Array< GO > &ghostedNodeCoarseGIDs) const
void getFineNodeGhostedTuple(const LO myLID, LO &i, LO &j, LO &k) const
std::vector< std::vector< GO > > getCoarseMeshData() const