1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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_;
85 // Private Member Functions
87 //- Find indices with value
88 static labelList select
90 const bool selectEqual,
91 const labelList& values,
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&);
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);
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
125 PtrList<FieldField<fvsPatchField, T> >& bflds
128 //- Map boundary fields
129 template <class T, class Mesh>
130 void mapBoundaryFields
132 const mapPolyMesh& map,
133 const PtrList<FieldField<fvsPatchField, T> >& oldBflds
136 //- Init patch fields of certain type
137 template<class GeoField, class PatchFieldType>
140 const typename GeoField::value_type& initVal
143 //- Delete all processor patches. Move any processor faces into
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
152 autoPtr<mapPolyMesh> repatch
154 const labelList& newPatchID,
155 labelListList& constructFaceMap
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
163 labelListList& constructPointMap
166 // Coupling information
168 //- Construct the local environment of all boundary faces.
169 void getNeighbourData
171 const labelList& distribution,
172 labelList& sourceFace,
173 labelList& sourceProc,
174 labelList& sourceNewProc
177 // Subset the neighbourCell/neighbourProc fields
178 static void subsetBoundaryData
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,
195 labelList& subNewProc
198 //- Find cells on mesh whose faceID/procID match the neighbour
199 // cell/proc of domainMesh. Store the matching face.
200 static void findCouples
202 const primitiveMesh&,
203 const labelList& sourceFace,
204 const labelList& sourceProc,
207 const primitiveMesh& domainMesh,
208 const labelList& domainFace,
209 const labelList& domainProc,
211 labelList& masterCoupledFaces,
212 labelList& slaveCoupledFaces
215 //- Map data on boundary faces to new mesh (resulting from adding
217 static labelList mapBoundaryData
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
229 //- Remove cells. Add all exposed faces to patch oldInternalPatchI
230 autoPtr<mapPolyMesh> doRemoveCells
232 const labelList& cellsToRemove,
233 const label oldInternalPatchI
236 //- Add processor patches. Changes mesh and returns per neighbour
237 // proc the processor patchID.
240 const labelList&, // processor that neighbour is on
241 labelList& procPatchID
244 //- Get boundary faces to be repatched. Is -1 or new patchID
245 static labelList getProcBoundaryPatch
247 const labelList& neighbourNewProc,// new processor per b. face
248 const labelList& procPatchID // patchID
251 //- Send mesh and coupling data.
256 const wordList& pointZoneNames,
257 const wordList& facesZoneNames,
258 const wordList& cellZoneNames,
259 const labelList& sourceFace,
260 const labelList& sourceProc,
261 const labelList& sourceNewProc,
264 //- Send subset of fields
265 template<class GeoField>
266 static void sendFields
269 const wordList& fieldNames,
274 //- Receive mesh. Opposite of sendMesh
275 static autoPtr<fvMesh> receiveMesh
278 const wordList& pointZoneNames,
279 const wordList& facesZoneNames,
280 const wordList& cellZoneNames,
282 labelList& domainSourceFace,
283 labelList& domainSourceProc,
284 labelList& domainSourceNewProc,
288 //- Receive fields. Opposite of sendFields
289 template<class GeoField>
290 static void receiveFields
293 const wordList& fieldNames,
296 const dictionary& fieldDicts
299 //- Do parallel exchange
300 template <class Container, class T>
303 const List<Container >& sendBufs,
304 List<Container >& recvBufs,
308 //- Disallow default bitwise copy construct
309 fvMeshDistribute(const fvMeshDistribute&);
311 //- Disallow default bitwise assignment
312 void operator=(const fvMeshDistribute&);
316 ClassName("fvMeshDistribute");
321 //- Construct from mesh and absolute merge tolerance
322 fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
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);
336 //- Print some info on coupling data
337 static void printCoupleInfo
339 const primitiveMesh&,
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 # include "fvMeshDistributeTemplates.C"
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
368 // ************************************************************************* //