GAMGAgglomeration.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-2016 OpenFOAM Foundation
9 Copyright (C) 2019-2022 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::GAMGAgglomeration
29
30Description
31 Geometric agglomerated algebraic multigrid agglomeration class.
32
33SourceFiles
34 GAMGAgglomeration.C
35 GAMGAgglomerationTemplates.C
36 GAMGAgglomerateLduAddressing.C
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef Foam_GAMGAgglomeration_H
41#define Foam_GAMGAgglomeration_H
42
43#include "MeshObject.H"
44#include "lduPrimitiveMesh.H"
46#include "primitiveFields.H"
48
49#include "boolList.H"
50
51// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52
53namespace Foam
54{
55
56class lduMesh;
57class lduMatrix;
58class mapDistribute;
59class GAMGProcAgglomeration;
60
61/*---------------------------------------------------------------------------*\
62 Class GAMGAgglomeration Declaration
63\*---------------------------------------------------------------------------*/
66:
67 public MeshObject<lduMesh, GeometricMeshObject, GAMGAgglomeration>
68{
69protected:
70
71 // Protected data
72
73 //- Max number of levels
74 const label maxLevels_;
75
76 //- Number of cells in coarsest level
78
79 //- Cached mesh interfaces
83
84 //- The number of cells in each level
86
87 //- Cell restriction addressing array.
88 // Maps from the finer to the coarser level.
90
91 //- The number of (coarse) faces in each level.
92 // max(faceRestrictAddressing)+1.
94
95 //- Face restriction addressing array.
96 // Maps from the finer to the coarser level.
97 // Positive indices map the finer faces which form part of the boundary
98 // of the coarser cells to the corresponding coarser cell face.
99 // Negative indices map the finer faces which are internal to the
100 // coarser cells to minus the corresponding coarser cell index minus 1.
102
103 //- Face flip: for faces mapped to internal faces stores whether
104 // the face is reversed or not. This is used to avoid having
105 // to access the coarse mesh at all when mapping
107
108 //- The number of (coarse) patch faces in each level.
109 // max(patchFaceRestrictAddressing_)+1.
111
112 //- Patch-local face restriction addressing array.
113 // Maps from the finer to the coarser level. Always positive.
114 // Extracted from GAMGInterfaces after agglomeration.
116
117 //- Hierarchy of mesh addressing
119
120
121 // Processor agglomeration
122
123 //- Per level, per processor the processor it agglomerates into
125
126 //- Per level the set of processors to agglomerate. Element 0 is
127 // the 'master' of the cluster.
129
130 //- Communicator for given level
132
133 //- Mapping from processor to procMeshLevel cells
135
136 //- Mapping from processor to procMeshLevel face
138
139 //- Mapping from processor to procMeshLevel boundary
141
142 //- Mapping from processor to procMeshLevel boundary face
144
145
146 // Protected Member Functions
147
148 //- Assemble coarse mesh addressing
149 void agglomerateLduAddressing(const label fineLevelIndex);
150
151 //- Combine a level with the previous one
152 void combineLevels(const label curLevel);
153
154 //- Shrink the number of levels to that specified
155 void compactLevels(const label nCreatedLevels);
156
157 //- Check the need for further agglomeration
159 (
160 const label nCells,
161 const label nCoarseCells
162 ) const;
163
164 void clearLevel(const label leveli);
165
166
167 // Processor agglomeration
168
169 //- Collect and combine processor meshes into allMesh:
170 //
171 // - allMeshComm : communicator for combined mesh.
172 // - procAgglomMap : per processor the new agglomerated
173 // processor (rank in allMeshComm!). Global information.
174 // - procIDs : local information: same for all in
175 // agglomerated processor.
177 (
178 const label comm,
180 const labelList& procIDs,
181 const label allMeshComm,
182 const label levelIndex
183 );
184
185 //- Collect and combine basic restriction addressing:
186 //
187 // - nCells_
188 // - restrictAddressing_
190 (
191 const label comm,
192 const labelList& procIDs,
193 const label levelIndex
194 );
195
196
197 //- No copy construct
198 GAMGAgglomeration(const GAMGAgglomeration&) = delete;
199
200 //- No copy assignment
201 void operator=(const GAMGAgglomeration&) = delete;
202
203
204public:
205
206 //- Declare friendship with GAMGProcAgglomeration
207 friend class GAMGProcAgglomeration;
208
209 //- Runtime type information
210 TypeName("GAMGAgglomeration");
211
212
213 // Declare run-time constructor selection tables
214
215 //- Runtime selection table for pure geometric agglomerators
217 (
218 autoPtr,
220 lduMesh,
221 (
222 const lduMesh& mesh,
224 ),
225 (
226 mesh,
228 )
229 );
230
231 //- Runtime selection table for matrix or mixed geometric/matrix
232 //- agglomerators
234 (
235 autoPtr,
237 lduMatrix,
238 (
239 const lduMatrix& matrix,
241 ),
242 (
243 matrix,
245 )
246 );
247
248 //- Runtime selection table for matrix or mixed geometric/matrix
249 //- agglomerators
251 (
252 autoPtr,
254 geometry,
255 (
256 const lduMesh& mesh,
257 const scalarField& cellVolumes,
258 const vectorField& faceAreas,
260 ),
261 (
262 mesh,
263 cellVolumes,
264 faceAreas,
266 )
267 );
268
269
270 // Constructors
271
272 //- Construct given mesh and controls
274 (
275 const lduMesh& mesh,
277 );
278
279
280 // Selectors
281
282 //- Return the selected geometric agglomerator
283 static const GAMGAgglomeration& New
284 (
285 const lduMesh& mesh,
287 );
288
289 //- Return the selected matrix agglomerator
290 static const GAMGAgglomeration& New
291 (
292 const lduMatrix& matrix,
294 );
295
296 //- Return the selected geometric agglomerator
297 static const GAMGAgglomeration& New
298 (
299 const lduMesh& mesh,
300 const scalarField& cellVolumes,
301 const vectorField& faceAreas,
303 );
304
305
306 //- Destructor
308
309
310 // Member Functions
311
312 // Access
314 label size() const
315 {
316 return meshLevels_.size();
317 }
318
319 //- Return LDU mesh of given level
320 const lduMesh& meshLevel(const label leveli) const;
321
322 //- Do we have mesh for given level?
323 bool hasMeshLevel(const label leveli) const;
324
325 //- Return LDU interface addressing of given level
327 (
328 const label leveli
329 ) const;
330
331 //- Return cell restrict addressing of given level
332 const labelField& restrictAddressing(const label leveli) const
333 {
334 return restrictAddressing_[leveli];
335 }
336
337 //- Return face restrict addressing of given level
338 const labelList& faceRestrictAddressing(const label leveli) const
339 {
340 return faceRestrictAddressing_[leveli];
341 }
343 const labelListList& patchFaceRestrictAddressing(const label leveli)
344 const
345 {
346 return patchFaceRestrictAddressing_[leveli];
347 }
348
349 //- Return face flip map of given level
350 const boolList& faceFlipMap(const label leveli) const
351 {
352 return faceFlipMap_[leveli];
353 }
354
355 //- Return number of coarse cells (before processor agglomeration)
356 label nCells(const label leveli) const
357 {
358 return nCells_[leveli];
359 }
360
361 //- Return number of coarse faces (before processor agglomeration)
362 label nFaces(const label leveli) const
363 {
364 return nFaces_[leveli];
365 }
366
367 //- Return number of coarse patch faces (before processor
368 //- agglomeration)
369 const labelList& nPatchFaces(const label leveli) const
370 {
371 return nPatchFaces_[leveli];
372 }
373
374
375 // Restriction and prolongation
376
377 //- Restrict (integrate by summation) cell field
378 template<class Type>
379 void restrictField
380 (
381 Field<Type>& cf,
382 const Field<Type>& ff,
383 const label fineLevelIndex,
384 const bool procAgglom
385 ) const;
386
387 //- Restrict (integrate by summation) face field
388 template<class Type>
390 (
391 Field<Type>& cf,
392 const Field<Type>& ff,
393 const label fineLevelIndex
394 ) const;
395
396 //- Restrict (integrate by summation) cell field
397 template<class Type>
398 void restrictField
399 (
400 Field<Type>& cf,
401 const Field<Type>& ff,
402 const labelList& fineToCoarse
403 ) const;
404
405 //- Prolong (interpolate by injection) cell field
406 template<class Type>
407 void prolongField
408 (
409 Field<Type>& ff,
410 const Field<Type>& cf,
411 const label coarseLevelIndex,
412 const bool procAgglom
413 ) const;
414
415
416 // Processor agglomeration. Note that the mesh and agglomeration is
417 // stored per fineLevel (even though it is the coarse level mesh that
418 // has been agglomerated). This is just for convenience and consistency
419 // with GAMGSolver notation.
420
421 //- Given fine to coarse processor map determine:
422 //
423 // - for each coarse processor a master (minimum of the fine
424 // processors)
425 // - for each coarse processor the set of fine processors
426 // (element 0 is the master processor)
427 static void calculateRegionMaster
428 (
429 const label comm,
431 labelList& masterProcs,
433 );
434
435 //- Whether to agglomerate across processors
436 bool processorAgglomerate() const
437 {
439 }
440
441 //- Mapping from processor to agglomerated processor (global, all
442 //- processors have the same information). Note that level is
443 //- the fine, not the coarse, level index. This is to be
444 //- consistent with the way the restriction is stored
445 const labelList& procAgglomMap(const label fineLeveli) const;
446
447 //- Set of processors to agglomerate. Element 0 is the
448 //- master processor. (local, same only on those processors that
449 //- agglomerate)
450 const labelList& agglomProcIDs(const label fineLeveli) const;
451
452 //- Check that level has combined mesh
453 bool hasProcMesh(const label fineLeveli) const;
454
455 //- Communicator for current level or -1
456 label procCommunicator(const label fineLeveli) const;
457
458 //- Mapping from processor to procMesh cells
459 const labelList& cellOffsets(const label fineLeveli) const;
460
461 //- Mapping from processor to procMesh face
462 const labelListList& faceMap(const label fineLeveli) const;
463
464 //- Mapping from processor to procMesh boundary
465 const labelListList& boundaryMap(const label fineLeveli) const;
466
467 //- Mapping from processor to procMesh boundary face
468 const labelListListList& boundaryFaceMap(const label fineLeveli)
469 const;
470
471 //- Given restriction determines if coarse cells are connected.
472 // Return ok is so, otherwise creates new restriction that is
473 static bool checkRestriction
474 (
475 labelList& newRestrict,
476 label& nNewCoarse,
477 const lduAddressing& fineAddressing,
478 const labelUList& restriction,
479 const label nCoarse
480 );
481};
482
483
484// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
485
486} // End namespace Foam
487
488// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
489
490#ifdef NoRepository
492#endif
493
494// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
495
496#endif
497
498// ************************************************************************* //
Geometric agglomerated algebraic multigrid agglomeration class.
const lduInterfacePtrsList meshInterfaces_
Cached mesh interfaces.
const labelList & nPatchFaces(const label leveli) const
const labelList & faceRestrictAddressing(const label leveli) const
Return face restrict addressing of given level.
void procAgglomerateRestrictAddressing(const label comm, const labelList &procIDs, const label levelIndex)
Collect and combine basic restriction addressing:
bool processorAgglomerate() const
Whether to agglomerate across processors.
TypeName("GAMGAgglomeration")
Runtime type information.
void clearLevel(const label leveli)
const labelListListList & boundaryFaceMap(const label fineLeveli) const
Mapping from processor to procMesh boundary face.
void restrictField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex, const bool procAgglom) const
Restrict (integrate by summation) cell field.
static const GAMGAgglomeration & New(const lduMesh &mesh, const dictionary &controlDict)
Return the selected geometric agglomerator.
void agglomerateLduAddressing(const label fineLevelIndex)
Assemble coarse mesh addressing.
static void calculateRegionMaster(const label comm, const labelList &procAgglomMap, labelList &masterProcs, List< label > &agglomProcIDs)
Given fine to coarse processor map determine:
PtrList< labelListList > patchFaceRestrictAddressing_
Patch-local face restriction addressing array.
PtrList< boolList > faceFlipMap_
Face flip: for faces mapped to internal faces stores whether.
void prolongField(Field< Type > &ff, const Field< Type > &cf, const label coarseLevelIndex, const bool procAgglom) const
Prolong (interpolate by injection) cell field.
PtrList< labelList > nPatchFaces_
The number of (coarse) patch faces in each level.
void operator=(const GAMGAgglomeration &)=delete
No copy assignment.
void procAgglomerateLduAddressing(const label comm, const labelList &procAgglomMap, const labelList &procIDs, const label allMeshComm, const label levelIndex)
Collect and combine processor meshes into allMesh:
const label maxLevels_
Max number of levels.
const labelListList & patchFaceRestrictAddressing(const label leveli) const
static bool checkRestriction(labelList &newRestrict, label &nNewCoarse, const lduAddressing &fineAddressing, const labelUList &restriction, const label nCoarse)
Given restriction determines if coarse cells are connected.
label nCellsInCoarsestLevel_
Number of cells in coarsest level.
const labelList & procAgglomMap(const label fineLeveli) const
autoPtr< GAMGProcAgglomeration > procAgglomeratorPtr_
void compactLevels(const label nCreatedLevels)
Shrink the number of levels to that specified.
labelList nFaces_
The number of (coarse) faces in each level.
const boolList & faceFlipMap(const label leveli) const
Return face flip map of given level.
PtrList< lduPrimitiveMesh > meshLevels_
Hierarchy of mesh addressing.
GAMGAgglomeration(const GAMGAgglomeration &)=delete
No copy construct.
const labelList & cellOffsets(const label fineLeveli) const
Mapping from processor to procMesh cells.
bool continueAgglomerating(const label nCells, const label nCoarseCells) const
Check the need for further agglomeration.
labelList nCells_
The number of cells in each level.
bool hasProcMesh(const label fineLeveli) const
Check that level has combined mesh.
declareRunTimeSelectionTable(autoPtr, GAMGAgglomeration, lduMesh,(const lduMesh &mesh, const dictionary &controlDict),(mesh, controlDict))
Runtime selection table for pure geometric agglomerators.
const labelListList & faceMap(const label fineLeveli) const
Mapping from processor to procMesh face.
labelList procCommunicator_
Communicator for given level.
PtrList< labelList > agglomProcIDs_
Per level the set of processors to agglomerate. Element 0 is.
void restrictFaceField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex) const
Restrict (integrate by summation) face field.
declareRunTimeSelectionTable(autoPtr, GAMGAgglomeration, lduMatrix,(const lduMatrix &matrix, const dictionary &controlDict),(matrix, controlDict))
PtrList< labelList > procAgglomMap_
Per level, per processor the processor it agglomerates into.
PtrList< labelListList > procBoundaryMap_
Mapping from processor to procMeshLevel boundary.
const labelListList & boundaryMap(const label fineLeveli) const
Mapping from processor to procMesh boundary.
void combineLevels(const label curLevel)
Combine a level with the previous one.
const labelList & agglomProcIDs(const label fineLeveli) const
PtrList< labelList > procCellOffsets_
Mapping from processor to procMeshLevel cells.
PtrList< labelField > restrictAddressing_
Cell restriction addressing array.
PtrList< labelListList > procFaceMap_
Mapping from processor to procMeshLevel face.
PtrList< labelList > faceRestrictAddressing_
Face restriction addressing array.
declareRunTimeSelectionTable(autoPtr, GAMGAgglomeration, geometry,(const lduMesh &mesh, const scalarField &cellVolumes, const vectorField &faceAreas, const dictionary &controlDict),(mesh, cellVolumes, faceAreas, controlDict))
const lduInterfacePtrsList & interfaceLevel(const label leveli) const
Return LDU interface addressing of given level.
const labelField & restrictAddressing(const label leveli) const
Return cell restrict addressing of given level.
bool hasMeshLevel(const label leveli) const
Do we have mesh for given level?
label nCells(const label leveli) const
Return number of coarse cells (before processor agglomeration)
label procCommunicator(const label fineLeveli) const
Communicator for current level or -1.
const lduMesh & meshLevel(const label leveli) const
Return LDU mesh of given level.
PtrList< labelListListList > procBoundaryFaceMap_
Mapping from processor to procMeshLevel boundary face.
label nFaces(const label leveli) const
Return number of coarse faces (before processor agglomeration)
Processor agglomeration of GAMGAgglomerations.
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:91
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
The class contains the addressing required by the lduMatrix: upper, lower and losort.
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: lduMatrix.H:84
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:63
runTime controlDict().readEntry("adjustTimeStep"
bool
Definition: EEqn.H:20
Namespace for OpenFOAM.
Specialisations of Field<T> for scalar, vector and tensor.
Macros to ease declaration of run-time selection tables.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes)
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73