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

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