OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

GAMGSolver.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::GAMGSolver
00027 
00028 Description
00029     Geometric agglomerated algebraic multigrid solver.
00030 
00031   Characteristics:
00032       - Requires positive definite, diagonally dominant matrix.
00033       - Agglomeration algorithm: selectable and optionally cached.
00034       - Restriction operator: summation.
00035       - Prolongation operator: injection.
00036       - Smoother: Gauss-Seidel.
00037       - Coarse matrix creation: central coefficient: summation of fine grid
00038         central coefficients with the removal of intra-cluster face;
00039         off-diagonal coefficient: summation of off-diagonal faces.
00040       - Coarse matrix scaling: performed by correction scaling, using steepest
00041         descent optimisation.
00042       - Type of cycle: V-cycle with optional pre-smoothing.
00043       - Coarsest-level matrix solved using ICCG or BICCG.
00044 
00045 SourceFiles
00046     GAMGSolver.C
00047     GAMGSolverCalcAgglomeration.C
00048     GAMGSolverMakeCoarseMatrix.C
00049     GAMGSolverOperations.C
00050     GAMGSolverSolve.C
00051 
00052 \*---------------------------------------------------------------------------*/
00053 
00054 #ifndef GAMGSolver_H
00055 #define GAMGSolver_H
00056 
00057 #include "GAMGAgglomeration.H"
00058 #include "lduMatrix.H"
00059 #include "labelField.H"
00060 #include "primitiveFields.H"
00061 #include "LUscalarMatrix.H"
00062 #include "Switch.H"
00063 
00064 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00065 
00066 namespace Foam
00067 {
00068 
00069 /*---------------------------------------------------------------------------*\
00070                            Class GAMGSolver Declaration
00071 \*---------------------------------------------------------------------------*/
00072 
00073 class GAMGSolver
00074 :
00075     public lduMatrix::solver
00076 {
00077     // Private data
00078 
00079         Switch cacheAgglomeration_;
00080 
00081         //- Number of pre-smoothing sweeps
00082         label nPreSweeps_;
00083 
00084         //- Number of post-smoothing sweeps
00085         label nPostSweeps_;
00086 
00087         //- Number of smoothing sweeps on finest mesh
00088         label nFinestSweeps_;
00089 
00090         //- Choose if the corrections should be scaled.
00091         //  By default corrections for symmetric matrices are scaled
00092         //  but not for asymmetric matrices.
00093         bool scaleCorrection_;
00094 
00095         //- Direct or iteratively solve the coarsest level
00096         bool directSolveCoarsest_;
00097 
00098         //- The agglomeration
00099         const GAMGAgglomeration& agglomeration_;
00100 
00101         //- Hierarchy of matrix levels
00102         PtrList<lduMatrix> matrixLevels_;
00103 
00104         //- Hierarchy of interfaces.
00105         //  Warning: Needs to be deleted explicitly.
00106         PtrList<lduInterfaceFieldPtrsList> interfaceLevels_;
00107 
00108         //- Hierarchy of interface boundary coefficients
00109         PtrList<FieldField<Field, scalar> > interfaceLevelsBouCoeffs_;
00110 
00111         //- Hierarchy of interface internal coefficients
00112         PtrList<FieldField<Field, scalar> > interfaceLevelsIntCoeffs_;
00113 
00114         //- LU decompsed coarsest matrix
00115         autoPtr<LUscalarMatrix> coarsestLUMatrixPtr_;
00116 
00117 
00118     // Private Member Functions
00119 
00120         //- Read control parameters from the control dictionary
00121         virtual void readControls();
00122 
00123         //- Simplified access to interface level
00124         const lduInterfaceFieldPtrsList& interfaceLevel
00125         (
00126             const label i
00127         ) const;
00128 
00129         //- Simplified access to matrix level
00130         const lduMatrix& matrixLevel(const label i) const;
00131 
00132         //- Simplified access to interface boundary coeffs level
00133         const FieldField<Field, scalar>& interfaceBouCoeffsLevel
00134         (
00135             const label i
00136         ) const;
00137 
00138         //- Simplified access to interface internal coeffs level
00139         const FieldField<Field, scalar>& interfaceIntCoeffsLevel
00140         (
00141             const label i
00142         ) const;
00143 
00144         //- Agglomerate coarse matrix
00145         void agglomerateMatrix(const label fineLevelIndex);
00146 
00147         //- Calculate and return the scaling factor from Acf, coarseSource
00148         //  and coarseField.
00149         //  At the same time do a Jacobi iteration on the coarseField using
00150         //  the Acf provided after the coarseField values are used for the 
00151         //  scaling factor.
00152         scalar scalingFactor
00153         (
00154             scalarField& field,
00155             const scalarField& source,
00156             const scalarField& Acf,
00157             const scalarField& D
00158         ) const;
00159 
00160         //- Calculate Acf and calculate and return the scaling factor.
00161         scalar scalingFactor
00162         (
00163             scalarField& Acf,
00164             const lduMatrix& A,
00165             scalarField& field,
00166             const FieldField<Field, scalar>& interfaceLevelBouCoeffs,
00167             const lduInterfaceFieldPtrsList& interfaceLevel,
00168             const scalarField& source,
00169             const direction cmpt
00170         ) const;
00171 
00172 
00173         //- Initialise the data structures for the V-cycle
00174         void initVcycle
00175         (
00176             PtrList<scalarField>& coarseCorrFields,
00177             PtrList<scalarField>& coarseSources,
00178             PtrList<lduMatrix::smoother>& smoothers
00179         ) const;
00180 
00181 
00182         //- Perform a single GAMG V-cycle with pre, post and finest smoothing.
00183         void Vcycle
00184         (
00185             const PtrList<lduMatrix::smoother>& smoothers,
00186             scalarField& psi,
00187             const scalarField& source,
00188             scalarField& Apsi,
00189             scalarField& finestCorrection,
00190             scalarField& finestResidual,
00191             PtrList<scalarField>& coarseCorrFields,
00192             PtrList<scalarField>& coarseSources,
00193             const direction cmpt=0
00194         ) const;
00195 
00196 
00197         //- Solve the coarsest level with either an iterative or direct solver
00198         void solveCoarsestLevel
00199         (
00200             scalarField& coarsestCorrField,
00201             const scalarField& coarsestSource
00202         ) const;
00203 
00204 
00205 public:
00206 
00207     friend class GAMGPreconditioner;
00208 
00209     //- Runtime type information
00210     TypeName("GAMG");
00211 
00212 
00213     // Constructors
00214 
00215         //- Construct from lduMatrix and solver controls
00216         GAMGSolver
00217         (
00218             const word& fieldName,
00219             const lduMatrix& matrix,
00220             const FieldField<Field, scalar>& interfaceBouCoeffs,
00221             const FieldField<Field, scalar>& interfaceIntCoeffs,
00222             const lduInterfaceFieldPtrsList& interfaces,
00223             const dictionary& solverControls
00224         );
00225 
00226 
00227     // Destructor
00228 
00229         virtual ~GAMGSolver();
00230 
00231 
00232     // Member Functions
00233 
00234         //- Solve
00235         virtual lduMatrix::solverPerformance solve
00236         (
00237             scalarField& psi,
00238             const scalarField& source,
00239             const direction cmpt=0
00240         ) const;
00241 };
00242 
00243 
00244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00245 
00246 } // End namespace Foam
00247 
00248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00249 
00250 #endif
00251 
00252 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd