ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / matrices / lduMatrix / solvers / GAMG / GAMGSolver.C
blob4d2ec30de2fe54dc4dc87a8a505c5df728746e65
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "GAMGSolver.H"
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 namespace Foam
32     defineTypeNameAndDebug(GAMGSolver, 0);
34     lduMatrix::solver::addsymMatrixConstructorToTable<GAMGSolver>
35         addGAMGSolverMatrixConstructorToTable_;
37     lduMatrix::solver::addasymMatrixConstructorToTable<GAMGSolver>
38         addGAMGAsymSolverMatrixConstructorToTable_;
42 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
44 Foam::GAMGSolver::GAMGSolver
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
54     lduMatrix::solver
55     (
56         fieldName,
57         matrix,
58         interfaceBouCoeffs,
59         interfaceIntCoeffs,
60         interfaces,
61         solverControls
62     ),
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_)),
74     matrixLevels_(agglomeration_.size()),
75     interfaceLevels_(agglomeration_.size()),
76     interfaceLevelsBouCoeffs_(agglomeration_.size()),
77     interfaceLevelsIntCoeffs_(agglomeration_.size())
79     readControls();
81     forAll(agglomeration_, fineLevelIndex)
82     {
83         agglomerateMatrix(fineLevelIndex);
84     }
86     if (matrixLevels_.size())
87     {
88         const label coarsestLevel = matrixLevels_.size() - 1;
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     {
105         FatalErrorIn
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     }
125 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
127 Foam::GAMGSolver::~GAMGSolver()
129     // Clear the the lists of pointers to the interfaces
130     forAll(interfaceLevels_, leveli)
131     {
132         lduInterfaceFieldPtrsList& curLevel = interfaceLevels_[leveli];
134         forAll(curLevel, i)
135         {
136             if (curLevel.set(i))
137             {
138                 delete curLevel(i);
139             }
140         }
141     }
143     if (!cacheAgglomeration_)
144     {
145         delete &agglomeration_;
146     }
150 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
152 void Foam::GAMGSolver::readControls()
154     lduMatrix::solver::readControls();
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_);
166 const Foam::lduMatrix& Foam::GAMGSolver::matrixLevel(const label i) const
168     if (i == 0)
169     {
170         return matrix_;
171     }
172     else
173     {
174         return matrixLevels_[i - 1];
175     }
179 const Foam::lduInterfaceFieldPtrsList& Foam::GAMGSolver::interfaceLevel
181     const label i
182 ) const
184     if (i == 0)
185     {
186         return interfaces_;
187     }
188     else
189     {
190         return interfaceLevels_[i - 1];
191     }
195 const Foam::FieldField<Foam::Field, Foam::scalar>&
196 Foam::GAMGSolver::interfaceBouCoeffsLevel
198     const label i
199 ) const
201     if (i == 0)
202     {
203         return interfaceBouCoeffs_;
204     }
205     else
206     {
207         return interfaceLevelsBouCoeffs_[i - 1];
208     }
212 const Foam::FieldField<Foam::Field, Foam::scalar>&
213 Foam::GAMGSolver::interfaceIntCoeffsLevel
215     const label i
216 ) const
218     if (i == 0)
219     {
220         return interfaceIntCoeffs_;
221     }
222     else
223     {
224         return interfaceLevelsIntCoeffs_[i - 1];
225     }
229 // ************************************************************************* //