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

PatchToolsSortEdges.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 "PatchTools.H"
00028 #include "SortableList.H"
00029 #include "transform.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 template
00034 <
00035     class Face,
00036     template<class> class FaceList,
00037     class PointField,
00038     class PointType
00039 >
00040 
00041 Foam::labelListList
00042 Foam::PatchTools::sortedEdgeFaces
00043 (
00044     const PrimitivePatch<Face, FaceList, PointField, PointType>& p
00045 )
00046 {
00047     const edgeList& edges = p.edges();
00048     const labelListList& edgeFaces = p.edgeFaces();
00049     const List<Face>& localFaces = p.localFaces();
00050     const Field<PointType>& localPoints = p.localPoints();
00051 
00052     // create the lists for the various results. (resized on completion)
00053     labelListList& sortedEdgeFaces = labelListList(edgeFaces.size());
00054 
00055     forAll(edgeFaces, edgeI)
00056     {
00057         const labelList& faceNbs = edgeFaces[edgeI];
00058 
00059         if (faceNbs.size() > 2)
00060         {
00061             // Get point on edge and normalized direction of edge (= e2 base
00062             // of our coordinate system)
00063             const edge& e = edges[edgeI];
00064 
00065             const point& edgePt = localPoints[e.start()];
00066 
00067             vector e2 = e.vec(localPoints);
00068             e2 /= mag(e2) + VSMALL;
00069 
00070             // Get opposite vertex for 0th face
00071             const Face& f = localFaces[faceNbs[0]];
00072 
00073             label fp0 = findIndex(f, e[0]);
00074             label fp1 = f.fcIndex(fp0);
00075             label vertI = (f[fp1] != e[1] ? f[fp1] : f.fcIndex(fp1));
00076 
00077             // Get vector normal both to e2 and to edge from opposite vertex
00078             // to edge (will be x-axis of our coordinate system)
00079             vector e0 = e2 ^ (localPoints[vertI] - edgePt);
00080             e0 /= mag(e0) + VSMALL;
00081 
00082             // Get y-axis of coordinate system
00083             vector e1 = e2 ^ e0;
00084 
00085             SortableList<scalar> faceAngles(faceNbs.size());
00086 
00087             // e0 is reference so angle is 0
00088             faceAngles[0] = 0;
00089 
00090             for (label nbI = 1; nbI < faceNbs.size(); nbI++)
00091             {
00092                 // Get opposite vertex
00093                 const Face& f = localFaces[faceNbs[nbI]];
00094                 label fp0 = findIndex(f, e[0]);
00095                 label fp1 = f.fcIndex(fp0);
00096                 label vertI = (f[fp1] != e[1] ? f[fp1] : f.fcIndex(fp1));
00097 
00098                 vector vec = e2 ^ (localPoints[vertI] - edgePt);
00099                 vec /= mag(vec) + VSMALL;
00100 
00101                 faceAngles[nbI] = pseudoAngle
00102                 (
00103                     e0,
00104                     e1,
00105                     vec
00106                 );
00107             }
00108 
00109             faceAngles.sort();
00110 
00111             sortedEdgeFaces[edgeI] = UIndirectList<label>
00112             (
00113                 faceNbs,
00114                 faceAngles.indices()
00115             );
00116         }
00117         else
00118         {
00119             // No need to sort. Just copy.
00120             sortedEdgeFaces[edgeI] = faceNbs;
00121         }
00122     }
00123 
00124     return sortedEdgeFaces;
00125 }
00126 
00127 
00128 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd