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

GAMGSolver.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 "GAMGSolver.H"
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033     defineTypeNameAndDebug(GAMGSolver, 0);
00034 
00035     lduMatrix::solver::addsymMatrixConstructorToTable<GAMGSolver>
00036         addGAMGSolverMatrixConstructorToTable_;
00037 
00038     lduMatrix::solver::addasymMatrixConstructorToTable<GAMGSolver>
00039         addGAMGAsymSolverMatrixConstructorToTable_;
00040 }
00041 
00042 
00043 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00044 
00045 Foam::GAMGSolver::GAMGSolver
00046 (
00047     const word& fieldName,
00048     const lduMatrix& matrix,
00049     const FieldField<Field, scalar>& interfaceBouCoeffs,
00050     const FieldField<Field, scalar>& interfaceIntCoeffs,
00051     const lduInterfaceFieldPtrsList& interfaces,
00052     const dictionary& solverControls
00053 )
00054 :
00055     lduMatrix::solver
00056     (
00057         fieldName,
00058         matrix,
00059         interfaceBouCoeffs,
00060         interfaceIntCoeffs,
00061         interfaces,
00062         solverControls
00063     ),
00064 
00065     // Default values for all controls
00066     // which may be overridden by those in controlDict
00067     cacheAgglomeration_(false),
00068     nPreSweeps_(0),
00069     nPostSweeps_(2),
00070     nFinestSweeps_(2),
00071     scaleCorrection_(matrix.symmetric()),
00072     directSolveCoarsest_(false),
00073     agglomeration_(GAMGAgglomeration::New(matrix_, controlDict_)),
00074 
00075     matrixLevels_(agglomeration_.size()),
00076     interfaceLevels_(agglomeration_.size()),
00077     interfaceLevelsBouCoeffs_(agglomeration_.size()),
00078     interfaceLevelsIntCoeffs_(agglomeration_.size())
00079 {
00080     readControls();
00081 
00082     forAll(agglomeration_, fineLevelIndex)
00083     {
00084         agglomerateMatrix(fineLevelIndex);
00085     }
00086 
00087     if (matrixLevels_.size())
00088     {
00089         const label coarsestLevel = matrixLevels_.size() - 1;
00090 
00091         if (directSolveCoarsest_)
00092         {
00093             coarsestLUMatrixPtr_.set
00094             (
00095                 new LUscalarMatrix
00096                 (
00097                     matrixLevels_[coarsestLevel],
00098                     interfaceLevelsBouCoeffs_[coarsestLevel],
00099                     interfaceLevels_[coarsestLevel]
00100                 )
00101             );
00102         }
00103     }
00104     else
00105     {
00106         FatalErrorIn
00107         (
00108             "GAMGSolver::GAMGSolver"
00109             "("
00110             "const word& fieldName,"
00111             "const lduMatrix& matrix,"
00112             "const FieldField<Field, scalar>& interfaceBouCoeffs,"
00113             "const FieldField<Field, scalar>& interfaceIntCoeffs,"
00114             "const lduInterfaceFieldPtrsList& interfaces,"
00115             "const dictionary& solverControls"
00116             ")"
00117         )   << "No coarse levels created, either matrix too small for GAMG"
00118                " or nCellsInCoarsestLevel too large.\n"
00119                "    Either choose another solver of reduce "
00120                "nCellsInCoarsestLevel."
00121             << exit(FatalError);
00122     }
00123 }
00124 
00125 
00126 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00127 
00128 Foam::GAMGSolver::~GAMGSolver()
00129 {
00130     // Clear the the lists of pointers to the interfaces
00131     forAll (interfaceLevels_, leveli)
00132     {
00133         lduInterfaceFieldPtrsList& curLevel = interfaceLevels_[leveli];
00134 
00135         forAll (curLevel, i)
00136         {
00137             if (curLevel.set(i))
00138             {
00139                 delete curLevel(i);
00140             }
00141         }
00142     }
00143 
00144     if (!cacheAgglomeration_)
00145     {
00146         delete &agglomeration_;
00147     }
00148 }
00149 
00150 
00151 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00152 
00153 void Foam::GAMGSolver::readControls()
00154 {
00155     lduMatrix::solver::readControls();
00156 
00157     // we could also consider supplying defaults here too
00158     controlDict_.readIfPresent("cacheAgglomeration", cacheAgglomeration_);
00159     controlDict_.readIfPresent("nPreSweeps", nPreSweeps_);
00160     controlDict_.readIfPresent("nPostSweeps", nPostSweeps_);
00161     controlDict_.readIfPresent("nFinestSweeps", nFinestSweeps_);
00162     controlDict_.readIfPresent("scaleCorrection", scaleCorrection_);
00163     controlDict_.readIfPresent("directSolveCoarsest", directSolveCoarsest_);
00164 }
00165 
00166 
00167 const Foam::lduMatrix& Foam::GAMGSolver::matrixLevel(const label i) const
00168 {
00169     if (i == 0)
00170     {
00171         return matrix_;
00172     }
00173     else
00174     {
00175         return matrixLevels_[i - 1];
00176     }
00177 }
00178 
00179 
00180 const Foam::lduInterfaceFieldPtrsList& Foam::GAMGSolver::interfaceLevel
00181 (
00182     const label i
00183 ) const
00184 {
00185     if (i == 0)
00186     {
00187         return interfaces_;
00188     }
00189     else
00190     {
00191         return interfaceLevels_[i - 1];
00192     }
00193 }
00194 
00195 
00196 const Foam::FieldField<Foam::Field, Foam::scalar>&
00197 Foam::GAMGSolver::interfaceBouCoeffsLevel
00198 (
00199     const label i
00200 ) const
00201 {
00202     if (i == 0)
00203     {
00204         return interfaceBouCoeffs_;
00205     }
00206     else
00207     {
00208         return interfaceLevelsBouCoeffs_[i - 1];
00209     }
00210 }
00211 
00212 
00213 const Foam::FieldField<Foam::Field, Foam::scalar>&
00214 Foam::GAMGSolver::interfaceIntCoeffsLevel
00215 (
00216     const label i
00217 ) const
00218 {
00219     if (i == 0)
00220     {
00221         return interfaceIntCoeffs_;
00222     }
00223     else
00224     {
00225         return interfaceLevelsIntCoeffs_[i - 1];
00226     }
00227 }
00228 
00229 
00230 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd