1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
56 #include "fvMeshSubset.H"
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 // Forward declaration of classes
64 class mapAddedPolyMesh;
65 class mapDistributePolyMesh;
67 /*---------------------------------------------------------------------------*\
68 Class fvMeshDistribute Declaration
69 \*---------------------------------------------------------------------------*/
71 class fvMeshDistribute
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
88 const bool selectEqual,
89 const labelList& values,
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&);
102 //- Find patch to put exposed faces into.
103 label findNonEmptyPatch() const;
105 //- Appends polyPatch. Returns patchID.
106 label addPatch(polyPatch*);
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
123 PtrList<FieldField<fvsPatchField, T> >& bflds
126 //- Map boundary fields
127 template <class T, class Mesh>
128 void mapBoundaryFields
130 const mapPolyMesh& map,
131 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
134 //- Init patch fields of certain type
135 template<class GeoField, class PatchFieldType>
138 const typename GeoField::value_type& initVal
141 //- Delete all processor patches. Move any processor faces into
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
150 autoPtr<mapPolyMesh> repatch
152 const labelList& newPatchID,
153 labelListList& constructFaceMap
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
161 labelListList& constructPointMap
164 // Coupling information
166 //- Construct the local environment of all boundary faces.
167 void getNeighbourData
169 const labelList& distribution,
170 labelList& sourceFace,
171 labelList& sourceProc,
172 labelList& sourcePatch,
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& sourcePatch,
191 const labelList& sourceNewProc,
196 labelList& subNewProc
199 //- Find cells on mesh whose faceID/procID match the neighbour
200 // cell/proc of domainMesh. Store the matching face.
201 static void findCouples
203 const primitiveMesh&,
204 const labelList& sourceFace,
205 const labelList& sourceProc,
206 const labelList& sourcePatch,
209 const primitiveMesh& domainMesh,
210 const labelList& domainFace,
211 const labelList& domainProc,
212 const labelList& domainPatch,
214 labelList& masterCoupledFaces,
215 labelList& slaveCoupledFaces
218 //- Map data on boundary faces to new mesh (resulting from adding
220 static labelList mapBoundaryData
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
232 //- Remove cells. Add all exposed faces to patch oldInternalPatchI
233 autoPtr<mapPolyMesh> doRemoveCells
235 const labelList& cellsToRemove,
236 const label oldInternalPatchI
239 //- Add processor patches. Changes mesh and returns per neighbour
240 // proc the processor patchID.
243 const labelList&, // processor that neighbour is now on
244 const labelList&, // -1 or patch that face originated from
245 List<Map<label> >& procPatchID
248 //- Get boundary faces to be repatched. Is -1 or new patchID
249 static labelList getBoundaryPatch
251 const labelList& neighbourNewProc, // new processor per b. face
252 const labelList& referPatchID, // -1 or original patch
253 const List<Map<label> >& procPatchID// patchID
256 //- Send mesh and coupling data.
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,
270 //- Send subset of fields
271 template<class GeoField>
272 static void sendFields
275 const wordList& fieldNames,
280 //- Receive mesh. Opposite of sendMesh
281 static autoPtr<fvMesh> receiveMesh
284 const wordList& pointZoneNames,
285 const wordList& facesZoneNames,
286 const wordList& cellZoneNames,
288 labelList& domainSourceFace,
289 labelList& domainSourceProc,
290 labelList& domainSourcePatch,
291 labelList& domainSourceNewProc,
295 //- Receive fields. Opposite of sendFields
296 template<class GeoField>
297 static void receiveFields
300 const wordList& fieldNames,
303 const dictionary& fieldDicts
306 //- Disallow default bitwise copy construct
307 fvMeshDistribute(const fvMeshDistribute&);
309 //- Disallow default bitwise assignment
310 void operator=(const fvMeshDistribute&);
314 ClassName("fvMeshDistribute");
319 //- Construct from mesh and absolute merge tolerance
320 fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
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);
334 //- Print some info on coupling data
335 static void printCoupleInfo
337 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 // ************************************************************************* //