fvMeshDistribute.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 local points that were remotely coupled.
167  // constructPointMap is adapted for the new point labels.
168  autoPtr<mapPolyMesh> mergeSharedPoints
169  (
170  const labelList& pointToGlobalMaster,
171  labelListList& constructPointMap
172  );
173 
174 
175  // Coupling information
176 
177  //- Construct the local environment of all boundary faces.
178  void getCouplingData
179  (
180  const labelList& distribution,
181  labelList& sourceFace,
182  labelList& sourceProc,
183  labelList& sourcePatch,
184  labelList& sourceNewProc,
185  labelList& sourcePointMaster
186  ) const;
187 
188  // Subset the neighbourCell/neighbourProc fields
189  static void subsetCouplingData
190  (
191  const fvMesh& mesh,
192  const labelList& pointMap,
193  const labelList& faceMap,
194  const labelList& cellMap,
195 
196  const labelList& oldDistribution,
197  const labelList& oldFaceOwner,
198  const labelList& oldFaceNeighbour,
199  const label oldInternalFaces,
200 
201  const labelList& sourceFace,
202  const labelList& sourceProc,
203  const labelList& sourcePatch,
204  const labelList& sourceNewProc,
205  const labelList& sourcePointMaster,
206 
207  labelList& subFace,
208  labelList& subProc,
209  labelList& subPatch,
210  labelList& subNewProc,
211  labelList& subPointMaster
212  );
213 
214  //- Find cells on mesh whose faceID/procID match the neighbour
215  // cell/proc of domainMesh. Store the matching face.
216  static void findCouples
217  (
218  const primitiveMesh&,
219  const labelList& sourceFace,
220  const labelList& sourceProc,
221  const labelList& sourcePatch,
222 
223  const label domain,
224  const primitiveMesh& domainMesh,
225  const labelList& domainFace,
226  const labelList& domainProc,
227  const labelList& domainPatch,
228 
229  labelList& masterCoupledFaces,
230  labelList& slaveCoupledFaces
231  );
232 
233  //- Map data on boundary faces to new mesh (resulting from adding
234  // two meshes)
235  static labelList mapBoundaryData
236  (
237  const primitiveMesh& mesh, // mesh after adding
238  const mapAddedPolyMesh& map,
239  const labelList& boundaryData0, // mesh before adding
240  const label nInternalFaces1,
241  const labelList& boundaryData1 // added mesh
242  );
243 
244  //- Map point data to new mesh (resulting from adding two meshes)
245  static labelList mapPointData
246  (
247  const primitiveMesh& mesh, // mesh after adding
248  const mapAddedPolyMesh& map,
249  const labelList& boundaryData0, // on mesh before adding
250  const labelList& boundaryData1 // on added mesh
251  );
252 
253  // Other
254 
255  //- Remove cells. Add all exposed faces to patch oldInternalPatchi
256  autoPtr<mapPolyMesh> doRemoveCells
257  (
258  const labelList& cellsToRemove,
259  const label oldInternalPatchi
260  );
261 
262  //- Add processor patches. Changes mesh and returns per neighbour
263  // proc the processor patchID.
264  void addProcPatches
265  (
266  const labelList&, // processor that neighbour is now on
267  const labelList&, // -1 or patch that face originated from
268  List<Map<label>>& procPatchID
269  );
270 
271  //- Get boundary faces to be repatched. Is -1 or new patchID
272  static labelList getBoundaryPatch
273  (
274  const labelList& neighbourNewProc, // new processor per b. face
275  const labelList& referPatchID, // -1 or original patch
276  const List<Map<label>>& procPatchID // patchID
277  );
278 
279  //- Send mesh and coupling data.
280  static void sendMesh
281  (
282  const label domain,
283  const fvMesh& mesh,
284  const wordList& pointZoneNames,
285  const wordList& facesZoneNames,
286  const wordList& cellZoneNames,
287  const labelList& sourceFace,
288  const labelList& sourceProc,
289  const labelList& sourcePatch,
290  const labelList& sourceNewProc,
291  const labelList& sourcePointMaster,
292  Ostream& toDomain
293  );
294  //- Send subset of fields
295  template<class GeoField>
296  static void sendFields
297  (
298  const label domain,
299  const wordList& fieldNames,
300  const fvMeshSubset&,
301  Ostream& toNbr
302  );
303 
304  //- Receive mesh. Opposite of sendMesh
305  static autoPtr<fvMesh> receiveMesh
306  (
307  const label domain,
308  const wordList& pointZoneNames,
309  const wordList& facesZoneNames,
310  const wordList& cellZoneNames,
311  const Time& runTime,
312  labelList& domainSourceFace,
313  labelList& domainSourceProc,
314  labelList& domainSourcePatch,
315  labelList& domainSourceNewProc,
316  labelList& domainSourcePointMaster,
317  Istream& fromNbr
318  );
319 
320  //- Receive fields. Opposite of sendFields
321  template<class GeoField>
322  static void receiveFields
323  (
324  const label domain,
325  const wordList& fieldNames,
326  typename GeoField::Mesh&,
328  const dictionary& fieldDicts
329  );
330 
331 
332 public:
333 
334  ClassName("fvMeshDistribute");
335 
336 
337  // Constructors
338 
339  //- Construct from mesh and absolute merge tolerance
340  fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
341 
342  //- Disallow default bitwise copy construction
343  fvMeshDistribute(const fvMeshDistribute&) = delete;
344 
345 
346  // Member Functions
347 
348  //- Helper function: count cells per processor in wanted distribution
349  static labelList countCells(const labelList&);
350 
351  //- Send cells to neighbours according to distribution
352  // (for every cell the new proc)
354 
355  // Debugging
356 
357  //- Print some info on coupling data
358  static void printCoupleInfo
359  (
360  const primitiveMesh&,
361  const labelList&,
362  const labelList&,
363  const labelList&,
364  const labelList&
365  );
366 
367  //- Print some field info
368  template<class GeoField>
369  static void printFieldInfo(const fvMesh&);
370 
371  //- Print some info on mesh.
372  static void printMeshInfo(const fvMesh&);
373 
374 
375  // Member Operators
376 
377  //- Disallow default bitwise assignment
378  void operator=(const fvMeshDistribute&) = delete;
379 };
380 
381 
382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383 
384 } // End namespace Foam
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 #ifdef NoRepository
389  #include "fvMeshDistributeTemplates.C"
390 #endif
391 
392 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
393 
394 #endif
395 
396 // ************************************************************************* //
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:158
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
engineTime & runTime
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
fvMeshDistribute(fvMesh &mesh, const scalar mergeTol)
Construct from mesh and absolute merge tolerance.
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:70
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:52
void operator=(const fvMeshDistribute &)=delete
Disallow default bitwise assignment.
static labelList countCells(const labelList &)
Helper function: count cells per processor in wanted distribution.
Namespace for OpenFOAM.