initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / polyMesh / mapPolyMesh / mapDistribute / mapDistribute.H
blobd2cfe64ca53c0dde02c3d424d5236b415728151d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::mapDistribute
28 Description
29     Class containing processor-to-processor mapping information.
31     We store mapping from the bits-to-send to the complete starting list
32     (subXXXMap) and from the received bits to their location in the new
33     list (constructXXXMap).
35 Note:
36     Schedule is a list of processor pairs (one send, one receive. One of
37     them will be myself) which forms a scheduled (i.e. non-buffered) exchange.
38     See distribute on how to use it.
39     Note2: number of items send on one processor have to equal the number
40     of items received on the other processor.
43 SourceFiles
44     mapDistribute.C
46 \*---------------------------------------------------------------------------*/
48 #ifndef mapDistribute_H
49 #define mapDistribute_H
51 #include "labelList.H"
52 #include "labelPair.H"
53 #include "Pstream.H"
54 #include "boolList.H"
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 namespace Foam
61 class mapPolyMesh;
63 /*---------------------------------------------------------------------------*\
64                            Class mapDistribute Declaration
65 \*---------------------------------------------------------------------------*/
67 class mapDistribute
69     // Private data
71         //- Size of reconstructed data
72         label constructSize_;
74         //- Maps from subsetted data back to original data
75         labelListList subMap_;
77         //- Maps from subsetted data to new reconstructed data
78         labelListList constructMap_;
80         //- Schedule
81         mutable autoPtr<List<labelPair> > schedulePtr_;
84 public:
86     // Constructors
88         //- Construct from components
89         mapDistribute
90         (
91             const label constructSize,
92             const labelListList& subMap,
93             const labelListList& constructMap
94         );
96         //- (optionally destructively) construct from components
97         mapDistribute
98         (
99             const label constructSize,
100             labelListList& subMap,
101             labelListList& constructMap,
102             const bool reUse                // clone or reuse
103         );
105         //- Construct from reverse addressing: per data item the send
106         //  processor and the receive processor. All processors get same data.
107         mapDistribute
108         (
109             const labelList& sendProcs,
110             const labelList& recvProcs
111         );
113         //- Construct copy
114         mapDistribute(const mapDistribute&);
117     // Member Functions
119         // Access
121             //- Constructed data size
122             label constructSize() const
123             {
124                 return constructSize_;
125             }
127             //- Constructed data size
128             label& constructSize()
129             {
130                 return constructSize_;
131             }
133             //- From subsetted data back to original data
134             const labelListList& subMap() const
135             {
136                 return subMap_;
137             }
139             //- From subsetted data back to original data
140             labelListList& subMap()
141             {
142                 return subMap_;
143             }
145             //- From subsetted data to new reconstructed data
146             const labelListList& constructMap() const
147             {
148                 return constructMap_;
149             }
151             //- From subsetted data to new reconstructed data
152             labelListList& constructMap()
153             {
154                 return constructMap_;
155             }
157             //- Calculate a schedule. See above.
158             static List<labelPair> schedule
159             (
160                 const labelListList& subMap,
161                 const labelListList& constructMap
162             );
164             //- Return a schedule. Demand driven. See above.
165             const List<labelPair>& schedule() const;
168         // Other
170             //- Compact maps. Gets per field a bool whether it is used (locally)
171             //  and works out itself what this side and sender side can remove
172             //  from maps.
173             void compact(const boolList& elemIsUsed);
176             //- Distribute data. Note:schedule only used for Pstream::scheduled
177             //  for now, all others just use send-to-all, receive-from-all.
178             template<class T>
179             static void distribute
180             (
181                 const Pstream::commsTypes commsType,
182                 const List<labelPair>& schedule,
183                 const label constructSize,
184                 const labelListList& subMap,
185                 const labelListList& constructMap,
186                 List<T>&
187             );
189             //- Distribute data. If multiple processors writing to same
190             //  position adds contributions using cop.
191             template<class T, class CombineOp>
192             static void distribute
193             (
194                 const Pstream::commsTypes commsType,
195                 const List<labelPair>& schedule,
196                 const label constructSize,
197                 const labelListList& subMap,
198                 const labelListList& constructMap,
199                 List<T>&,
200                 const CombineOp& cop,
201                 const T& nullValue
202             );
204             //- Distribute data using default commsType.
205             template<class T>
206             void distribute(List<T>& fld) const
207             {
208                 if
209                 (
210                     Pstream::defaultCommsType == Pstream::nonBlocking
211                  && contiguous<T>()
212                 )
213                 {
214                     distribute
215                     (
216                         Pstream::nonBlocking,
217                         List<labelPair>(),
218                         constructSize_,
219                         subMap_,
220                         constructMap_,
221                         fld
222                     );
223                 }
224                 else if (Pstream::defaultCommsType == Pstream::scheduled)
225                 {
226                     distribute
227                     (
228                         Pstream::scheduled,
229                         schedule(),
230                         constructSize_,
231                         subMap_,
232                         constructMap_,
233                         fld
234                     );
235                 }
236                 else
237                 {
238                     distribute
239                     (
240                         Pstream::blocking,
241                         List<labelPair>(),
242                         constructSize_,
243                         subMap_,
244                         constructMap_,
245                         fld
246                     );
247                 }
248             }
250             //- Correct for topo change.
251             void updateMesh(const mapPolyMesh&)
252             {
253                 notImplemented
254                 (
255                     "mapDistribute::updateMesh(const mapPolyMesh&)"
256                 );
257             }
259     // Member Operators
261         void operator=(const mapDistribute&);
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 } // End namespace Foam
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 #ifdef NoRepository
273 #   include "mapDistributeTemplates.C"
274 #endif
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 #endif
280 // ************************************************************************* //