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

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