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