faceI.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2017-2025 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 inline Foam::face::face(const label sz)
32 :
33  labelList(sz, -1)
34 {}
35 
36 
37 inline Foam::face::face(const labelUList& list)
38 :
39  labelList(list)
40 {}
41 
42 
43 inline Foam::face::face(labelList&& list)
44 :
45  labelList(std::move(list))
46 {}
47 
48 
49 inline Foam::face::face(std::initializer_list<label> list)
50 :
51  labelList(list)
52 {}
53 
54 
55 template<unsigned N>
56 inline Foam::face::face(const FixedList<label, N>& list)
57 :
58  labelList(list)
59 {}
60 
61 
62 inline Foam::face::face(const labelUList& list, const labelUList& indices)
63 :
64  labelList(list, indices)
65 {}
66 
67 
68 template<unsigned N>
69 inline Foam::face::face
70 (
71  const labelUList& list,
72  const FixedList<label, N>& indices
73 )
74 :
75  labelList(list, indices)
76 {}
77 
78 
79 inline Foam::face::face(Istream& is)
80 :
81  labelList(is)
82 {}
83 
84 
85 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86 
88 {
89  // There are as many points as there are labels for them
90  pointField p(size());
91 
92  auto iter = p.begin();
93 
94  for (const label pointi : *this)
95  {
96  *iter = pts[pointi];
97  ++iter;
98  }
99 
100  return p;
101 }
102 
103 
104 inline Foam::vector Foam::face::unitNormal(const UList<point>& p) const
105 {
106  vector n(areaNormal(p));
107  (void) n.normalise(ROOTVSMALL);
108  return n;
109 }
110 
112 inline Foam::scalar Foam::face::mag(const UList<point>& p) const
113 {
114  return ::Foam::mag(areaNormal(p));
115 }
116 
117 
118 inline Foam::scalar Foam::face::magSqr(const UList<point>& p) const
119 {
120  return ::Foam::magSqr(areaNormal(p));
121 }
122 
123 
125 Foam::face::box(const UList<point>& pts) const
126 {
127  Pair<point> bb(point::rootMax, point::rootMin);
128 
129  for (const label pointi : *this)
130  {
131  bb.first() = min(bb.first(), pts[pointi]);
132  bb.second() = max(bb.second(), pts[pointi]);
133  }
134 
135  return bb;
136 }
137 
138 
139 inline Foam::label Foam::face::nEdges() const noexcept
140 {
141  // for a closed polygon a number of edges is the same as number of points
142  return size();
143 }
144 
145 
146 inline Foam::edge Foam::face::edge(const label edgei) const
147 {
148  return Foam::edge(thisLabel(edgei), nextLabel(edgei));
149 }
150 
151 
153 (
154  const label edgei,
156 ) const
157 {
158  return vector(pts[nextLabel(edgei)] - pts[thisLabel(edgei)]);
159 }
160 
161 
162 inline Foam::edge Foam::face::rcEdge(const label edgei) const
163 {
164  // Edge 0 (forward and reverse) always starts at [0]
165  // for consistency with face flipping
166  const label pointi = edgei ? (nEdges() - edgei) : 0;
167  return Foam::edge(thisLabel(pointi), prevLabel(pointi));
168 }
169 
170 
172 (
173  const label edgei,
174  const UList<point>& pts
175 ) const
176 {
177  // Edge 0 (forward and reverse) always starts at [0]
178  // for consistency with face flipping
179  const label pointi = edgei ? (nEdges() - edgei) : 0;
180  return vector(pts[prevLabel(pointi)] - pts[thisLabel(pointi)]);
181 }
182 
184 inline Foam::label Foam::face::which(const label vertex) const
185 {
186  return labelList::find(vertex);
187 }
188 
190 inline Foam::label Foam::face::thisLabel(const label i) const
191 {
192  return labelList::operator[](i);
193 }
194 
196 inline Foam::label Foam::face::nextLabel(const label i) const
197 {
198  return labelList::fcValue(i);
199 }
200 
202 inline Foam::label Foam::face::prevLabel(const label i) const
203 {
204  return labelList::rcValue(i);
205 }
206 
208 inline Foam::label Foam::face::nTriangles() const noexcept
209 {
210  return labelList::size() - 2;
211 }
212 
213 
214 inline bool Foam::face::connected(const labelUList& other) const
215 {
216  for (const label pointi : *this)
217  {
218  if (other.contains(pointi))
219  {
220  return true;
221  }
222  }
223  return false;
224 }
225 
226 
227 template<unsigned N>
228 inline bool Foam::face::connected(const FixedList<label, N>& other) const
229 {
230  for (const label pointi : *this)
231  {
232  if (other.contains(pointi))
233  {
234  return true;
235  }
236  }
237  return false;
238 }
239 
240 
241 inline bool Foam::face::contains(const Foam::edge& e) const
242 {
243  // or (find(e) >= 0)
244  return (edgeDirection(e) != 0);
245 }
246 
247 
248 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
249 
250 inline void Foam::face::operator+=(const label vertexOffset)
251 {
252  if (vertexOffset)
253  {
254  for (label& vrt : static_cast<labelList&>(*this))
255  {
256  vrt += vertexOffset;
257  }
258  }
259 }
260 
261 
262 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
263 
264 inline bool Foam::operator==(const face& a, const face& b)
265 {
266  return face::compare(a,b) != 0;
267 }
268 
269 inline bool Foam::operator!=(const face& a, const face& b)
270 {
271  return face::compare(a,b) == 0;
272 }
273 
274 
275 // ************************************************************************* //
scalar mag(const UList< point > &p) const
Magnitude of face area.
Definition: faceI.H:105
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:107
label nTriangles() const noexcept
Number of triangles after splitting.
Definition: faceI.H:201
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
scalar magSqr(const UList< point > &p) const
Magnitude squared of face area.
Definition: faceI.H:111
constexpr face() noexcept=default
Default construct.
label nextLabel(const label i) const
Next vertex on face.
Definition: faceI.H:189
Foam::edge rcEdge(const label edgei) const
Return i-th face edge in reverse walk order.
Definition: faceI.H:155
vector unitNormal(const UList< point > &p) const
The unit normal.
Definition: faceI.H:97
Pair< point > box(const UList< point > &pts) const
The enclosing (bounding) box for the face.
Definition: faceI.H:118
bool contains(const T &val) const
True if the value is contained in the list.
Definition: UListI.H:293
label prevLabel(const label i) const
Previous vertex on face.
Definition: faceI.H:195
label & operator[](const label i)
Return element of UList.
Definition: UListI.H:362
pointField points(const UList< point > &pts) const
Return the points corresponding to this face.
Definition: faceI.H:80
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: instant.H:46
const label & fcValue(const label i) const
Return forward circular value (ie, next value in the list)
Definition: UListI.H:104
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition: edge.H:59
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
label which(const label vertex) const
Find local vertex on face for the vertex label, same as find()
Definition: faceI.H:177
Vector< scalar > vector
Definition: vector.H:57
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:385
label find(const label &val) const
Find index of the first occurrence of the value.
Definition: UList.C:172
void operator+=(const label vertexOffset)
Increment (offset) vertices by given amount.
Definition: faceI.H:243
const direction noexcept
Definition: scalarImpl.H:255
label nEdges() const noexcept
Return number of edges.
Definition: faceI.H:132
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
label size() const noexcept
The number of elements in the container.
Definition: UList.H:702
Foam::edge edge(const label edgei) const
Return i-th face edge (forward walk order).
Definition: faceI.H:139
bool connected(const labelUList &other) const
True if the face has at least one vertex in common with other.
Definition: faceI.H:207
bool contains(const Foam::edge &e) const
True if face contains(edge)
Definition: faceI.H:234
label thisLabel(const label i) const
The vertex on face - identical to operator[], but with naming similar to nextLabel(), prevLabel()
Definition: faceI.H:183
label n
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:297
static int compare(const face &a, const face &b)
Compare faces.
Definition: face.C:273
volScalarField & p
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
const label & rcValue(const label i) const
Return reverse circular value (ie, previous value in the list)
Definition: UListI.H:118
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
const pointField & pts