edgeI.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 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 \*---------------------------------------------------------------------------*/
25 
26 #include "IOstreams.H"
27 #include "Swap.H"
28 
29 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
30 
31 
32 // return
33 // - 0: different
34 // - +1: identical
35 // - -1: same edge, but different orientation
36 inline int Foam::edge::compare(const edge& a, const edge& b)
37 {
38  if (a[0] == b[0] && a[1] == b[1])
39  {
40  return 1;
41  }
42  else if (a[0] == b[1] && a[1] == b[0])
43  {
44  return -1;
45  }
46  else
47  {
48  return 0;
49  }
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
56 {}
57 
58 
59 inline Foam::edge::edge(const label a, const label b)
60 {
61  start() = a;
62  end() = b;
63 }
64 
65 
67 {
68  start() = a[0];
69  end() = a[1];
70 }
71 
72 
74 :
75  FixedList<label, 2>(is)
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
82 {
83  return operator[](0);
84 }
85 
87 {
88  return operator[](0);
89 }
90 
91 
93 {
94  return operator[](1);
95 }
96 
98 {
99  return operator[](1);
100 }
101 
102 
104 {
105  if (a == start())
106  {
107  return end();
108  }
109  else if (a == end())
110  {
111  return start();
112  }
113  else
114  {
115  // The given vertex is not on the edge in the first place.
116  return -1;
117  }
118 }
119 
120 
122 {
123  if (start() == a.start() || start() == a.end())
124  {
125  return start();
126  }
127  else if (end() == a.start() || end() == a.end())
128  {
129  return end();
130  }
131  else
132  {
133  // No shared vertex.
134  return -1;
135  }
136 }
137 
138 
139 inline void Foam::edge::flip()
140 {
141  Swap(operator[](0), operator[](1));
142 }
143 
144 
146 {
147  return edge(end(), start());
148 }
149 
150 
152 {
153  return 0.5*(p[start()] + p[end()]);
154 }
155 
156 
158 {
159  return p[end()] - p[start()];
160 }
161 
162 
163 inline Foam::scalar Foam::edge::mag(const pointField& p) const
164 {
166 }
167 
168 
170 {
171  return linePointRef(p[start()], p[end()]);
172 }
173 
174 
175 // * * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * //
176 
177 inline bool Foam::operator==(const edge& a, const edge& b)
178 {
179  return edge::compare(a,b) != 0;
180 }
181 
182 
183 inline bool Foam::operator!=(const edge& a, const edge& b)
184 {
185  return edge::compare(a,b) == 0;
186 }
187 
188 
189 // ************************************************************************* //
static int compare(const edge &, const edge &)
Compare edges.
Definition: edgeI.H:36
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
label commonVertex(const edge &a) const
Return common vertex.
Definition: edgeI.H:121
dimensioned< scalar > mag(const dimensioned< Type > &)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
edge()
Null constructor for lists.
Definition: edgeI.H:55
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
void flip()
Flip the edge in-place.
Definition: edgeI.H:139
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
A line primitive.
Definition: line.H:56
scalar mag(const pointField &) const
Return scalar magnitude.
Definition: edgeI.H:163
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
edge reverseEdge() const
Return reverse edge.
Definition: edgeI.H:145
volScalarField & p
Definition: createFields.H:51
label & operator[](const label)
Return element of FixedList.
linePointRef line(const pointField &) const
Return edge line.
Definition: edgeI.H:169
bool operator!=(const particle &, const particle &)
Definition: particle.C:147
label otherVertex(const label a) const
Given one vertex, return the other.
Definition: edgeI.H:103
Swap its arguments.
vector vec(const pointField &) const
Return the vector (end - start)
Definition: edgeI.H:157
void Swap(T &a, T &b)
Definition: Swap.H:43
label end() const
Return end vertex label.
Definition: edgeI.H:92
label start() const
Return start vertex label.
Definition: edgeI.H:81
line< point, const point & > linePointRef
Line using referred points.
Definition: linePointRef.H:45
point centre(const pointField &) const
Return centre (centroid)
Definition: edgeI.H:151