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-2023 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  wordList fieldNames(const word& typeName, label& nFields) const;
98 
99  //- Check all procs have same names and in exactly same order
100  // and return the number of fields
101  static label checkEqualWordList(const word& typeName, const wordList&);
102 
103  //- Merge wordlists over all processors
104  static wordList mergeWordList(const wordList&);
105 
106 
107  // Patch handling
108 
109  //- Find internal patch to put exposed internal faces into
110  // Used when fields are present and require mapping
111  label findInternalPatch() const;
112 
113  //- Find non-empty patch to put exposed internal faces into
114  // Used when no fields require mapping
115  label findNonEmptyPatch() const;
116 
117  //- Save boundary fields
118  template<class Type, class Mesh>
119  void saveBoundaryFields
120  (
122  ) const;
123 
124  //- Map boundary fields
125  template<class Type, class Mesh>
126  void mapBoundaryFields
127  (
128  const polyTopoChangeMap& map,
130  );
131 
132  //- Set value of exposed patch faces
133  template<class Type>
134  void initMapExposedFaces(PtrList<Field<Type>>& iflds) const;
135 
136  //- Set value of exposed patch faces
137  template<class Type>
138  void mapExposedFaces
139  (
140  const polyTopoChangeMap& map,
141  const PtrList<Field<Type>>& oldFlds
142  );
143 
144  //- Correct coupled patch fields
145  template<class GeoField>
146  void correctCoupledPatchFields();
147 
148  //- Delete all processor patches. Move any processor faces into
149  // destinationPatch
150  autoPtr<polyTopoChangeMap> deleteProcPatches
151  (
152  const label destinationPatch
153  );
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)
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  //
169  // Detect shared points. Need processor patches to be present.
170  // Background: when adding bits of mesh one can get points which
171  // share the same position but are only detectable to be
172  // topologically the same point when doing parallel analysis. This
173  // routine will merge those points.
174  autoPtr<polyTopoChangeMap> mergeSharedPoints
175  (
176  const labelList& pointToGlobalMaster,
177  labelListList& constructPointMap
178  );
179 
180 
181  // Coupling information
182 
183  //- Construct the local environment of all boundary faces.
184  void getCouplingData
185  (
186  const labelList& distribution,
187  labelList& sourceFace,
188  labelList& sourceProc,
189  labelList& sourcePatch,
190  labelList& sourceNbrPatch,
191  labelList& sourceNewProc,
192  labelList& sourcePointMaster
193  ) const;
194 
195  // Subset the neighbourCell/neighbourProc fields
196  static void subsetCouplingData
197  (
198  const fvMesh& mesh,
199  const labelList& pointMap,
200  const labelList& faceMap,
201  const labelList& cellMap,
202 
203  const labelList& oldDistribution,
204  const labelList& oldFaceOwner,
205  const labelList& oldFaceNeighbour,
206  const label oldInternalFaces,
207 
208  const labelList& sourceFace,
209  const labelList& sourceProc,
210  const labelList& sourcePatch,
211  const labelList& sourceNbrPatch,
212  const labelList& sourceNewProc,
213  const labelList& sourcePointMaster,
214 
215  labelList& subFace,
216  labelList& subProc,
217  labelList& subPatch,
218  labelList& subNbrPatch,
219  labelList& subNewProc,
220  labelList& subPointMaster
221  );
222 
223  //- Find cells on mesh whose faceID/procID match the neighbour
224  // cell/proc of domainMesh. Store the matching face.
225  static void findCouples
226  (
227  const primitiveMesh&,
228  const labelList& sourceFace,
229  const labelList& sourceProc,
230  const labelList& sourcePatch,
231 
232  const label domain,
233  const primitiveMesh& domainMesh,
234  const labelList& domainFace,
235  const labelList& domainProc,
236  const labelList& domainPatch,
237 
238  labelList& masterCoupledFaces,
239  labelList& slaveCoupledFaces
240  );
241 
242  //- Map data on boundary faces to new mesh (resulting from adding
243  // two meshes)
244  static labelList mapBoundaryData
245  (
246  const primitiveMesh& mesh, // mesh after adding
247  const mapAddedPolyMesh& map,
248  const labelList& boundaryData0, // mesh before adding
249  const label nInternalFaces1,
250  const labelList& boundaryData1 // added mesh
251  );
252 
253  //- Map point data to new mesh (resulting from adding two meshes)
254  static labelList mapPointData
255  (
256  const primitiveMesh& mesh, // mesh after adding
257  const mapAddedPolyMesh& map,
258  const labelList& boundaryData0, // on mesh before adding
259  const labelList& boundaryData1 // on added mesh
260  );
261 
262  // Other
263 
264  //- Remove cells. Add all exposed faces to patch oldInternalPatchi
265  autoPtr<polyTopoChangeMap> doRemoveCells
266  (
267  const labelList& cellsToRemove,
268  const label oldInternalPatchi
269  );
270 
271  //- Add processor patches. Changes mesh and returns per neighbour
272  // proc the processor patchID.
273  void addProcPatches
274  (
275  const labelList& nbrProc, // Processor that neighbour
276  // is now on
277  const labelList& referPatchID, // Original patch ID (or -1)
278  const labelList& referNbrPatchID, // Original neighbour patch
279  // ID (or -1)
280  List<Map<label>>& procPatchID
281  );
282 
283  //- Get boundary faces to be repatched. Is -1 or new patchID
284  static labelList getBoundaryPatch
285  (
286  const labelList& neighbourNewProc, // new processor per b. face
287  const labelList& referPatchID, // -1 or original patch
288  const List<Map<label>>& procPatchID // patchID
289  );
290 
291  //- Send mesh and coupling data.
292  static void sendMesh
293  (
294  const label domain,
295  const fvMesh& mesh,
296  const wordList& pointZoneNames,
297  const wordList& facesZoneNames,
298  const wordList& cellZoneNames,
299  const labelList& sourceFace,
300  const labelList& sourceProc,
301  const labelList& sourcePatch,
302  const labelList& sourceNbrPatch,
303  const labelList& sourceNewProc,
304  const labelList& sourcePointMaster,
305  Ostream& toDomain
306  );
307 
308  //- Send subset of fields
309  template<class GeoField>
310  static void sendFields
311  (
312  const label domain,
313  const wordList& fieldNames,
314  const fvMeshSubset&,
315  Ostream& toNbr
316  );
317 
318  //- Receive mesh. Opposite of sendMesh
319  static autoPtr<fvMesh> receiveMesh
320  (
321  const label domain,
322  const wordList& pointZoneNames,
323  const wordList& facesZoneNames,
324  const wordList& cellZoneNames,
325  const Time& runTime,
326  labelList& domainSourceFace,
327  labelList& domainSourceProc,
328  labelList& domainSourcePatch,
329  labelList& domainSourceNbrPatch,
330  labelList& domainSourceNewProc,
331  labelList& domainSourcePointMaster,
332  Istream& fromNbr
333  );
334 
335  //- Receive fields. Opposite of sendFields
336  template<class GeoField>
337  static void receiveFields
338  (
339  const label domain,
340  const wordList& fieldNames,
341  typename GeoField::Mesh&,
343  const dictionary& fieldDicts
344  );
345 
346 
347 public:
348 
349  ClassName("fvMeshDistribute");
350 
351 
352  // Constructors
353 
354  //- Construct from mesh
355  fvMeshDistribute(fvMesh& mesh);
356 
357  //- Disallow default bitwise copy construction
358  fvMeshDistribute(const fvMeshDistribute&) = delete;
359 
360 
361  // Member Functions
362 
363  //- Helper function: count cells per processor in wanted distribution
364  static labelList countCells(const labelList&);
365 
366  //- Send cells to neighbours according to distribution
367  // (for every cell the new proc)
369 
370  // Debugging
371 
372  //- Print some info on coupling data
373  static void printCoupleInfo
374  (
375  const primitiveMesh&,
376  const labelList&,
377  const labelList&,
378  const labelList&,
379  const labelList&
380  );
381 
382  //- Print some field info
383  template<class GeoField>
384  static void printFieldInfo(const fvMesh&);
385 
386  //- Print some info on mesh.
387  static void printMeshInfo(const fvMesh&);
388 
389 
390  // Member Operators
391 
392  //- Disallow default bitwise assignment
393  void operator=(const fvMeshDistribute&) = delete;
394 };
395 
396 
397 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
398 
399 } // End namespace Foam
400 
401 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
402 
403 #ifdef NoRepository
404  #include "fvMeshDistributeTemplates.C"
405 #endif
406 
407 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
408 
409 #endif
410 
411 // ************************************************************************* //
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
A class for handling words, derived from string.
Definition: word.H:62
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)