FreeFOAM The Cross-Platform CFD Toolkit
GAMGAgglomeration.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 
26 #include "GAMGAgglomeration.H"
27 #include <OpenFOAM/lduMesh.H>
28 #include <OpenFOAM/lduMatrix.H>
29 #include <OpenFOAM/Time.H>
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(GAMGAgglomeration, 0);
37  defineRunTimeSelectionTable(GAMGAgglomeration, lduMesh);
38  defineRunTimeSelectionTable(GAMGAgglomeration, lduMatrix);
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::GAMGAgglomeration::compactLevels(const label nCreatedLevels)
45 {
46  nCells_.setSize(nCreatedLevels);
47  restrictAddressing_.setSize(nCreatedLevels);
48  meshLevels_.setSize(nCreatedLevels);
49  interfaceLevels_.setSize(nCreatedLevels + 1);
50 }
51 
52 
54 (
55  const label nCoarseCells
56 ) const
57 {
58  // Check the need for further agglomeration on all processors
59  bool contAgg = nCoarseCells >= nCellsInCoarsestLevel_;
60  reduce(contAgg, andOp<bool>());
61  return contAgg;
62 }
63 
64 
65 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
66 
68 (
69  const lduMesh& mesh,
70  const dictionary& controlDict
71 )
72 :
74 
75  maxLevels_(50),
76 
77  nCellsInCoarsestLevel_
78  (
79  readLabel(controlDict.lookup("nCellsInCoarsestLevel"))
80  ),
81 
82  nCells_(maxLevels_),
83  restrictAddressing_(maxLevels_),
84  faceRestrictAddressing_(maxLevels_),
85 
86  meshLevels_(maxLevels_),
87  interfaceLevels_(maxLevels_ + 1)
88 {}
89 
90 
92 (
93  const lduMesh& mesh,
94  const dictionary& controlDict
95 )
96 {
97  if
98  (
100  (
101  GAMGAgglomeration::typeName
102  )
103  )
104  {
105  word agglomeratorType(controlDict.lookup("agglomerator"));
106 
108  (
109  controlDict,
110  "geometricGAMGAgglomerationLibs",
111  lduMeshConstructorTablePtr_
112  );
113 
114  lduMeshConstructorTable::iterator cstrIter =
115  lduMeshConstructorTablePtr_->find(agglomeratorType);
116 
117  if (cstrIter == lduMeshConstructorTablePtr_->end())
118  {
120  (
121  "GAMGAgglomeration::New"
122  "(const lduMesh& mesh, const dictionary& controlDict)"
123  ) << "Unknown GAMGAgglomeration type "
124  << agglomeratorType << ".\n"
125  << "Valid algebraic GAMGAgglomeration types are :"
126  << lduMatrixConstructorTablePtr_->sortedToc() << endl
127  << "Valid algebraic GAMGAgglomeration types are :"
128  << lduMeshConstructorTablePtr_->sortedToc()
129  << exit(FatalError);
130  }
131 
132  return store(cstrIter()(mesh, controlDict).ptr());
133  }
134  else
135  {
136  return mesh.thisDb().lookupObject<GAMGAgglomeration>
137  (
138  GAMGAgglomeration::typeName
139  );
140  }
141 }
142 
143 
145 (
146  const lduMatrix& matrix,
147  const dictionary& controlDict
148 )
149 {
150  const lduMesh& mesh = matrix.mesh();
151 
152  if
153  (
155  (
156  GAMGAgglomeration::typeName
157  )
158  )
159  {
160  word agglomeratorType(controlDict.lookup("agglomerator"));
161 
163  (
164  controlDict,
165  "algebraicGAMGAgglomerationLibs",
166  lduMatrixConstructorTablePtr_
167  );
168 
169  if
170  (
171  !lduMatrixConstructorTablePtr_
172  || !lduMatrixConstructorTablePtr_->found(agglomeratorType)
173  )
174  {
175  return New(mesh, controlDict);
176  }
177  else
178  {
179  lduMatrixConstructorTable::iterator cstrIter =
180  lduMatrixConstructorTablePtr_->find(agglomeratorType);
181 
182  return store(cstrIter()(matrix, controlDict).ptr());
183  }
184  }
185  else
186  {
187  return mesh.thisDb().lookupObject<GAMGAgglomeration>
188  (
189  GAMGAgglomeration::typeName
190  );
191  }
192 }
193 
194 
195 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
196 
198 {
199  // Clear the interface storage by hand.
200  // It is a list of ptrs not a PtrList for consistency of the interface
201  for (label leveli=1; leveli<interfaceLevels_.size(); leveli++)
202  {
203  lduInterfacePtrsList& curLevel = interfaceLevels_[leveli];
204 
205  forAll (curLevel, i)
206  {
207  if (curLevel.set(i))
208  {
209  delete curLevel(i);
210  }
211  }
212  }
213 }
214 
215 
216 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
217 
219 (
220  const label i
221 ) const
222 {
223  if (i == 0)
224  {
225  return mesh_;
226  }
227  else
228  {
229  return meshLevels_[i - 1];
230  }
231 }
232 
233 
235 (
236  const label i
237 ) const
238 {
239  return interfaceLevels_[i];
240 }
241 
242 
243 // ************************ vim: set sw=4 sts=4 et: ************************ //