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

primitiveMeshPointCells.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 #include "cell.H"
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 void Foam::primitiveMesh::calcPointCells() const
00033 {
00034     // Loop through cells and mark up points
00035 
00036     if (debug)
00037     {
00038         Pout<< "primitiveMesh::calcPointCells() : "
00039             << "calculating pointCells"
00040             << endl;
00041 
00042         if (debug == -1)
00043         {
00044             // For checking calls:abort so we can quickly hunt down
00045             // origin of call
00046             FatalErrorIn("primitiveMesh::calcPointCells()")
00047                 << abort(FatalError);
00048         }
00049     }
00050 
00051     // It is an error to attempt to recalculate pointCells
00052     // if the pointer is already set
00053     if (pcPtr_)
00054     {
00055         FatalErrorIn("primitiveMesh::calcPointCells() const")
00056             << "pointCells already calculated"
00057             << abort(FatalError);
00058     }
00059     else
00060     {
00061         const cellList& cf = cells();
00062 
00063         // Count number of cells per point
00064 
00065         labelList npc(nPoints(), 0);
00066 
00067         forAll (cf, cellI)
00068         {
00069             const labelList curPoints = cf[cellI].labels(faces());
00070 
00071             forAll (curPoints, pointI)
00072             {
00073                 label ptI = curPoints[pointI];
00074 
00075                 npc[ptI]++;
00076             }
00077         }
00078 
00079 
00080         // Size and fill cells per point
00081 
00082         pcPtr_ = new labelListList(npc.size());
00083         labelListList& pointCellAddr = *pcPtr_;
00084 
00085         forAll (pointCellAddr, pointI)
00086         {
00087             pointCellAddr[pointI].setSize(npc[pointI]);
00088         }
00089         npc = 0;
00090 
00091 
00092         forAll (cf, cellI)
00093         {
00094             const labelList curPoints = cf[cellI].labels(faces());
00095 
00096             forAll (curPoints, pointI)
00097             {
00098                 label ptI = curPoints[pointI];
00099 
00100                 pointCellAddr[ptI][npc[ptI]++] = cellI;
00101             }
00102         }
00103     }
00104 }
00105 
00106 
00107 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00108 
00109 const Foam::labelListList& Foam::primitiveMesh::pointCells() const
00110 {
00111     if (!pcPtr_)
00112     {
00113         calcPointCells();
00114     }
00115 
00116     return *pcPtr_;
00117 }
00118 
00119 
00120 const Foam::labelList& Foam::primitiveMesh::pointCells
00121 (
00122     const label pointI,
00123     DynamicList<label>& storage
00124 ) const
00125 {
00126     if (hasPointCells())
00127     {
00128         return pointCells()[pointI];
00129     }
00130     else
00131     {
00132         const labelList& own = faceOwner();
00133         const labelList& nei = faceNeighbour();
00134         const labelList& pFaces = pointFaces()[pointI];
00135 
00136         storage.clear();
00137 
00138         forAll(pFaces, i)
00139         {
00140             const label faceI = pFaces[i];
00141 
00142             // Append owner
00143             storage.append(own[faceI]);
00144 
00145             // Append neighbour
00146             if (faceI < nInternalFaces())
00147             {
00148                 storage.append(nei[faceI]);
00149             }
00150         }
00151 
00152         // Filter duplicates
00153         if (storage.size() > 1)
00154         {
00155             sort(storage);
00156 
00157             label n = 1;
00158             for (label i = 1; i < storage.size(); i++)
00159             {
00160                 if (storage[i-1] != storage[i])
00161                 {
00162                     storage[n++] = storage[i];
00163                 }
00164             }
00165 
00166             // truncate addressed list
00167             storage.setSize(n);
00168         }
00169 
00170         return storage;
00171     }
00172 }
00173 
00174 
00175 const Foam::labelList& Foam::primitiveMesh::pointCells(const label pointI) const
00176 {
00177     return pointCells(pointI, labels_);
00178 }
00179 
00180 
00181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00182 
00183 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd