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

triSurfaceAddressing.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     Contains fix for PrimitivePatch addressing (which doesn't work if surface
00027     is non-manifold). Should be moved into PrimitivePatch.
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #include "triSurface.H"
00032 #include "HashTable.H"
00033 #include "SortableList.H"
00034 #include "transform.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040 
00041 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00042 
00043 void triSurface::calcSortedEdgeFaces() const
00044 {
00045     if (sortedEdgeFacesPtr_)
00046     {
00047         FatalErrorIn("triSurface::calcSortedEdgeFaces()")
00048             << "sortedEdgeFacesPtr_ already set"
00049             << abort(FatalError);
00050     }
00051 
00052     const labelListList& eFaces = edgeFaces();
00053 
00054     // create the lists for the various results. (resized on completion)
00055     sortedEdgeFacesPtr_ = new labelListList(eFaces.size());
00056     labelListList& sortedEdgeFaces = *sortedEdgeFacesPtr_;
00057 
00058     forAll(eFaces, edgeI)
00059     {
00060         const labelList& myFaceNbs = eFaces[edgeI];
00061 
00062         if (myFaceNbs.size() > 2)
00063         {
00064             // Get point on edge and normalized direction of edge (= e2 base
00065             // of our coordinate system)
00066             const edge& e = edges()[edgeI];
00067 
00068             const point& edgePt = localPoints()[e.start()];
00069 
00070             vector e2 = e.vec(localPoints());
00071             e2 /= mag(e2) + VSMALL;
00072 
00073 
00074             // Get opposite vertex for 0th face
00075             const labelledTri& f = localFaces()[myFaceNbs[0]];
00076             label fp0 = findIndex(f, e[0]);
00077             label fp1 = f.fcIndex(fp0);
00078             label vertI = (f[fp1] != e[1] ? f[fp1] : f.fcIndex(fp1));
00079 
00080             // Get vector normal both to e2 and to edge from opposite vertex
00081             // to edge (will be x-axis of our coordinate system)
00082             vector e0 = e2 ^ (localPoints()[vertI] - edgePt);
00083             e0 /= mag(e0) + VSMALL;
00084 
00085             // Get y-axis of coordinate system
00086             vector e1 = e2 ^ e0;
00087 
00088 
00089             SortableList<scalar> faceAngles(myFaceNbs.size());
00090 
00091             // e0 is reference so angle is 0
00092             faceAngles[0] = 0;
00093 
00094             for(label nbI = 1; nbI < myFaceNbs.size(); nbI++)
00095             {
00096                 // Get opposite vertex
00097                 const labelledTri& f = localFaces()[myFaceNbs[nbI]];
00098                 label fp0 = findIndex(f, e[0]);
00099                 label fp1 = f.fcIndex(fp0);
00100                 label vertI = (f[fp1] != e[1] ? f[fp1] : f.fcIndex(fp1));
00101 
00102                 vector vec = e2 ^ (localPoints()[vertI] - edgePt);
00103                 vec /= mag(vec) + VSMALL;
00104 
00105                 faceAngles[nbI] = pseudoAngle
00106                 (
00107                     e0,
00108                     e1,
00109                     vec
00110                 );
00111             }
00112 
00113             faceAngles.sort();
00114 
00115             sortedEdgeFaces[edgeI] = UIndirectList<label>
00116             (
00117                 myFaceNbs,
00118                 faceAngles.indices()
00119             );
00120         }
00121         else
00122         {
00123             // No need to sort. Just copy.
00124             sortedEdgeFaces[edgeI] = myFaceNbs;
00125         }
00126     }
00127 }
00128 
00129 
00130 void triSurface::calcEdgeOwner() const
00131 {
00132     if (edgeOwnerPtr_)
00133     {
00134         FatalErrorIn("triSurface::calcEdgeOwner()")
00135             << "edgeOwnerPtr_ already set"
00136             << abort(FatalError);
00137     }
00138 
00139     // create the owner list
00140     edgeOwnerPtr_ = new labelList(nEdges());
00141     labelList& edgeOwner = *edgeOwnerPtr_;
00142 
00143     forAll(edges(), edgeI)
00144     {
00145         const edge& e = edges()[edgeI];
00146 
00147         const labelList& myFaces = edgeFaces()[edgeI];
00148 
00149         if (myFaces.size() == 1)
00150         {
00151             edgeOwner[edgeI] = myFaces[0];
00152         }
00153         else
00154         {
00155             // Find the first face whose vertices are aligned with the edge.
00156             // (in case of multiply connected edge the best we can do)
00157             edgeOwner[edgeI] = -1;
00158 
00159             forAll(myFaces, i)
00160             {
00161                 const labelledTri& f = localFaces()[myFaces[i]];
00162 
00163                 if
00164                 (
00165                     ((f[0] == e.start()) && (f[1] == e.end()))
00166                  || ((f[1] == e.start()) && (f[2] == e.end()))
00167                  || ((f[2] == e.start()) && (f[0] == e.end()))
00168                 )
00169                 {
00170                     edgeOwner[edgeI] = myFaces[i];
00171 
00172                     break;
00173                 }
00174             }
00175 
00176             if (edgeOwner[edgeI] == -1)
00177             {
00178                 FatalErrorIn("triSurface::calcEdgeOwner()")
00179                     << "Edge " << edgeI << " vertices:" << e
00180                     << " is used by faces " << myFaces
00181                     << " vertices:"
00182                     << UIndirectList<labelledTri>(localFaces(), myFaces)()
00183                     << " none of which use the edge vertices in the same order"
00184                     << nl << "I give up" << abort(FatalError);
00185             }
00186         }
00187     }
00188 }
00189 
00190 
00191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00192 
00193 } // End namespace Foam
00194 
00195 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd