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

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