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

edge.H

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 Class
00026     Foam::edge
00027 
00028 Description
00029     An edge is a list of two point labels. The functionality it provides
00030     supports the discretisation on a 2-D flat mesh.
00031 
00032 SourceFiles
00033     edgeI.H
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef edge_H
00038 #define edge_H
00039 
00040 #include "FixedList.H"
00041 #include "pointField.H"
00042 #include "linePointRef.H"
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 // Forward declaration of friend functions and operators
00050 
00051 class edge;
00052 inline bool operator==(const edge& a, const edge& b);
00053 inline bool operator!=(const edge& a, const edge& b);
00054 
00055 
00056 /*---------------------------------------------------------------------------*\
00057                            Class edge Declaration
00058 \*---------------------------------------------------------------------------*/
00059 
00060 class edge
00061 :
00062     public FixedList<label, 2>
00063 {
00064 
00065 public:
00066 
00067     // Static data members
00068 
00069         static const char* const typeName;
00070 
00071 
00072     // Constructors
00073 
00074         //- Null constructor for lists
00075         inline edge();
00076 
00077         //- Construct from components
00078         inline edge(const label a, const label b);
00079 
00080         //- Construct from FixedList
00081         inline edge(const FixedList<label, 2>&);
00082 
00083         //- Construct from Istream
00084         inline edge(Istream&);
00085 
00086 
00087     // Member Functions
00088 
00089         //- Return start vertex label
00090         inline label start() const;
00091 
00092         //- Return start vertex label
00093         inline label& start();
00094 
00095         //- Return end vertex label
00096         inline label end() const;
00097 
00098         //- Return end vertex label
00099         inline label& end();
00100 
00101         //- Given one vertex, return the other
00102         inline label otherVertex(const label a) const;
00103 
00104         //- Return common vertex
00105         inline label commonVertex(const edge& a) const;
00106 
00107         //- Return reverse edge
00108         inline edge reverseEdge() const;
00109 
00110         //- Return centre (centroid)
00111         inline point centre(const pointField&) const;
00112 
00113         //- Return the vector (end - start)
00114         inline vector vec(const pointField&) const;
00115 
00116         //- Return scalar magnitude
00117         inline scalar mag(const pointField&) const;
00118 
00119         //- Return edge line
00120         inline linePointRef line(const pointField&) const;
00121 
00122         //- compare edges
00123         //  -  0: different
00124         //  - +1: identical
00125         //  - -1: same edge, but different orientation
00126         static inline int compare(const edge&, const edge&);
00127 
00128 
00129     // Friend Operators
00130 
00131         friend bool operator==(const edge& a, const edge& b);
00132         friend bool operator!=(const edge& a, const edge& b);
00133 };
00134 
00135 
00136 //- Hash specialization for hashing edges - a commutative hash value.
00137 //  Hash incrementally.
00138 template<>
00139 inline unsigned Hash<edge>::operator()(const edge& e, unsigned seed) const
00140 {
00141     unsigned val = seed;
00142 
00143     if (e[0] < e[1])
00144     {
00145         val = Hash<label>()(e[0], val);
00146         val = Hash<label>()(e[1], val);
00147     }
00148     else
00149     {
00150         val = Hash<label>()(e[1], val);
00151         val = Hash<label>()(e[0], val);
00152     }
00153 
00154     return val;
00155 }
00156 
00157 
00158 //- Hash specialization for hashing edges - a commutative hash value.
00159 //  Hash incrementally.
00160 template<>
00161 inline unsigned Hash<edge>::operator()(const edge& e) const
00162 {
00163     return Hash<edge>()(e, 0);
00164 }
00165 
00166 
00167 template<>
00168 inline bool contiguous<edge>()  {return true;}
00169 
00170 
00171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00172 
00173 } // End namespace Foam
00174 
00175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00176 
00177 #include "edgeI.H"
00178 
00179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00180 
00181 #endif
00182 
00183 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd