initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / dynamicMesh / fvMeshDistribute / fvMeshDistribute.H
blobc35bd4584c8ef6422982ee286cbb078b5bceddfa
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::fvMeshDistribute
28 Description
29     Sends/receives parts of mesh+fvfields to neighbouring processors.
30     Used in load balancing.
32     Input is per local cell the processor it should move to. Moves meshes
33     and volFields/surfaceFields and returns map which can be used to
34     distribute other.
36     Notes:
37     - does not handle cyclics. Will probably handle separated proc patches.
38     - if all cells move off processor also all its processor patches will
39       get deleted so comms might be screwed up (since e.g. globalMeshData
40       expects procPatches on all)
41     - initial mesh has to have procPatches last and all normal patches common
42       to all processors and in the same order. This is checked.
43     - faces are matched topologically but points on the faces are not. So
44       expect problems -on separated patches (cyclics?) -on zero sized processor
45       edges.
47 SourceFiles
48     fvMeshDistribute.C
49     fvMeshDistributeTemplates.C
51 \*---------------------------------------------------------------------------*/
53 #ifndef fvMeshDistribute_H
54 #define fvMeshDistribute_H
56 #include "Field.H"
57 #include "uLabel.H"
58 #include "fvMeshSubset.H"
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 namespace Foam
65 // Forward declaration of classes
66 class mapAddedPolyMesh;
67 class mapDistributePolyMesh;
69 /*---------------------------------------------------------------------------*\
70                            Class fvMeshDistribute Declaration
71 \*---------------------------------------------------------------------------*/
73 class fvMeshDistribute
75     // Private data
77         //- Underlying fvMesh
78         fvMesh& mesh_;
80         //- Absolute merging tolerance (constructing meshes gets done using
81         //  geometric matching)
82         const scalar mergeTol_;
85     // Private classes
87         //- Check words are the same. Used in patch type checking of similarly
88         //  named patches.
89         class checkEqualType
90         {
91         public:
93             void operator()(word& x, const word& y) const
94             {
95                 if (x != y)
96                 {
97                     FatalErrorIn("checkEqualType()(word&, const word&) const")
98                         << "Patch type " << x << " possibly on processor "
99                         << Pstream::myProcNo()
100                         << " does not equal patch type " << y
101                         << " on some other processor." << nl
102                         << "Please check similarly named patches for"
103                         << " having exactly the same type."
104                         << abort(FatalError);
105                 }
106             }
107         };
110     // Private Member Functions
112         //- Given distribution work out a communication schedule. Is list
113         //  of pairs. First element of pair is send processor, second is
114         //  receive processor.
115         //static List<labelPair> getSchedule(const labelList&);
117         //- Find indices with value
118         static labelList select
119         (
120             const bool selectEqual,
121             const labelList& values,
122             const label value
123         );
125         //- Check all procs have same names and in exactly same order.
126         static void checkEqualWordList(const wordList&);
128         //- Merge wordlists over all processors
129         static wordList mergeWordList(const wordList&);
132         // Patch handling
134             //- Find patch to put exposed faces into.
135             label findNonEmptyPatch() const;
137             //- Appends processorPolyPatch. Returns patchID.
138             label addProcPatch(const word& patchName, const label nbrProc);
140             //- Add patch field
141             template<class GeoField>
142             void addPatchFields(const word& patchFieldType);
144             //- Deletes last patch.
145             void deleteTrailingPatch();
147             // Delete trailing patch fields
148             template<class GeoField>
149             void deleteTrailingPatchFields();
151             //- Save boundary fields
152             template <class T, class Mesh>
153             void saveBoundaryFields
154             (
155                 PtrList<FieldField<fvsPatchField, T> >& bflds
156             ) const;
158             //- Map boundary fields
159             template <class T, class Mesh>
160             void mapBoundaryFields
161             (
162                 const mapPolyMesh& map,
163                 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
164             );
166             //- Init patch fields of certain type
167             template<class GeoField>
168             void initPatchFields
169             (
170                 const word& patchFieldType,
171                 const typename GeoField::value_type& initVal
172             );
174             //- Delete all processor patches. Move any processor faces into
175             //  patchI.
176             autoPtr<mapPolyMesh> deleteProcPatches(const label patchI);
178             //- Repatch the mesh. This is only nessecary for the proc
179             //  boundary faces. newPatchID is over all boundary faces: -1 or
180             //  new patchID. constructFaceMap is being adapted for the
181             //  possible new face position (since proc faces get automatically
182             //  matched)
183             autoPtr<mapPolyMesh> repatch
184             (
185                 const labelList& newPatchID,
186                 labelListList& constructFaceMap
187             );
189             //- Merge any shared points that are geometrically shared. Needs
190             //  parallel valid mesh - uses globalMeshData.
191             //  constructPointMap is adapted for the new point labels.
192             autoPtr<mapPolyMesh> mergeSharedPoints
193             (
194                 labelListList& constructPointMap
195             );
197         // Coupling information
199             //- Construct the local environment of all boundary faces.
200             void getNeighbourData
201             (
202                 const labelList& distribution,
203                 labelList& sourceFace,
204                 labelList& sourceProc,
205                 labelList& sourceNewProc
206             ) const;
208             // Subset the neighbourCell/neighbourProc fields
209             static void subsetBoundaryData
210             (
211                 const fvMesh& mesh,
212                 const labelList& faceMap,
213                 const labelList& cellMap,
215                 const labelList& oldDistribution,
216                 const labelList& oldFaceOwner,
217                 const labelList& oldFaceNeighbour,
218                 const label oldInternalFaces,
220                 const labelList& sourceFace,
221                 const labelList& sourceProc,
222                 const labelList& sourceNewProc,
224                 labelList& subFace,
225                 labelList& subProc,
226                 labelList& subNewProc
227             );
229             //- Find cells on mesh whose faceID/procID match the neighbour
230             //  cell/proc of domainMesh. Store the matching face.
231             static void findCouples
232             (
233                 const primitiveMesh&,
234                 const labelList& sourceFace,
235                 const labelList& sourceProc,
237                 const label domain,
238                 const primitiveMesh& domainMesh,
239                 const labelList& domainFace,
240                 const labelList& domainProc,
242                 labelList& masterCoupledFaces,
243                 labelList& slaveCoupledFaces
244             );
246             //- Map data on boundary faces to new mesh (resulting from adding
247             //  two meshes)
248             static labelList mapBoundaryData
249             (
250                 const primitiveMesh& mesh,      // mesh after adding
251                 const mapAddedPolyMesh& map,
252                 const labelList& boundaryData0, // mesh before adding
253                 const label nInternalFaces1,
254                 const labelList& boundaryData1  // added mesh
255             );
258         // Other
260             //- Remove cells. Add all exposed faces to patch oldInternalPatchI
261             autoPtr<mapPolyMesh> doRemoveCells
262             (
263                 const labelList& cellsToRemove,
264                 const label oldInternalPatchI
265             );
267             //- Add processor patches. Changes mesh and returns per neighbour
268             //  proc the processor patchID.
269             void addProcPatches
270             (
271                 const labelList&, // processor that neighbour is on
272                 labelList& procPatchID
273             );
275             //- Get boundary faces to be repatched. Is -1 or new patchID
276             static labelList getProcBoundaryPatch
277             (
278                 const labelList& neighbourNewProc,// new processor per b. face
279                 const labelList& procPatchID      // patchID
280             );
282             //- Send mesh and coupling data.
283             static void sendMesh
284             (
285                 const label domain,
286                 const fvMesh& mesh,
287                 const wordList& pointZoneNames,
288                 const wordList& facesZoneNames,
289                 const wordList& cellZoneNames,
290                 const labelList& sourceFace,
291                 const labelList& sourceProc,
292                 const labelList& sourceNewProc
293             );
294             //- Send subset of fields
295             template<class GeoField>
296             static void sendFields
297             (
298                 const label domain,
299                 const wordList& fieldNames,
300                 const fvMeshSubset&
301             );
303             //- Receive mesh. Opposite of sendMesh
304             static autoPtr<fvMesh> receiveMesh
305             (
306                 const label domain,
307                 const wordList& pointZoneNames,
308                 const wordList& facesZoneNames,
309                 const wordList& cellZoneNames,
310                 const Time& runTime,
311                 labelList& domainSourceFace,
312                 labelList& domainSourceProc,
313                 labelList& domainSourceNewProc
314             );
316             //- Receive fields. Opposite of sendFields
317             template<class GeoField>
318             static void receiveFields
319             (
320                 const label domain,
321                 const wordList& fieldNames,
322                 fvMesh&,
323                 PtrList<GeoField>&
324             );
326             //- Disallow default bitwise copy construct
327             fvMeshDistribute(const fvMeshDistribute&);
329             //- Disallow default bitwise assignment
330             void operator=(const fvMeshDistribute&);
332 public:
334     ClassName("fvMeshDistribute");
337     // Constructors
339         //- Construct from mesh and absolute merge tolerance
340         fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
343     // Member Functions
345         //- Helper function: count cells per processor in wanted distribution
346         static labelList countCells(const labelList&);
348         //- Send cells to neighbours according to distribution
349         //  (for every cell the new proc)
350         autoPtr<mapDistributePolyMesh> distribute(const labelList& dist);
352         // Debugging
354             //- Print some info on coupling data
355             static void printCoupleInfo
356             (
357                 const primitiveMesh&,
358                 const labelList&,
359                 const labelList&,
360                 const labelList&
361             );
363             //- Print some field info
364             template<class GeoField>
365             static void printFieldInfo(const fvMesh&);
367             //- Print some info on mesh.
368             static void printMeshInfo(const fvMesh&);
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374 } // End namespace Foam
376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
378 #ifdef NoRepository
379 #   include "fvMeshDistributeTemplates.C"
380 #endif
382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 #endif
386 // ************************************************************************* //