FreeFOAM The Cross-Platform CFD Toolkit
GAMGSolver.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 <OpenFOAM/GAMGSolver.H>
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(GAMGSolver, 0);
33 
34  lduMatrix::solver::addsymMatrixConstructorToTable<GAMGSolver>
36 
37  lduMatrix::solver::addasymMatrixConstructorToTable<GAMGSolver>
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 (
46  const word& fieldName,
47  const lduMatrix& matrix,
48  const FieldField<Field, scalar>& interfaceBouCoeffs,
49  const FieldField<Field, scalar>& interfaceIntCoeffs,
50  const lduInterfaceFieldPtrsList& interfaces,
51  const dictionary& solverControls
52 )
53 :
55  (
56  fieldName,
57  matrix,
58  interfaceBouCoeffs,
59  interfaceIntCoeffs,
60  interfaces,
61  solverControls
62  ),
63 
64  // Default values for all controls
65  // which may be overridden by those in controlDict
66  cacheAgglomeration_(false),
67  nPreSweeps_(0),
68  nPostSweeps_(2),
69  nFinestSweeps_(2),
70  scaleCorrection_(matrix.symmetric()),
71  directSolveCoarsest_(false),
72  agglomeration_(GAMGAgglomeration::New(matrix_, controlDict_)),
73 
74  matrixLevels_(agglomeration_.size()),
75  interfaceLevels_(agglomeration_.size()),
76  interfaceLevelsBouCoeffs_(agglomeration_.size()),
77  interfaceLevelsIntCoeffs_(agglomeration_.size())
78 {
79  readControls();
80 
81  forAll(agglomeration_, fineLevelIndex)
82  {
83  agglomerateMatrix(fineLevelIndex);
84  }
85 
86  if (matrixLevels_.size())
87  {
88  const label coarsestLevel = matrixLevels_.size() - 1;
89 
90  if (directSolveCoarsest_)
91  {
92  coarsestLUMatrixPtr_.set
93  (
94  new LUscalarMatrix
95  (
96  matrixLevels_[coarsestLevel],
97  interfaceLevelsBouCoeffs_[coarsestLevel],
98  interfaceLevels_[coarsestLevel]
99  )
100  );
101  }
102  }
103  else
104  {
106  (
107  "GAMGSolver::GAMGSolver"
108  "("
109  "const word& fieldName,"
110  "const lduMatrix& matrix,"
111  "const FieldField<Field, scalar>& interfaceBouCoeffs,"
112  "const FieldField<Field, scalar>& interfaceIntCoeffs,"
113  "const lduInterfaceFieldPtrsList& interfaces,"
114  "const dictionary& solverControls"
115  ")"
116  ) << "No coarse levels created, either matrix too small for GAMG"
117  " or nCellsInCoarsestLevel too large.\n"
118  " Either choose another solver of reduce "
119  "nCellsInCoarsestLevel."
120  << exit(FatalError);
121  }
122 }
123 
124 
125 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
126 
128 {
129  // Clear the the lists of pointers to the interfaces
130  forAll (interfaceLevels_, leveli)
131  {
132  lduInterfaceFieldPtrsList& curLevel = interfaceLevels_[leveli];
133 
134  forAll (curLevel, i)
135  {
136  if (curLevel.set(i))
137  {
138  delete curLevel(i);
139  }
140  }
141  }
142 
143  if (!cacheAgglomeration_)
144  {
145  delete &agglomeration_;
146  }
147 }
148 
149 
150 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
151 
152 void Foam::GAMGSolver::readControls()
153 {
155 
156  // we could also consider supplying defaults here too
157  controlDict_.readIfPresent("cacheAgglomeration", cacheAgglomeration_);
158  controlDict_.readIfPresent("nPreSweeps", nPreSweeps_);
159  controlDict_.readIfPresent("nPostSweeps", nPostSweeps_);
160  controlDict_.readIfPresent("nFinestSweeps", nFinestSweeps_);
161  controlDict_.readIfPresent("scaleCorrection", scaleCorrection_);
162  controlDict_.readIfPresent("directSolveCoarsest", directSolveCoarsest_);
163 }
164 
165 
166 const Foam::lduMatrix& Foam::GAMGSolver::matrixLevel(const label i) const
167 {
168  if (i == 0)
169  {
170  return matrix_;
171  }
172  else
173  {
174  return matrixLevels_[i - 1];
175  }
176 }
177 
178 
179 const Foam::lduInterfaceFieldPtrsList& Foam::GAMGSolver::interfaceLevel
180 (
181  const label i
182 ) const
183 {
184  if (i == 0)
185  {
186  return interfaces_;
187  }
188  else
189  {
190  return interfaceLevels_[i - 1];
191  }
192 }
193 
194 
196 Foam::GAMGSolver::interfaceBouCoeffsLevel
197 (
198  const label i
199 ) const
200 {
201  if (i == 0)
202  {
203  return interfaceBouCoeffs_;
204  }
205  else
206  {
207  return interfaceLevelsBouCoeffs_[i - 1];
208  }
209 }
210 
211 
213 Foam::GAMGSolver::interfaceIntCoeffsLevel
214 (
215  const label i
216 ) const
217 {
218  if (i == 0)
219  {
220  return interfaceIntCoeffs_;
221  }
222  else
223  {
224  return interfaceLevelsIntCoeffs_[i - 1];
225  }
226 }
227 
228 
229 // ************************ vim: set sw=4 sts=4 et: ************************ //