initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / matrices / lduMatrix / solvers / GAMG / GAMGSolver.C
blobc11f4bb765e6808ec373830f98b81c70c76895da
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "GAMGSolver.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 namespace Foam
33     defineTypeNameAndDebug(GAMGSolver, 0);
35     lduMatrix::solver::addsymMatrixConstructorToTable<GAMGSolver>
36         addGAMGSolverMatrixConstructorToTable_;
38     lduMatrix::solver::addasymMatrixConstructorToTable<GAMGSolver>
39         addGAMGAsymSolverMatrixConstructorToTable_;
43 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
45 Foam::GAMGSolver::GAMGSolver
47     const word& fieldName,
48     const lduMatrix& matrix,
49     const FieldField<Field, scalar>& interfaceBouCoeffs,
50     const FieldField<Field, scalar>& interfaceIntCoeffs,
51     const lduInterfaceFieldPtrsList& interfaces,
52     const dictionary& solverControls
55     lduMatrix::solver
56     (
57         fieldName,
58         matrix,
59         interfaceBouCoeffs,
60         interfaceIntCoeffs,
61         interfaces,
62         solverControls
63     ),
65     // Default values for all controls
66     // which may be overridden by those in controlDict
67     cacheAgglomeration_(false),
68     nPreSweeps_(0),
69     nPostSweeps_(2),
70     nFinestSweeps_(2),
71     scaleCorrection_(matrix.symmetric()),
72     directSolveCoarsest_(false),
73     agglomeration_(GAMGAgglomeration::New(matrix_, controlDict_)),
75     matrixLevels_(agglomeration_.size()),
76     interfaceLevels_(agglomeration_.size()),
77     interfaceLevelsBouCoeffs_(agglomeration_.size()),
78     interfaceLevelsIntCoeffs_(agglomeration_.size())
80     readControls();
82     forAll(agglomeration_, fineLevelIndex)
83     {
84         agglomerateMatrix(fineLevelIndex);
85     }
87     if (matrixLevels_.size())
88     {
89         const label coarsestLevel = matrixLevels_.size() - 1;
91         if (directSolveCoarsest_)
92         {
93             coarsestLUMatrixPtr_.set
94             (
95                 new LUscalarMatrix
96                 (
97                     matrixLevels_[coarsestLevel],
98                     interfaceLevelsBouCoeffs_[coarsestLevel],
99                     interfaceLevels_[coarsestLevel]
100                 )
101             );
102         }
103     }
104     else
105     {
106         FatalErrorIn
107         (
108             "GAMGSolver::GAMGSolver"
109             "("
110             "const word& fieldName,"
111             "const lduMatrix& matrix,"
112             "const FieldField<Field, scalar>& interfaceBouCoeffs,"
113             "const FieldField<Field, scalar>& interfaceIntCoeffs,"
114             "const lduInterfaceFieldPtrsList& interfaces,"
115             "const dictionary& solverControls"
116             ")"
117         )   << "No coarse levels created, either matrix too small for GAMG"
118                " or nCellsInCoarsestLevel too large.\n"
119                "    Either choose another solver of reduce "
120                "nCellsInCoarsestLevel."
121             << exit(FatalError);
122     }
126 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
128 Foam::GAMGSolver::~GAMGSolver()
130     // Clear the the lists of pointers to the interfaces
131     forAll (interfaceLevels_, leveli)
132     {
133         lduInterfaceFieldPtrsList& curLevel = interfaceLevels_[leveli];
135         forAll (curLevel, i)
136         {
137             if (curLevel.set(i))
138             {
139                 delete curLevel(i);
140             }
141         }
142     }
144     if (!cacheAgglomeration_)
145     {
146         delete &agglomeration_;
147     }
151 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
153 void Foam::GAMGSolver::readControls()
155     lduMatrix::solver::readControls();
157     // we could also consider supplying defaults here too
158     controlDict_.readIfPresent("cacheAgglomeration", cacheAgglomeration_);
159     controlDict_.readIfPresent("nPreSweeps", nPreSweeps_);
160     controlDict_.readIfPresent("nPostSweeps", nPostSweeps_);
161     controlDict_.readIfPresent("nFinestSweeps", nFinestSweeps_);
162     controlDict_.readIfPresent("scaleCorrection", scaleCorrection_);
163     controlDict_.readIfPresent("directSolveCoarsest", directSolveCoarsest_);
167 const Foam::lduMatrix& Foam::GAMGSolver::matrixLevel(const label i) const
169     if (i == 0)
170     {
171         return matrix_;
172     }
173     else
174     {
175         return matrixLevels_[i - 1];
176     }
180 const Foam::lduInterfaceFieldPtrsList& Foam::GAMGSolver::interfaceLevel
182     const label i
183 ) const
185     if (i == 0)
186     {
187         return interfaces_;
188     }
189     else
190     {
191         return interfaceLevels_[i - 1];
192     }
196 const Foam::FieldField<Foam::Field, Foam::scalar>&
197 Foam::GAMGSolver::interfaceBouCoeffsLevel
199     const label i
200 ) const
202     if (i == 0)
203     {
204         return interfaceBouCoeffs_;
205     }
206     else
207     {
208         return interfaceLevelsBouCoeffs_[i - 1];
209     }
213 const Foam::FieldField<Foam::Field, Foam::scalar>&
214 Foam::GAMGSolver::interfaceIntCoeffsLevel
216     const label i
217 ) const
219     if (i == 0)
220     {
221         return interfaceIntCoeffs_;
222     }
223     else
224     {
225         return interfaceLevelsIntCoeffs_[i - 1];
226     }
230 // ************************************************************************* //