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

primitiveMeshCellCells.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 "primitiveMesh.H"
00028 
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 void Foam::primitiveMesh::calcCellCells() const
00033 {
00034     // Loop through faceCells and mark up neighbours
00035 
00036     if (debug)
00037     {
00038         Pout<< "primitiveMesh::calcCellCells() : calculating cellCells"
00039             << endl;
00040 
00041         if (debug == -1)
00042         {
00043             // For checking calls:abort so we can quickly hunt down
00044             // origin of call
00045             FatalErrorIn("primitiveMesh::calcCellCells()")
00046                 << abort(FatalError);
00047         }
00048     }
00049 
00050     // It is an error to attempt to recalculate cellCells
00051     // if the pointer is already set
00052     if (ccPtr_)
00053     {
00054         FatalErrorIn("primitiveMesh::calcCellCells() const")
00055             << "cellCells already calculated"
00056             << abort(FatalError);
00057     }
00058     else
00059     {
00060         // 1. Count number of internal faces per cell
00061 
00062         labelList ncc(nCells(), 0);
00063 
00064         const labelList& own = faceOwner();
00065         const labelList& nei = faceNeighbour();
00066 
00067         forAll (nei, faceI)
00068         {
00069             ncc[own[faceI]]++;
00070             ncc[nei[faceI]]++;
00071         }
00072 
00073         // Create the storage
00074         ccPtr_ = new labelListList(ncc.size());
00075         labelListList& cellCellAddr = *ccPtr_;
00076 
00077 
00078 
00079         // 2. Size and fill cellFaceAddr
00080 
00081         forAll (cellCellAddr, cellI)
00082         {
00083             cellCellAddr[cellI].setSize(ncc[cellI]);
00084         }
00085         ncc = 0;
00086 
00087         forAll (nei, faceI)
00088         {
00089             label ownCellI = own[faceI];
00090             label neiCellI = nei[faceI];
00091 
00092             cellCellAddr[ownCellI][ncc[ownCellI]++] = neiCellI;
00093             cellCellAddr[neiCellI][ncc[neiCellI]++] = ownCellI;
00094         }
00095     }
00096 }
00097 
00098 
00099 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00100 
00101 const Foam::labelListList& Foam::primitiveMesh::cellCells() const
00102 {
00103     if (!ccPtr_)
00104     {
00105         calcCellCells();
00106     }
00107 
00108     return *ccPtr_;
00109 }
00110 
00111 
00112 const Foam::labelList& Foam::primitiveMesh::cellCells
00113 (
00114     const label cellI,
00115     DynamicList<label>& storage
00116 ) const
00117 {
00118     if (hasCellCells())
00119     {
00120         return cellCells()[cellI];
00121     }
00122     else
00123     {
00124         const labelList& own = faceOwner();
00125         const labelList& nei = faceNeighbour();
00126         const cell& cFaces = cells()[cellI];
00127 
00128         storage.clear();
00129 
00130         forAll(cFaces, i)
00131         {
00132             label faceI = cFaces[i];
00133 
00134             if (faceI < nInternalFaces())
00135             {
00136                 if (own[faceI] == cellI)
00137                 {
00138                     storage.append(nei[faceI]);
00139                 }
00140                 else
00141                 {
00142                     storage.append(own[faceI]);
00143                 }
00144             }
00145         }
00146 
00147         return storage;
00148     }
00149 }
00150 
00151 
00152 const Foam::labelList& Foam::primitiveMesh::cellCells(const label cellI) const
00153 {
00154     return cellCells(cellI, labels_);
00155 }
00156 
00157 
00158 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd