face.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-2016 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 Class
28  Foam::face
29 
30 Description
31  A face is a list of labels corresponding to mesh vertices.
32 
33 See also
34  Foam::triFace
35 
36 SourceFiles
37  faceI.H
38  face.C
39  faceIntersection.C
40  faceContactSphere.C
41  faceAreaInContact.C
42  faceTemplates.C
43 
44 \*---------------------------------------------------------------------------*/
45 
46 #ifndef Foam_face_H
47 #define Foam_face_H
48 
49 #include "pointField.H"
50 #include "labelList.H"
51 #include "edgeList.H"
52 #include "vectorField.H"
53 #include "faceListFwd.H"
54 #include "intersection.H"
55 #include "pointHit.H"
56 #include "FixedList.H"
57 #include "ListListOps.H"
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 namespace Foam
62 {
63 
64 // Forward Declarations
65 class face;
66 class triFace;
67 template<class T, int SizeMin> class DynamicList;
68 
69 /*---------------------------------------------------------------------------*\
70  Class face Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 class face
74 :
75  public labelList
76 {
77  // Private Member Functions
78 
79  //- Construct list of edge vectors for face
80  tmp<vectorField> calcEdgeVectors
81  (
82  const UList<point>& points
83  ) const;
84 
85  //- Find index of largest internal angle on face
86  label mostConcaveAngle
87  (
88  const UList<point>& points,
89  const vectorField& edges,
90  scalar& edgeCos
91  ) const;
92 
93  //- Enumeration listing the modes for split()
94  enum splitMode
95  {
96  COUNTTRIANGLE,
97  COUNTQUAD,
98  SPLITTRIANGLE,
99  SPLITQUAD
100  };
101 
102  //- Split face into triangles or triangles and quads.
103  // Stores results quadFaces[quadI], triFaces[triI]
104  // \return number of new faces created
105  label split
106  (
107  const splitMode mode,
108  const UList<point>& points,
109  label& triI,
110  label& quadI,
111  faceList& triFaces,
112  faceList& quadFaces
113  ) const;
114 
115 
116 public:
117 
118  // Public Typedefs
119 
120  //- The proximity classifications
121  enum proxType
122  {
123  NONE = 0,
124  POINT,
125  EDGE
126  };
128 
129  // Static Data Members
131  static const char* const typeName;
132 
133 
134  // Constructors
135 
136  //- Default construct
137  constexpr face() noexcept = default;
138 
139  //- Construct given size, with invalid vertex labels (-1)
140  inline explicit face(const label sz);
141 
142  //- Copy construct from list of vertex labels
143  inline explicit face(const labelUList& list);
144 
145  //- Move construct from list of vertex labels
146  inline explicit face(labelList&& list);
147 
148  //- Copy construct from an initializer list of vertex labels
149  inline explicit face(std::initializer_list<label> list);
150 
151  //- Copy construct from list of vertex labels
152  template<unsigned N>
153  inline explicit face(const FixedList<label, N>& list);
154 
155  //- Copy construct from subset of vertex labels
156  inline face(const labelUList& list, const labelUList& indices);
157 
158  //- Copy construct from subset of vertex labels
159  template<unsigned N>
160  inline face(const labelUList& list, const FixedList<label, N>& indices);
161 
162  //- Copy construct from triFace
163  face(const triFace& f);
164 
165  //- Construct from Istream
166  inline face(Istream& is);
167 
168 
169  // Member Functions
170 
171  //- Collapse face by removing duplicate vertex labels
172  // \return the collapsed size
173  label collapse();
174 
175  //- Flip the face in-place.
176  // The starting vertex of the original and flipped face are identical.
177  void flip();
178 
179  //- Return the points corresponding to this face
180  inline pointField points(const UList<point>& pts) const;
181 
182  //- Centre point of face
183  point centre(const UList<point>& points) const;
184 
185  //- Calculate average value at centroid of face
186  template<class Type>
187  Type average
188  (
189  const UList<point>& meshPoints,
190  const Field<Type>& fld
191  ) const;
192 
193  //- The area normal - with magnitude equal to area of face
194  vector areaNormal(const UList<point>& p) const;
195 
196  //- The unit normal
197  inline vector unitNormal(const UList<point>& p) const;
198 
199  //- Legacy name for areaNormal()
200  // \deprecated(2018-06) Deprecated for new use
201  FOAM_DEPRECATED_FOR(2018-12, "areaNormal() or unitNormal()")
202  vector normal(const UList<point>& p) const
203  {
204  return areaNormal(p); // Legacy definition
205  }
206 
207  //- Magnitude of face area
208  inline scalar mag(const UList<point>& p) const;
209 
210  //- Magnitude squared of face area
211  inline scalar magSqr(const UList<point>& p) const;
212 
213  //- The enclosing (bounding) box for the face
214  inline Pair<point> box(const UList<point>& pts) const;
215 
216  //- Return face with reverse direction
217  // The starting vertex of the original and reverse face are identical.
218  face reverseFace() const;
219 
220 
221  // Navigation through face vertices
222 
223  //- Find local vertex on face for the vertex label, same as find()
224  // \return position in face (0,1,2,...) or -1 if not found.
225  inline label which(const label vertex) const;
226 
227  //- The vertex on face - identical to operator[], but with naming
228  //- similar to nextLabel(), prevLabel()
229  inline label thisLabel(const label i) const;
230 
231  //- Next vertex on face
232  inline label nextLabel(const label i) const;
233 
234  //- Previous vertex on face
235  inline label prevLabel(const label i) const;
236 
237 
238  //- Return the volume swept out by the face when its points move
239  scalar sweptVol
240  (
241  const UList<point>& oldPoints,
242  const UList<point>& newPoints
243  ) const;
244 
245  //- Return the inertia tensor, with optional reference
246  //- point and density specification
248  (
249  const UList<point>& p,
250  const point& refPt = vector::zero,
251  scalar density = 1.0
252  ) const;
253 
254  //- Return potential intersection with face with a ray starting
255  //- at p, direction n (does not need to be normalized)
256  // Does face-centre decomposition and returns triangle intersection
257  // point closest to p. Face-centre is calculated from point average.
258  // For a hit, the distance is signed. Positive number
259  // represents the point in front of triangle
260  // In case of miss the point is the nearest point on the face
261  // and the distance is the distance between the intersection point
262  // and the original point.
263  // The half-ray or full-ray intersection and the contact
264  // sphere adjustment of the projection vector is set by the
265  // intersection parameters
266  pointHit ray
267  (
268  const point& p,
269  const vector& n,
270  const UList<point>& meshPoints,
273  ) const;
274 
275  //- Fast intersection with a ray.
276  // Does face-centre decomposition and returns triangle intersection
277  // point closest to p. See triangle::intersection for details.
279  (
280  const point& p,
281  const vector& q,
282  const point& ctr,
283  const UList<point>& meshPoints,
284  const intersection::algorithm alg,
285  const scalar tol = 0.0
286  ) const;
287 
288  //- Return nearest point to face
290  (
291  const point& p,
292  const UList<point>& meshPoints
293  ) const;
294 
295  //- Return nearest point to face and classify it:
296  // + near point (nearType=POINT, nearLabel=0, 1, 2)
297  // + near edge (nearType=EDGE, nearLabel=0, 1, 2)
298  // Note: edges are counted from starting vertex so
299  // e.g. edge n is from f[n] to f[0], where the face has n + 1
300  // points
302  (
303  const point& p,
304  const UList<point>& meshPoints,
305  label& nearType,
306  label& nearLabel
307  ) const;
308 
309  //- The sign for the side of the face plane the point is on,
310  //- using three evenly distributed face points for the estimated normal.
311  // Uses the supplied tolerance for rounding around zero.
312  // \return
313  // - 0: on plane
314  // - +1: front-side
315  // - -1: back-side
316  int sign
317  (
318  const point& p,
319  const UList<point>& points,
320  const scalar tol = SMALL
321  ) const;
322 
323  //- Return contact sphere diameter
324  scalar contactSphereDiameter
325  (
326  const point& p,
327  const vector& n,
328  const UList<point>& meshPoints
329  ) const;
330 
331  //- Return area in contact, given the displacement in vertices
332  scalar areaInContact
333  (
334  const UList<point>& meshPoints,
335  const scalarField& v
336  ) const;
337 
338  //- Return number of edges
339  inline label nEdges() const noexcept;
340 
341  //- Return i-th face edge (forward walk order).
342  // The edge 0 is from [0] to [1]
343  // and edge 1 is from [1] to [2]
344  inline Foam::edge edge(const label edgei) const;
345 
346  //- Return vector of i-th face edge (forward walk order).
347  // The edge 0 is from [0] to [1]
348  // and edge 1 is from [1] to [2]
349  inline vector edge(const label edgei, const UList<point>& pts) const;
350 
351  //- Return i-th face edge in reverse walk order.
352  // The rcEdge 0 is from [0] to [n-1]
353  // and rcEdge 1 is from [n-1] to [n-2]
354  inline Foam::edge rcEdge(const label edgei) const;
355 
356  //- Return vector of i-th face edge in reverse walk order.
357  // The rcEdge 0 is from [0] to [n-1]
358  // and rcEdge 1 is from [n-1] to [n-2]
359  inline vector rcEdge(const label edgei, const UList<point>& pts) const;
360 
361  //- Return list of edges in forward walk order.
362  // The edge 0 is from [0] to [1]
363  // and edge 1 is from [1] to [2]
364  edgeList edges() const;
365 
366  //- Return list of edges in reverse walk order.
367  // The rcEdge 0 is from [0] to [n-1]
368  // and rcEdge 1 is from [n-1] to [n-2]
369  edgeList rcEdges() const;
370 
371 
372  // Searching
373 
374  //- Regular contains(pointi) tests
375  using labelList::contains;
376 
377  //- True if face contains(edge)
378  inline bool contains(const Foam::edge& e) const;
379 
380  //- Regular find pointi within face
381  using labelList::find;
382 
383  //- Find the edge within the face.
384  // \return the edge index or -1 if not found
385  label find(const Foam::edge& e) const;
386 
387  //- Test the edge direction on the face
388  // \return
389  // - 0: edge not found on the face
390  // - +1: forward (counter-clockwise) on the face
391  // - -1: reverse (clockwise) on the face
392  int edgeDirection(const Foam::edge& e) const;
393 
394  //- Find the longest edge on a face.
395  label longestEdge(const UList<point>& pts) const;
396 
397 
398  // Face splitting utilities
399 
400  //- Number of triangles after splitting
401  inline label nTriangles() const noexcept;
402 
403  //- Number of triangles after splitting
404  label nTriangles(const UList<point>& unused) const;
405 
406  //- Split into triangles using existing points.
407  // Result in triFaces[triI..triI+nTri].
408  // Splits intelligently to maximize triangle quality.
409  // \Return number of faces created.
410  label triangles
411  (
412  const UList<point>& points,
413  label& triI,
414  faceList& triFaces
415  ) const;
416 
417  //- Split into triangles using existing points.
418  // Append to DynamicList.
419  // \Return number of faces created.
420  template<int SizeMin>
421  label triangles
422  (
423  const UList<point>& points,
424  DynamicList<face, SizeMin>& triFaces
425  ) const;
426 
427  //- Number of triangles and quads after splitting
428  // Returns the sum of both
429  label nTrianglesQuads
430  (
431  const UList<point>& points,
432  label& nTris,
433  label& nQuads
434  ) const;
435 
436  //- Split into triangles and quads.
437  // Results in triFaces (starting at triI) and quadFaces
438  // (starting at quadI).
439  // Returns number of new faces created.
440  label trianglesQuads
441  (
442  const UList<point>& points,
443  label& triI,
444  label& quadI,
445  faceList& triFaces,
446  faceList& quadFaces
447  ) const;
448 
449 
450  //- True if the face has at least one vertex in common with other
451  inline bool connected(const labelUList& other) const;
452 
453  //- True if the face has at least one vertex in common with other
454  template<unsigned N>
455  inline bool connected(const FixedList<label, N>& other) const;
456 
457  //- Compare faces
458  // \return
459  // - 0: different
460  // - +1: identical
461  // - -1: same face, but different orientation
462  static int compare(const face& a, const face& b);
463 
464  //- True if the faces have all the same vertices
465  static bool sameVertices(const face& a, const face& b);
466 
467 
468  // Member Operators
469 
470  //- Increment (offset) vertices by given amount
471  inline void operator+=(const label vertexOffset);
472 
473 
474  // Hashing
475 
476  //- The symmetric hash value for face.
477  // Starts with lowest vertex value and walks in the direction
478  // of the next lowest value.
479  static unsigned symmhash_code(const UList<label>& f, unsigned seed=0);
480 
481  //- The hash value for face.
482  // Currently hashes as sequential contiguous data,
483  // but could/should be commutative
484  inline unsigned hash_code(unsigned seed=0) const
485  {
486  return Foam::Hasher(this->cdata(), this->size_bytes(), seed);
487  }
488 
489  //- The symmetric hash value for face.
490  // Starts with lowest vertex value and walks in the direction
491  // of the next lowest value.
492  inline unsigned symmhash_code(unsigned seed=0) const
493  {
494  return face::symmhash_code(*this, seed);
495  }
496 
497  //- Hashing functor for face
498  struct hasher
499  {
500  unsigned operator()(const face& obj, unsigned seed=0) const
501  {
502  return obj.hash_code(seed);
503  }
504  };
505 
506  //- Symmetric hashing functor for face
507  struct symmHasher
508  {
509  unsigned operator()(const face& obj, unsigned seed=0) const
510  {
511  return face::symmhash_code(obj, seed);
512  }
513  };
514 
515 
516  // Housekeeping
517 
518  //- Identical to edge()
519  Foam::edge faceEdge(label edgei) const { return this->edge(edgei); }
520 };
521 
522 
523 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
524 
525 //- Hash face as contiguous (non-commutative) list data
526 template<> struct Hash<face> : face::hasher {};
527 
528 
529 //- Specialization to offset faces, used in ListListOps::combineOffset
530 template<>
531 struct offsetOp<face>
532 {
533  face operator()(const face& x, const label offset) const
534  {
535  face f(x);
536  f += offset;
537  return f;
538  }
539 };
540 
541 
542 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
543 
544 inline bool operator==(const face& a, const face& b);
545 inline bool operator!=(const face& a, const face& b);
546 
547 
548 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
549 
550 } // End namespace Foam
551 
552 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
553 
554 #include "faceI.H"
555 
556 #ifdef NoRepository
557  #include "faceTemplates.C"
558 #endif
559 
560 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
561 
562 #endif
563 
564 // ************************************************************************* //
Close to point.
Definition: face.H:130
scalar areaInContact(const UList< point > &meshPoints, const scalarField &v) const
Return area in contact, given the displacement in vertices.
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
proxType
The proximity classifications.
Definition: face.H:127
edgeList edges() const
Return list of edges in forward walk order.
Definition: face.C:764
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
pointHit intersection(const point &p, const vector &q, const point &ctr, const UList< point > &meshPoints, const intersection::algorithm alg, const scalar tol=0.0) const
Fast intersection with a ray.
Unknown proximity.
Definition: face.H:129
label triangles(const UList< point > &points, label &triI, faceList &triFaces) const
Split into triangles using existing points.
Definition: face.C:860
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 areaNormal(const UList< point > &p) const
The area normal - with magnitude equal to area of face.
Definition: face.C:569
vector unitNormal(const UList< point > &p) const
The unit normal.
Definition: faceI.H:97
Close to edge.
Definition: face.H:131
Pair< point > box(const UList< point > &pts) const
The enclosing (bounding) box for the face.
Definition: faceI.H:118
static unsigned symmhash_code(const UList< label > &f, unsigned seed=0)
The symmetric hash value for face.
Definition: face.C:414
unsigned operator()(const face &obj, unsigned seed=0) const
Definition: face.H:657
unsigned operator()(const face &obj, unsigned seed=0) const
Definition: face.H:668
label prevLabel(const label i) const
Previous vertex on face.
Definition: faceI.H:195
T operator()(const T &x, const label offset) const
Definition: ListListOps.H:101
FOAM_DEPRECATED_FOR(2018-12, "areaNormal() or unitNormal()") vector normal(const UList< point > &p) const
Legacy name for areaNormal()
Definition: face.H:246
label collapse()
Collapse face by removing duplicate vertex labels.
Definition: face.C:467
pointField points(const UList< point > &pts) const
Return the points corresponding to this face.
Definition: faceI.H:80
face reverseFace() const
Return face with reverse direction.
Definition: face.C:627
pointHit ray(const point &p, const vector &n, const UList< point > &meshPoints, const intersection::algorithm alg=intersection::FULL_RAY, const intersection::direction dir=intersection::VECTOR) const
Return potential intersection with face with a ray starting at p, direction n (does not need to be no...
int sign(const point &p, const UList< point > &points, const scalar tol=SMALL) const
The sign for the side of the face plane the point is on, using three evenly distributed face points f...
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
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
int edgeDirection(const Foam::edge &e) const
Test the edge direction on the face.
Definition: face.C:831
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:65
face triFace(3)
label longestEdge(const UList< point > &pts) const
Find the longest edge on a face.
Definition: face.C:900
scalar sweptVol(const UList< point > &oldPoints, const UList< point > &newPoints) const
Return the volume swept out by the face when its points move.
Definition: face.C:650
label which(const label vertex) const
Find local vertex on face for the vertex label, same as find()
Definition: faceI.H:177
tensor inertia(const UList< point > &p, const point &refPt=vector::zero, scalar density=1.0) const
Return the inertia tensor, with optional reference point and density specification.
Definition: face.C:729
Describes the interaction of a object and a (templated) point. It carries the info of a successful hi...
Definition: pointHit.H:43
label trianglesQuads(const UList< point > &points, label &triI, label &quadI, faceList &triFaces, faceList &quadFaces) const
Split into triangles and quads.
Definition: face.C:888
label find(const Foam::edge &e) const
Find the edge within the face.
Definition: face.C:806
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
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...
Foam::edge edge(const label edgei) const
Return i-th face edge (forward walk order).
Definition: faceI.H:139
static const char *const typeName
Definition: face.H:137
pointHit nearestPointClassify(const point &p, const UList< point > &meshPoints, label &nearType, label &nearLabel) const
Return nearest point to face and classify it:
pointHit nearestPoint(const point &p, const UList< point > &meshPoints) const
Return nearest point to face.
labelList f(nPoints)
const Vector< label > N(dict.get< Vector< label >>("N"))
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Forwards for various types of face lists.
unsigned Hasher(const void *data, size_t len, unsigned seed=0)
Bob Jenkins&#39;s 96-bit mixer hashing function (lookup3)
Definition: Hasher.C:575
Type average(const UList< point > &meshPoints, const Field< Type > &fld) const
Calculate average value at centroid of face.
Definition: faceTemplates.C:46
scalar contactSphereDiameter(const point &p, const vector &n, const UList< point > &meshPoints) const
Return contact sphere diameter.
Foam::edge faceEdge(label edgei) const
Identical to edge()
Definition: face.H:680
bool connected(const labelUList &other) const
True if the face has at least one vertex in common with other.
Definition: faceI.H:207
label nTrianglesQuads(const UList< point > &points, label &nTris, label &nQuads) const
Number of triangles and quads after splitting.
Definition: face.C:874
void flip()
Flip the face in-place.
Definition: face.C:492
bool contains(const Foam::edge &e) const
True if face contains(edge)
Definition: faceI.H:234
edgeList rcEdges() const
Return list of edges in reverse walk order.
Definition: face.C:785
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
point centre(const UList< point > &points) const
Centre point of face.
Definition: face.C:506
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:297
const label * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:258
static int compare(const face &a, const face &b)
Compare faces.
Definition: face.C:273
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
static bool sameVertices(const face &a, const face &b)
True if the faces have all the same vertices.
Definition: face.C:374
Tensor of scalars, i.e. Tensor<scalar>.
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
Definition: POSIX.C:775
unsigned hash_code(unsigned seed=0) const
The hash value for face.
Definition: face.H:636
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
Definition: UListI.H:286
Namespace for OpenFOAM.
const pointField & pts