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

GAMGAgglomeration.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 "GAMGAgglomeration.H"
00027 #include <OpenFOAM/lduMesh.H>
00028 #include <OpenFOAM/lduMatrix.H>
00029 #include <OpenFOAM/Time.H>
00030 #include <OpenFOAM/dlLibraryTable.H>
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036     defineTypeNameAndDebug(GAMGAgglomeration, 0);
00037     defineRunTimeSelectionTable(GAMGAgglomeration, lduMesh);
00038     defineRunTimeSelectionTable(GAMGAgglomeration, lduMatrix);
00039 }
00040 
00041 
00042 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00043 
00044 void Foam::GAMGAgglomeration::compactLevels(const label nCreatedLevels)
00045 {
00046     nCells_.setSize(nCreatedLevels);
00047     restrictAddressing_.setSize(nCreatedLevels);
00048     meshLevels_.setSize(nCreatedLevels);
00049     interfaceLevels_.setSize(nCreatedLevels + 1);
00050 }
00051 
00052 
00053 bool Foam::GAMGAgglomeration::continueAgglomerating
00054 (
00055     const label nCoarseCells
00056 ) const
00057 {
00058     // Check the need for further agglomeration on all processors
00059     bool contAgg = nCoarseCells >= nCellsInCoarsestLevel_;
00060     reduce(contAgg, andOp<bool>());
00061     return contAgg;
00062 }
00063 
00064 
00065 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00066 
00067 Foam::GAMGAgglomeration::GAMGAgglomeration
00068 (
00069     const lduMesh& mesh,
00070     const dictionary& controlDict
00071 )
00072 :
00073     MeshObject<lduMesh, GAMGAgglomeration>(mesh),
00074 
00075     maxLevels_(50),
00076 
00077     nCellsInCoarsestLevel_
00078     (
00079         readLabel(controlDict.lookup("nCellsInCoarsestLevel"))
00080     ),
00081 
00082     nCells_(maxLevels_),
00083     restrictAddressing_(maxLevels_),
00084     faceRestrictAddressing_(maxLevels_),
00085 
00086     meshLevels_(maxLevels_),
00087     interfaceLevels_(maxLevels_ + 1)
00088 {}
00089 
00090 
00091 const Foam::GAMGAgglomeration& Foam::GAMGAgglomeration::New
00092 (
00093     const lduMesh& mesh,
00094     const dictionary& controlDict
00095 )
00096 {
00097     if
00098     (
00099         !mesh.thisDb().foundObject<GAMGAgglomeration>
00100         (
00101             GAMGAgglomeration::typeName
00102         )
00103     )
00104     {
00105         word agglomeratorType(controlDict.lookup("agglomerator"));
00106 
00107         dlLibraryTable::open
00108         (
00109             controlDict,
00110             "geometricGAMGAgglomerationLibs",
00111             lduMeshConstructorTablePtr_
00112         );
00113 
00114         lduMeshConstructorTable::iterator cstrIter =
00115             lduMeshConstructorTablePtr_->find(agglomeratorType);
00116 
00117         if (cstrIter == lduMeshConstructorTablePtr_->end())
00118         {
00119             FatalErrorIn
00120             (
00121                 "GAMGAgglomeration::New"
00122                 "(const lduMesh& mesh, const dictionary& controlDict)"
00123             )   << "Unknown GAMGAgglomeration type "
00124                 << agglomeratorType << ".\n"
00125                 << "Valid algebraic GAMGAgglomeration types are :"
00126                 << lduMatrixConstructorTablePtr_->sortedToc() << endl
00127                 << "Valid algebraic GAMGAgglomeration types are :"
00128                 << lduMeshConstructorTablePtr_->sortedToc()
00129                 << exit(FatalError);
00130         }
00131 
00132         return store(cstrIter()(mesh, controlDict).ptr());
00133     }
00134     else
00135     {
00136         return mesh.thisDb().lookupObject<GAMGAgglomeration>
00137         (
00138             GAMGAgglomeration::typeName
00139         );
00140     }
00141 }
00142 
00143 
00144 const Foam::GAMGAgglomeration& Foam::GAMGAgglomeration::New
00145 (
00146     const lduMatrix& matrix,
00147     const dictionary& controlDict
00148 )
00149 {
00150     const lduMesh& mesh = matrix.mesh();
00151 
00152     if
00153     (
00154         !mesh.thisDb().foundObject<GAMGAgglomeration>
00155         (
00156             GAMGAgglomeration::typeName
00157         )
00158     )
00159     {
00160         word agglomeratorType(controlDict.lookup("agglomerator"));
00161 
00162         dlLibraryTable::open
00163         (
00164             controlDict,
00165             "algebraicGAMGAgglomerationLibs",
00166             lduMatrixConstructorTablePtr_
00167         );
00168 
00169         if
00170         (
00171             !lduMatrixConstructorTablePtr_
00172          || !lduMatrixConstructorTablePtr_->found(agglomeratorType)
00173         )
00174         {
00175             return New(mesh, controlDict);
00176         }
00177         else
00178         {
00179             lduMatrixConstructorTable::iterator cstrIter =
00180                 lduMatrixConstructorTablePtr_->find(agglomeratorType);
00181 
00182             return store(cstrIter()(matrix, controlDict).ptr());
00183         }
00184     }
00185     else
00186     {
00187         return mesh.thisDb().lookupObject<GAMGAgglomeration>
00188         (
00189             GAMGAgglomeration::typeName
00190         );
00191     }
00192 }
00193 
00194 
00195 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00196 
00197 Foam::GAMGAgglomeration::~GAMGAgglomeration()
00198 {
00199     // Clear the interface storage by hand.
00200     // It is a list of ptrs not a PtrList for consistency of the interface
00201     for (label leveli=1; leveli<interfaceLevels_.size(); leveli++)
00202     {
00203         lduInterfacePtrsList& curLevel = interfaceLevels_[leveli];
00204 
00205         forAll (curLevel, i)
00206         {
00207             if (curLevel.set(i))
00208             {
00209                 delete curLevel(i);
00210             }
00211         }
00212     }
00213 }
00214 
00215 
00216 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00217 
00218 const Foam::lduMesh& Foam::GAMGAgglomeration::meshLevel
00219 (
00220     const label i
00221 ) const
00222 {
00223     if (i == 0)
00224     {
00225         return mesh_;
00226     }
00227     else
00228     {
00229         return meshLevels_[i - 1];
00230     }
00231 }
00232 
00233 
00234 const Foam::lduInterfacePtrsList& Foam::GAMGAgglomeration::interfaceLevel
00235 (
00236     const label i
00237 ) const
00238 {
00239     return interfaceLevels_[i];
00240 }
00241 
00242 
00243 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines