initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / matrices / lduMatrix / solvers / GAMG / GAMGSolver.H
blobcc46f7931b0c46946e8b8224d0f5c7168bd679e0
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 Class
26     Foam::GAMGSolver
28 Description
29     Geometric agglomerated algebraic multigrid solver.
31   Characteristics:
32       - Requires positive definite, diagonally dominant matrix.
33       - Agglomeration algorithm: selectable and optionally cached.
34       - Restriction operator: summation.
35       - Prolongation operator: injection.
36       - Smoother: Gauss-Seidel.
37       - Coarse matrix creation: central coefficient: summation of fine grid
38         central coefficients with the removal of intra-cluster face;
39         off-diagonal coefficient: summation of off-diagonal faces.
40       - Coarse matrix scaling: performed by correction scaling, using steepest
41         descent optimisation.
42       - Type of cycle: V-cycle with optional pre-smoothing.
43       - Coarsest-level matrix solved using ICCG or BICCG.
45 SourceFiles
46     GAMGSolver.C
47     GAMGSolverCalcAgglomeration.C
48     GAMGSolverMakeCoarseMatrix.C
49     GAMGSolverOperations.C
50     GAMGSolverSolve.C
52 \*---------------------------------------------------------------------------*/
54 #ifndef GAMGSolver_H
55 #define GAMGSolver_H
57 #include "GAMGAgglomeration.H"
58 #include "lduMatrix.H"
59 #include "labelField.H"
60 #include "primitiveFields.H"
61 #include "LUscalarMatrix.H"
62 #include "Switch.H"
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 namespace Foam
69 /*---------------------------------------------------------------------------*\
70                            Class GAMGSolver Declaration
71 \*---------------------------------------------------------------------------*/
73 class GAMGSolver
75     public lduMatrix::solver
77     // Private data
79         Switch cacheAgglomeration_;
81         //- Number of pre-smoothing sweeps
82         label nPreSweeps_;
84         //- Number of post-smoothing sweeps
85         label nPostSweeps_;
87         //- Number of smoothing sweeps on finest mesh
88         label nFinestSweeps_;
90         //- Choose if the corrections should be scaled.
91         //  By default corrections for symmetric matrices are scaled
92         //  but not for asymmetric matrices.
93         bool scaleCorrection_;
95         //- Direct or iteratively solve the coarsest level
96         bool directSolveCoarsest_;
98         //- The agglomeration
99         const GAMGAgglomeration& agglomeration_;
101         //- Hierarchy of matrix levels
102         PtrList<lduMatrix> matrixLevels_;
104         //- Hierarchy of interfaces.
105         //  Warning: Needs to be deleted explicitly.
106         PtrList<lduInterfaceFieldPtrsList> interfaceLevels_;
108         //- Hierarchy of interface boundary coefficients
109         PtrList<FieldField<Field, scalar> > interfaceLevelsBouCoeffs_;
111         //- Hierarchy of interface internal coefficients
112         PtrList<FieldField<Field, scalar> > interfaceLevelsIntCoeffs_;
114         //- LU decompsed coarsest matrix
115         autoPtr<LUscalarMatrix> coarsestLUMatrixPtr_;
118     // Private Member Functions
120         //- Read control parameters from the control dictionary
121         virtual void readControls();
123         //- Simplified access to interface level
124         const lduInterfaceFieldPtrsList& interfaceLevel
125         (
126             const label i
127         ) const;
129         //- Simplified access to matrix level
130         const lduMatrix& matrixLevel(const label i) const;
132         //- Simplified access to interface boundary coeffs level
133         const FieldField<Field, scalar>& interfaceBouCoeffsLevel
134         (
135             const label i
136         ) const;
138         //- Simplified access to interface internal coeffs level
139         const FieldField<Field, scalar>& interfaceIntCoeffsLevel
140         (
141             const label i
142         ) const;
144         //- Agglomerate coarse matrix
145         void agglomerateMatrix(const label fineLevelIndex);
147         //- Calculate and return the scaling factor from Acf, coarseSource
148         //  and coarseField.
149         //  At the same time do a Jacobi iteration on the coarseField using
150         //  the Acf provided after the coarseField values are used for the 
151         //  scaling factor.
152         scalar scalingFactor
153         (
154             scalarField& field,
155             const scalarField& source,
156             const scalarField& Acf,
157             const scalarField& D
158         ) const;
160         //- Calculate Acf and calculate and return the scaling factor.
161         scalar scalingFactor
162         (
163             scalarField& Acf,
164             const lduMatrix& A,
165             scalarField& field,
166             const FieldField<Field, scalar>& interfaceLevelBouCoeffs,
167             const lduInterfaceFieldPtrsList& interfaceLevel,
168             const scalarField& source,
169             const direction cmpt
170         ) const;
173         //- Initialise the data structures for the V-cycle
174         void initVcycle
175         (
176             PtrList<scalarField>& coarseCorrFields,
177             PtrList<scalarField>& coarseSources,
178             PtrList<lduMatrix::smoother>& smoothers
179         ) const;
182         //- Perform a single GAMG V-cycle with pre, post and finest smoothing.
183         void Vcycle
184         (
185             const PtrList<lduMatrix::smoother>& smoothers,
186             scalarField& psi,
187             const scalarField& source,
188             scalarField& Apsi,
189             scalarField& finestCorrection,
190             scalarField& finestResidual,
191             PtrList<scalarField>& coarseCorrFields,
192             PtrList<scalarField>& coarseSources,
193             const direction cmpt=0
194         ) const;
197         //- Solve the coarsest level with either an iterative or direct solver
198         void solveCoarsestLevel
199         (
200             scalarField& coarsestCorrField,
201             const scalarField& coarsestSource
202         ) const;
205 public:
207     friend class GAMGPreconditioner;
209     //- Runtime type information
210     TypeName("GAMG");
213     // Constructors
215         //- Construct from lduMatrix and solver controls
216         GAMGSolver
217         (
218             const word& fieldName,
219             const lduMatrix& matrix,
220             const FieldField<Field, scalar>& interfaceBouCoeffs,
221             const FieldField<Field, scalar>& interfaceIntCoeffs,
222             const lduInterfaceFieldPtrsList& interfaces,
223             const dictionary& solverControls
224         );
227     // Destructor
229         virtual ~GAMGSolver();
232     // Member Functions
234         //- Solve
235         virtual lduMatrix::solverPerformance solve
236         (
237             scalarField& psi,
238             const scalarField& source,
239             const direction cmpt=0
240         ) const;
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 } // End namespace Foam
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 #endif
252 // ************************************************************************* //