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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2018 OpenFOAM Foundation
9  Copyright (C) 2016-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::fvMeshDistribute
29 
30 Description
31  Sends/receives parts of mesh+fvfields to neighbouring processors.
32  Used in load balancing.
33 
34  Input is per local cell the processor it should move to. Moves meshes
35  and volFields/surfaceFields and returns map which can be used to
36  distribute other.
37 
38  Notes:
39  - does not handle cyclics. Will probably handle separated proc patches.
40  - if all cells move off processor also all its processor patches will
41  get deleted so comms might be screwed up (since e.g. globalMeshData
42  expects procPatches on all)
43  - initial mesh has to have procPatches last and all normal patches common
44  to all processors and in the same order. This is checked.
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 Declarations
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  //- Merge wordlists over all processors
98  static wordList mergeWordList(const wordList&);
99 
100  //- Reorder zones according to names
101  template<class ZoneType, class ZoneMesh>
102  void reorderZones
103  (
104  const wordList& zoneNames,
105  ZoneMesh& zones
106  );
107 
108 
109  // Patch handling
110 
111  //- Find patch to put exposed faces into.
112  label findNonEmptyPatch() const;
113 
114  //- Save boundary fields
115  template<class T, class Mesh>
116  void saveBoundaryFields
117  (
119  ) const;
120 
121  //- Map boundary fields
122  template<class T, class Mesh>
123  void mapBoundaryFields
124  (
125  const mapPolyMesh& map,
126  const PtrList<FieldField<fvsPatchField, T>>& oldBflds
127  );
128 
129  //- Save internal fields of surfaceFields
130  template<class T>
131  void saveInternalFields(PtrList<Field<T>>& iflds) const;
132 
133  //- Set value of patch faces resulting from internal faces
134  template<class T>
135  void mapExposedFaces
136  (
137  const mapPolyMesh& map,
138  const PtrList<Field<T>>& oldFlds
139  );
140 
141  //- Init patch fields of certain type
142  template<class GeoField, class PatchFieldType>
143  void initPatchFields
144  (
145  const typename GeoField::value_type& initVal
146  );
147 
149  //template<class GeoField>
150  //void correctBoundaryConditions();
151 
152  //- Delete all processor patches. Move any processor faces into
153  // patchi.
154  autoPtr<mapPolyMesh> deleteProcPatches(const label patchi);
155 
156  //- Repatch the mesh. This is only necessary for the proc
157  // boundary faces. newPatchID is over all boundary faces: -1 or
158  // new patchID. constructFaceMap is being adapted for the
159  // possible new face position (since proc faces get automatically
160  // matched)
161  autoPtr<mapPolyMesh> repatch
162  (
163  const labelList& newPatchID,
164  labelListList& constructFaceMap
165  );
166 
167  //- Merge any local points that were remotely coupled.
168  // constructPointMap is adapted for the new point labels.
169  autoPtr<mapPolyMesh> mergeSharedPoints
170  (
171  const labelList& pointToGlobalMaster,
172  labelListList& constructPointMap
173  );
174 
175 
176  // Coupling information
177 
178  //- Construct the local environment of all boundary faces.
179  void getCouplingData
180  (
181  const labelList& distribution,
182  labelList& sourceFace,
183  labelList& sourceProc,
184  labelList& sourcePatch,
185  labelList& sourceNewProc,
186  labelList& sourcePointMaster
187  ) const;
188 
189  // Subset the neighbourCell/neighbourProc fields
190  static void subsetCouplingData
191  (
192  const fvMesh& mesh,
193  const labelList& pointMap,
194  const labelList& faceMap,
195  const labelList& cellMap,
196 
197  const labelList& oldDistribution,
198  const labelList& oldFaceOwner,
199  const labelList& oldFaceNeighbour,
200  const label oldInternalFaces,
201 
202  const labelList& sourceFace,
203  const labelList& sourceProc,
204  const labelList& sourcePatch,
205  const labelList& sourceNewProc,
206  const labelList& sourcePointMaster,
207 
208  labelList& subFace,
209  labelList& subProc,
210  labelList& subPatch,
211  labelList& subNewProc,
212  labelList& subPointMaster
213  );
214 
215  //- Find cells on mesh whose faceID/procID match the neighbour
216  // cell/proc of domainMesh. Store the matching face.
217  static void findCouples
218  (
219  const primitiveMesh&,
220  const labelList& sourceFace,
221  const labelList& sourceProc,
222  const labelList& sourcePatch,
223 
224  const label domain,
225  const primitiveMesh& domainMesh,
226  const labelList& domainFace,
227  const labelList& domainProc,
228  const labelList& domainPatch,
229 
230  labelList& masterCoupledFaces,
231  labelList& slaveCoupledFaces
232  );
233 
234  //- Find cells on mesh whose faceID/procID match the neighbour
235  // cell/proc of domainMesh. Store the matching face pairs
236  static void findCouples
237  (
238  const UPtrList<polyMesh>& meshes,
239  const PtrList<labelList>& domainSourceFaces,
240  const PtrList<labelList>& domainSourceProcs,
241  const PtrList<labelList>& domainSourcePatchs,
242 
243  labelListList& localBoundaryFace,
244  labelListList& remoteFaceProc,
245  labelListList& remoteBoundaryFace
246  );
247 
248  //- Map data on boundary faces to new mesh (resulting from adding
249  // two meshes)
250  static labelList mapBoundaryData
251  (
252  const primitiveMesh& mesh, // mesh after adding
253  const mapAddedPolyMesh& map,
254  const labelList& boundaryData0, // mesh before adding
255  const label nInternalFaces1,
256  const labelList& boundaryData1 // added mesh
257  );
258 
259  //- Map point data to new mesh (resulting from adding two meshes)
260  static labelList mapPointData
261  (
262  const primitiveMesh& mesh, // mesh after adding
263  const mapAddedPolyMesh& map,
264  const labelList& boundaryData0, // on mesh before adding
265  const labelList& boundaryData1 // on added mesh
266  );
267 
268  // Other
269 
270  //- Remove cells. Add all exposed faces to patch oldInternalPatchi
271  autoPtr<mapPolyMesh> doRemoveCells
272  (
273  const labelList& cellsToRemove,
274  const label oldInternalPatchi
275  );
276 
277  //- Add processor patches. Changes mesh and returns per neighbour
278  // proc the processor patchID.
279  void addProcPatches
280  (
281  const labelList&, // processor that neighbour is now on
282  const labelList&, // -1 or patch that face originated from
283  List<Map<label>>& procPatchID
284  );
285 
286  //- Get boundary faces to be repatched. Is -1 or new patchID
287  static labelList getBoundaryPatch
288  (
289  const labelList& neighbourNewProc, // new processor per b. face
290  const labelList& referPatchID, // -1 or original patch
291  const List<Map<label>>& procPatchID // patchID
292  );
293 
294  //- Send mesh and coupling data.
295  static void sendMesh
296  (
297  const label domain,
298  const fvMesh& mesh,
299  const wordList& pointZoneNames,
300  const wordList& facesZoneNames,
301  const wordList& cellZoneNames,
302  const labelList& sourceFace,
303  const labelList& sourceProc,
304  const labelList& sourcePatch,
305  const labelList& sourceNewProc,
306  const labelList& sourcePointMaster,
307  Ostream& toDomain
308  );
309 
310  //- Get sorted names of GeoField, optionally test
311  //- that all procs have the same names.
312  template<class GeoField>
313  static void getFieldNames
314  (
315  const fvMesh& mesh,
316  HashTable<wordList>& allFieldNames,
317  const word& excludeType = word::null,
318  const bool syncPar = true
319  );
320 
321  //- Send subset of fields
322  template<class GeoField>
323  static void sendFields
324  (
325  const label domain,
326  const HashTable<wordList>& allFieldNames,
327  const fvMeshSubset& subsetter,
328  Ostream&
329  );
330 
331  //- Receive mesh. Opposite of sendMesh
332  static autoPtr<fvMesh> receiveMesh
333  (
334  const label domain,
335  const wordList& pointZoneNames,
336  const wordList& facesZoneNames,
337  const wordList& cellZoneNames,
338  const Time& runTime,
339  labelList& domainSourceFace,
340  labelList& domainSourceProc,
341  labelList& domainSourcePatch,
342  labelList& domainSourceNewProc,
343  labelList& domainSourcePointMaster,
344  Istream& fromNbr
345  );
346 
347  //- Receive fields. Opposite of sendFields
348  template<class GeoField>
349  static void receiveFields
350  (
351  const label domain,
352  const HashTable<wordList>& allFieldNames,
353  fvMesh& mesh,
355  const dictionary& allFieldsDict
356  );
357 
358  //- No copy construct
359  fvMeshDistribute(const fvMeshDistribute&) = delete;
360 
361  //- No copy assignment
362  void operator=(const fvMeshDistribute&) = delete;
363 
364 public:
365 
366  ClassName("fvMeshDistribute");
367 
368 
369  // Constructors
370 
371  //- Construct from mesh
372  explicit fvMeshDistribute(fvMesh& mesh);
373 
374 
375  // Member Functions
376 
377  //- Helper function: count cells per processor in wanted distribution
378  static labelList countCells(const labelList&);
379 
380  //- Send cells to neighbours according to distribution
381  // (for every cell the new proc)
383 
384  // Debugging
385 
386  //- Print some info on coupling data
387  static void printCoupleInfo
388  (
389  const primitiveMesh&,
390  const labelList&,
391  const labelList&,
392  const labelList&,
393  const labelList&
394  );
395 
396  //- Print some field info
397  template<class GeoField>
398  static void printIntFieldInfo(const fvMesh&);
399 
400  //- Print some field info
401  template<class GeoField>
402  static void printFieldInfo(const fvMesh&);
403 
404  //- Print some info on mesh.
405  static void printMeshInfo(const fvMesh&);
406 
407  //- Generate a test field on faces
409 
410  //- Check whether field consistent with face orientation
411  static void testField(const surfaceScalarField&);
412 };
413 
414 
415 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
416 
417 } // End namespace Foam
418 
419 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
420 
421 #ifdef NoRepository
422  #include "fvMeshDistributeTemplates.C"
423 #endif
424 
425 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
426 
427 #endif
428 
429 // ************************************************************************* //
fvMeshDistributeTemplates.C
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::fvMeshDistribute::countCells
static labelList countCells(const labelList &)
Helper function: count cells per processor in wanted distribution.
Definition: fvMeshDistribute.C:1852
Foam::distribution
Accumulating histogram of values. Specified bin resolution automatic generation of bins.
Definition: distribution.H:61
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::FieldField
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:53
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::fvMeshSubset
Given the original mesh and the list of selected cells, it creates the mesh consisting only of the de...
Definition: fvMeshSubset.H:73
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
fvMeshSubset.H
Foam::fvMeshDistribute::printFieldInfo
static void printFieldInfo(const fvMesh &)
Print some field info.
Definition: fvMeshDistributeTemplates.C:109
Foam::Map< label >
Foam::fvMeshDistribute::ClassName
ClassName("fvMeshDistribute")
Foam::fvMeshDistribute::generateTestField
static tmp< surfaceScalarField > generateTestField(const fvMesh &)
Generate a test field on faces.
Definition: fvMeshDistribute.C:405
Foam::Field< T >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
meshes
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
Field.H
Foam::ZoneMesh
A list of mesh zones.
Definition: cellZoneMeshFwd.H:44
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:62
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::HashTable< wordList >
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::fvMeshDistribute::printMeshInfo
static void printMeshInfo(const fvMesh &)
Print some info on mesh.
Definition: fvMeshDistribute.C:225
Foam::List< label >
Foam::fvMeshDistribute::printCoupleInfo
static void printCoupleInfo(const primitiveMesh &, const labelList &, const labelList &, const labelList &, const labelList &)
Print some info on coupling data.
Definition: fvMeshDistribute.C:285
Foam::UList< label >
Foam::fvMeshDistribute::printIntFieldInfo
static void printIntFieldInfo(const fvMesh &)
Print some field info.
Definition: fvMeshDistributeTemplates.C:81
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::fvMeshDistribute::testField
static void testField(const surfaceScalarField &)
Check whether field consistent with face orientation.
Definition: fvMeshDistribute.C:455
Foam::fvMeshDistribute::distribute
autoPtr< mapDistributePolyMesh > distribute(const labelList &dist)
Send cells to neighbours according to distribution.
Definition: fvMeshDistribute.C:1876
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::mapAddedPolyMesh
Class containing mesh-to-mesh mapping information after a mesh addition where we add a mesh ('added m...
Definition: mapAddedPolyMesh.H:58
Foam::GeometricField< scalar, fvsPatchField, surfaceMesh >
Foam::fvMeshDistribute
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
Definition: fvMeshDistribute.H:70
fields
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78