ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / dynamicMesh / fvMeshDistribute / fvMeshDistribute.H
blob3933c901a4bc3bf0f73d7d15b59ca9c3452c9d5c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::fvMeshDistribute
27 Description
28     Sends/receives parts of mesh+fvfields to neighbouring processors.
29     Used in load balancing.
31     Input is per local cell the processor it should move to. Moves meshes
32     and volFields/surfaceFields and returns map which can be used to
33     distribute other.
35     Notes:
36     - does not handle cyclics. Will probably handle separated proc patches.
37     - if all cells move off processor also all its processor patches will
38       get deleted so comms might be screwed up (since e.g. globalMeshData
39       expects procPatches on all)
40     - initial mesh has to have procPatches last and all normal patches common
41       to all processors and in the same order. This is checked.
42     - faces are matched topologically but points on the faces are not. So
43       expect problems -on separated patches (cyclics?) -on zero sized processor
44       edges.
46 SourceFiles
47     fvMeshDistribute.C
48     fvMeshDistributeTemplates.C
50 \*---------------------------------------------------------------------------*/
52 #ifndef fvMeshDistribute_H
53 #define fvMeshDistribute_H
55 #include "Field.H"
56 #include "fvMeshSubset.H"
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 namespace Foam
63 // Forward declaration of classes
64 class mapAddedPolyMesh;
65 class mapDistributePolyMesh;
67 /*---------------------------------------------------------------------------*\
68                            Class fvMeshDistribute Declaration
69 \*---------------------------------------------------------------------------*/
71 class fvMeshDistribute
73     // Private data
75         //- Underlying fvMesh
76         fvMesh& mesh_;
78         //- Absolute merging tolerance (constructing meshes gets done using
79         //  geometric matching)
80         const scalar mergeTol_;
83     // Private Member Functions
85         //- Find indices with value
86         static labelList select
87         (
88             const bool selectEqual,
89             const labelList& values,
90             const label value
91         );
93         //- Check all procs have same names and in exactly same order.
94         static void checkEqualWordList(const string&, const wordList&);
96         //- Merge wordlists over all processors
97         static wordList mergeWordList(const wordList&);
100         // Patch handling
102             //- Find patch to put exposed faces into.
103             label findNonEmptyPatch() const;
105             //- Appends polyPatch. Returns patchID.
106             label addPatch(polyPatch*);
108             //- Add patch field
109             template<class GeoField>
110             void addPatchFields(const word& patchFieldType);
112             //- Deletes last patch.
113             void deleteTrailingPatch();
115             // Delete trailing patch fields
116             template<class GeoField>
117             void deleteTrailingPatchFields();
119             //- Save boundary fields
120             template <class T, class Mesh>
121             void saveBoundaryFields
122             (
123                 PtrList<FieldField<fvsPatchField, T> >& bflds
124             ) const;
126             //- Map boundary fields
127             template <class T, class Mesh>
128             void mapBoundaryFields
129             (
130                 const mapPolyMesh& map,
131                 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
132             );
134             //- Init patch fields of certain type
135             template<class GeoField, class PatchFieldType>
136             void initPatchFields
137             (
138                 const typename GeoField::value_type& initVal
139             );
141             //- Delete all processor patches. Move any processor faces into
142             //  patchI.
143             autoPtr<mapPolyMesh> deleteProcPatches(const label patchI);
145             //- Repatch the mesh. This is only nessecary for the proc
146             //  boundary faces. newPatchID is over all boundary faces: -1 or
147             //  new patchID. constructFaceMap is being adapted for the
148             //  possible new face position (since proc faces get automatically
149             //  matched)
150             autoPtr<mapPolyMesh> repatch
151             (
152                 const labelList& newPatchID,
153                 labelListList& constructFaceMap
154             );
156             //- Merge any shared points that are geometrically shared. Needs
157             //  parallel valid mesh - uses globalMeshData.
158             //  constructPointMap is adapted for the new point labels.
159             autoPtr<mapPolyMesh> mergeSharedPoints
160             (
161                 labelListList& constructPointMap
162             );
164         // Coupling information
166             //- Construct the local environment of all boundary faces.
167             void getNeighbourData
168             (
169                 const labelList& distribution,
170                 labelList& sourceFace,
171                 labelList& sourceProc,
172                 labelList& sourcePatch,
173                 labelList& sourceNewProc
174             ) const;
176             // Subset the neighbourCell/neighbourProc fields
177             static void subsetBoundaryData
178             (
179                 const fvMesh& mesh,
180                 const labelList& faceMap,
181                 const labelList& cellMap,
183                 const labelList& oldDistribution,
184                 const labelList& oldFaceOwner,
185                 const labelList& oldFaceNeighbour,
186                 const label oldInternalFaces,
188                 const labelList& sourceFace,
189                 const labelList& sourceProc,
190                 const labelList& sourcePatch,
191                 const labelList& sourceNewProc,
193                 labelList& subFace,
194                 labelList& subProc,
195                 labelList& subPatch,
196                 labelList& subNewProc
197             );
199             //- Find cells on mesh whose faceID/procID match the neighbour
200             //  cell/proc of domainMesh. Store the matching face.
201             static void findCouples
202             (
203                 const primitiveMesh&,
204                 const labelList& sourceFace,
205                 const labelList& sourceProc,
206                 const labelList& sourcePatch,
208                 const label domain,
209                 const primitiveMesh& domainMesh,
210                 const labelList& domainFace,
211                 const labelList& domainProc,
212                 const labelList& domainPatch,
214                 labelList& masterCoupledFaces,
215                 labelList& slaveCoupledFaces
216             );
218             //- Map data on boundary faces to new mesh (resulting from adding
219             //  two meshes)
220             static labelList mapBoundaryData
221             (
222                 const primitiveMesh& mesh,      // mesh after adding
223                 const mapAddedPolyMesh& map,
224                 const labelList& boundaryData0, // mesh before adding
225                 const label nInternalFaces1,
226                 const labelList& boundaryData1  // added mesh
227             );
230         // Other
232             //- Remove cells. Add all exposed faces to patch oldInternalPatchI
233             autoPtr<mapPolyMesh> doRemoveCells
234             (
235                 const labelList& cellsToRemove,
236                 const label oldInternalPatchI
237             );
239             //- Add processor patches. Changes mesh and returns per neighbour
240             //  proc the processor patchID.
241             void addProcPatches
242             (
243                 const labelList&, // processor that neighbour is now on
244                 const labelList&, // -1 or patch that face originated from 
245                 List<Map<label> >& procPatchID
246             );
248             //- Get boundary faces to be repatched. Is -1 or new patchID
249             static labelList getBoundaryPatch
250             (
251                 const labelList& neighbourNewProc,  // new processor per b. face
252                 const labelList& referPatchID,      // -1 or original patch
253                 const List<Map<label> >& procPatchID// patchID
254             );
256             //- Send mesh and coupling data.
257             static void sendMesh
258             (
259                 const label domain,
260                 const fvMesh& mesh,
261                 const wordList& pointZoneNames,
262                 const wordList& facesZoneNames,
263                 const wordList& cellZoneNames,
264                 const labelList& sourceFace,
265                 const labelList& sourceProc,
266                 const labelList& sourcePatch,
267                 const labelList& sourceNewProc,
268                 UOPstream& toDomain
269             );
270             //- Send subset of fields
271             template<class GeoField>
272             static void sendFields
273             (
274                 const label domain,
275                 const wordList& fieldNames,
276                 const fvMeshSubset&,
277                 UOPstream& toNbr
278             );
280             //- Receive mesh. Opposite of sendMesh
281             static autoPtr<fvMesh> receiveMesh
282             (
283                 const label domain,
284                 const wordList& pointZoneNames,
285                 const wordList& facesZoneNames,
286                 const wordList& cellZoneNames,
287                 const Time& runTime,
288                 labelList& domainSourceFace,
289                 labelList& domainSourceProc,
290                 labelList& domainSourcePatch,
291                 labelList& domainSourceNewProc,
292                 UIPstream& fromNbr
293             );
295             //- Receive fields. Opposite of sendFields
296             template<class GeoField>
297             static void receiveFields
298             (
299                 const label domain,
300                 const wordList& fieldNames,
301                 fvMesh&,
302                 PtrList<GeoField>&,
303                 const dictionary& fieldDicts
304             );
306             //- Disallow default bitwise copy construct
307             fvMeshDistribute(const fvMeshDistribute&);
309             //- Disallow default bitwise assignment
310             void operator=(const fvMeshDistribute&);
312 public:
314     ClassName("fvMeshDistribute");
317     // Constructors
319         //- Construct from mesh and absolute merge tolerance
320         fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
323     // Member Functions
325         //- Helper function: count cells per processor in wanted distribution
326         static labelList countCells(const labelList&);
328         //- Send cells to neighbours according to distribution
329         //  (for every cell the new proc)
330         autoPtr<mapDistributePolyMesh> distribute(const labelList& dist);
332         // Debugging
334             //- Print some info on coupling data
335             static void printCoupleInfo
336             (
337                 const primitiveMesh&,
338                 const labelList&,
339                 const labelList&,
340                 const labelList&,
341                 const labelList&
342             );
344             //- Print some field info
345             template<class GeoField>
346             static void printFieldInfo(const fvMesh&);
348             //- Print some info on mesh.
349             static void printMeshInfo(const fvMesh&);
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 } // End namespace Foam
357 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 #ifdef NoRepository
360 #   include "fvMeshDistributeTemplates.C"
361 #endif
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 #endif
367 // ************************************************************************* //