1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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/>.
25 Foam::fvMeshDistribute
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
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
48 fvMeshDistributeTemplates.C
50 \*---------------------------------------------------------------------------*/
52 #ifndef fvMeshDistribute_H
53 #define fvMeshDistribute_H
57 #include "fvMeshSubset.H"
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 // Forward declaration of classes
65 class mapAddedPolyMesh;
66 class mapDistributePolyMesh;
68 /*---------------------------------------------------------------------------*\
69 Class fvMeshDistribute Declaration
70 \*---------------------------------------------------------------------------*/
72 class fvMeshDistribute
79 //- Absolute merging tolerance (constructing meshes gets done using
80 // geometric matching)
81 const scalar mergeTol_;
84 // Private Member Functions
86 //- Find indices with value
87 static labelList select
89 const bool selectEqual,
90 const labelList& values,
94 //- Check all procs have same names and in exactly same order.
95 static void checkEqualWordList(const string&, const wordList&);
97 //- Merge wordlists over all processors
98 static wordList mergeWordList(const wordList&);
103 //- Find patch to put exposed faces into.
104 label findNonEmptyPatch() const;
106 //- Appends processorPolyPatch. Returns patchID.
107 label addProcPatch(const word& patchName, const label nbrProc);
110 template<class GeoField>
111 void addPatchFields(const word& patchFieldType);
113 //- Deletes last patch.
114 void deleteTrailingPatch();
116 // Delete trailing patch fields
117 template<class GeoField>
118 void deleteTrailingPatchFields();
120 //- Save boundary fields
121 template <class T, class Mesh>
122 void saveBoundaryFields
124 PtrList<FieldField<fvsPatchField, T> >& bflds
127 //- Map boundary fields
128 template <class T, class Mesh>
129 void mapBoundaryFields
131 const mapPolyMesh& map,
132 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
135 //- Init patch fields of certain type
136 template<class GeoField, class PatchFieldType>
139 const typename GeoField::value_type& initVal
142 //- Delete all processor patches. Move any processor faces into
144 autoPtr<mapPolyMesh> deleteProcPatches(const label patchI);
146 //- Repatch the mesh. This is only nessecary for the proc
147 // boundary faces. newPatchID is over all boundary faces: -1 or
148 // new patchID. constructFaceMap is being adapted for the
149 // possible new face position (since proc faces get automatically
151 autoPtr<mapPolyMesh> repatch
153 const labelList& newPatchID,
154 labelListList& constructFaceMap
157 //- Merge any shared points that are geometrically shared. Needs
158 // parallel valid mesh - uses globalMeshData.
159 // constructPointMap is adapted for the new point labels.
160 autoPtr<mapPolyMesh> mergeSharedPoints
162 labelListList& constructPointMap
165 // Coupling information
167 //- Construct the local environment of all boundary faces.
168 void getNeighbourData
170 const labelList& distribution,
171 labelList& sourceFace,
172 labelList& sourceProc,
173 labelList& sourceNewProc
176 // Subset the neighbourCell/neighbourProc fields
177 static void subsetBoundaryData
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& sourceNewProc,
194 labelList& subNewProc
197 //- Find cells on mesh whose faceID/procID match the neighbour
198 // cell/proc of domainMesh. Store the matching face.
199 static void findCouples
201 const primitiveMesh&,
202 const labelList& sourceFace,
203 const labelList& sourceProc,
206 const primitiveMesh& domainMesh,
207 const labelList& domainFace,
208 const labelList& domainProc,
210 labelList& masterCoupledFaces,
211 labelList& slaveCoupledFaces
214 //- Map data on boundary faces to new mesh (resulting from adding
216 static labelList mapBoundaryData
218 const primitiveMesh& mesh, // mesh after adding
219 const mapAddedPolyMesh& map,
220 const labelList& boundaryData0, // mesh before adding
221 const label nInternalFaces1,
222 const labelList& boundaryData1 // added mesh
228 //- Remove cells. Add all exposed faces to patch oldInternalPatchI
229 autoPtr<mapPolyMesh> doRemoveCells
231 const labelList& cellsToRemove,
232 const label oldInternalPatchI
235 //- Add processor patches. Changes mesh and returns per neighbour
236 // proc the processor patchID.
239 const labelList&, // processor that neighbour is on
240 labelList& procPatchID
243 //- Get boundary faces to be repatched. Is -1 or new patchID
244 static labelList getProcBoundaryPatch
246 const labelList& neighbourNewProc,// new processor per b. face
247 const labelList& procPatchID // patchID
250 //- Send mesh and coupling data.
255 const wordList& pointZoneNames,
256 const wordList& facesZoneNames,
257 const wordList& cellZoneNames,
258 const labelList& sourceFace,
259 const labelList& sourceProc,
260 const labelList& sourceNewProc,
263 //- Send subset of fields
264 template<class GeoField>
265 static void sendFields
268 const wordList& fieldNames,
273 //- Receive mesh. Opposite of sendMesh
274 static autoPtr<fvMesh> receiveMesh
277 const wordList& pointZoneNames,
278 const wordList& facesZoneNames,
279 const wordList& cellZoneNames,
281 labelList& domainSourceFace,
282 labelList& domainSourceProc,
283 labelList& domainSourceNewProc,
287 //- Receive fields. Opposite of sendFields
288 template<class GeoField>
289 static void receiveFields
292 const wordList& fieldNames,
295 const dictionary& fieldDicts
298 //- Do parallel exchange
299 template <class Container, class T>
302 const List<Container >& sendBufs,
303 List<Container >& recvBufs,
307 //- Disallow default bitwise copy construct
308 fvMeshDistribute(const fvMeshDistribute&);
310 //- Disallow default bitwise assignment
311 void operator=(const fvMeshDistribute&);
315 ClassName("fvMeshDistribute");
320 //- Construct from mesh and absolute merge tolerance
321 fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
326 //- Helper function: count cells per processor in wanted distribution
327 static labelList countCells(const labelList&);
329 //- Send cells to neighbours according to distribution
330 // (for every cell the new proc)
331 autoPtr<mapDistributePolyMesh> distribute(const labelList& dist);
335 //- Print some info on coupling data
336 static void printCoupleInfo
338 const primitiveMesh&,
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
360 # include "fvMeshDistributeTemplates.C"
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 // ************************************************************************* //