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

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