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