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

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