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