FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::GAMGSolver
00026 
00027 Description
00028     Geometric agglomerated algebraic multigrid solver.
00029 
00030   Characteristics:
00031       - Requires positive definite, diagonally dominant matrix.
00032       - Agglomeration algorithm: selectable and optionally cached.
00033       - Restriction operator: summation.
00034       - Prolongation operator: injection.
00035       - Smoother: Gauss-Seidel.
00036       - Coarse matrix creation: central coefficient: summation of fine grid
00037         central coefficients with the removal of intra-cluster face;
00038         off-diagonal coefficient: summation of off-diagonal faces.
00039       - Coarse matrix scaling: performed by correction scaling, using steepest
00040         descent optimisation.
00041       - Type of cycle: V-cycle with optional pre-smoothing.
00042       - Coarsest-level matrix solved using ICCG or BICCG.
00043 
00044 SourceFiles
00045     GAMGSolver.C
00046     GAMGSolverCalcAgglomeration.C
00047     GAMGSolverMakeCoarseMatrix.C
00048     GAMGSolverOperations.C
00049     GAMGSolverSolve.C
00050 
00051 \*---------------------------------------------------------------------------*/
00052 
00053 #ifndef GAMGSolver_H
00054 #define GAMGSolver_H
00055 
00056 #include <OpenFOAM/GAMGAgglomeration.H>
00057 #include <OpenFOAM/lduMatrix.H>
00058 #include <OpenFOAM/labelField.H>
00059 #include <OpenFOAM/primitiveFields.H>
00060 #include <OpenFOAM/LUscalarMatrix.H>
00061 #include <OpenFOAM/Switch.H>
00062 
00063 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00064 
00065 namespace Foam
00066 {
00067 
00068 /*---------------------------------------------------------------------------*\
00069                            Class GAMGSolver Declaration
00070 \*---------------------------------------------------------------------------*/
00071 
00072 class GAMGSolver
00073 :
00074     public lduMatrix::solver
00075 {
00076     // Private data
00077 
00078         Switch cacheAgglomeration_;
00079 
00080         //- Number of pre-smoothing sweeps
00081         label nPreSweeps_;
00082 
00083         //- Number of post-smoothing sweeps
00084         label nPostSweeps_;
00085 
00086         //- Number of smoothing sweeps on finest mesh
00087         label nFinestSweeps_;
00088 
00089         //- Choose if the corrections should be scaled.
00090         //  By default corrections for symmetric matrices are scaled
00091         //  but not for asymmetric matrices.
00092         bool scaleCorrection_;
00093 
00094         //- Direct or iteratively solve the coarsest level
00095         bool directSolveCoarsest_;
00096 
00097         //- The agglomeration
00098         const GAMGAgglomeration& agglomeration_;
00099 
00100         //- Hierarchy of matrix levels
00101         PtrList<lduMatrix> matrixLevels_;
00102 
00103         //- Hierarchy of interfaces.
00104         //  Warning: Needs to be deleted explicitly.
00105         PtrList<lduInterfaceFieldPtrsList> interfaceLevels_;
00106 
00107         //- Hierarchy of interface boundary coefficients
00108         PtrList<FieldField<Field, scalar> > interfaceLevelsBouCoeffs_;
00109 
00110         //- Hierarchy of interface internal coefficients
00111         PtrList<FieldField<Field, scalar> > interfaceLevelsIntCoeffs_;
00112 
00113         //- LU decompsed coarsest matrix
00114         autoPtr<LUscalarMatrix> coarsestLUMatrixPtr_;
00115 
00116 
00117     // Private Member Functions
00118 
00119         //- Read control parameters from the control dictionary
00120         virtual void readControls();
00121 
00122         //- Simplified access to interface level
00123         const lduInterfaceFieldPtrsList& interfaceLevel
00124         (
00125             const label i
00126         ) const;
00127 
00128         //- Simplified access to matrix level
00129         const lduMatrix& matrixLevel(const label i) const;
00130 
00131         //- Simplified access to interface boundary coeffs level
00132         const FieldField<Field, scalar>& interfaceBouCoeffsLevel
00133         (
00134             const label i
00135         ) const;
00136 
00137         //- Simplified access to interface internal coeffs level
00138         const FieldField<Field, scalar>& interfaceIntCoeffsLevel
00139         (
00140             const label i
00141         ) const;
00142 
00143         //- Agglomerate coarse matrix
00144         void agglomerateMatrix(const label fineLevelIndex);
00145 
00146         //- Calculate and return the scaling factor from Acf, coarseSource
00147         //  and coarseField.
00148         //  At the same time do a Jacobi iteration on the coarseField using
00149         //  the Acf provided after the coarseField values are used for the 
00150         //  scaling factor.
00151         scalar scalingFactor
00152         (
00153             scalarField& field,
00154             const scalarField& source,
00155             const scalarField& Acf,
00156             const scalarField& D
00157         ) const;
00158 
00159         //- Calculate Acf and calculate and return the scaling factor.
00160         scalar scalingFactor
00161         (
00162             scalarField& Acf,
00163             const lduMatrix& A,
00164             scalarField& field,
00165             const FieldField<Field, scalar>& interfaceLevelBouCoeffs,
00166             const lduInterfaceFieldPtrsList& interfaceLevel,
00167             const scalarField& source,
00168             const direction cmpt
00169         ) const;
00170 
00171 
00172         //- Initialise the data structures for the V-cycle
00173         void initVcycle
00174         (
00175             PtrList<scalarField>& coarseCorrFields,
00176             PtrList<scalarField>& coarseSources,
00177             PtrList<lduMatrix::smoother>& smoothers
00178         ) const;
00179 
00180 
00181         //- Perform a single GAMG V-cycle with pre, post and finest smoothing.
00182         void Vcycle
00183         (
00184             const PtrList<lduMatrix::smoother>& smoothers,
00185             scalarField& psi,
00186             const scalarField& source,
00187             scalarField& Apsi,
00188             scalarField& finestCorrection,
00189             scalarField& finestResidual,
00190             PtrList<scalarField>& coarseCorrFields,
00191             PtrList<scalarField>& coarseSources,
00192             const direction cmpt=0
00193         ) const;
00194 
00195 
00196         //- Solve the coarsest level with either an iterative or direct solver
00197         void solveCoarsestLevel
00198         (
00199             scalarField& coarsestCorrField,
00200             const scalarField& coarsestSource
00201         ) const;
00202 
00203 
00204 public:
00205 
00206     friend class GAMGPreconditioner;
00207 
00208     //- Runtime type information
00209     TypeName("GAMG");
00210 
00211 
00212     // Constructors
00213 
00214         //- Construct from lduMatrix and solver controls
00215         GAMGSolver
00216         (
00217             const word& fieldName,
00218             const lduMatrix& matrix,
00219             const FieldField<Field, scalar>& interfaceBouCoeffs,
00220             const FieldField<Field, scalar>& interfaceIntCoeffs,
00221             const lduInterfaceFieldPtrsList& interfaces,
00222             const dictionary& solverControls
00223         );
00224 
00225 
00226     // Destructor
00227 
00228         virtual ~GAMGSolver();
00229 
00230 
00231     // Member Functions
00232 
00233         //- Solve
00234         virtual lduMatrix::solverPerformance solve
00235         (
00236             scalarField& psi,
00237             const scalarField& source,
00238             const direction cmpt=0
00239         ) const;
00240 };
00241 
00242 
00243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00244 
00245 } // End namespace Foam
00246 
00247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00248 
00249 #endif
00250 
00251 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines