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

MGridGenGAMGAgglomeration.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 "MGridGenGAMGAgglomeration.H"
00027 #include <finiteVolume/fvMesh.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     defineTypeNameAndDebug(MGridGenGAMGAgglomeration, 0);
00035 
00036     addToRunTimeSelectionTable
00037     (
00038         GAMGAgglomeration,
00039         MGridGenGAMGAgglomeration,
00040         lduMesh
00041     );
00042 }
00043 
00044 
00045 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00046 
00047 Foam::MGridGenGAMGAgglomeration::MGridGenGAMGAgglomeration
00048 (
00049     const lduMesh& mesh,
00050     const dictionary& controlDict
00051 )
00052 :
00053     GAMGAgglomeration(mesh, controlDict),
00054     fvMesh_(refCast<const fvMesh>(mesh))
00055 {
00056     // Min, max size of agglomerated cells
00057     label minSize(readLabel(controlDict.lookup("minSize")));
00058     label maxSize(readLabel(controlDict.lookup("maxSize")));
00059 
00060 
00061     // Get the finest-level interfaces from the mesh
00062     interfaceLevels_.set
00063     (
00064         0,
00065         new lduInterfacePtrsList(fvMesh_.boundary().interfaces())
00066     );
00067 
00068     // Start geometric agglomeration from the cell volumes and areas of the mesh
00069     scalarField* VPtr = const_cast<scalarField*>(&fvMesh_.cellVolumes());
00070     vectorField* SfPtr = const_cast<vectorField*>(&fvMesh_.faceAreas());
00071 
00072     // Create the boundary area cell field
00073     scalarField* SbPtr(new scalarField(fvMesh_.nCells(), 0));
00074 
00075     {
00076         scalarField& Sb = *SbPtr;
00077 
00078         const labelList& own = fvMesh_.faceOwner();
00079         const vectorField& Sf = fvMesh_.faceAreas();
00080 
00081         forAll(Sf, facei)
00082         {
00083             if (!fvMesh_.isInternalFace(facei))
00084             {
00085                 Sb[own[facei]] += mag(Sf[facei]);
00086             }
00087         }
00088     }
00089 
00090 
00091     // Agglomerate until the required number of cells in the coarsest level
00092     // is reached
00093 
00094     label nCreatedLevels = 0;
00095 
00096     while (nCreatedLevels < maxLevels_ - 1)
00097     {
00098         label nCoarseCells = -1;
00099 
00100         tmp<labelField> finalAgglomPtr = agglomerate
00101         (
00102             nCoarseCells,
00103             minSize,
00104             maxSize,
00105             meshLevel(nCreatedLevels).lduAddr(),
00106             *VPtr,
00107             *SfPtr,
00108             *SbPtr
00109         );
00110 
00111         if (continueAgglomerating(nCoarseCells))
00112         {
00113             nCells_[nCreatedLevels] = nCoarseCells;
00114             restrictAddressing_.set(nCreatedLevels, finalAgglomPtr);
00115         }
00116         else
00117         {
00118             break;
00119         }
00120 
00121         agglomerateLduAddressing(nCreatedLevels);
00122 
00123         // Agglomerate the cell volumes field for the next level
00124         {
00125             scalarField* aggVPtr
00126             (
00127                 new scalarField(meshLevels_[nCreatedLevels].size())
00128             );
00129 
00130             restrictField(*aggVPtr, *VPtr, nCreatedLevels);
00131 
00132             if (nCreatedLevels)
00133             {
00134                 delete VPtr;
00135             }
00136 
00137             VPtr = aggVPtr;
00138         }
00139 
00140         // Agglomerate the face areas field for the next level
00141         {
00142             vectorField* aggSfPtr
00143             (
00144                 new vectorField
00145                 (
00146                     meshLevels_[nCreatedLevels].upperAddr().size(),
00147                     vector::zero
00148                 )
00149             );
00150 
00151             restrictFaceField(*aggSfPtr, *SfPtr, nCreatedLevels);
00152 
00153             if (nCreatedLevels)
00154             {
00155                 delete SfPtr;
00156             }
00157 
00158             SfPtr = aggSfPtr;
00159         }
00160 
00161         // Agglomerate the cell boundary areas field for the next level
00162         {
00163             scalarField* aggSbPtr
00164             (
00165                 new scalarField(meshLevels_[nCreatedLevels].size())
00166             );
00167 
00168             restrictField(*aggSbPtr, *SbPtr, nCreatedLevels);
00169 
00170             delete SbPtr;
00171             SbPtr = aggSbPtr;
00172         }
00173 
00174         nCreatedLevels++;
00175     }
00176 
00177     // Shrink the storage of the levels to those created
00178     compactLevels(nCreatedLevels);
00179 
00180     // Delete temporary geometry storage
00181     if (nCreatedLevels)
00182     {
00183         delete VPtr;
00184         delete SfPtr;
00185     }
00186     delete SbPtr;
00187 }
00188 
00189 
00190 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines