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

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