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-2021 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 "fvMeshSubset.H"
56 #include "FieldField.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 
79  // Private Member Functions
80 
81  static void inplaceRenumberWithFlip
82  (
83  const labelUList& oldToNew,
84  const bool oldToNewHasFlip,
85  const bool lstHasFlip,
86  labelUList& lst
87  );
88 
89  //- Find indices with value
90  static labelList select
91  (
92  const bool selectEqual,
93  const labelList& values,
94  const label value
95  );
96 
97  //- Check all procs have same names and in exactly same order.
98  static void checkEqualWordList(const string&, const wordList&);
99 
100  //- Merge wordlists over all processors
101  static wordList mergeWordList(const wordList&);
102 
103 
104  // Patch handling
105 
106  //- Find patch to put exposed internal faces into
107  label findInternalPatch() const;
108 
109  //- Save boundary fields
110  template<class T, class Mesh>
111  void saveBoundaryFields
112  (
114  ) const;
115 
116  //- Map boundary fields
117  template<class T, class Mesh>
118  void mapBoundaryFields
119  (
120  const mapPolyMesh& map,
121  const PtrList<FieldField<fvsPatchField, T>>& oldBflds
122  );
123 
124  //- Save internal fields of surfaceFields
125  template<class T>
126  void saveInternalFields(PtrList<Field<T>>& iflds) const;
127 
128  //- Set value of patch faces resulting from internal faces
129  template<class T>
130  void mapExposedFaces
131  (
132  const mapPolyMesh& map,
133  const PtrList<Field<T>>& oldFlds
134  );
135 
136  //- Correct processor patch fields
137  template<class GeoField>
138  void correctProcessorPatchFields();
139 
140  //- Delete all processor patches. Move any processor faces into
141  // patchi.
142  autoPtr<mapPolyMesh> deleteProcPatches(const label patchi);
143 
144  //- Repatch the mesh. This is only necessary for the proc
145  // boundary faces. newPatchID is over all boundary faces: -1 or
146  // new patchID. constructFaceMap is being adapted for the
147  // possible new face position (since proc faces get automatically
148  // matched)
149  autoPtr<mapPolyMesh> repatch
150  (
151  const labelList& newPatchID,
152  labelListList& constructFaceMap
153  );
154 
155  //- Merge any local points that were remotely coupled.
156  // constructPointMap is adapted for the new point labels.
157  autoPtr<mapPolyMesh> mergeSharedPoints
158  (
159  const labelList& pointToGlobalMaster,
160  labelListList& constructPointMap
161  );
162 
163 
164  // Coupling information
165 
166  //- Construct the local environment of all boundary faces.
167  void getCouplingData
168  (
169  const labelList& distribution,
170  labelList& sourceFace,
171  labelList& sourceProc,
172  labelList& sourcePatch,
173  labelList& sourceNbrPatch,
174  labelList& sourceNewProc,
175  labelList& sourcePointMaster
176  ) const;
177 
178  // Subset the neighbourCell/neighbourProc fields
179  static void subsetCouplingData
180  (
181  const fvMesh& mesh,
182  const labelList& pointMap,
183  const labelList& faceMap,
184  const labelList& cellMap,
185 
186  const labelList& oldDistribution,
187  const labelList& oldFaceOwner,
188  const labelList& oldFaceNeighbour,
189  const label oldInternalFaces,
190 
191  const labelList& sourceFace,
192  const labelList& sourceProc,
193  const labelList& sourcePatch,
194  const labelList& sourceNbrPatch,
195  const labelList& sourceNewProc,
196  const labelList& sourcePointMaster,
197 
198  labelList& subFace,
199  labelList& subProc,
200  labelList& subPatch,
201  labelList& subNbrPatch,
202  labelList& subNewProc,
203  labelList& subPointMaster
204  );
205 
206  //- Find cells on mesh whose faceID/procID match the neighbour
207  // cell/proc of domainMesh. Store the matching face.
208  static void findCouples
209  (
210  const primitiveMesh&,
211  const labelList& sourceFace,
212  const labelList& sourceProc,
213  const labelList& sourcePatch,
214 
215  const label domain,
216  const primitiveMesh& domainMesh,
217  const labelList& domainFace,
218  const labelList& domainProc,
219  const labelList& domainPatch,
220 
221  labelList& masterCoupledFaces,
222  labelList& slaveCoupledFaces
223  );
224 
225  //- Map data on boundary faces to new mesh (resulting from adding
226  // two meshes)
227  static labelList mapBoundaryData
228  (
229  const primitiveMesh& mesh, // mesh after adding
230  const mapAddedPolyMesh& map,
231  const labelList& boundaryData0, // mesh before adding
232  const label nInternalFaces1,
233  const labelList& boundaryData1 // added mesh
234  );
235 
236  //- Map point data to new mesh (resulting from adding two meshes)
237  static labelList mapPointData
238  (
239  const primitiveMesh& mesh, // mesh after adding
240  const mapAddedPolyMesh& map,
241  const labelList& boundaryData0, // on mesh before adding
242  const labelList& boundaryData1 // on added mesh
243  );
244 
245  // Other
246 
247  //- Remove cells. Add all exposed faces to patch oldInternalPatchi
248  autoPtr<mapPolyMesh> doRemoveCells
249  (
250  const labelList& cellsToRemove,
251  const label oldInternalPatchi
252  );
253 
254  //- Add processor patches. Changes mesh and returns per neighbour
255  // proc the processor patchID.
256  void addProcPatches
257  (
258  const labelList& nbrProc, // Processor that neighbour
259  // is now on
260  const labelList& referPatchID, // Original patch ID (or -1)
261  const labelList& referNbrPatchID, // Original neighbour patch
262  // ID (or -1)
263  List<Map<label>>& procPatchID
264  );
265 
266  //- Get boundary faces to be repatched. Is -1 or new patchID
267  static labelList getBoundaryPatch
268  (
269  const labelList& neighbourNewProc, // new processor per b. face
270  const labelList& referPatchID, // -1 or original patch
271  const List<Map<label>>& procPatchID // patchID
272  );
273 
274  //- Send mesh and coupling data.
275  static void sendMesh
276  (
277  const label domain,
278  const fvMesh& mesh,
279  const wordList& pointZoneNames,
280  const wordList& facesZoneNames,
281  const wordList& cellZoneNames,
282  const labelList& sourceFace,
283  const labelList& sourceProc,
284  const labelList& sourcePatch,
285  const labelList& sourceNbrPatch,
286  const labelList& sourceNewProc,
287  const labelList& sourcePointMaster,
288  Ostream& toDomain
289  );
290  //- Send subset of fields
291  template<class GeoField>
292  static void sendFields
293  (
294  const label domain,
295  const wordList& fieldNames,
296  const fvMeshSubset&,
297  Ostream& toNbr
298  );
299 
300  //- Receive mesh. Opposite of sendMesh
301  static autoPtr<fvMesh> receiveMesh
302  (
303  const label domain,
304  const wordList& pointZoneNames,
305  const wordList& facesZoneNames,
306  const wordList& cellZoneNames,
307  const Time& runTime,
308  labelList& domainSourceFace,
309  labelList& domainSourceProc,
310  labelList& domainSourcePatch,
311  labelList& domainSourceNbrPatch,
312  labelList& domainSourceNewProc,
313  labelList& domainSourcePointMaster,
314  Istream& fromNbr
315  );
316 
317  //- Receive fields. Opposite of sendFields
318  template<class GeoField>
319  static void receiveFields
320  (
321  const label domain,
322  const wordList& fieldNames,
323  typename GeoField::Mesh&,
325  const dictionary& fieldDicts
326  );
327 
328 
329 public:
330 
331  ClassName("fvMeshDistribute");
332 
333 
334  // Constructors
335 
336  //- Construct from mesh
337  fvMeshDistribute(fvMesh& mesh);
338 
339  //- Disallow default bitwise copy construction
340  fvMeshDistribute(const fvMeshDistribute&) = delete;
341 
342 
343  // Member Functions
344 
345  //- Helper function: count cells per processor in wanted distribution
346  static labelList countCells(const labelList&);
347 
348  //- Send cells to neighbours according to distribution
349  // (for every cell the new proc)
351 
352  // Debugging
353 
354  //- Print some info on coupling data
355  static void printCoupleInfo
356  (
357  const primitiveMesh&,
358  const labelList&,
359  const labelList&,
360  const labelList&,
361  const labelList&
362  );
363 
364  //- Print some field info
365  template<class GeoField>
366  static void printFieldInfo(const fvMesh&);
367 
368  //- Print some info on mesh.
369  static void printMeshInfo(const fvMesh&);
370 
371 
372  // Member Operators
373 
374  //- Disallow default bitwise assignment
375  void operator=(const fvMeshDistribute&) = delete;
376 };
377 
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 } // End namespace Foam
382 
383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 
385 #ifdef NoRepository
386  #include "fvMeshDistributeTemplates.C"
387 #endif
388 
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390 
391 #endif
392 
393 // ************************************************************************* //
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
fvMeshDistribute(fvMesh &mesh)
Construct from mesh.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
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
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:54
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.