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

MGridGenGAMGAgglomerate.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 Description
00026     Agglomerate one level using the MGridGen algorithm.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "MGridGenGAMGAgglomeration.H"
00031 #include "fvMesh.H"
00032 #include "syncTools.H"
00033 
00034 //extern "C"
00035 //{
00036 //#   include "mgridgen.h"
00037 //}
00038 
00039 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00040 
00041 void Foam::MGridGenGAMGAgglomeration::
00042 makeCompactCellFaceAddressingAndFaceWeights
00043 (
00044     const lduAddressing& fineAddressing,
00045     List<idxtype>& cellCells,
00046     List<idxtype>& cellCellOffsets,
00047     const vectorField& Si,
00048     List<scalar>& faceWeights
00049 )
00050 {
00051     const label nFineCells = fineAddressing.size();
00052     const label nFineFaces = fineAddressing.upperAddr().size();
00053 
00054     const unallocLabelList& upperAddr = fineAddressing.upperAddr();
00055     const unallocLabelList& lowerAddr = fineAddressing.lowerAddr();
00056 
00057     // Number of neighbours for each cell
00058     labelList nNbrs(nFineCells, 0);
00059 
00060     forAll (upperAddr, facei)
00061     {
00062         nNbrs[upperAddr[facei]]++;
00063     }
00064 
00065     forAll (lowerAddr, facei)
00066     {
00067         nNbrs[lowerAddr[facei]]++;
00068     }
00069 
00070     // Set the sizes of the addressing and faceWeights arrays
00071     cellCellOffsets.setSize(nFineCells + 1);
00072     cellCells.setSize(2*nFineFaces);
00073     faceWeights.setSize(2*nFineFaces);
00074 
00075 
00076     cellCellOffsets[0] = 0;
00077     forAll (nNbrs, celli)
00078     {
00079         cellCellOffsets[celli+1] = cellCellOffsets[celli] + nNbrs[celli];
00080     }
00081 
00082     // reset the whole list to use as counter
00083     nNbrs = 0;
00084 
00085     forAll (upperAddr, facei)
00086     {
00087         label own = upperAddr[facei];
00088         label nei = lowerAddr[facei];
00089 
00090         label l1 = cellCellOffsets[own] + nNbrs[own]++;
00091         label l2 = cellCellOffsets[nei] + nNbrs[nei]++;
00092 
00093         cellCells[l1] = nei;
00094         cellCells[l2] = own;
00095 
00096         faceWeights[l1] = mag(Si[facei]);
00097         faceWeights[l2] = mag(Si[facei]);
00098     }
00099 }
00100 
00101 
00102 Foam::tmp<Foam::labelField> Foam::MGridGenGAMGAgglomeration::agglomerate
00103 (
00104     label& nCoarseCells,
00105     const label minSize,
00106     const label maxSize,
00107     const lduAddressing& fineAddressing,
00108     const scalarField& V,
00109     const vectorField& Sf,
00110     const scalarField& Sb
00111 )
00112 {
00113     const label nFineCells = fineAddressing.size();
00114 
00115     // Compact addressing for cellCells
00116     List<idxtype> cellCells;
00117     List<idxtype> cellCellOffsets;
00118 
00119     // Face weights = face areas of the internal faces
00120     List<scalar> faceWeights;
00121 
00122     // Create the compact addressing for cellCells and faceWeights
00123     makeCompactCellFaceAddressingAndFaceWeights
00124     (
00125         fineAddressing,
00126         cellCells,
00127         cellCellOffsets,
00128         Sf,
00129         faceWeights
00130     );
00131 
00132     // agglomeration options.
00133     List<int> options(4, 0);
00134     options[0] = 4;                   // globular agglom
00135     options[1] = 6;                   // objective F3 and F2
00136     options[2] = 128;                 // debugging output level
00137     options[3] = fvMesh_.nGeometricD(); // Dimensionality of the grid
00138 
00139 
00140     // output: cell -> processor addressing
00141     List<int> finalAgglom(nFineCells);
00142     int nMoves = -1;
00143         
00144     MGridGen
00145     (
00146         nFineCells,
00147         cellCellOffsets.begin(),
00148         const_cast<scalar*>(V.begin()),
00149         const_cast<scalar*>(Sb.begin()),
00150         cellCells.begin(),
00151         faceWeights.begin(),
00152         minSize,
00153         maxSize,
00154         options.begin(),
00155         &nMoves,
00156         &nCoarseCells,
00157         finalAgglom.begin()
00158     );
00159 
00160     return tmp<labelField>(new labelField(finalAgglom));
00161 }
00162 
00163 
00164 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd