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-2014 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  // - allMeshComm : communicator for combined mesh.
176  // - procAgglomMap : per processor the new agglomerated processor
177  // (rank in allMeshComm!). Global information.
178  // - procIDs : local information: same for all in
179  // agglomerated processor.
181  (
182  const label comm,
183  const labelList& procAgglomMap,
184  const labelList& procIDs,
185  const label allMeshComm,
186  const label levelIndex
187  );
188 
189  //- Collect and combine basic restriction addressing:
190  // nCells_
191  // restrictAddressing_
193  (
194  const label comm,
195  const labelList& procIDs,
196  const label levelIndex
197  );
198 
199 
200 private:
201 
202  // Private Member Functions
203 
204  //- Disallow default bitwise copy construct
206 
207  //- Disallow default bitwise assignment
208  void operator=(const GAMGAgglomeration&);
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,
234  controlDict
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,
251  controlDict
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,
272  controlDict
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 
287  // Selectors
288 
289  //- Return the selected geometric agglomerator
290  static const GAMGAgglomeration& New
291  (
292  const lduMesh& mesh,
293  const dictionary& controlDict
294  );
295 
296  //- Return the selected matrix agglomerator
297  static const GAMGAgglomeration& New
298  (
299  const lduMatrix& matrix,
300  const dictionary& controlDict
301  );
302 
303  //- Return the selected geometric agglomerator
305  (
306  const lduMesh& mesh,
307  const scalarField& cellVolumes,
308  const vectorField& faceAreas,
309  const dictionary& controlDict
310  );
311 
312 
313  //- Destructor
315 
316 
317  // Member Functions
318 
319  // Access
321  label size() const
322  {
323  return meshLevels_.size();
324  }
325 
326  //- Return LDU mesh of given level
327  const lduMesh& meshLevel(const label leveli) const;
328 
329  //- Do we have mesh for given level?
330  bool hasMeshLevel(const label leveli) const;
331 
332  //- Return LDU interface addressing of given level
334  (
335  const label leveli
336  ) const;
337 
338  //- Return cell restrict addressing of given level
339  const labelField& restrictAddressing(const label leveli) const
340  {
341  return restrictAddressing_[leveli];
342  }
343 
344  //- Return face restrict addressing of given level
345  const labelList& faceRestrictAddressing(const label leveli) const
346  {
347  return faceRestrictAddressing_[leveli];
348  }
350  const labelListList& patchFaceRestrictAddressing(const label leveli)
351  const
352  {
353  return patchFaceRestrictAddressing_[leveli];
354  }
355 
356  //- Return face flip map of given level
357  const boolList& faceFlipMap(const label leveli) const
358  {
359  return faceFlipMap_[leveli];
360  }
361 
362  //- Return number of coarse cells (before processor agglomeration)
363  label nCells(const label leveli) const
364  {
365  return nCells_[leveli];
366  }
367 
368  //- Return number of coarse faces (before processor agglomeration)
369  label nFaces(const label leveli) const
370  {
371  return nFaces_[leveli];
372  }
373 
374  //- Return number of coarse patch faces (before processor
375  // agglomeration)
376  const labelList& nPatchFaces(const label leveli) const
377  {
378  return nPatchFaces_[leveli];
379  }
380 
381 
382  // Restriction and prolongation
383 
384  //- Restrict (integrate by summation) cell field
385  template<class Type>
386  void restrictField
387  (
388  Field<Type>& cf,
389  const Field<Type>& ff,
390  const label fineLevelIndex,
391  const bool procAgglom
392  ) const;
393 
394  //- Restrict (integrate by summation) face field
395  template<class Type>
396  void restrictFaceField
397  (
398  Field<Type>& cf,
399  const Field<Type>& ff,
400  const label fineLevelIndex
401  ) const;
402 
403  //- Restrict (integrate by summation) cell field
404  template<class Type>
405  void restrictField
406  (
407  Field<Type>& cf,
408  const Field<Type>& ff,
409  const labelList& fineToCoarse
410  ) const;
411 
412  //- Prolong (interpolate by injection) cell field
413  template<class Type>
414  void prolongField
415  (
416  Field<Type>& ff,
417  const Field<Type>& cf,
418  const label coarseLevelIndex,
419  const bool procAgglom
420  ) const;
421 
422 
423  // Procesor agglomeration. Note that the mesh and agglomeration is
424  // stored per fineLevel (even though it is the coarse level mesh that
425  // has been agglomerated). This is just for convenience and consistency
426  // with GAMGSolver notation.
427 
428  //- Given fine to coarse processor map determine:
429  // - for each coarse processor a master (minimum of the fine
430  // processors)
431  // - for each coarse processor the set of fine processors
432  // (element 0 is the master processor)
433  static void calculateRegionMaster
434  (
435  const label comm,
436  const labelList& procAgglomMap,
437  labelList& masterProcs,
439  );
440 
441  //- Whether to agglomerate across processors
442  bool processorAgglomerate() const
443  {
444  return procAgglomeratorPtr_.valid();
445  }
446 
447  //- Mapping from processor to agglomerated processor (global, all
448  // processors have the same information). Note that level is
449  // the fine, not the coarse, level index. This is to be
450  // consistent with the way the restriction is stored
451  const labelList& procAgglomMap(const label fineLeveli) const;
452 
453  //- Set of processors to agglomerate. Element 0 is the
454  // master processor. (local, same only on those processors that
455  // agglomerate)
456  const labelList& agglomProcIDs(const label fineLeveli) const;
457 
458  //- Check that level has combined mesh
459  bool hasProcMesh(const label fineLeveli) const;
460 
461  //- Communicator for current level or -1
462  label procCommunicator(const label fineLeveli) const;
463 
464  //- Mapping from processor to procMesh cells
465  const labelList& cellOffsets(const label fineLeveli) const;
466 
467  //- Mapping from processor to procMesh face
468  const labelListList& faceMap(const label fineLeveli) const;
469 
470  //- Mapping from processor to procMesh boundary
471  const labelListList& boundaryMap(const label fineLeveli) const;
472 
473  //- Mapping from processor to procMesh boundary face
474  const labelListListList& boundaryFaceMap(const label fineLeveli)
475  const;
476 
477  //- Given restriction determines if coarse cells are connected.
478  // Return ok is so, otherwise creates new restriction that is
479  static bool checkRestriction
480  (
481  labelList& newRestrict,
482  label& nNewCoarse,
483  const lduAddressing& fineAddressing,
484  const labelUList& restrict,
485  const label nCoarse
486  );
487 };
488 
489 
490 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
491 
492 } // End namespace Foam
493 
494 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
495 
496 #ifdef NoRepository
498 #endif
499 
500 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
501 
502 #endif
503 
504 // ************************************************************************* //
bool continueAgglomerating(const label nCoarseCells) const
Check the need for further agglomeration.
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 & nPatchFaces(const label leveli) const
Return number of coarse patch faces (before processor.
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
static void calculateRegionMaster(const label comm, const labelList &procAgglomMap, labelList &masterProcs, List< label > &agglomProcIDs)
Given fine to coarse processor map determine:
PtrList< boolList > faceFlipMap_
Face flip: for faces mapped to internal faces stores whether.
const labelList & cellOffsets(const label fineLeveli) const
Mapping from processor to procMesh cells.
Geometric agglomerated algebraic multigrid agglomeration class.
PtrList< lduPrimitiveMesh > meshLevels_
Hierarchy of mesh addressing.
labelList procCommunicator_
Communicator for given level.
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set).
Definition: autoPtrI.H:83
TypeName("GAMGAgglomeration")
Runtime type information.
Macros to ease declaration of run-time selection tables.
const lduInterfacePtrsList meshInterfaces_
Cached mesh interfaces.
static const GAMGAgglomeration & New(const lduMesh &mesh, const dictionary &controlDict)
Return the selected geometric agglomerator.
PtrList< labelListListList > procBoundaryFaceMap_
Mapping from processor to procMeshLevel boundary face.
void procAgglomerateRestrictAddressing(const label comm, const labelList &procIDs, const label levelIndex)
Collect and combine basic restriction addressing:
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
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].
Specialisations of Field<T> for scalar, vector and tensor.
const labelList & faceRestrictAddressing(const label leveli) const
Return face restrict addressing of given level.
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:51
static bool checkRestriction(labelList &newRestrict, label &nNewCoarse, const lduAddressing &fineAddressing, const labelUList &restrict, const label nCoarse)
Given restriction determines if coarse cells are connected.
PtrList< labelList > procCellOffsets_
Mapping from processor to procMeshLevel cells.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
PtrList< labelList > procAgglomMap_
Per level, per processor the processor it agglomerates into.
PtrList< labelListList > procBoundaryMap_
Mapping from processor to procMeshLevel boundary.
Namespace for OpenFOAM.
const labelList & procAgglomMap(const label fineLeveli) const
Mapping from processor to agglomerated processor (global, all.
autoPtr< GAMGProcAgglomeration > procAgglomeratorPtr_
const lduMesh & meshLevel(const label leveli) const
Return LDU mesh of given level.
const labelListList & faceMap(const label fineLeveli) const
Mapping from processor to procMesh face.
const labelListListList & boundaryFaceMap(const label fineLeveli) const
Mapping from processor to procMesh boundary face.
bool hasMeshLevel(const label leveli) const
Do we have mesh for given level?
PtrList< labelList > nPatchFaces_
The number of (coarse) patch faces in each level.
lduMatrix is a general matrix class in which the coefficients are stored as three arrays...
Definition: lduMatrix.H:77
PtrList< labelList > agglomProcIDs_
Per level the set of processors to agglomerate. Element 0 is.
PtrList< labelListList > patchFaceRestrictAddressing_
Patch-local face restriction addressing array.
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:451
void procAgglomerateLduAddressing(const label comm, const labelList &procAgglomMap, const labelList &procIDs, const label allMeshComm, const label levelIndex)
Collect and combine processor meshes into allMesh.
label nFaces(const label leveli) const
Return number of coarse faces (before processor agglomeration)
bool processorAgglomerate() const
Whether to agglomerate across processors.
PtrList< labelList > faceRestrictAddressing_
Face restriction addressing array.
declareRunTimeSelectionTable(autoPtr, GAMGAgglomeration, lduMesh,( const lduMesh &mesh, const dictionary &controlDict ),( mesh, controlDict ))
Runtime selection table for pure geometric agglomerators.
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:81
const FieldField< fvPatchField, Type > & ff(const FieldField< fvPatchField, Type > &bf)
void compactLevels(const label nCreatedLevels)
Shrink the number of levels to that specified.
const labelList & agglomProcIDs(const label fineLeveli) const
Set of processors to agglomerate. Element 0 is the.
const labelField & restrictAddressing(const label leveli) const
Return cell restrict addressing of given level.
const boolList & faceFlipMap(const label leveli) const
Return face flip map of given level.
void clearLevel(const label leveli)
bool hasProcMesh(const label fineLeveli) const
Check that level has combined mesh.
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
const lduInterfacePtrsList & interfaceLevel(const label leveli) const
Return LDU interface addressing of given level.
label nCells(const label leveli) const
Return number of coarse cells (before processor agglomeration)
const labelListList & patchFaceRestrictAddressing(const label leveli) const
const label maxLevels_
Max number of levels.
labelList nCells_
The number of cells in each level.
The class contains the addressing required by the lduMatrix: upper, lower and losort.
void restrictFaceField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex) const
Restrict (integrate by summation) face field.
~GAMGAgglomeration()
Destructor.
Processor agglomeration of GAMGAgglomerations.
labelList nFaces_
The number of (coarse) faces in each level.
PtrList< labelListList > procFaceMap_
Mapping from processor to procMeshLevel face.
PtrList< labelField > restrictAddressing_
Cell restriction addressing array.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
void restrictField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex, const bool procAgglom) const
Restrict (integrate by summation) cell field.
void prolongField(Field< Type > &ff, const Field< Type > &cf, const label coarseLevelIndex, const bool procAgglom) const
Prolong (interpolate by injection) cell field.
void agglomerateLduAddressing(const label fineLevelIndex)
Assemble coarse mesh addressing.
label procCommunicator(const label fineLeveli) const
Communicator for current level or -1.
const label nCellsInCoarsestLevel_
Number of cells in coarsest level.