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

primitiveMeshPointPoints.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::calcPointPoints() const
00032 {
00033     if (debug)
00034     {
00035         Pout<< "primitiveMesh::calcPointPoints() : "
00036             << "calculating pointPoints"
00037             << endl;
00038 
00039         if (debug == -1)
00040         {
00041             // For checking calls:abort so we can quickly hunt down
00042             // origin of call
00043             FatalErrorIn("primitiveMesh::calcPointPoints()")
00044                 << abort(FatalError);
00045         }
00046     }
00047 
00048     // It is an error to attempt to recalculate pointPoints
00049     // if the pointer is already set
00050     if (ppPtr_)
00051     {
00052         FatalErrorIn("primitiveMesh::calcPointPoints() const")
00053             << "pointPoints already calculated"
00054             << abort(FatalError);
00055     }
00056     else
00057     {
00058         const edgeList& e = edges();
00059         const labelListList& pe = pointEdges();
00060 
00061         ppPtr_ = new labelListList(pe.size());
00062         labelListList& pp = *ppPtr_;
00063 
00064         forAll (pe, pointI)
00065         {
00066             pp[pointI].setSize(pe[pointI].size());
00067 
00068             forAll (pe[pointI], ppi)
00069             {
00070                 if (e[pe[pointI][ppi]].start() == pointI)
00071                 {
00072                     pp[pointI][ppi] = e[pe[pointI][ppi]].end();
00073                 }
00074                 else if (e[pe[pointI][ppi]].end() == pointI)
00075                 {
00076                     pp[pointI][ppi] = e[pe[pointI][ppi]].start();
00077                 }
00078                 else
00079                 {
00080                     FatalErrorIn("primitiveMesh::calcPointPoints() const")
00081                         << "something wrong with edges"
00082                         << abort(FatalError);
00083                 }
00084             }
00085         }
00086     }
00087 }
00088 
00089 
00090 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00091 
00092 const Foam::labelListList& Foam::primitiveMesh::pointPoints() const
00093 {
00094     if (!ppPtr_)
00095     {
00096         calcPointPoints();
00097     }
00098 
00099     return *ppPtr_;
00100 }
00101 
00102 
00103 const Foam::labelList& Foam::primitiveMesh::pointPoints
00104 (
00105     const label pointI,
00106     DynamicList<label>& storage
00107 ) const
00108 {
00109     if (hasPointPoints())
00110     {
00111         return pointPoints()[pointI];
00112     }
00113     else
00114     {
00115         const edgeList& edges = this->edges();
00116         const labelList& pEdges = pointEdges()[pointI];
00117 
00118         storage.clear();
00119 
00120         if (pEdges.size() > storage.capacity())
00121         {
00122             storage.setCapacity(pEdges.size());
00123         }
00124 
00125         forAll(pEdges, i)
00126         {
00127             storage.append(edges[pEdges[i]].otherVertex(pointI));
00128         }
00129 
00130         return storage;
00131     }
00132 }
00133 
00134 
00135 const Foam::labelList& Foam::primitiveMesh::pointPoints
00136 (
00137     const label pointI
00138 ) const
00139 {
00140     return pointPoints(pointI, labels_);
00141 }
00142 
00143 
00144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00145 
00146 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd