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

GAMGAgglomerateLduAddressing.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 "GAMGAgglomeration.H"
00028 #include "GAMGInterface.H"
00029 
00030 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00031 
00032 void Foam::GAMGAgglomeration::agglomerateLduAddressing
00033 (
00034     const label fineLevelIndex
00035 )
00036 {
00037     const lduMesh& fineMesh = meshLevel(fineLevelIndex);
00038     const lduAddressing& fineMeshAddr = fineMesh.lduAddr();
00039 
00040     const unallocLabelList& upperAddr = fineMeshAddr.upperAddr();
00041     const unallocLabelList& lowerAddr = fineMeshAddr.lowerAddr();
00042 
00043     label nFineFaces = upperAddr.size();
00044 
00045     // Get restriction map for current level
00046     const labelField& restrictMap = restrictAddressing(fineLevelIndex);
00047 
00048     if (min(restrictMap) == -1)
00049     {
00050         FatalErrorIn("GAMGAgglomeration::agglomerateLduAddressing")
00051             << "min(restrictMap) == -1" << exit(FatalError);
00052     }
00053 
00054     if (restrictMap.size() != fineMeshAddr.size())
00055     {
00056         FatalErrorIn
00057         (
00058             "GAMGAgglomeration::agglomerateLduAddressing"
00059             "(const label fineLevelIndex)"
00060         )   << "restrict map does not correspond to fine level. " << endl
00061             << " Sizes: restrictMap: " << restrictMap.size()
00062             << " nEqns: " << fineMeshAddr.size()
00063             << abort(FatalError);
00064     }
00065 
00066 
00067     // Get the number of coarse cells
00068     const label nCoarseCells = nCells_[fineLevelIndex];
00069 
00070     // Storage for coarse cell neighbours and coefficients
00071 
00072     // Guess initial maximum number of neighbours in coarse cell
00073     label maxNnbrs = 10;
00074 
00075     // Number of faces for each coarse-cell
00076     labelList cCellnFaces(nCoarseCells, 0);
00077 
00078     // Setup initial packed storage for coarse-cell faces
00079     labelList cCellFaces(maxNnbrs*nCoarseCells);
00080 
00081     // Create face-restriction addressing
00082     faceRestrictAddressing_.set(fineLevelIndex, new labelList(nFineFaces));
00083     labelList& faceRestrictAddr = faceRestrictAddressing_[fineLevelIndex];
00084 
00085     // Initial neighbour array (not in upper-triangle order)
00086     labelList initCoarseNeighb(nFineFaces);
00087 
00088     // Counter for coarse faces
00089     label nCoarseFaces = 0;
00090 
00091     // Loop through all fine faces
00092     forAll (upperAddr, fineFacei)
00093     {
00094         label rmUpperAddr = restrictMap[upperAddr[fineFacei]];
00095         label rmLowerAddr = restrictMap[lowerAddr[fineFacei]];
00096 
00097         if (rmUpperAddr == rmLowerAddr)
00098         {
00099             // For each fine face inside of a coarse cell keep the address
00100             // of the cell corresponding to the face in the faceRestrictAddr
00101             // as a negative index
00102             faceRestrictAddr[fineFacei] = -(rmUpperAddr + 1);
00103         }
00104         else
00105         {
00106             // this face is a part of a coarse face
00107 
00108             label cOwn = rmUpperAddr;
00109             label cNei = rmLowerAddr;
00110 
00111             // get coarse owner and neighbour
00112             if (rmUpperAddr > rmLowerAddr)
00113             {
00114                 cOwn = rmLowerAddr;
00115                 cNei = rmUpperAddr;
00116             }
00117 
00118             // check the neighbour to see if this face has already been found
00119             label* ccFaces = &cCellFaces[maxNnbrs*cOwn];
00120 
00121             bool nbrFound = false;
00122             label& ccnFaces = cCellnFaces[cOwn];
00123 
00124             for (int i=0; i<ccnFaces; i++)
00125             {
00126                 if (initCoarseNeighb[ccFaces[i]] == cNei)
00127                 {
00128                     nbrFound = true;
00129                     faceRestrictAddr[fineFacei] = ccFaces[i];
00130                     break;
00131                 }
00132             }
00133 
00134             if (!nbrFound)
00135             {
00136                 if (ccnFaces >= maxNnbrs)
00137                 {
00138                     label oldMaxNnbrs = maxNnbrs;
00139                     maxNnbrs *= 2;
00140 
00141                     cCellFaces.setSize(maxNnbrs*nCoarseCells);
00142 
00143                     forAllReverse(cCellnFaces, i)
00144                     {
00145                         label* oldCcNbrs = &cCellFaces[oldMaxNnbrs*i];
00146                         label* newCcNbrs = &cCellFaces[maxNnbrs*i];
00147 
00148                         for (int j=0; j<cCellnFaces[i]; j++)
00149                         {
00150                             newCcNbrs[j] = oldCcNbrs[j];
00151                         }
00152                     }
00153 
00154                     ccFaces = &cCellFaces[maxNnbrs*cOwn];
00155                 }
00156 
00157                 ccFaces[ccnFaces] = nCoarseFaces;
00158                 initCoarseNeighb[nCoarseFaces] = cNei;
00159                 faceRestrictAddr[fineFacei] = nCoarseFaces;
00160                 ccnFaces++;
00161 
00162                 // new coarse face created
00163                 nCoarseFaces++;
00164             }
00165         }
00166     } // end for all fine faces
00167 
00168 
00169     // Renumber into upper-triangular order
00170 
00171     // All coarse owner-neighbour storage
00172     labelList coarseOwner(nCoarseFaces);
00173     labelList coarseNeighbour(nCoarseFaces);
00174     labelList coarseFaceMap(nCoarseFaces);
00175 
00176     label coarseFacei = 0;
00177 
00178     forAll (cCellnFaces, cci)
00179     {
00180         label* cFaces = &cCellFaces[maxNnbrs*cci];
00181         label ccnFaces = cCellnFaces[cci];
00182 
00183         for (int i=0; i<ccnFaces; i++)
00184         {
00185             coarseOwner[coarseFacei] = cci;
00186             coarseNeighbour[coarseFacei] = initCoarseNeighb[cFaces[i]];
00187             coarseFaceMap[cFaces[i]] = coarseFacei;
00188             coarseFacei++;
00189         }
00190     }
00191 
00192     forAll(faceRestrictAddr, fineFacei)
00193     {
00194         if (faceRestrictAddr[fineFacei] >= 0)
00195         {
00196             faceRestrictAddr[fineFacei] =
00197                 coarseFaceMap[faceRestrictAddr[fineFacei]];
00198         }
00199     }
00200 
00201     // Clear the temporary storage for the coarse cell data
00202     cCellnFaces.setSize(0);
00203     cCellFaces.setSize(0);
00204     initCoarseNeighb.setSize(0);
00205     coarseFaceMap.setSize(0);
00206 
00207 
00208     // Create coarse-level interfaces
00209 
00210     // Get reference to fine-level interfaces
00211     const lduInterfacePtrsList& fineInterfaces =
00212         interfaceLevels_[fineLevelIndex];
00213 
00214     // Create coarse-level interfaces
00215     interfaceLevels_.set
00216     (
00217         fineLevelIndex + 1,
00218         new lduInterfacePtrsList(fineInterfaces.size())
00219     );
00220 
00221     lduInterfacePtrsList& coarseInterfaces =
00222         interfaceLevels_[fineLevelIndex + 1];
00223 
00224     labelListList coarseInterfaceAddr(fineInterfaces.size());
00225 
00226     // Initialise transfer of restrict addressing on the interface
00227     forAll (fineInterfaces, inti)
00228     {
00229         if (fineInterfaces.set(inti))
00230         {
00231             fineInterfaces[inti].initInternalFieldTransfer
00232             (
00233                 Pstream::blocking,
00234                 restrictMap
00235             );
00236         }
00237     }
00238 
00239     // Add the coarse level
00240     forAll (fineInterfaces, inti)
00241     {
00242         if (fineInterfaces.set(inti))
00243         {
00244             coarseInterfaces.set
00245             (
00246                 inti,
00247                 GAMGInterface::New
00248                 (
00249                     fineInterfaces[inti],
00250                     fineInterfaces[inti].interfaceInternalField(restrictMap),
00251                     fineInterfaces[inti].internalFieldTransfer
00252                     (
00253                         Pstream::blocking,
00254                         restrictMap
00255                     )
00256                 ).ptr()
00257             );
00258             
00259             coarseInterfaceAddr[inti] = coarseInterfaces[inti].faceCells();
00260         }
00261     }
00262 
00263 
00264     // Set the coarse ldu addressing onto the list
00265     meshLevels_.set
00266     (
00267         fineLevelIndex,
00268         new lduPrimitiveMesh
00269         (
00270             nCoarseCells,
00271             coarseOwner,
00272             coarseNeighbour,
00273             coarseInterfaceAddr,
00274             coarseInterfaces,
00275             fineMeshAddr.patchSchedule(),
00276             true
00277         )
00278     );
00279 }
00280 
00281 
00282 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd