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

GAMGPreconditioner.C

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 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/GAMGPreconditioner.H>
00027 
00028 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00029 
00030 namespace Foam
00031 {
00032     defineTypeNameAndDebug(GAMGPreconditioner, 0);
00033 
00034     lduMatrix::preconditioner::addsymMatrixConstructorToTable
00035     <GAMGPreconditioner> addGAMGPreconditionerSymMatrixConstructorToTable_;
00036 
00037     lduMatrix::preconditioner::addasymMatrixConstructorToTable
00038     <GAMGPreconditioner> addGAMGPreconditionerAsymMatrixConstructorToTable_;
00039 }
00040 
00041 
00042 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00043 
00044 Foam::GAMGPreconditioner::GAMGPreconditioner
00045 (
00046     const lduMatrix::solver& sol,
00047     const dictionary& solverControls
00048 )
00049 :
00050     GAMGSolver
00051     (
00052         sol.fieldName(),
00053         sol.matrix(),
00054         sol.interfaceBouCoeffs(),
00055         sol.interfaceIntCoeffs(),
00056         sol.interfaces(),
00057         solverControls
00058     ),
00059     lduMatrix::preconditioner(sol),
00060     nVcycles_(2)
00061 {
00062     readControls();
00063 }
00064 
00065 
00066 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00067 
00068 Foam::GAMGPreconditioner::~GAMGPreconditioner()
00069 {}
00070 
00071 
00072 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00073 
00074 void Foam::GAMGPreconditioner::readControls()
00075 {
00076     GAMGSolver::readControls();
00077     nVcycles_ = controlDict_.lookupOrDefault<label>("nVcycles", 2);
00078 }
00079 
00080 
00081 void Foam::GAMGPreconditioner::precondition
00082 (
00083     scalarField& wA,
00084     const scalarField& rA,
00085     const direction cmpt
00086 ) const
00087 {
00088     wA = 0.0;
00089     scalarField AwA(wA.size());
00090     scalarField finestCorrection(wA.size());
00091     scalarField finestResidual(rA);
00092 
00093     // Create coarse grid correction fields
00094     PtrList<scalarField> coarseCorrFields;
00095 
00096     // Create coarse grid sources
00097     PtrList<scalarField> coarseSources;
00098 
00099     // Create the smoothers for all levels
00100     PtrList<lduMatrix::smoother> smoothers;
00101 
00102     // Initialise the above data structures
00103     initVcycle(coarseCorrFields, coarseSources, smoothers);
00104 
00105     for (label cycle=0; cycle<nVcycles_; cycle++)
00106     {
00107         Vcycle
00108         (
00109             smoothers,
00110             wA,
00111             rA,
00112             AwA,
00113             finestCorrection,
00114             finestResidual,
00115             coarseCorrFields,
00116             coarseSources,
00117             cmpt
00118         );
00119 
00120         if (cycle < nVcycles_-1)
00121         {
00122             // Calculate finest level residual field
00123             matrix_.Amul(AwA, wA, interfaceBouCoeffs_, interfaces_, cmpt);
00124             finestResidual = rA;
00125             finestResidual -= AwA;
00126         }
00127     }
00128 }
00129 
00130 
00131 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines