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

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