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) 2011-2015 OpenFOAM Foundation
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 "FixedList.H"
40 #include "pointField.H"
41 #include "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  //- Flip the edge in-place.
107  inline void flip();
108 
109  //- Return reverse edge
110  inline edge reverseEdge() const;
111 
112  //- Return centre (centroid)
113  inline point centre(const pointField&) const;
114 
115  //- Return the vector (end - start)
116  inline vector vec(const pointField&) const;
117 
118  //- Return scalar magnitude
119  inline scalar mag(const pointField&) const;
120 
121  //- Return edge line
122  inline linePointRef line(const pointField&) const;
123 
124  //- Compare edges
125  // Returns:
126  // - 0: different
127  // - +1: identical
128  // - -1: same edge, but different orientation
129  static inline int compare(const edge&, const edge&);
130 
131 
132  // Friend Operators
133 
134  friend bool operator==(const edge& a, const edge& b);
135  friend bool operator!=(const edge& a, const edge& b);
136 };
137 
138 
139 //- Hash specialization for hashing edges - a commutative hash value.
140 // Hash incrementally.
141 template<>
142 inline unsigned Hash<edge>::operator()(const edge& e, unsigned seed) const
143 {
144  unsigned val = seed;
145 
146  if (e[0] < e[1])
147  {
148  val = Hash<label>()(e[0], val);
149  val = Hash<label>()(e[1], val);
150  }
151  else
152  {
153  val = Hash<label>()(e[1], val);
154  val = Hash<label>()(e[0], val);
155  }
156 
157  return val;
158 }
159 
160 
161 //- Hash specialization for hashing edges - a commutative hash value.
162 // Hash incrementally.
163 template<>
164 inline unsigned Hash<edge>::operator()(const edge& e) const
165 {
166  return Hash<edge>()(e, 0);
167 }
168 
169 
170 template<>
171 inline bool contiguous<edge>() {return true;}
172 
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 } // End namespace Foam
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 #include "edgeI.H"
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 #endif
185 
186 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A line primitive.
Definition: line.H:56
const double e
Elementary charge.
Definition: doubleFloat.H:78
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:54
bool contiguous< edge >()
Definition: edge.H:170
edge reverseEdge() const
Return reverse edge.
Definition: edgeI.H:145
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static int compare(const edge &, const edge &)
Compare edges.
Definition: edgeI.H:36
label otherVertex(const label a) const
Given one vertex, return the other.
Definition: edgeI.H:103
unsigned operator()(const PrimitiveType &p, unsigned seed) const
Definition: Hash.H:61
label commonVertex(const edge &a) const
Return common vertex.
Definition: edgeI.H:121
point centre(const pointField &) const
Return centre (centroid)
Definition: edgeI.H:151
linePointRef line(const pointField &) const
Return edge line.
Definition: edgeI.H:169
friend bool operator!=(const edge &a, const edge &b)
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
scalar mag(const pointField &) const
Return scalar magnitude.
Definition: edgeI.H:163
vector vec(const pointField &) const
Return the vector (end - start)
Definition: edgeI.H:157
static const char *const typeName
Definition: edge.H:67
friend bool operator==(const edge &a, const edge &b)
label end() const
Return end vertex label.
Definition: edgeI.H:92
edge()
Null constructor for lists.
Definition: edgeI.H:55
Hash function class for primitives. All non-primitives used to hash entries on hash tables likely nee...
Definition: Hash.H:54
void flip()
Flip the edge in-place.
Definition: edgeI.H:139
bool operator!=(const particle &, const particle &)
Definition: particle.C:1106
label start() const
Return start vertex label.
Definition: edgeI.H:81
Namespace for OpenFOAM.