Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::fvMeshDistribute
29
30Description
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
46SourceFiles
47 fvMeshDistribute.C
48 fvMeshDistributeTemplates.C
49
50\*---------------------------------------------------------------------------*/
51
52#ifndef Foam_fvMeshDistribute_H
53#define Foam_fvMeshDistribute_H
54
55#include "Field.H"
56#include "fvMeshSubset.H"
57
58// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59
60namespace Foam
61{
62
63// Forward Declarations
67/*---------------------------------------------------------------------------*\
68 Class fvMeshDistribute Declaration
69\*---------------------------------------------------------------------------*/
70
71class 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 ZoneMesh>
102 void reorderZones(const wordList& zoneNames, ZoneMesh& zones);
103
104
105 // Patch handling
106
107 //- Find patch to put exposed faces into.
108 label findNonEmptyPatch() const;
109
110 //- Save boundary fields
111 template<class T, class Mesh>
112 void saveBoundaryFields
113 (
115 ) const;
116
117 //- Map boundary fields
118 template<class T, class Mesh>
119 void mapBoundaryFields
120 (
121 const mapPolyMesh& map,
123 );
124
125 //- Save internal fields of surfaceFields
126 template<class T>
127 void saveInternalFields(PtrList<Field<T>>& iflds) const;
128
129 //- Set value of patch faces resulting from internal faces
130 template<class T>
131 void mapExposedFaces
132 (
133 const mapPolyMesh& map,
134 const PtrList<Field<T>>& oldFlds
135 );
136
137 //- Init patch fields of certain type
138 template<class GeoField, class PatchFieldType>
139 void initPatchFields
140 (
141 const typename GeoField::value_type& initVal
142 );
143
145 //template<class GeoField>
146 //void correctBoundaryConditions();
147
148 //- Delete all processor patches. Move any processor faces into
149 // patchi.
150 autoPtr<mapPolyMesh> deleteProcPatches(const label patchi);
151
152 //- Repatch the mesh. This is only necessary for the proc
153 // boundary faces. newPatchID is over all boundary faces: -1 or
154 // new patchID. constructFaceMap is being adapted for the
155 // possible new face position (since proc faces get automatically
156 // matched)
158 (
159 const labelList& newPatchID,
160 labelListList& constructFaceMap
161 );
162
163 //- Merge any local points that were remotely coupled.
164 // constructPointMap is adapted for the new point labels.
165 autoPtr<mapPolyMesh> mergeSharedPoints
166 (
167 const labelList& pointToGlobalMaster,
168 labelListList& constructPointMap
169 );
170
171
172 // Coupling information
173
174 //- Construct the local environment of all boundary faces.
175 void getCouplingData
176 (
177 const labelList& distribution,
178 labelList& sourceFace,
179 labelList& sourceProc,
180 labelList& sourcePatch,
181 labelList& sourceNewProc,
182 labelList& sourcePointMaster
183 ) const;
184
185 // Subset the neighbourCell/neighbourProc fields
186 static void subsetCouplingData
187 (
188 const fvMesh& mesh,
189 const labelList& pointMap,
190 const labelList& faceMap,
191 const labelList& cellMap,
192
193 const labelList& oldDistribution,
194 const labelList& oldFaceOwner,
195 const labelList& oldFaceNeighbour,
196 const label oldInternalFaces,
197
198 const labelList& sourceFace,
199 const labelList& sourceProc,
200 const labelList& sourcePatch,
201 const labelList& sourceNewProc,
202 const labelList& sourcePointMaster,
203
204 labelList& subFace,
205 labelList& subProc,
206 labelList& subPatch,
207 labelList& subNewProc,
208 labelList& subPointMaster
209 );
210
211 //- Find cells on mesh whose faceID/procID match the neighbour
212 // cell/proc of domainMesh. Store the matching face.
213 static void findCouples
214 (
215 const primitiveMesh&,
216 const labelList& sourceFace,
217 const labelList& sourceProc,
218 const labelList& sourcePatch,
219
220 const label domain,
221 const primitiveMesh& domainMesh,
222 const labelList& domainFace,
223 const labelList& domainProc,
224 const labelList& domainPatch,
225
226 labelList& masterCoupledFaces,
227 labelList& slaveCoupledFaces
228 );
229
230 //- Find cells on mesh whose faceID/procID match the neighbour
231 // cell/proc of domainMesh. Store the matching face pairs
232 static void findCouples
233 (
235 const PtrList<labelList>& domainSourceFaces,
236 const PtrList<labelList>& domainSourceProcs,
237 const PtrList<labelList>& domainSourcePatchs,
238
239 labelListList& localBoundaryFace,
240 labelListList& remoteFaceProc,
241 labelListList& remoteBoundaryFace
242 );
243
244 //- Map data on boundary faces to new mesh (resulting from adding
245 // two meshes)
246 static labelList mapBoundaryData
247 (
248 const primitiveMesh& mesh, // mesh after adding
249 const mapAddedPolyMesh& map,
250 const labelList& boundaryData0, // mesh before adding
251 const label nInternalFaces1,
252 const labelList& boundaryData1 // added mesh
253 );
254
255 //- Map point data to new mesh (resulting from adding two meshes)
256 static labelList mapPointData
257 (
258 const primitiveMesh& mesh, // mesh after adding
259 const mapAddedPolyMesh& map,
260 const labelList& boundaryData0, // on mesh before adding
261 const labelList& boundaryData1 // on added mesh
262 );
263
264 // Other
265
266 //- Remove cells. Add all exposed faces to patch oldInternalPatchi
267 autoPtr<mapPolyMesh> doRemoveCells
268 (
269 const labelList& cellsToRemove,
270 const label oldInternalPatchi
271 );
272
273 //- Add processor patches. Changes mesh and returns per neighbour
274 // proc the processor patchID.
275 void addProcPatches
276 (
277 const labelList&, // processor that neighbour is now on
278 const labelList&, // -1 or patch that face originated from
279 List<Map<label>>& procPatchID
280 );
281
282 //- Get boundary faces to be repatched. Is -1 or new patchID
283 static labelList getBoundaryPatch
284 (
285 const labelList& neighbourNewProc, // new processor per b. face
286 const labelList& referPatchID, // -1 or original patch
287 const List<Map<label>>& procPatchID // patchID
288 );
289
290 //- Send mesh and coupling data.
291 static void sendMesh
292 (
293 const label domain,
294 const fvMesh& mesh,
295 const wordList& pointZoneNames,
296 const wordList& facesZoneNames,
297 const wordList& cellZoneNames,
298 const labelList& sourceFace,
299 const labelList& sourceProc,
300 const labelList& sourcePatch,
301 const labelList& sourceNewProc,
302 const labelList& sourcePointMaster,
303 Ostream& toDomain
304 );
305
306 //- Get sorted names of GeoField, optionally test
307 //- that all procs have the same names.
308 template<class GeoField>
309 static void getFieldNames
310 (
311 const fvMesh& mesh,
312 HashTable<wordList>& allFieldNames,
313 const word& excludeType = word::null,
314 const bool syncPar = true
315 );
316
317 //- Send subset of fields
318 template<class GeoField>
319 static void sendFields
320 (
321 const label domain,
322 const HashTable<wordList>& allFieldNames,
323 const fvMeshSubset& subsetter,
324 Ostream&
325 );
326
327 //- Receive mesh. Opposite of sendMesh
328 static autoPtr<fvMesh> receiveMesh
329 (
330 const label domain,
331 const wordList& pointZoneNames,
332 const wordList& facesZoneNames,
333 const wordList& cellZoneNames,
334 const Time& runTime,
335 labelList& domainSourceFace,
336 labelList& domainSourceProc,
337 labelList& domainSourcePatch,
338 labelList& domainSourceNewProc,
339 labelList& domainSourcePointMaster,
340 Istream& fromNbr
341 );
342
343 //- Receive fields. Opposite of sendFields
344 template<class GeoField>
345 static void receiveFields
346 (
347 const label domain,
348 const HashTable<wordList>& allFieldNames,
349 fvMesh& mesh,
351 const dictionary& allFieldsDict
352 );
353
354 //- No copy construct
355 fvMeshDistribute(const fvMeshDistribute&) = delete;
356
357 //- No copy assignment
358 void operator=(const fvMeshDistribute&) = delete;
359
360public:
361
362 ClassName("fvMeshDistribute");
363
364
365 // Constructors
366
367 //- Construct from mesh
368 explicit fvMeshDistribute(fvMesh& mesh);
369
370
371 // Member Functions
372
373 //- Helper function: count cells per processor in wanted distribution
374 static labelList countCells(const labelList&);
375
376 //- Send cells to neighbours according to distribution
377 // (for every cell the new proc)
379
380 // Debugging
381
382 //- Print some info on coupling data
383 static void printCoupleInfo
384 (
385 const primitiveMesh&,
386 const labelList&,
387 const labelList&,
388 const labelList&,
389 const labelList&
390 );
391
392 //- Print some field info
393 template<class GeoField>
394 static void printIntFieldInfo(const fvMesh&);
395
396 //- Print some field info
397 template<class GeoField>
398 static void printFieldInfo(const fvMesh&);
399
400 //- Print some info on mesh.
401 static void printMeshInfo(const polyMesh&);
402
403 //- Generate a test field on faces
405
406 //- Check whether field consistent with face orientation
407 static void testField(const surfaceScalarField&);
408};
409
410
411// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
412
413} // End namespace Foam
414
415// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
416
417#ifdef NoRepository
419#endif
421// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
422
423#endif
424
425// ************************************************************************* //
A field of fields is a PtrList of fields with reference counting.
Definition FieldField.H:77
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A HashTable to objects of type <T> with a label key.
Definition Map.H:54
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition UPtrList.H:101
A list of mesh zones.
Definition ZoneMesh.H:65
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Accumulating histogram of values. Specified bin resolution automatic generation of bins.
ClassName("fvMeshDistribute")
static void printCoupleInfo(const primitiveMesh &, const labelList &, const labelList &, const labelList &, const labelList &)
Print some info on coupling data.
static void printMeshInfo(const polyMesh &)
Print some info on mesh.
static void printIntFieldInfo(const fvMesh &)
Print some field info.
static labelList countCells(const labelList &)
Helper function: count cells per processor in wanted distribution.
static tmp< surfaceScalarField > generateTestField(const fvMesh &)
Generate a test field on faces.
static void printFieldInfo(const fvMesh &)
Print some field info.
autoPtr< mapDistributePolyMesh > distribute(const labelList &dist)
Send cells to neighbours according to distribution.
static void testField(const surfaceScalarField &)
Check whether field consistent with face orientation.
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
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 mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
Cell-face mesh analysis engine.
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
static const word null
An empty word.
Definition word.H:84
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74
dynamicFvMesh & mesh
engineTime & runTime
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
Namespace for OpenFOAM.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
List< word > wordList
List of word.
Definition fileName.H:60
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
UList< label > labelUList
A UList of labels.
Definition UList.H:75
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields