BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / src / dynamicMesh / dynamicFvMesh / fvMeshDistribute / fvMeshDistribute.H
blob646a6196a25a7183370ca76273223e365eeab90c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 Member Functions
87         //- Find indices with value
88         static labelList select
89         (
90             const bool selectEqual,
91             const labelList& values,
92             const label value
93         );
95         //- Check all procs have same names and in exactly same order.
96         static void checkEqualWordList(const string&, const wordList&);
98         //- Merge wordlists over all processors
99         static wordList mergeWordList(const wordList&);
102         // Patch handling
104             //- Find patch to put exposed faces into.
105             label findNonEmptyPatch() const;
107             //- Appends processorPolyPatch. Returns patchID.
108             label addProcPatch(const word& patchName, const label nbrProc);
110             //- Add patch field
111             template<class GeoField>
112             void addPatchFields(const word& patchFieldType);
114             //- Deletes last patch.
115             void deleteTrailingPatch();
117             // Delete trailing patch fields
118             template<class GeoField>
119             void deleteTrailingPatchFields();
121             //- Save boundary fields
122             template <class T, class Mesh>
123             void saveBoundaryFields
124             (
125                 PtrList<FieldField<fvsPatchField, T> >& bflds
126             ) const;
128             //- Map boundary fields
129             template <class T, class Mesh>
130             void mapBoundaryFields
131             (
132                 const mapPolyMesh& map,
133                 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
134             );
136             //- Init patch fields of certain type
137             template<class GeoField, class PatchFieldType>
138             void initPatchFields
139             (
140                 const typename GeoField::value_type& initVal
141             );
143             //- Delete all processor patches. Move any processor faces into
144             //  patchI.
145             autoPtr<mapPolyMesh> deleteProcPatches(const label patchI);
147             //- Repatch the mesh. This is only nessecary for the proc
148             //  boundary faces. newPatchID is over all boundary faces: -1 or
149             //  new patchID. constructFaceMap is being adapted for the
150             //  possible new face position (since proc faces get automatically
151             //  matched)
152             autoPtr<mapPolyMesh> repatch
153             (
154                 const labelList& newPatchID,
155                 labelListList& constructFaceMap
156             );
158             //- Merge any shared points that are geometrically shared. Needs
159             //  parallel valid mesh - uses globalMeshData.
160             //  constructPointMap is adapted for the new point labels.
161             autoPtr<mapPolyMesh> mergeSharedPoints
162             (
163                 labelListList& constructPointMap
164             );
166         // Coupling information
168             //- Construct the local environment of all boundary faces.
169             void getNeighbourData
170             (
171                 const labelList& distribution,
172                 labelList& sourceFace,
173                 labelList& sourceProc,
174                 labelList& sourceNewProc
175             ) const;
177             // Subset the neighbourCell/neighbourProc fields
178             static void subsetBoundaryData
179             (
180                 const fvMesh& mesh,
181                 const labelList& faceMap,
182                 const labelList& cellMap,
184                 const labelList& oldDistribution,
185                 const labelList& oldFaceOwner,
186                 const labelList& oldFaceNeighbour,
187                 const label oldInternalFaces,
189                 const labelList& sourceFace,
190                 const labelList& sourceProc,
191                 const labelList& sourceNewProc,
193                 labelList& subFace,
194                 labelList& subProc,
195                 labelList& subNewProc
196             );
198             //- Find cells on mesh whose faceID/procID match the neighbour
199             //  cell/proc of domainMesh. Store the matching face.
200             static void findCouples
201             (
202                 const primitiveMesh&,
203                 const labelList& sourceFace,
204                 const labelList& sourceProc,
206                 const label domain,
207                 const primitiveMesh& domainMesh,
208                 const labelList& domainFace,
209                 const labelList& domainProc,
211                 labelList& masterCoupledFaces,
212                 labelList& slaveCoupledFaces
213             );
215             //- Map data on boundary faces to new mesh (resulting from adding
216             //  two meshes)
217             static labelList mapBoundaryData
218             (
219                 const primitiveMesh& mesh,      // mesh after adding
220                 const mapAddedPolyMesh& map,
221                 const labelList& boundaryData0, // mesh before adding
222                 const label nInternalFaces1,
223                 const labelList& boundaryData1  // added mesh
224             );
227         // Other
229             //- Remove cells. Add all exposed faces to patch oldInternalPatchI
230             autoPtr<mapPolyMesh> doRemoveCells
231             (
232                 const labelList& cellsToRemove,
233                 const label oldInternalPatchI
234             );
236             //- Add processor patches. Changes mesh and returns per neighbour
237             //  proc the processor patchID.
238             void addProcPatches
239             (
240                 const labelList&, // processor that neighbour is on
241                 labelList& procPatchID
242             );
244             //- Get boundary faces to be repatched. Is -1 or new patchID
245             static labelList getProcBoundaryPatch
246             (
247                 const labelList& neighbourNewProc,// new processor per b. face
248                 const labelList& procPatchID      // patchID
249             );
251             //- Send mesh and coupling data.
252             static void sendMesh
253             (
254                 const label domain,
255                 const fvMesh& mesh,
256                 const wordList& pointZoneNames,
257                 const wordList& facesZoneNames,
258                 const wordList& cellZoneNames,
259                 const labelList& sourceFace,
260                 const labelList& sourceProc,
261                 const labelList& sourceNewProc,
262                 OSstream& toDomain
263             );
264             //- Send subset of fields
265             template<class GeoField>
266             static void sendFields
267             (
268                 const label domain,
269                 const wordList& fieldNames,
270                 const fvMeshSubset&,
271                 OSstream& toNbr
272             );
274             //- Receive mesh. Opposite of sendMesh
275             static autoPtr<fvMesh> receiveMesh
276             (
277                 const label domain,
278                 const wordList& pointZoneNames,
279                 const wordList& facesZoneNames,
280                 const wordList& cellZoneNames,
281                 const Time& runTime,
282                 labelList& domainSourceFace,
283                 labelList& domainSourceProc,
284                 labelList& domainSourceNewProc,
285                 ISstream& fromNbr
286             );
288             //- Receive fields. Opposite of sendFields
289             template<class GeoField>
290             static void receiveFields
291             (
292                 const label domain,
293                 const wordList& fieldNames,
294                 fvMesh&,
295                 PtrList<GeoField>&,
296                 const dictionary& fieldDicts
297             );
299             //- Do parallel exchange
300             template <class Container, class T>
301             static void exchange
302             (
303                 const List<Container >& sendBufs,
304                 List<Container >& recvBufs,
305                 labelListList& sizes
306             );
308             //- Disallow default bitwise copy construct
309             fvMeshDistribute(const fvMeshDistribute&);
311             //- Disallow default bitwise assignment
312             void operator=(const fvMeshDistribute&);
314 public:
316     ClassName("fvMeshDistribute");
319     // Constructors
321         //- Construct from mesh and absolute merge tolerance
322         fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
325     // Member Functions
327         //- Helper function: count cells per processor in wanted distribution
328         static labelList countCells(const labelList&);
330         //- Send cells to neighbours according to distribution
331         //  (for every cell the new proc)
332         autoPtr<mapDistributePolyMesh> distribute(const labelList& dist);
334         // Debugging
336             //- Print some info on coupling data
337             static void printCoupleInfo
338             (
339                 const primitiveMesh&,
340                 const labelList&,
341                 const labelList&,
342                 const labelList&
343             );
345             //- Print some field info
346             template<class GeoField>
347             static void printFieldInfo(const fvMesh&);
349             //- Print some info on mesh.
350             static void printMeshInfo(const fvMesh&);
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 } // End namespace Foam
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
360 #ifdef NoRepository
361 #   include "fvMeshDistributeTemplates.C"
362 #endif
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 #endif
368 // ************************************************************************* //