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

processorGAMGInterface.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 "processorGAMGInterface.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     defineTypeNameAndDebug(processorGAMGInterface, 0);
00035     addToRunTimeSelectionTable
00036     (
00037         GAMGInterface,
00038         processorGAMGInterface,
00039         lduInterface
00040     );
00041 }
00042 
00043 
00044 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00045 
00046 Foam::processorGAMGInterface::processorGAMGInterface
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     fineProcInterface_(refCast<const processorLduInterface>(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     forAll (localRestrictAddressing, ffi)
00076     {
00077         label curMaster = -1;
00078         label curSlave = -1;
00079 
00080         // Do switching on master/slave indexes based on the owner/neighbour of
00081         // the processor index such that both sides get the same answer.
00082         if (myProcNo() < neighbProcNo())
00083         {
00084             // Master side
00085             curMaster = localRestrictAddressing[ffi];
00086             curSlave = neighbourRestrictAddressing[ffi];
00087         }
00088         else
00089         {
00090             // Slave side
00091             curMaster = neighbourRestrictAddressing[ffi];
00092             curSlave = localRestrictAddressing[ffi];
00093         }
00094 
00095         // Look for the master cell.  If it has already got a face,
00096         // add the coefficient to the face.  If not, create a new face.
00097         if (neighboursTable.found(curMaster))
00098         {
00099             // Check all current neighbours to see if the current slave already
00100             // exists and if so, add the fine face to the agglomeration.
00101 
00102             SLList<label>& curNbrs = neighboursTable.find(curMaster)();
00103 
00104             SLList<SLList<label> >& curFaceFaces =
00105                 faceFaceTable.find(curMaster)();
00106 
00107             bool nbrFound = false;
00108 
00109             SLList<label>::iterator nbrsIter = curNbrs.begin();
00110 
00111             SLList<SLList<label> >::iterator faceFacesIter =
00112                 curFaceFaces.begin();
00113 
00114             for
00115             (
00116                 ;
00117                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
00118                 ++nbrsIter, ++faceFacesIter
00119             )
00120             {
00121                 if (nbrsIter() == curSlave)
00122                 {
00123                     nbrFound = true;
00124                     faceFacesIter().append(ffi);
00125                     break;
00126                 }
00127             }
00128 
00129             if (!nbrFound)
00130             {
00131                 curNbrs.append(curSlave);
00132                 curFaceFaces.append(ffi);
00133 
00134                 // New coarse face created
00135                 nCoarseFaces++;
00136             }
00137         }
00138         else
00139         {
00140             // This master has got no neighbours yet.  Add a neighbour
00141             // and a coefficient, thus creating a new face
00142             neighboursTable.insert(curMaster, SLList<label>(curSlave));
00143             faceFaceTable.insert(curMaster, SLList<SLList<label> >(ffi));
00144 
00145             // New coarse face created
00146             nCoarseFaces++;
00147         }
00148     } // end for all fine faces
00149 
00150 
00151 
00152     faceCells_.setSize(nCoarseFaces, -1);
00153     faceRestrictAddressing_.setSize(localRestrictAddressing.size());
00154 
00155     labelList contents = neighboursTable.toc();
00156 
00157     // Reset face counter for re-use
00158     nCoarseFaces = 0;
00159 
00160     if (myProcNo() < neighbProcNo())
00161     {
00162         // On master side, the owner addressing is stored in table of contents
00163         forAll (contents, masterI)
00164         {
00165             SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
00166 
00167             SLList<SLList<label> >& curFaceFaces =
00168                 faceFaceTable.find(contents[masterI])();
00169 
00170             SLList<label>::iterator nbrsIter = curNbrs.begin();
00171 
00172             SLList<SLList<label> >::iterator faceFacesIter =
00173                 curFaceFaces.begin();
00174 
00175             for
00176             (
00177                 ;
00178                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
00179                 ++nbrsIter, ++faceFacesIter
00180             )
00181             {
00182                 faceCells_[nCoarseFaces] = contents[masterI];
00183 
00184                 for
00185                 (
00186                     SLList<label>::iterator facesIter = faceFacesIter().begin();
00187                     facesIter != faceFacesIter().end();
00188                     ++facesIter
00189                 )
00190                 {
00191                     faceRestrictAddressing_[facesIter()] = nCoarseFaces;
00192                 }
00193 
00194                 nCoarseFaces++;
00195             }
00196         }
00197     }
00198     else
00199     {
00200         // On slave side, the owner addressing is stored in linked lists
00201         forAll (contents, masterI)
00202         {
00203             SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
00204 
00205             SLList<SLList<label> >& curFaceFaces =
00206                 faceFaceTable.find(contents[masterI])();
00207 
00208             SLList<label>::iterator nbrsIter = curNbrs.begin();
00209 
00210             SLList<SLList<label> >::iterator faceFacesIter =
00211                 curFaceFaces.begin();
00212 
00213             for
00214             (
00215                 ;
00216                 nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
00217                 ++nbrsIter, ++faceFacesIter
00218             )
00219             {
00220                 faceCells_[nCoarseFaces] = nbrsIter();
00221 
00222                 for
00223                 (
00224                     SLList<label>::iterator facesIter = faceFacesIter().begin();
00225                     facesIter != faceFacesIter().end();
00226                     ++facesIter
00227                 )
00228                 {
00229                     faceRestrictAddressing_[facesIter()] = nCoarseFaces;
00230                 }
00231 
00232                 nCoarseFaces++;
00233             }
00234         }
00235     }
00236 }
00237 
00238 
00239 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
00240 
00241 Foam::processorGAMGInterface::~processorGAMGInterface()
00242 {}
00243 
00244 
00245 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00246 
00247 void Foam::processorGAMGInterface::initTransfer
00248 (
00249     const Pstream::commsTypes commsType,
00250     const unallocLabelList& interfaceData
00251 ) const
00252 {
00253     send(commsType, interfaceData);
00254 }
00255 
00256 
00257 Foam::tmp<Foam::labelField> Foam::processorGAMGInterface::transfer
00258 (
00259     const Pstream::commsTypes commsType,
00260     const unallocLabelList& interfaceData
00261 ) const
00262 {
00263     return receive<label>(commsType, this->size());
00264 }
00265 
00266 
00267 void Foam::processorGAMGInterface::initInternalFieldTransfer
00268 (
00269     const Pstream::commsTypes commsType,
00270     const unallocLabelList& iF
00271 ) const
00272 {
00273     send(commsType, interfaceInternalField(iF)());
00274 }
00275 
00276 
00277 Foam::tmp<Foam::labelField> Foam::processorGAMGInterface::internalFieldTransfer
00278 (
00279     const Pstream::commsTypes commsType,
00280     const unallocLabelList& iF
00281 ) const
00282 {
00283     return receive<label>(commsType, this->size());
00284 }
00285 
00286 
00287 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd