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

PrimitivePatchMeshEdges.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 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "PrimitivePatch.H"
00030 
00031 
00032 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00033 
00034 template
00035 <
00036     class Face,
00037     template<class> class FaceList,
00038     class PointField,
00039     class PointType
00040 >
00041 
00042 Foam::labelList
00043 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00044 meshEdges
00045 (
00046     const edgeList& allEdges,
00047     const labelListList& cellEdges,
00048     const labelList& faceCells
00049 ) const
00050 {
00051     if (debug)
00052     {
00053         Info<< "labelList PrimitivePatch<Face, FaceList, PointField, PointType>"
00054             << "::meshEdges() : "
00055             << "calculating labels of patch edges in mesh edge list"
00056             << endl;
00057     }
00058 
00059     // get reference to the list of edges on the patch
00060     const edgeList& PatchEdges = edges();
00061 
00062     const labelListList& EdgeFaces = edgeFaces();
00063 
00064     // create the storage
00065     labelList meshEdges(PatchEdges.size());
00066 
00067     register bool found = false;
00068 
00069     // get reference to the points on the patch
00070     const labelList& pp = meshPoints();
00071 
00072     // WARNING: Remember that local edges address into local point list;
00073     // local-to-global point label translation is necessary
00074     forAll (PatchEdges, edgeI)
00075     {
00076         const edge curEdge
00077             (pp[PatchEdges[edgeI].start()], pp[PatchEdges[edgeI].end()]);
00078 
00079         found = false;
00080 
00081         // get the patch faces sharing the edge
00082         const labelList& curFaces = EdgeFaces[edgeI];
00083 
00084         forAll (curFaces, faceI)
00085         {
00086             // get the cell next to the face
00087             label curCell = faceCells[curFaces[faceI]];
00088 
00089             // get reference to edges on the cell
00090             const labelList& ce = cellEdges[curCell];
00091 
00092             forAll (ce, cellEdgeI)
00093             {
00094                 if (allEdges[ce[cellEdgeI]] == curEdge)
00095                 {
00096                     found = true;
00097 
00098                     meshEdges[edgeI] = ce[cellEdgeI];
00099 
00100                     break;
00101                 }
00102             }
00103 
00104             if (found) break;
00105         }
00106     }
00107 
00108     return meshEdges;
00109 }
00110 
00111 
00112 template
00113 <
00114     class Face,
00115     template<class> class FaceList,
00116     class PointField,
00117     class PointType
00118 >
00119 
00120 Foam::labelList
00121 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00122 meshEdges
00123 (
00124     const edgeList& allEdges,
00125     const labelListList& pointEdges
00126 ) const
00127 {
00128     if (debug)
00129     {
00130         Info<< "labelList PrimitivePatch<Face, FaceList, PointField, PointType>"
00131             << "::meshEdges() : "
00132             << "calculating labels of patch edges in mesh edge list"
00133             << endl;
00134     }
00135 
00136     // get reference to the list of edges on the patch
00137     const edgeList& PatchEdges = edges();
00138 
00139     // create the storage
00140     labelList meshEdges(PatchEdges.size());
00141 
00142     // get reference to the points on the patch
00143     const labelList& pp = meshPoints();
00144 
00145     // WARNING: Remember that local edges address into local point list;
00146     // local-to-global point label translation is necessary
00147     forAll (PatchEdges, edgeI)
00148     {
00149         const label globalPointI = pp[PatchEdges[edgeI].start()];
00150         const edge curEdge(globalPointI, pp[PatchEdges[edgeI].end()]);
00151 
00152         const labelList& pe = pointEdges[globalPointI];
00153 
00154         forAll (pe, i)
00155         {
00156             if (allEdges[pe[i]] == curEdge)
00157             {
00158                 meshEdges[edgeI] = pe[i];
00159                 break;
00160             }
00161         }
00162     }
00163 
00164     return meshEdges;
00165 }
00166 
00167 
00168 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00169 
00170 template
00171 <
00172     class Face,
00173     template<class> class FaceList,
00174     class PointField,
00175     class PointType
00176 >
00177 
00178 Foam::label
00179 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00180 whichEdge
00181 (
00182     const edge& e
00183 ) const
00184 {
00185     // Get pointEdges from the starting point and search all the candidates
00186     const edgeList& Edges = edges();
00187 
00188     if (e.start() > -1 && e.start() < nPoints())
00189     {
00190         const labelList& pe = pointEdges()[e.start()];
00191 
00192         forAll (pe, peI)
00193         {
00194             if (e == Edges[pe[peI]])
00195             {
00196                 return pe[peI];
00197             }
00198         }
00199     }
00200 
00201     // Edge not found.  Return -1
00202     return -1;
00203 }
00204 
00205 
00206 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd