FreeFOAM The Cross-Platform CFD Toolkit
edge.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::edge
26 
27 Description
28  An edge is a list of two point labels. The functionality it provides
29  supports the discretisation on a 2-D flat mesh.
30 
31 SourceFiles
32  edgeI.H
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef edge_H
37 #define edge_H
38 
39 #include <OpenFOAM/FixedList.H>
40 #include <OpenFOAM/pointField.H>
41 #include <OpenFOAM/linePointRef.H>
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of friend functions and operators
49 
50 class edge;
51 inline bool operator==(const edge& a, const edge& b);
52 inline bool operator!=(const edge& a, const edge& b);
53 
54 
55 /*---------------------------------------------------------------------------*\
56  Class edge Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 class edge
60 :
61  public FixedList<label, 2>
62 {
63 
64 public:
65 
66  // Static data members
67 
68  static const char* const typeName;
69 
70 
71  // Constructors
72 
73  //- Null constructor for lists
74  inline edge();
75 
76  //- Construct from components
77  inline edge(const label a, const label b);
78 
79  //- Construct from FixedList
80  inline edge(const FixedList<label, 2>&);
81 
82  //- Construct from Istream
83  inline edge(Istream&);
84 
85 
86  // Member Functions
87 
88  //- Return start vertex label
89  inline label start() const;
90 
91  //- Return start vertex label
92  inline label& start();
93 
94  //- Return end vertex label
95  inline label end() const;
96 
97  //- Return end vertex label
98  inline label& end();
99 
100  //- Given one vertex, return the other
101  inline label otherVertex(const label a) const;
102 
103  //- Return common vertex
104  inline label commonVertex(const edge& a) const;
105 
106  //- Return reverse edge
107  inline edge reverseEdge() const;
108 
109  //- Return centre (centroid)
110  inline point centre(const pointField&) const;
111 
112  //- Return the vector (end - start)
113  inline vector vec(const pointField&) const;
114 
115  //- Return scalar magnitude
116  inline scalar mag(const pointField&) const;
117 
118  //- Return edge line
119  inline linePointRef line(const pointField&) const;
120 
121  //- compare edges
122  // - 0: different
123  // - +1: identical
124  // - -1: same edge, but different orientation
125  static inline int compare(const edge&, const edge&);
126 
127 
128  // Friend Operators
129 
130  friend bool operator==(const edge& a, const edge& b);
131  friend bool operator!=(const edge& a, const edge& b);
132 };
133 
134 
135 //- Hash specialization for hashing edges - a commutative hash value.
136 // Hash incrementally.
137 template<>
138 inline unsigned Hash<edge>::operator()(const edge& e, unsigned seed) const
139 {
140  unsigned val = seed;
141 
142  if (e[0] < e[1])
143  {
144  val = Hash<label>()(e[0], val);
145  val = Hash<label>()(e[1], val);
146  }
147  else
148  {
149  val = Hash<label>()(e[1], val);
150  val = Hash<label>()(e[0], val);
151  }
152 
153  return val;
154 }
155 
156 
157 //- Hash specialization for hashing edges - a commutative hash value.
158 // Hash incrementally.
159 template<>
160 inline unsigned Hash<edge>::operator()(const edge& e) const
161 {
162  return Hash<edge>()(e, 0);
163 }
164 
165 
166 template<>
167 inline bool contiguous<edge>() {return true;}
168 
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 } // End namespace Foam
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 #include <OpenFOAM/edgeI.H>
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 #endif
181 
182 // ************************ vim: set sw=4 sts=4 et: ************************ //