1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 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
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
26 Foam::fvMeshDistribute
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
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
49 fvMeshDistributeTemplates.C
51 \*---------------------------------------------------------------------------*/
53 #ifndef fvMeshDistribute_H
54 #define fvMeshDistribute_H
58 #include "fvMeshSubset.H"
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 // Forward declaration of classes
66 class mapAddedPolyMesh;
67 class mapDistributePolyMesh;
69 /*---------------------------------------------------------------------------*\
70 Class fvMeshDistribute Declaration
71 \*---------------------------------------------------------------------------*/
73 class fvMeshDistribute
80 //- Absolute merging tolerance (constructing meshes gets done using
81 // geometric matching)
82 const scalar mergeTol_;
87 //- Check words are the same. Used in patch type checking of similarly
93 void operator()(word& x, const word& y) const
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);
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
120 const bool selectEqual,
121 const labelList& values,
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&);
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);
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
155 PtrList<FieldField<fvsPatchField, T> >& bflds
158 //- Map boundary fields
159 template <class T, class Mesh>
160 void mapBoundaryFields
162 const mapPolyMesh& map,
163 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
166 //- Init patch fields of certain type
167 template<class GeoField>
170 const word& patchFieldType,
171 const typename GeoField::value_type& initVal
174 //- Delete all processor patches. Move any processor faces into
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
183 autoPtr<mapPolyMesh> repatch
185 const labelList& newPatchID,
186 labelListList& constructFaceMap
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
194 labelListList& constructPointMap
197 // Coupling information
199 //- Construct the local environment of all boundary faces.
200 void getNeighbourData
202 const labelList& distribution,
203 labelList& sourceFace,
204 labelList& sourceProc,
205 labelList& sourceNewProc
208 // Subset the neighbourCell/neighbourProc fields
209 static void subsetBoundaryData
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,
226 labelList& subNewProc
229 //- Find cells on mesh whose faceID/procID match the neighbour
230 // cell/proc of domainMesh. Store the matching face.
231 static void findCouples
233 const primitiveMesh&,
234 const labelList& sourceFace,
235 const labelList& sourceProc,
238 const primitiveMesh& domainMesh,
239 const labelList& domainFace,
240 const labelList& domainProc,
242 labelList& masterCoupledFaces,
243 labelList& slaveCoupledFaces
246 //- Map data on boundary faces to new mesh (resulting from adding
248 static labelList mapBoundaryData
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
260 //- Remove cells. Add all exposed faces to patch oldInternalPatchI
261 autoPtr<mapPolyMesh> doRemoveCells
263 const labelList& cellsToRemove,
264 const label oldInternalPatchI
267 //- Add processor patches. Changes mesh and returns per neighbour
268 // proc the processor patchID.
271 const labelList&, // processor that neighbour is on
272 labelList& procPatchID
275 //- Get boundary faces to be repatched. Is -1 or new patchID
276 static labelList getProcBoundaryPatch
278 const labelList& neighbourNewProc,// new processor per b. face
279 const labelList& procPatchID // patchID
282 //- Send mesh and coupling data.
287 const wordList& pointZoneNames,
288 const wordList& facesZoneNames,
289 const wordList& cellZoneNames,
290 const labelList& sourceFace,
291 const labelList& sourceProc,
292 const labelList& sourceNewProc
294 //- Send subset of fields
295 template<class GeoField>
296 static void sendFields
299 const wordList& fieldNames,
303 //- Receive mesh. Opposite of sendMesh
304 static autoPtr<fvMesh> receiveMesh
307 const wordList& pointZoneNames,
308 const wordList& facesZoneNames,
309 const wordList& cellZoneNames,
311 labelList& domainSourceFace,
312 labelList& domainSourceProc,
313 labelList& domainSourceNewProc
316 //- Receive fields. Opposite of sendFields
317 template<class GeoField>
318 static void receiveFields
321 const wordList& fieldNames,
326 //- Disallow default bitwise copy construct
327 fvMeshDistribute(const fvMeshDistribute&);
329 //- Disallow default bitwise assignment
330 void operator=(const fvMeshDistribute&);
334 ClassName("fvMeshDistribute");
339 //- Construct from mesh and absolute merge tolerance
340 fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
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);
354 //- Print some info on coupling data
355 static void printCoupleInfo
357 const primitiveMesh&,
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
379 # include "fvMeshDistributeTemplates.C"
382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
386 // ************************************************************************* //