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-2022 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 polyDistributionMap;
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  // and return the number of fields
99  static label checkEqualWordList(const string&, const wordList&);
100 
101  //- Merge wordlists over all processors
102  static wordList mergeWordList(const wordList&);
103 
104 
105  // Patch handling
106 
107  //- Find internal patch to put exposed internal faces into
108  // Used when fields are present and require mapping
109  label findInternalPatch() const;
110 
111  //- Find non-empty patch to put exposed internal faces into
112  // Used when no fields require mapping
113  label findNonEmptyPatch() const;
114 
115  //- Save boundary fields
116  template<class Type, class Mesh>
117  void saveBoundaryFields
118  (
120  ) const;
121 
122  //- Map boundary fields
123  template<class Type, class Mesh>
124  void mapBoundaryFields
125  (
126  const polyTopoChangeMap& map,
128  );
129 
130  //- Set value of exposed patch faces
131  template<class Type>
132  void initMapExposedFaces(PtrList<Field<Type>>& iflds) const;
133 
134  //- Set value of exposed patch faces
135  template<class Type>
136  void mapExposedFaces
137  (
138  const polyTopoChangeMap& map,
139  const PtrList<Field<Type>>& oldFlds
140  );
141 
142  //- Correct coupled patch fields
143  template<class GeoField>
144  void correctCoupledPatchFields();
145 
146  //- Delete all processor patches. Move any processor faces into
147  // destinationPatch
148  autoPtr<polyTopoChangeMap> deleteProcPatches
149  (
150  const label destinationPatch
151  );
152 
153  //- Repatch the mesh. This is only necessary for the proc
154  // boundary faces. newPatchID is over all boundary faces: -1 or
155  // new patchID. constructFaceMap is being adapted for the
156  // possible new face position (since proc faces get automatically
157  // matched)
159  (
160  const labelList& newPatchID,
161  labelListList& constructFaceMap
162  );
163 
164  //- Merge any local points that were remotely coupled.
165  // constructPointMap is adapted for the new point labels.
166  //
167  // Detect shared points. Need processor patches to be present.
168  // Background: when adding bits of mesh one can get points which
169  // share the same position but are only detectable to be
170  // topologically the same point when doing parallel analysis. This
171  // routine will merge those points.
172  autoPtr<polyTopoChangeMap> mergeSharedPoints
173  (
174  const labelList& pointToGlobalMaster,
175  labelListList& constructPointMap
176  );
177 
178 
179  // Coupling information
180 
181  //- Construct the local environment of all boundary faces.
182  void getCouplingData
183  (
184  const labelList& distribution,
185  labelList& sourceFace,
186  labelList& sourceProc,
187  labelList& sourcePatch,
188  labelList& sourceNbrPatch,
189  labelList& sourceNewProc,
190  labelList& sourcePointMaster
191  ) const;
192 
193  // Subset the neighbourCell/neighbourProc fields
194  static void subsetCouplingData
195  (
196  const fvMesh& mesh,
197  const labelList& pointMap,
198  const labelList& faceMap,
199  const labelList& cellMap,
200 
201  const labelList& oldDistribution,
202  const labelList& oldFaceOwner,
203  const labelList& oldFaceNeighbour,
204  const label oldInternalFaces,
205 
206  const labelList& sourceFace,
207  const labelList& sourceProc,
208  const labelList& sourcePatch,
209  const labelList& sourceNbrPatch,
210  const labelList& sourceNewProc,
211  const labelList& sourcePointMaster,
212 
213  labelList& subFace,
214  labelList& subProc,
215  labelList& subPatch,
216  labelList& subNbrPatch,
217  labelList& subNewProc,
218  labelList& subPointMaster
219  );
220 
221  //- Find cells on mesh whose faceID/procID match the neighbour
222  // cell/proc of domainMesh. Store the matching face.
223  static void findCouples
224  (
225  const primitiveMesh&,
226  const labelList& sourceFace,
227  const labelList& sourceProc,
228  const labelList& sourcePatch,
229 
230  const label domain,
231  const primitiveMesh& domainMesh,
232  const labelList& domainFace,
233  const labelList& domainProc,
234  const labelList& domainPatch,
235 
236  labelList& masterCoupledFaces,
237  labelList& slaveCoupledFaces
238  );
239 
240  //- Map data on boundary faces to new mesh (resulting from adding
241  // two meshes)
242  static labelList mapBoundaryData
243  (
244  const primitiveMesh& mesh, // mesh after adding
245  const mapAddedPolyMesh& map,
246  const labelList& boundaryData0, // mesh before adding
247  const label nInternalFaces1,
248  const labelList& boundaryData1 // added mesh
249  );
250 
251  //- Map point data to new mesh (resulting from adding two meshes)
252  static labelList mapPointData
253  (
254  const primitiveMesh& mesh, // mesh after adding
255  const mapAddedPolyMesh& map,
256  const labelList& boundaryData0, // on mesh before adding
257  const labelList& boundaryData1 // on added mesh
258  );
259 
260  // Other
261 
262  //- Remove cells. Add all exposed faces to patch oldInternalPatchi
263  autoPtr<polyTopoChangeMap> doRemoveCells
264  (
265  const labelList& cellsToRemove,
266  const label oldInternalPatchi
267  );
268 
269  //- Add processor patches. Changes mesh and returns per neighbour
270  // proc the processor patchID.
271  void addProcPatches
272  (
273  const labelList& nbrProc, // Processor that neighbour
274  // is now on
275  const labelList& referPatchID, // Original patch ID (or -1)
276  const labelList& referNbrPatchID, // Original neighbour patch
277  // ID (or -1)
278  List<Map<label>>& procPatchID
279  );
280 
281  //- Get boundary faces to be repatched. Is -1 or new patchID
282  static labelList getBoundaryPatch
283  (
284  const labelList& neighbourNewProc, // new processor per b. face
285  const labelList& referPatchID, // -1 or original patch
286  const List<Map<label>>& procPatchID // patchID
287  );
288 
289  //- Send mesh and coupling data.
290  static void sendMesh
291  (
292  const label domain,
293  const fvMesh& mesh,
294  const wordList& pointZoneNames,
295  const wordList& facesZoneNames,
296  const wordList& cellZoneNames,
297  const labelList& sourceFace,
298  const labelList& sourceProc,
299  const labelList& sourcePatch,
300  const labelList& sourceNbrPatch,
301  const labelList& sourceNewProc,
302  const labelList& sourcePointMaster,
303  Ostream& toDomain
304  );
305 
306  //- Send subset of fields
307  template<class GeoField>
308  static void sendFields
309  (
310  const label domain,
311  const wordList& fieldNames,
312  const fvMeshSubset&,
313  Ostream& toNbr
314  );
315 
316  //- Receive mesh. Opposite of sendMesh
317  static autoPtr<fvMesh> receiveMesh
318  (
319  const label domain,
320  const wordList& pointZoneNames,
321  const wordList& facesZoneNames,
322  const wordList& cellZoneNames,
323  const Time& runTime,
324  labelList& domainSourceFace,
325  labelList& domainSourceProc,
326  labelList& domainSourcePatch,
327  labelList& domainSourceNbrPatch,
328  labelList& domainSourceNewProc,
329  labelList& domainSourcePointMaster,
330  Istream& fromNbr
331  );
332 
333  //- Receive fields. Opposite of sendFields
334  template<class GeoField>
335  static void receiveFields
336  (
337  const label domain,
338  const wordList& fieldNames,
339  typename GeoField::Mesh&,
341  const dictionary& fieldDicts
342  );
343 
344 
345 public:
346 
347  ClassName("fvMeshDistribute");
348 
349 
350  // Constructors
351 
352  //- Construct from mesh
353  fvMeshDistribute(fvMesh& mesh);
354 
355  //- Disallow default bitwise copy construction
356  fvMeshDistribute(const fvMeshDistribute&) = delete;
357 
358 
359  // Member Functions
360 
361  //- Helper function: count cells per processor in wanted distribution
362  static labelList countCells(const labelList&);
363 
364  //- Send cells to neighbours according to distribution
365  // (for every cell the new proc)
367 
368  // Debugging
369 
370  //- Print some info on coupling data
371  static void printCoupleInfo
372  (
373  const primitiveMesh&,
374  const labelList&,
375  const labelList&,
376  const labelList&,
377  const labelList&
378  );
379 
380  //- Print some field info
381  template<class GeoField>
382  static void printFieldInfo(const fvMesh&);
383 
384  //- Print some info on mesh.
385  static void printMeshInfo(const fvMesh&);
386 
387 
388  // Member Operators
389 
390  //- Disallow default bitwise assignment
391  void operator=(const fvMeshDistribute&) = delete;
392 };
393 
394 
395 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
396 
397 } // End namespace Foam
398 
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
400 
401 #ifdef NoRepository
402  #include "fvMeshDistributeTemplates.C"
403 #endif
404 
405 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406 
407 #endif
408 
409 // ************************************************************************* //
Generic field type.
Definition: FieldField.H:77
Pre-declare SubField and related Field type.
Definition: Field.H:82
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Accumulating histogram of values. Specified bin resolution automatic generation of bins.
Definition: distribution.H:61
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
ClassName("fvMeshDistribute")
static void printCoupleInfo(const primitiveMesh &, const labelList &, const labelList &, const labelList &, const labelList &)
Print some info on coupling data.
fvMeshDistribute(fvMesh &mesh)
Construct from mesh.
void operator=(const fvMeshDistribute &)=delete
Disallow default bitwise assignment.
autoPtr< polyDistributionMap > distribute(const labelList &dist)
Send cells to neighbours according to distribution.
static void printMeshInfo(const fvMesh &)
Print some info on mesh.
static labelList countCells(const labelList &)
Helper function: count cells per processor in wanted distribution.
static void printFieldInfo(const fvMesh &)
Print some field info.
Post-processing mesh subset tool. Given the original mesh and the list of selected cells,...
Definition: fvMeshSubset.H:74
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
Class containing mesh-to-mesh mapping information after a mesh addition where we add a mesh ('added m...
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
static List< word > fieldNames
Definition: globalFoam.H:46
Namespace for OpenFOAM.
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
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)