FreeFOAM The Cross-Platform CFD Toolkit
MGridGenGAMGAgglomeration.C
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) 1991-2010 OpenCFD Ltd.
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 \*---------------------------------------------------------------------------*/
25 
27 #include <finiteVolume/fvMesh.H>
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(MGridGenGAMGAgglomeration, 0);
35 
37  (
38  GAMGAgglomeration,
39  MGridGenGAMGAgglomeration,
40  lduMesh
41  );
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
47 Foam::MGridGenGAMGAgglomeration::MGridGenGAMGAgglomeration
48 (
49  const lduMesh& mesh,
50  const dictionary& controlDict
51 )
52 :
53  GAMGAgglomeration(mesh, controlDict),
54  fvMesh_(refCast<const fvMesh>(mesh))
55 {
56  // Min, max size of agglomerated cells
57  label minSize(readLabel(controlDict.lookup("minSize")));
58  label maxSize(readLabel(controlDict.lookup("maxSize")));
59 
60 
61  // Get the finest-level interfaces from the mesh
62  interfaceLevels_.set
63  (
64  0,
65  new lduInterfacePtrsList(fvMesh_.boundary().interfaces())
66  );
67 
68  // Start geometric agglomeration from the cell volumes and areas of the mesh
69  scalarField* VPtr = const_cast<scalarField*>(&fvMesh_.cellVolumes());
70  vectorField* SfPtr = const_cast<vectorField*>(&fvMesh_.faceAreas());
71 
72  // Create the boundary area cell field
73  scalarField* SbPtr(new scalarField(fvMesh_.nCells(), 0));
74 
75  {
76  scalarField& Sb = *SbPtr;
77 
78  const labelList& own = fvMesh_.faceOwner();
79  const vectorField& Sf = fvMesh_.faceAreas();
80 
81  forAll(Sf, facei)
82  {
83  if (!fvMesh_.isInternalFace(facei))
84  {
85  Sb[own[facei]] += mag(Sf[facei]);
86  }
87  }
88  }
89 
90 
91  // Agglomerate until the required number of cells in the coarsest level
92  // is reached
93 
94  label nCreatedLevels = 0;
95 
96  while (nCreatedLevels < maxLevels_ - 1)
97  {
98  label nCoarseCells = -1;
99 
100  tmp<labelField> finalAgglomPtr = agglomerate
101  (
102  nCoarseCells,
103  minSize,
104  maxSize,
105  meshLevel(nCreatedLevels).lduAddr(),
106  *VPtr,
107  *SfPtr,
108  *SbPtr
109  );
110 
111  if (continueAgglomerating(nCoarseCells))
112  {
113  nCells_[nCreatedLevels] = nCoarseCells;
114  restrictAddressing_.set(nCreatedLevels, finalAgglomPtr);
115  }
116  else
117  {
118  break;
119  }
120 
121  agglomerateLduAddressing(nCreatedLevels);
122 
123  // Agglomerate the cell volumes field for the next level
124  {
125  scalarField* aggVPtr
126  (
127  new scalarField(meshLevels_[nCreatedLevels].size())
128  );
129 
130  restrictField(*aggVPtr, *VPtr, nCreatedLevels);
131 
132  if (nCreatedLevels)
133  {
134  delete VPtr;
135  }
136 
137  VPtr = aggVPtr;
138  }
139 
140  // Agglomerate the face areas field for the next level
141  {
142  vectorField* aggSfPtr
143  (
144  new vectorField
145  (
146  meshLevels_[nCreatedLevels].upperAddr().size(),
148  )
149  );
150 
151  restrictFaceField(*aggSfPtr, *SfPtr, nCreatedLevels);
152 
153  if (nCreatedLevels)
154  {
155  delete SfPtr;
156  }
157 
158  SfPtr = aggSfPtr;
159  }
160 
161  // Agglomerate the cell boundary areas field for the next level
162  {
163  scalarField* aggSbPtr
164  (
165  new scalarField(meshLevels_[nCreatedLevels].size())
166  );
167 
168  restrictField(*aggSbPtr, *SbPtr, nCreatedLevels);
169 
170  delete SbPtr;
171  SbPtr = aggSbPtr;
172  }
173 
174  nCreatedLevels++;
175  }
176 
177  // Shrink the storage of the levels to those created
178  compactLevels(nCreatedLevels);
179 
180  // Delete temporary geometry storage
181  if (nCreatedLevels)
182  {
183  delete VPtr;
184  delete SfPtr;
185  }
186  delete SbPtr;
187 }
188 
189 
190 // ************************ vim: set sw=4 sts=4 et: ************************ //