fvMeshDistribute.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::fvMeshDistribute
26 
27 Description
28  Sends/receives parts of mesh+fvfields to neighbouring processors.
29  Used in load balancing.
30 
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.
34 
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.
45 
46 SourceFiles
47  fvMeshDistribute.C
48  fvMeshDistributeTemplates.C
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef fvMeshDistribute_H
53 #define fvMeshDistribute_H
54 
55 #include "Field.H"
56 #include "fvMeshSubset.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 // Forward declaration of classes
64 class mapAddedPolyMesh;
65 class mapDistributePolyMesh;
66 
67 /*---------------------------------------------------------------------------*\
68  Class fvMeshDistribute Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 class fvMeshDistribute
72 {
73  // Private data
74 
75  //- Underlying fvMesh
76  fvMesh& mesh_;
77 
78  //- Absolute merging tolerance (constructing meshes gets done using
79  // geometric matching)
80  const scalar mergeTol_;
81 
82 
83  // Private Member Functions
84 
85  static void inplaceRenumberWithFlip
86  (
87  const labelUList& oldToNew,
88  const bool oldToNewHasFlip,
89  const bool lstHasFlip,
90  labelUList& lst
91  );
92 
93  //- Find indices with value
94  static labelList select
95  (
96  const bool selectEqual,
97  const labelList& values,
98  const label value
99  );
100 
101  //- Check all procs have same names and in exactly same order.
102  static void checkEqualWordList(const string&, const wordList&);
103 
104  //- Merge wordlists over all processors
105  static wordList mergeWordList(const wordList&);
106 
107 
108  // Patch handling
109 
110  //- Find patch to put exposed faces into.
111  label findNonEmptyPatch() const;
112 
113  //- Save boundary fields
114  template<class T, class Mesh>
115  void saveBoundaryFields
116  (
118  ) const;
119 
120  //- Map boundary fields
121  template<class T, class Mesh>
122  void mapBoundaryFields
123  (
124  const mapPolyMesh& map,
125  const PtrList<FieldField<fvsPatchField, T>>& oldBflds
126  );
127 
128  //- Save internal fields of surfaceFields
129  template<class T>
130  void saveInternalFields(PtrList<Field<T>>& iflds) const;
131 
132  //- Set value of patch faces resulting from internal faces
133  template<class T>
134  void mapExposedFaces
135  (
136  const mapPolyMesh& map,
137  const PtrList<Field<T>>& oldFlds
138  );
139 
140  //- Init patch fields of certain type
141  template<class GeoField, class PatchFieldType>
142  void initPatchFields
143  (
144  const typename GeoField::value_type& initVal
145  );
146 
147  //- Call correctBoundaryConditions on fields
148  template<class GeoField>
149  void correctBoundaryConditions();
150 
151  //- Delete all processor patches. Move any processor faces into
152  // patchi.
153  autoPtr<mapPolyMesh> deleteProcPatches(const label patchi);
154 
155  //- Repatch the mesh. This is only necessary for the proc
156  // boundary faces. newPatchID is over all boundary faces: -1 or
157  // new patchID. constructFaceMap is being adapted for the
158  // possible new face position (since proc faces get automatically
159  // matched)
160  autoPtr<mapPolyMesh> repatch
161  (
162  const labelList& newPatchID,
163  labelListList& constructFaceMap
164  );
165 
166  //- Merge any shared points that are geometrically shared. Needs
167  // parallel valid mesh - uses globalMeshData.
168  // constructPointMap is adapted for the new point labels.
169  autoPtr<mapPolyMesh> mergeSharedPoints
170  (
171  labelListList& constructPointMap
172  );
173 
174 
175  // Coupling information
176 
177  //- Construct the local environment of all boundary faces.
178  void getNeighbourData
179  (
180  const labelList& distribution,
181  labelList& sourceFace,
182  labelList& sourceProc,
183  labelList& sourcePatch,
184  labelList& sourceNewProc
185  ) const;
186 
187  // Subset the neighbourCell/neighbourProc fields
188  static void subsetBoundaryData
189  (
190  const fvMesh& mesh,
191  const labelList& faceMap,
192  const labelList& cellMap,
193 
194  const labelList& oldDistribution,
195  const labelList& oldFaceOwner,
196  const labelList& oldFaceNeighbour,
197  const label oldInternalFaces,
198 
199  const labelList& sourceFace,
200  const labelList& sourceProc,
201  const labelList& sourcePatch,
202  const labelList& sourceNewProc,
203 
204  labelList& subFace,
205  labelList& subProc,
206  labelList& subPatch,
207  labelList& subNewProc
208  );
209 
210  //- Find cells on mesh whose faceID/procID match the neighbour
211  // cell/proc of domainMesh. Store the matching face.
212  static void findCouples
213  (
214  const primitiveMesh&,
215  const labelList& sourceFace,
216  const labelList& sourceProc,
217  const labelList& sourcePatch,
218 
219  const label domain,
220  const primitiveMesh& domainMesh,
221  const labelList& domainFace,
222  const labelList& domainProc,
223  const labelList& domainPatch,
224 
225  labelList& masterCoupledFaces,
226  labelList& slaveCoupledFaces
227  );
228 
229  //- Map data on boundary faces to new mesh (resulting from adding
230  // two meshes)
231  static labelList mapBoundaryData
232  (
233  const primitiveMesh& mesh, // mesh after adding
234  const mapAddedPolyMesh& map,
235  const labelList& boundaryData0, // mesh before adding
236  const label nInternalFaces1,
237  const labelList& boundaryData1 // added mesh
238  );
239 
240 
241  // Other
242 
243  //- Remove cells. Add all exposed faces to patch oldInternalPatchi
244  autoPtr<mapPolyMesh> doRemoveCells
245  (
246  const labelList& cellsToRemove,
247  const label oldInternalPatchi
248  );
249 
250  //- Add processor patches. Changes mesh and returns per neighbour
251  // proc the processor patchID.
252  void addProcPatches
253  (
254  const labelList&, // processor that neighbour is now on
255  const labelList&, // -1 or patch that face originated from
256  List<Map<label>>& procPatchID
257  );
258 
259  //- Get boundary faces to be repatched. Is -1 or new patchID
260  static labelList getBoundaryPatch
261  (
262  const labelList& neighbourNewProc, // new processor per b. face
263  const labelList& referPatchID, // -1 or original patch
264  const List<Map<label>>& procPatchID // patchID
265  );
266 
267  //- Send mesh and coupling data.
268  static void sendMesh
269  (
270  const label domain,
271  const fvMesh& mesh,
272  const wordList& pointZoneNames,
273  const wordList& facesZoneNames,
274  const wordList& cellZoneNames,
275  const labelList& sourceFace,
276  const labelList& sourceProc,
277  const labelList& sourcePatch,
278  const labelList& sourceNewProc,
279  Ostream& toDomain
280  );
281  //- Send subset of fields
282  template<class GeoField>
283  static void sendFields
284  (
285  const label domain,
286  const wordList& fieldNames,
287  const fvMeshSubset&,
288  Ostream& toNbr
289  );
290 
291  //- Receive mesh. Opposite of sendMesh
292  static autoPtr<fvMesh> receiveMesh
293  (
294  const label domain,
295  const wordList& pointZoneNames,
296  const wordList& facesZoneNames,
297  const wordList& cellZoneNames,
298  const Time& runTime,
299  labelList& domainSourceFace,
300  labelList& domainSourceProc,
301  labelList& domainSourcePatch,
302  labelList& domainSourceNewProc,
303  Istream& fromNbr
304  );
305 
306  //- Receive fields. Opposite of sendFields
307  template<class GeoField>
308  static void receiveFields
309  (
310  const label domain,
311  const wordList& fieldNames,
312  fvMesh&,
314  const dictionary& fieldDicts
315  );
316 
317  //- Disallow default bitwise copy construct
319 
320  //- Disallow default bitwise assignment
321  void operator=(const fvMeshDistribute&);
322 
323 public:
324 
325  ClassName("fvMeshDistribute");
326 
327 
328  // Constructors
329 
330  //- Construct from mesh and absolute merge tolerance
331  fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
332 
333 
334  // Member Functions
335 
336  //- Helper function: count cells per processor in wanted distribution
337  static labelList countCells(const labelList&);
338 
339  //- Send cells to neighbours according to distribution
340  // (for every cell the new proc)
342 
343  // Debugging
344 
345  //- Print some info on coupling data
346  static void printCoupleInfo
347  (
348  const primitiveMesh&,
349  const labelList&,
350  const labelList&,
351  const labelList&,
352  const labelList&
353  );
354 
355  //- Print some field info
356  template<class GeoField>
357  static void printFieldInfo(const fvMesh&);
358 
359  //- Print some info on mesh.
360  static void printMeshInfo(const fvMesh&);
361 };
362 
363 
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 
366 } // End namespace Foam
367 
368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
369 
370 #ifdef NoRepository
371  #include "fvMeshDistributeTemplates.C"
372 #endif
373 
374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
375 
376 #endif
377 
378 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
ClassName("fvMeshDistribute")
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Class containing mesh-to-mesh mapping information after a mesh addition where we add a mesh (&#39;added m...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Generic field type.
Definition: FieldField.H:51
static List< word > fieldNames
Definition: globalFoam.H:46
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
dynamicFvMesh & mesh
Accumulating histogram of values. Specified bin resolution automatic generation of bins...
Definition: distribution.H:58
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static void printFieldInfo(const fvMesh &)
Print some field info.
autoPtr< mapDistributePolyMesh > distribute(const labelList &dist)
Send cells to neighbours according to distribution.
Post-processing mesh subset tool. Given the original mesh and the list of selected cells...
Definition: fvMeshSubset.H:73
static void printMeshInfo(const fvMesh &)
Print some info on mesh.
label patchi
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:62
static void printCoupleInfo(const primitiveMesh &, const labelList &, const labelList &, const labelList &, const labelList &)
Print some info on coupling data.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
static labelList countCells(const labelList &)
Helper function: count cells per processor in wanted distribution.
Namespace for OpenFOAM.