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

cyclicGAMGInterface.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 "cyclicGAMGInterface.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033     defineTypeNameAndDebug(cyclicGAMGInterface, 0);
00034     addToRunTimeSelectionTable
00035     (
00036         GAMGInterface,
00037         cyclicGAMGInterface,
00038         lduInterface
00039     );
00040 }
00041 
00042 
00043 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00044 
00045 Foam::cyclicGAMGInterface::cyclicGAMGInterface
00046 (
00047     const lduInterface& fineInterface,
00048     const labelField& localRestrictAddressing,
00049     const labelField& neighbourRestrictAddressing
00050 )
00051 :
00052     GAMGInterface
00053     (
00054         fineInterface,
00055         localRestrictAddressing,
00056         neighbourRestrictAddressing
00057     ),
00058     fineCyclicInterface_(refCast<const cyclicLduInterface>(fineInterface))
00059 {
00060     // Make a lookup table of entries for owner/neighbour
00061     HashTable<SLList<label>, label, Hash<label> > neighboursTable
00062     (
00063         localRestrictAddressing.size()
00064     );
00065 
00066     // Table of face-sets to be agglomerated
00067     HashTable<SLList<SLList<label> >, label, Hash<label> > faceFaceTable
00068     (
00069         localRestrictAddressing.size()
00070     );
00071 
00072     label nCoarseFaces = 0;
00073 
00074     label sizeBy2 = localRestrictAddressing.size()/2;
00075 
00076     for (label ffi=0; ffi<sizeBy2; ffi++)
00077     {
00078         label curMaster = localRestrictAddressing[ffi];
00079         label curSlave = localRestrictAddressing[ffi + sizeBy2];
00080 
00081         // Look for the master cell.  If it has already got a face,
00082         // add the coefficient to the face.  If not, create a new
00083         // face.
00084         if (neighboursTable.found(curMaster))
00085         {
00086             // Check all current neighbours to see if the current
00087             // slave already exists.  If so, add the coefficient.
00088 
00089             SLList<label>& curNbrs = neighboursTable.find(curMaster)();
00090 
00091             SLList<SLList<label> >& curFaceFaces =
00092                 faceFaceTable.find(curMaster)();
00093 
00094             bool nbrFound = false;
00095 
00096             SLList<label>::iterator nbrsIter = curNbrs.begin();
00097 
00098             SLList<SLList<label> >::iterator faceFacesIter =
00099                 curFaceFaces.begin();
00100 
00101             for
00102             (
00103                 ;
00104                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
00105                 ++nbrsIter, ++faceFacesIter
00106             )
00107             {
00108                 if (nbrsIter() == curSlave)
00109                 {
00110                     nbrFound = true;
00111                     faceFacesIter().append(ffi);
00112                     break;
00113                 }
00114             }
00115 
00116             if (!nbrFound)
00117             {
00118                 curNbrs.append(curSlave);
00119                 curFaceFaces.append(ffi);
00120 
00121                 // New coarse face created
00122                 nCoarseFaces++;
00123             }
00124         }
00125         else
00126         {
00127             // This master has got no neighbours yet.  Add a neighbour
00128             // and a coefficient, thus creating a new face
00129             neighboursTable.insert(curMaster, SLList<label>(curSlave));
00130             faceFaceTable.insert(curMaster, SLList<SLList<label> >(ffi));
00131 
00132             // New coarse face created
00133             nCoarseFaces++;
00134         }
00135     } // end for all fine faces
00136 
00137 
00138     faceCells_.setSize(2*nCoarseFaces, -1);
00139     faceRestrictAddressing_.setSize(localRestrictAddressing.size(), -1);
00140 
00141     labelList contents = neighboursTable.toc();
00142 
00143     // Reset face counter for re-use
00144     nCoarseFaces = 0;
00145 
00146     // On master side, the owner addressing is stored in table of contents
00147     forAll (contents, masterI)
00148     {
00149         SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
00150 
00151         SLList<SLList<label> >& curFaceFaces =
00152             faceFaceTable.find(contents[masterI])();
00153 
00154         SLList<label>::iterator nbrsIter = curNbrs.begin();
00155         SLList<SLList<label> >::iterator faceFacesIter = curFaceFaces.begin();
00156 
00157         for
00158         (
00159             ;
00160             nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
00161             ++nbrsIter, ++faceFacesIter
00162         )
00163         {
00164             faceCells_[nCoarseFaces] = contents[masterI];
00165 
00166             for
00167             (
00168                 SLList<label>::iterator facesIter = faceFacesIter().begin();
00169                 facesIter != faceFacesIter().end();
00170                 ++facesIter
00171             )
00172             {
00173                 faceRestrictAddressing_[facesIter()] = nCoarseFaces;
00174             }
00175 
00176             nCoarseFaces++;
00177         }
00178     }
00179 
00180     // On slave side, the owner addressing is stored in linked lists
00181     forAll (contents, masterI)
00182     {
00183         SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
00184 
00185         SLList<SLList<label> >& curFaceFaces =
00186             faceFaceTable.find(contents[masterI])();
00187 
00188         SLList<label>::iterator nbrsIter = curNbrs.begin();
00189         SLList<SLList<label> >::iterator faceFacesIter = curFaceFaces.begin();
00190 
00191         for
00192         (
00193             ;
00194             nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
00195             ++nbrsIter, ++faceFacesIter
00196         )
00197         {
00198             faceCells_[nCoarseFaces] = nbrsIter();
00199 
00200             for
00201             (
00202                 SLList<label>::iterator facesIter = faceFacesIter().begin();
00203                 facesIter != faceFacesIter().end();
00204                 ++facesIter
00205             )
00206             {
00207                 faceRestrictAddressing_[facesIter() + sizeBy2] = nCoarseFaces;
00208             }
00209 
00210             nCoarseFaces++;
00211         }
00212     }
00213 }
00214 
00215 
00216 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
00217 
00218 Foam::cyclicGAMGInterface::~cyclicGAMGInterface()
00219 {}
00220 
00221 
00222 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00223 
00224 Foam::tmp<Foam::labelField> Foam::cyclicGAMGInterface::transfer
00225 (
00226     const Pstream::commsTypes,
00227     const unallocLabelList& interfaceData
00228 ) const
00229 {
00230     tmp<labelField> tpnf(new labelField(size()));
00231     labelField& pnf = tpnf();
00232 
00233     label sizeby2 = size()/2;
00234 
00235     for (label facei=0; facei<sizeby2; facei++)
00236     {
00237         pnf[facei] = interfaceData[facei + sizeby2];
00238         pnf[facei + sizeby2] = interfaceData[facei];
00239     }
00240 
00241     return tpnf;
00242 }
00243 
00244 
00245 Foam::tmp<Foam::labelField> Foam::cyclicGAMGInterface::internalFieldTransfer
00246 (
00247     const Pstream::commsTypes,
00248     const unallocLabelList& iF
00249 ) const
00250 {
00251     tmp<labelField> tpnf(new labelField(size()));
00252     labelField& pnf = tpnf();
00253 
00254     label sizeby2 = size()/2;
00255 
00256     for (label facei=0; facei<sizeby2; facei++)
00257     {
00258         pnf[facei] = iF[faceCells_[facei + sizeby2]];
00259         pnf[facei + sizeby2] = iF[faceCells_[facei]];
00260     }
00261 
00262     return tpnf;
00263 }
00264 
00265 
00266 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines