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-2018 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 mapDistribute;
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 private:
207 
208  // Private Member Functions
209 
210  //- Disallow default bitwise copy construct
212 
213  //- Disallow default bitwise assignment
214  void operator=(const GAMGAgglomeration&);
215 
216 
217 public:
218 
219  //- Declare friendship with GAMGProcAgglomeration
220  friend class GAMGProcAgglomeration;
221 
222  //- Runtime type information
223  TypeName("GAMGAgglomeration");
224 
225 
226  // Declare run-time constructor selection tables
227 
228  //- Runtime selection table for pure geometric agglomerators
230  (
231  autoPtr,
233  lduMesh,
234  (
235  const lduMesh& mesh,
236  const dictionary& controlDict
237  ),
238  (
239  mesh,
240  controlDict
241  )
242  );
243 
244  //- Runtime selection table for matrix or mixed geometric/matrix
245  // agglomerators
247  (
248  autoPtr,
250  lduMatrix,
251  (
252  const lduMatrix& matrix,
253  const dictionary& controlDict
254  ),
255  (
256  matrix,
257  controlDict
258  )
259  );
260 
261  //- Runtime selection table for matrix or mixed geometric/matrix
262  // agglomerators
264  (
265  autoPtr,
267  geometry,
268  (
269  const lduMesh& mesh,
270  const scalarField& cellVolumes,
271  const vectorField& faceAreas,
272  const dictionary& controlDict
273  ),
274  (
275  mesh,
276  cellVolumes,
277  faceAreas,
278  controlDict
279  )
280  );
281 
282 
283  // Constructors
284 
285  //- Construct given mesh and controls
287  (
288  const lduMesh& mesh,
289  const dictionary& controlDict
290  );
291 
292 
293  // Selectors
294 
295  //- Return the selected geometric agglomerator
296  static const GAMGAgglomeration& New
297  (
298  const lduMesh& mesh,
299  const dictionary& controlDict
300  );
301 
302  //- Return the selected matrix agglomerator
303  static const GAMGAgglomeration& New
304  (
305  const lduMatrix& matrix,
306  const dictionary& controlDict
307  );
308 
309  //- Return the selected geometric agglomerator
311  (
312  const lduMesh& mesh,
313  const scalarField& cellVolumes,
314  const vectorField& faceAreas,
315  const dictionary& controlDict
316  );
317 
318 
319  //- Destructor
321 
322 
323  // Member Functions
324 
325  // Access
327  label size() const
328  {
329  return meshLevels_.size();
330  }
331 
332  //- Return LDU mesh of given level
333  const lduMesh& meshLevel(const label leveli) const;
334 
335  //- Do we have mesh for given level?
336  bool hasMeshLevel(const label leveli) const;
337 
338  //- Return LDU interface addressing of given level
340  (
341  const label leveli
342  ) const;
343 
344  //- Return cell restrict addressing of given level
345  const labelField& restrictAddressing(const label leveli) const
346  {
347  return restrictAddressing_[leveli];
348  }
349 
350  //- Return face restrict addressing of given level
351  const labelList& faceRestrictAddressing(const label leveli) const
352  {
353  return faceRestrictAddressing_[leveli];
354  }
356  const labelListList& patchFaceRestrictAddressing(const label leveli)
357  const
358  {
359  return patchFaceRestrictAddressing_[leveli];
360  }
361 
362  //- Return face flip map of given level
363  const boolList& faceFlipMap(const label leveli) const
364  {
365  return faceFlipMap_[leveli];
366  }
367 
368  //- Return number of coarse cells (before processor agglomeration)
369  label nCells(const label leveli) const
370  {
371  return nCells_[leveli];
372  }
373 
374  //- Return number of coarse faces (before processor agglomeration)
375  label nFaces(const label leveli) const
376  {
377  return nFaces_[leveli];
378  }
379 
380  //- Return number of coarse patch faces (before processor
381  // agglomeration)
382  const labelList& nPatchFaces(const label leveli) const
383  {
384  return nPatchFaces_[leveli];
385  }
386 
387 
388  // Restriction and prolongation
389 
390  //- Restrict (integrate by summation) cell field
391  template<class Type>
392  void restrictField
393  (
394  Field<Type>& cf,
395  const Field<Type>& ff,
396  const label fineLevelIndex,
397  const bool procAgglom
398  ) const;
399 
400  //- Restrict (integrate by summation) face field
401  template<class Type>
402  void restrictFaceField
403  (
404  Field<Type>& cf,
405  const Field<Type>& ff,
406  const label fineLevelIndex
407  ) const;
408 
409  //- Restrict (integrate by summation) cell field
410  template<class Type>
411  void restrictField
412  (
413  Field<Type>& cf,
414  const Field<Type>& ff,
415  const labelList& fineToCoarse
416  ) const;
417 
418  //- Prolong (interpolate by injection) cell field
419  template<class Type>
420  void prolongField
421  (
422  Field<Type>& ff,
423  const Field<Type>& cf,
424  const label coarseLevelIndex,
425  const bool procAgglom
426  ) const;
427 
428 
429  // Procesor agglomeration. Note that the mesh and agglomeration is
430  // stored per fineLevel (even though it is the coarse level mesh that
431  // has been agglomerated). This is just for convenience and consistency
432  // with GAMGSolver notation.
433 
434  //- Given fine to coarse processor map determine:
435  //
436  // - for each coarse processor a master (minimum of the fine
437  // processors)
438  // - for each coarse processor the set of fine processors
439  // (element 0 is the master processor)
440  static void calculateRegionMaster
441  (
442  const label comm,
443  const labelList& procAgglomMap,
444  labelList& masterProcs,
446  );
447 
448  //- Whether to agglomerate across processors
449  bool processorAgglomerate() const
450  {
451  return procAgglomeratorPtr_.valid();
452  }
453 
454  //- Mapping from processor to agglomerated processor (global, all
455  // processors have the same information). Note that level is
456  // the fine, not the coarse, level index. This is to be
457  // consistent with the way the restriction is stored
458  const labelList& procAgglomMap(const label fineLeveli) const;
459 
460  //- Set of processors to agglomerate. Element 0 is the
461  // master processor. (local, same only on those processors that
462  // agglomerate)
463  const labelList& agglomProcIDs(const label fineLeveli) const;
464 
465  //- Check that level has combined mesh
466  bool hasProcMesh(const label fineLeveli) const;
467 
468  //- Communicator for current level or -1
469  label procCommunicator(const label fineLeveli) const;
470 
471  //- Mapping from processor to procMesh cells
472  const labelList& cellOffsets(const label fineLeveli) const;
473 
474  //- Mapping from processor to procMesh face
475  const labelListList& faceMap(const label fineLeveli) const;
476 
477  //- Mapping from processor to procMesh boundary
478  const labelListList& boundaryMap(const label fineLeveli) const;
479 
480  //- Mapping from processor to procMesh boundary face
481  const labelListListList& boundaryFaceMap(const label fineLeveli)
482  const;
483 
484  //- Given restriction determines if coarse cells are connected.
485  // Return ok is so, otherwise creates new restriction that is
486  static bool checkRestriction
487  (
488  labelList& newRestrict,
489  label& nNewCoarse,
490  const lduAddressing& fineAddressing,
491  const labelUList& restrict,
492  const label nCoarse
493  );
494 };
495 
496 
497 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
498 
499 } // End namespace Foam
500 
501 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
502 
503 #ifdef NoRepository
505 #endif
506 
507 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
508 
509 #endif
510 
511 // ************************************************************************* //
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.
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
const boolList & faceFlipMap(const label leveli) const
Return face flip map of given level.
PtrList< labelListList > patchFaceRestrictAddressing_
Patch-local face restriction addressing array.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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:474
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:85
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:61
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:63
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 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.