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

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