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

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