face.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-2022 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::face
26 
27 Description
28  A face is a list of labels corresponding to mesh vertices.
29 
30 See also
31  Foam::triFace
32 
33 SourceFiles
34  faceI.H
35  face.C
36  faceIntersection.C
37  faceContactSphere.C
38  faceAreaInContact.C
39  faceTemplates.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef face_H
44 #define face_H
45 
46 #include "pointField.H"
47 #include "labelList.H"
48 #include "edgeList.H"
49 #include "vectorField.H"
50 #include "faceListFwd.H"
51 #include "DynamicListFwd.H"
52 #include "intersection.H"
53 #include "pointHit.H"
54 #include "ListListOps.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // Forward declaration of friend functions and operators
62 
63 class face;
64 class triFace;
65 
66 inline bool operator==(const face& a, const face& b);
67 inline bool operator!=(const face& a, const face& b);
68 inline Istream& operator>>(Istream&, face&);
69 
70 /*---------------------------------------------------------------------------*\
71  Class face Declaration
72 \*---------------------------------------------------------------------------*/
73 
74 class face
75 :
76  public labelList
77 {
78 public:
79 
80  //- Return types for classify
81  enum proxType
82  {
84  POINT, // Close to point
85  EDGE // Close to edge
86  };
87 
88  // Static Data Members
89 
90  static const char* const typeName;
91 
92 
93  // Static Functions
94 
95  //- Return centre point given face points
96  template<class PointField>
97  static vector centre(const PointField& ps);
98 
99  //- Return vector area given face points
100  template<class PointField>
101  static vector area(const PointField& ps);
102 
103 
104  // Constructors
105 
106  //- Construct null
107  inline face();
108 
109  //- Construct given size
110  explicit inline face(label);
111 
112  //- Construct from list of labels
113  explicit inline face(const labelUList&);
114 
115  //- Construct from list of labels
116  explicit inline face(const labelList&);
117 
118  //- Construct by transferring the parameter contents
119  explicit inline face(labelList&&);
120 
121  //- Copy construct from triFace
122  face(const triFace&);
123 
124  //- Construct from Istream
125  inline face(Istream&);
126 
127 
128  // Member Functions
129 
130  //- Collapse face by removing duplicate point labels
131  // return the collapsed size
132  label collapse();
133 
134  //- Flip the face in-place.
135  // The starting points of the original and flipped face are identical.
136  void flip();
137 
138  //- Return the points corresponding to this face
139  inline pointField points(const pointField&) const;
140 
141  //- Centre point of face
142  point centre(const pointField&) const;
143 
144  //- Calculate average value at centroid of face
145  template<class Type>
146  Type average(const pointField&, const Field<Type>&) const;
147 
148  //- Return vector area
149  vector area(const pointField&) const;
150 
151  //- Return scalar magnitude
152  inline scalar mag(const pointField&) const;
153 
154  //- Return unit normal
155  vector normal(const pointField&) const;
156 
157  //- Return face with reverse direction
158  // The starting points of the original and reverse face are identical.
159  face reverseFace() const;
160 
161  //- Navigation through face vertices
162 
163  //- Which vertex on face (face index given a global index)
164  // returns -1 if not found
165  label which(const label globalIndex) const;
166 
167  //- Next vertex on face
168  inline label nextLabel(const label i) const;
169 
170  //- Previous vertex on face
171  inline label prevLabel(const label i) const;
172 
173 
174  //- Return the volume swept out by the face when its points move
175  scalar sweptVol
176  (
177  const pointField& oldPoints,
178  const pointField& newPoints
179  ) const;
180 
181  //- Return the inertia tensor, with optional reference
182  // point and density specification
184  (
185  const pointField&,
186  const point& refPt = vector::zero,
187  scalar density = 1.0
188  ) const;
189 
190  //- Return potential intersection with face with a ray starting
191  // at p, direction n (does not need to be normalised)
192  // Does face-centre decomposition and returns triangle intersection
193  // point closest to p. Face-centre is calculated from point average.
194  // For a hit, the distance is signed. Positive number
195  // represents the point in front of triangle
196  // In case of miss the point is the nearest point on the face
197  // and the distance is the distance between the intersection point
198  // and the original point.
199  // The half-ray or full-ray intersection and the contact
200  // sphere adjustment of the projection vector is set by the
201  // intersection parameters
202  pointHit ray
203  (
204  const point& p,
205  const vector& n,
206  const pointField&,
207  const intersection::algorithm alg =
209  const intersection::direction dir =
211  ) const;
212 
213  //- Fast intersection with a ray.
214  // Does face-centre decomposition and returns triangle intersection
215  // point closest to p. See triangle::intersection for details.
217  (
218  const point& p,
219  const vector& q,
220  const point& ctr,
221  const pointField&,
222  const intersection::algorithm alg,
223  const scalar tol = 0.0
224  ) const;
225 
226  //- Return nearest point to face
228  (
229  const point& p,
230  const pointField&
231  ) const;
232 
233  //- Return nearest point to face and classify it:
234  // + near point (nearType=POINT, nearLabel=0, 1, 2)
235  // + near edge (nearType=EDGE, nearLabel=0, 1, 2)
236  // Note: edges are counted from starting vertex so
237  // e.g. edge n is from f[n] to f[0], where the face has n + 1
238  // points
240  (
241  const point& p,
242  const pointField&,
243  label& nearType,
244  label& nearLabel
245  ) const;
246 
247  //- Return contact sphere diameter
248  scalar contactSphereDiameter
249  (
250  const point& p,
251  const vector& n,
252  const pointField&
253  ) const;
254 
255  //- Return area in contact, given the displacement in vertices
256  scalar areaInContact
257  (
258  const pointField&,
259  const scalarField& v
260  ) const;
261 
262  //- Return number of edges
263  inline label nEdges() const;
264 
265  //- Return edges in face point ordering,
266  // i.e. edges()[0] is edge between [0] and [1]
267  edgeList edges() const;
268 
269  //- Return n-th face edge
270  inline edge faceEdge(const label n) const;
271 
272  //- Return the edge direction on the face
273  // Returns:
274  // - 0: edge not found on the face
275  // - +1: forward (counter-clockwise) on the face
276  // - -1: reverse (clockwise) on the face
277  int edgeDirection(const edge&) const;
278 
279  //- Size of the face's triangulation
280  inline label nTriangles() const;
281 
282  //- Compare faces
283  // 0: different
284  // +1: identical
285  // -1: same face, but different orientation
286  static int compare(const face&, const face&);
287 
288  //- Return true if the faces have the same vertices
289  static bool sameVertices(const face&, const face&);
290 
291 
292  // Member Operators
293 
294  //- Move assignment labelList
295  inline void operator=(labelList&&);
296 
297 
298  // Friend Operators
299 
300  friend bool operator==(const face& a, const face& b);
301  friend bool operator!=(const face& a, const face& b);
302 
303 
304  // Istream Operator
305 
306  friend Istream& operator>>(Istream&, face&);
307 };
308 
309 
310 //- Hash specialisation to offset faces in ListListOps::combineOffset
311 template<>
312 class offsetOp<face>
313 {
314 
315 public:
316 
317  inline face operator()
318  (
319  const face& x,
320  const label offset
321  ) const
322  {
323  face result(x.size());
324 
325  forAll(x, xI)
326  {
327  result[xI] = x[xI] + offset;
328  }
329  return result;
330  }
331 };
332 
333 
334 // Global functions
335 
336 //- Find the longest edge on a face. Face point labels index into pts.
337 label longestEdge(const face& f, const pointField& pts);
338 
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 } // End namespace Foam
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 #include "faceI.H"
347 
348 #ifdef NoRepository
349  #include "faceTemplates.C"
350 #endif
351 
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353 
354 #endif
355 
356 // ************************************************************************* //
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
static const Form zero
Definition: VectorSpace.H:113
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:61
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
pointHit intersection(const point &p, const vector &q, const point &ctr, const pointField &, const intersection::algorithm alg, const scalar tol=0.0) const
Fast intersection with a ray.
void flip()
Flip the face in-place.
Definition: face.C:224
pointField points(const pointField &) const
Return the points corresponding to this face.
Definition: faceI.H:64
face()
Construct null.
Definition: faceI.H:28
tensor inertia(const pointField &, const point &refPt=vector::zero, scalar density=1.0) const
Return the inertia tensor, with optional reference.
Definition: face.C:371
scalar areaInContact(const pointField &, const scalarField &v) const
Return area in contact, given the displacement in vertices.
scalar mag(const pointField &) const
Return scalar magnitude.
Definition: faceI.H:81
int edgeDirection(const edge &) const
Return the edge direction on the face.
Definition: face.C:424
pointHit ray(const point &p, const vector &n, const pointField &, const intersection::algorithm alg=intersection::algorithm::fullRay, const intersection::direction dir=intersection::direction::vector) const
Return potential intersection with face with a ray starting.
pointHit nearestPoint(const point &p, const pointField &) const
Return nearest point to face.
friend Istream & operator>>(Istream &, face &)
static int compare(const face &, const face &)
Compare faces.
Definition: face.C:48
proxType
Return types for classify.
Definition: face.H:81
@ POINT
Definition: face.H:83
@ EDGE
Definition: face.H:84
@ NONE
Definition: face.H:82
static bool sameVertices(const face &, const face &)
Return true if the faces have the same vertices.
Definition: face.C:150
friend bool operator==(const face &a, const face &b)
scalar sweptVol(const pointField &oldPoints, const pointField &newPoints) const
Return the volume swept out by the face when its points move.
Definition: face.C:292
void operator=(labelList &&)
Move assignment labelList.
Definition: faceI.H:120
label nextLabel(const label i) const
Next vertex on face.
Definition: faceI.H:100
static vector centre(const PointField &ps)
Return centre point given face points.
vector normal(const pointField &) const
Return unit normal.
Definition: face.C:250
label collapse()
Collapse face by removing duplicate point labels.
Definition: face.C:199
face reverseFace() const
Return face with reverse direction.
Definition: face.C:256
label nTriangles() const
Size of the face's triangulation.
Definition: faceI.H:112
Type average(const pointField &, const Field< Type > &) const
Calculate average value at centroid of face.
edgeList edges() const
Return edges in face point ordering,.
Definition: face.C:406
scalar contactSphereDiameter(const point &p, const vector &n, const pointField &) const
Return contact sphere diameter.
static vector area(const PointField &ps)
Return vector area given face points.
pointHit nearestPointClassify(const point &p, const pointField &, label &nearType, label &nearLabel) const
Return nearest point to face and classify it:
label which(const label globalIndex) const
Navigation through face vertices.
Definition: face.C:275
friend bool operator!=(const face &a, const face &b)
label prevLabel(const label i) const
Previous vertex on face.
Definition: faceI.H:106
label nEdges() const
Return number of edges.
Definition: faceI.H:87
static const char *const typeName
Definition: face.H:89
edge faceEdge(const label n) const
Return n-th face edge.
Definition: faceI.H:94
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:64
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:71
volScalarField & b
Definition: createFields.H:27
Namespace for OpenFOAM.
bool operator!=(const particle &, const particle &)
Definition: particle.C:1257
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
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Istream & operator>>(Istream &, directionInfo &)
label longestEdge(const face &f, const pointField &pts)
Find the longest edge on a face. Face point labels index into pts.
Definition: face.C:467
void offset(label &lst, const label o)
face triFace(3)
labelList f(nPoints)
volScalarField & p