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 | Copyright (C) 2011-2016 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
155  bool continueAgglomerating(const label nCoarseCells) const;
156 
157  //- Gather value from all procIDs onto procIDs[0]
158  template<class Type>
159  static void gatherList
160  (
161  const label comm,
162  const labelList& procIDs,
163 
164  const Type& myVal,
165  List<Type>& allVals,
166  const int tag = Pstream::msgType()
167  );
168 
169  void clearLevel(const label leveli);
170 
171 
172  // Processor agglomeration
173 
174  //- Collect and combine processor meshes into allMesh:
175  //
176  // - allMeshComm : communicator for combined mesh.
177  // - procAgglomMap : per processor the new agglomerated
178  // processor (rank in allMeshComm!). Global information.
179  // - procIDs : local information: same for all in
180  // agglomerated processor.
182  (
183  const label comm,
184  const labelList& procAgglomMap,
185  const labelList& procIDs,
186  const label allMeshComm,
187  const label levelIndex
188  );
189 
190  //- Collect and combine basic restriction addressing:
191  //
192  // - nCells_
193  // - restrictAddressing_
195  (
196  const label comm,
197  const labelList& procIDs,
198  const label levelIndex
199  );
200 
201 
202 private:
203 
204  // Private Member Functions
205 
206  //- Disallow default bitwise copy construct
208 
209  //- Disallow default bitwise assignment
210  void operator=(const GAMGAgglomeration&);
211 
212 
213 public:
214 
215  //- Declare friendship with GAMGProcAgglomeration
216  friend class GAMGProcAgglomeration;
217 
218  //- Runtime type information
219  TypeName("GAMGAgglomeration");
220 
221 
222  // Declare run-time constructor selection tables
223 
224  //- Runtime selection table for pure geometric agglomerators
226  (
227  autoPtr,
229  lduMesh,
230  (
231  const lduMesh& mesh,
232  const dictionary& controlDict
233  ),
234  (
235  mesh,
236  controlDict
237  )
238  );
239 
240  //- Runtime selection table for matrix or mixed geometric/matrix
241  // agglomerators
243  (
244  autoPtr,
246  lduMatrix,
247  (
248  const lduMatrix& matrix,
249  const dictionary& controlDict
250  ),
251  (
252  matrix,
253  controlDict
254  )
255  );
256 
257  //- Runtime selection table for matrix or mixed geometric/matrix
258  // agglomerators
260  (
261  autoPtr,
263  geometry,
264  (
265  const lduMesh& mesh,
266  const scalarField& cellVolumes,
267  const vectorField& faceAreas,
268  const dictionary& controlDict
269  ),
270  (
271  mesh,
272  cellVolumes,
273  faceAreas,
274  controlDict
275  )
276  );
277 
278 
279  // Constructors
280 
281  //- Construct given mesh and controls
283  (
284  const lduMesh& mesh,
285  const dictionary& controlDict
286  );
287 
288 
289  // Selectors
290 
291  //- Return the selected geometric agglomerator
292  static const GAMGAgglomeration& New
293  (
294  const lduMesh& mesh,
295  const dictionary& controlDict
296  );
297 
298  //- Return the selected matrix agglomerator
299  static const GAMGAgglomeration& New
300  (
301  const lduMatrix& matrix,
302  const dictionary& controlDict
303  );
304 
305  //- Return the selected geometric agglomerator
307  (
308  const lduMesh& mesh,
309  const scalarField& cellVolumes,
310  const vectorField& faceAreas,
311  const dictionary& controlDict
312  );
313 
314 
315  //- Destructor
317 
318 
319  // Member Functions
320 
321  // Access
323  label size() const
324  {
325  return meshLevels_.size();
326  }
327 
328  //- Return LDU mesh of given level
329  const lduMesh& meshLevel(const label leveli) const;
330 
331  //- Do we have mesh for given level?
332  bool hasMeshLevel(const label leveli) const;
333 
334  //- Return LDU interface addressing of given level
336  (
337  const label leveli
338  ) const;
339 
340  //- Return cell restrict addressing of given level
341  const labelField& restrictAddressing(const label leveli) const
342  {
343  return restrictAddressing_[leveli];
344  }
345 
346  //- Return face restrict addressing of given level
347  const labelList& faceRestrictAddressing(const label leveli) const
348  {
349  return faceRestrictAddressing_[leveli];
350  }
352  const labelListList& patchFaceRestrictAddressing(const label leveli)
353  const
354  {
355  return patchFaceRestrictAddressing_[leveli];
356  }
357 
358  //- Return face flip map of given level
359  const boolList& faceFlipMap(const label leveli) const
360  {
361  return faceFlipMap_[leveli];
362  }
363 
364  //- Return number of coarse cells (before processor agglomeration)
365  label nCells(const label leveli) const
366  {
367  return nCells_[leveli];
368  }
369 
370  //- Return number of coarse faces (before processor agglomeration)
371  label nFaces(const label leveli) const
372  {
373  return nFaces_[leveli];
374  }
375 
376  //- Return number of coarse patch faces (before processor
377  // agglomeration)
378  const labelList& nPatchFaces(const label leveli) const
379  {
380  return nPatchFaces_[leveli];
381  }
382 
383 
384  // Restriction and prolongation
385 
386  //- Restrict (integrate by summation) cell field
387  template<class Type>
388  void restrictField
389  (
390  Field<Type>& cf,
391  const Field<Type>& ff,
392  const label fineLevelIndex,
393  const bool procAgglom
394  ) const;
395 
396  //- Restrict (integrate by summation) face field
397  template<class Type>
398  void restrictFaceField
399  (
400  Field<Type>& cf,
401  const Field<Type>& ff,
402  const label fineLevelIndex
403  ) const;
404 
405  //- Restrict (integrate by summation) cell field
406  template<class Type>
407  void restrictField
408  (
409  Field<Type>& cf,
410  const Field<Type>& ff,
411  const labelList& fineToCoarse
412  ) const;
413 
414  //- Prolong (interpolate by injection) cell field
415  template<class Type>
416  void prolongField
417  (
418  Field<Type>& ff,
419  const Field<Type>& cf,
420  const label coarseLevelIndex,
421  const bool procAgglom
422  ) const;
423 
424 
425  // Procesor agglomeration. Note that the mesh and agglomeration is
426  // stored per fineLevel (even though it is the coarse level mesh that
427  // has been agglomerated). This is just for convenience and consistency
428  // with GAMGSolver notation.
429 
430  //- Given fine to coarse processor map determine:
431  //
432  // - for each coarse processor a master (minimum of the fine
433  // processors)
434  // - for each coarse processor the set of fine processors
435  // (element 0 is the master processor)
436  static void calculateRegionMaster
437  (
438  const label comm,
439  const labelList& procAgglomMap,
440  labelList& masterProcs,
442  );
443 
444  //- Whether to agglomerate across processors
445  bool processorAgglomerate() const
446  {
447  return procAgglomeratorPtr_.valid();
448  }
449 
450  //- Mapping from processor to agglomerated processor (global, all
451  // processors have the same information). Note that level is
452  // the fine, not the coarse, level index. This is to be
453  // consistent with the way the restriction is stored
454  const labelList& procAgglomMap(const label fineLeveli) const;
455 
456  //- Set of processors to agglomerate. Element 0 is the
457  // master processor. (local, same only on those processors that
458  // agglomerate)
459  const labelList& agglomProcIDs(const label fineLeveli) const;
460 
461  //- Check that level has combined mesh
462  bool hasProcMesh(const label fineLeveli) const;
463 
464  //- Communicator for current level or -1
465  label procCommunicator(const label fineLeveli) const;
466 
467  //- Mapping from processor to procMesh cells
468  const labelList& cellOffsets(const label fineLeveli) const;
469 
470  //- Mapping from processor to procMesh face
471  const labelListList& faceMap(const label fineLeveli) const;
472 
473  //- Mapping from processor to procMesh boundary
474  const labelListList& boundaryMap(const label fineLeveli) const;
475 
476  //- Mapping from processor to procMesh boundary face
477  const labelListListList& boundaryFaceMap(const label fineLeveli)
478  const;
479 
480  //- Given restriction determines if coarse cells are connected.
481  // Return ok is so, otherwise creates new restriction that is
482  static bool checkRestriction
483  (
484  labelList& newRestrict,
485  label& nNewCoarse,
486  const lduAddressing& fineAddressing,
487  const labelUList& restrict,
488  const label nCoarse
489  );
490 };
491 
492 
493 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
494 
495 } // End namespace Foam
496 
497 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
498 
499 #ifdef NoRepository
501 #endif
502 
503 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
504 
505 #endif
506 
507 // ************************************************************************* //
autoPtr< GAMGProcAgglomeration > procAgglomeratorPtr_
PtrList< labelListList > procBoundaryMap_
Mapping from processor to procMeshLevel boundary.
PtrList< labelListList > procFaceMap_
Mapping from processor to procMeshLevel face.
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
PtrList< labelListList > patchFaceRestrictAddressing_
Patch-local face restriction addressing array.
const labelList & procAgglomMap(const label fineLeveli) const
Mapping from processor to agglomerated processor (global, all.
bool hasProcMesh(const label fineLeveli) const
Check that level has combined mesh.
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.
PtrList< labelList > procCellOffsets_
Mapping from processor to procMeshLevel cells.
bool hasMeshLevel(const label leveli) const
Do we have mesh for given level?
~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:464
bool processorAgglomerate() const
Whether to agglomerate across processors.
const lduMesh & meshLevel(const label leveli) const
Return LDU mesh of given level.
const labelList & cellOffsets(const label fineLeveli) const
Mapping from processor to procMesh cells.
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.
label nFaces(const label leveli) const
Return number of coarse faces (before processor agglomeration)
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)
const labelList & faceRestrictAddressing(const label leveli) const
Return face restrict addressing of given level.
PtrList< labelList > agglomProcIDs_
Per level the set of processors to agglomerate. Element 0 is.
const labelList & nPatchFaces(const label leveli) const
Return number of coarse patch faces (before processor.
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 labelListList & faceMap(const label fineLeveli) const
Mapping from processor to procMesh face.
const lduInterfacePtrsList meshInterfaces_
Cached mesh interfaces.
const labelListList & patchFaceRestrictAddressing(const label leveli) const
label nCells(const label leveli) const
Return number of coarse cells (before processor agglomeration)
PtrList< lduPrimitiveMesh > meshLevels_
Hierarchy of mesh addressing.
const label nCellsInCoarsestLevel_
Number of cells in coarsest level.
labelList nCells_
The number of cells in each level.
const labelField & restrictAddressing(const label leveli) const
Return cell restrict addressing of given level.
labelList nFaces_
The number of (coarse) faces in each level.
const labelListListList & boundaryFaceMap(const label fineLeveli) const
Mapping from processor to procMesh boundary face.
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set).
Definition: autoPtrI.H:83
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.
const label maxLevels_
Max number of levels.
const lduInterfacePtrsList & interfaceLevel(const label leveli) const
Return LDU interface addressing of given level.
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
void prolongField(Field< Type > &ff, const Field< Type > &cf, const label coarseLevelIndex, const bool procAgglom) const
Prolong (interpolate by injection) cell field.
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:
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:62
Processor agglomeration of GAMGAgglomerations.
PtrList< labelList > procAgglomMap_
Per level, per processor the processor it agglomerates into.
declareRunTimeSelectionTable(autoPtr, GAMGAgglomeration, lduMesh,(const lduMesh &mesh, const dictionary &controlDict),(mesh, controlDict))
Runtime selection table for pure geometric agglomerators.
void restrictFaceField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex) const
Restrict (integrate by summation) face field.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
The class contains the addressing required by the lduMatrix: upper, lower and losort.
bool continueAgglomerating(const label nCoarseCells) const
Check the need for further agglomeration.
PtrList< boolList > faceFlipMap_
Face flip: for faces mapped to internal faces stores whether.
Macros to ease declaration of run-time selection tables.
label procCommunicator(const label fineLeveli) const
Communicator for current level or -1.
const labelListList & boundaryMap(const label fineLeveli) const
Mapping from processor to procMesh boundary.
void restrictField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex, const bool procAgglom) const
Restrict (integrate by summation) cell field.
Geometric agglomerated algebraic multigrid agglomeration class.
const boolList & faceFlipMap(const label leveli) const
Return face flip map of given level.
static void calculateRegionMaster(const label comm, const labelList &procAgglomMap, labelList &masterProcs, List< label > &agglomProcIDs)
Given fine to coarse processor map determine:
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.
const labelList & agglomProcIDs(const label fineLeveli) const
Set of processors to agglomerate. Element 0 is the.
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
void compactLevels(const label nCreatedLevels)
Shrink the number of levels to that specified.