All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
edge.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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  //- Return true if connected to given edge
101  inline bool connected(const edge& a) const;
102 
103  //- Return common vertex
104  inline label commonVertex(const edge& a) const;
105 
106  //- Given one vertex, return the other
107  inline label otherVertex(const label a) const;
108 
109  //- Flip the edge in-place.
110  inline void flip();
111 
112  //- Return reverse edge
113  inline edge reverseEdge() const;
114 
115  //- Return centre (centroid)
116  inline point centre(const pointField&) const;
117 
118  //- Return the vector (end - start)
119  inline vector vec(const pointField&) const;
120 
121  //- Return scalar magnitude
122  inline scalar mag(const pointField&) const;
123 
124  //- Return edge line
125  inline linePointRef line(const pointField&) const;
126 
127  //- Compare edges
128  // Returns:
129  // - 0: different
130  // - +1: identical
131  // - -1: same edge, but different orientation
132  static inline int compare(const edge&, const edge&);
133 
134 
135  // Friend Operators
136 
137  friend bool operator==(const edge& a, const edge& b);
138  friend bool operator!=(const edge& a, const edge& b);
139 };
140 
141 
142 //- Hash specialization for hashing edges - a commutative hash value.
143 // Hash incrementally.
144 template<>
145 inline unsigned Hash<edge>::operator()(const edge& e, unsigned seed) const
146 {
147  unsigned val = seed;
148 
149  if (e[0] < e[1])
150  {
151  val = Hash<label>()(e[0], val);
152  val = Hash<label>()(e[1], val);
153  }
154  else
155  {
156  val = Hash<label>()(e[1], val);
157  val = Hash<label>()(e[0], val);
158  }
159 
160  return val;
161 }
162 
163 
164 //- Hash specialization for hashing edges - a commutative hash value.
165 // Hash incrementally.
166 template<>
167 inline unsigned Hash<edge>::operator()(const edge& e) const
168 {
169  return Hash<edge>()(e, 0);
170 }
171 
172 
173 template<>
174 inline bool contiguous<edge>() {return true;}
175 
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 } // End namespace Foam
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #include "edgeI.H"
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #endif
188 
189 // ************************************************************************* //
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
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:54
bool contiguous< edge >()
Definition: edge.H:173
edge reverseEdge() const
Return reverse edge.
Definition: edgeI.H:163
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:140
unsigned operator()(const PrimitiveType &p, unsigned seed) const
Definition: Hash.H:61
label commonVertex(const edge &a) const
Return common vertex.
Definition: edgeI.H:122
point centre(const pointField &) const
Return centre (centroid)
Definition: edgeI.H:169
linePointRef line(const pointField &) const
Return edge line.
Definition: edgeI.H:187
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:181
bool connected(const edge &a) const
Return true if connected to given edge.
Definition: edgeI.H:103
vector vec(const pointField &) const
Return the vector (end - start)
Definition: edgeI.H:175
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
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:105
void flip()
Flip the edge in-place.
Definition: edgeI.H:157
bool operator!=(const particle &, const particle &)
Definition: particle.C:1204
label start() const
Return start vertex label.
Definition: edgeI.H:81
Namespace for OpenFOAM.