FreeFOAM The Cross-Platform CFD Toolkit
mapDistribute.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::mapDistribute
26 
27 Description
28  Class containing processor-to-processor mapping information.
29 
30  We store mapping from the bits-to-send to the complete starting list
31  (subXXXMap) and from the received bits to their location in the new
32  list (constructXXXMap).
33 
34 Note:
35  Schedule is a list of processor pairs (one send, one receive. One of
36  them will be myself) which forms a scheduled (i.e. non-buffered) exchange.
37  See distribute on how to use it.
38  Note2: number of items send on one processor have to equal the number
39  of items received on the other processor.
40 
41 
42 SourceFiles
43  mapDistribute.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef mapDistribute_H
48 #define mapDistribute_H
49 
50 #include <OpenFOAM/labelList.H>
51 #include <OpenFOAM/labelPair.H>
52 #include <OpenFOAM/Pstream.H>
53 #include <OpenFOAM/boolList.H>
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 class mapPolyMesh;
61 
62 /*---------------------------------------------------------------------------*\
63  Class mapDistribute Declaration
64 \*---------------------------------------------------------------------------*/
65 
67 {
68  // Private data
69 
70  //- Size of reconstructed data
71  label constructSize_;
72 
73  //- Maps from subsetted data back to original data
74  labelListList subMap_;
75 
76  //- Maps from subsetted data to new reconstructed data
77  labelListList constructMap_;
78 
79  //- Schedule
80  mutable autoPtr<List<labelPair> > schedulePtr_;
81 
82 
83 public:
84 
85  // Constructors
86 
87  //- Construct from components
89  (
90  const label constructSize,
91  const labelListList& subMap,
93  );
94 
95  //- (optionally destructively) construct from components
97  (
98  const label constructSize,
99  labelListList& subMap,
100  labelListList& constructMap,
101  const bool reUse // clone or reuse
102  );
103 
104  //- Construct from reverse addressing: per data item the send
105  // processor and the receive processor. All processors get same data.
107  (
108  const labelList& sendProcs,
109  const labelList& recvProcs
110  );
111 
112  //- Construct copy
114 
115 
116  // Member Functions
117 
118  // Access
119 
120  //- Constructed data size
121  label constructSize() const
122  {
123  return constructSize_;
124  }
125 
126  //- Constructed data size
127  label& constructSize()
128  {
129  return constructSize_;
130  }
131 
132  //- From subsetted data back to original data
133  const labelListList& subMap() const
134  {
135  return subMap_;
136  }
137 
138  //- From subsetted data back to original data
140  {
141  return subMap_;
142  }
143 
144  //- From subsetted data to new reconstructed data
146  {
147  return constructMap_;
148  }
149 
150  //- From subsetted data to new reconstructed data
152  {
153  return constructMap_;
154  }
155 
156  //- Calculate a schedule. See above.
158  (
159  const labelListList& subMap,
160  const labelListList& constructMap
161  );
162 
163  //- Return a schedule. Demand driven. See above.
164  const List<labelPair>& schedule() const;
165 
166 
167  // Other
168 
169  //- Compact maps. Gets per field a bool whether it is used (locally)
170  // and works out itself what this side and sender side can remove
171  // from maps.
172  void compact(const boolList& elemIsUsed);
173 
174 
175  //- Distribute data. Note:schedule only used for Pstream::scheduled
176  // for now, all others just use send-to-all, receive-from-all.
177  template<class T>
178  static void distribute
179  (
180  const Pstream::commsTypes commsType,
181  const List<labelPair>& schedule,
182  const label constructSize,
183  const labelListList& subMap,
184  const labelListList& constructMap,
185  List<T>&
186  );
187 
188  //- Distribute data. If multiple processors writing to same
189  // position adds contributions using cop.
190  template<class T, class CombineOp>
191  static void distribute
192  (
193  const Pstream::commsTypes commsType,
194  const List<labelPair>& schedule,
195  const label constructSize,
196  const labelListList& subMap,
197  const labelListList& constructMap,
198  List<T>&,
199  const CombineOp& cop,
200  const T& nullValue
201  );
202 
203  //- Distribute data using default commsType.
204  template<class T>
205  void distribute(List<T>& fld) const
206  {
207  if
208  (
210  && contiguous<T>()
211  )
212  {
213  distribute
214  (
216  List<labelPair>(),
217  constructSize_,
218  subMap_,
219  constructMap_,
220  fld
221  );
222  }
224  {
225  distribute
226  (
228  schedule(),
229  constructSize_,
230  subMap_,
231  constructMap_,
232  fld
233  );
234  }
235  else
236  {
237  distribute
238  (
240  List<labelPair>(),
241  constructSize_,
242  subMap_,
243  constructMap_,
244  fld
245  );
246  }
247  }
248 
249  //- Correct for topo change.
250  void updateMesh(const mapPolyMesh&)
251  {
253  (
254  "mapDistribute::updateMesh(const mapPolyMesh&)"
255  );
256  }
257 
258  // Member Operators
259 
260  void operator=(const mapDistribute&);
261 
262 };
263 
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 } // End namespace Foam
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 #ifdef NoRepository
272 # include "mapDistributeTemplates.C"
273 #endif
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #endif
278 
279 // ************************ vim: set sw=4 sts=4 et: ************************ //