FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 SourceFiles
31  faceI.H
32  face.C
33  faceIntersection.C
34  faceContactSphere.C
35  faceAreaInContact.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef face_H
40 #define face_H
41 
42 #include <OpenFOAM/pointField.H>
43 #include <OpenFOAM/labelList.H>
44 #include <OpenFOAM/edgeList.H>
45 #include <OpenFOAM/vectorField.H>
46 #include "faceListFwd.H"
47 #include <OpenFOAM/intersection.H>
48 #include <OpenFOAM/pointHit.H>
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward declaration of friend functions and operators
56 
57 class face;
58 class triFace;
59 
60 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
61 class DynamicList;
62 
63 inline bool operator==(const face& a, const face& b);
64 inline bool operator!=(const face& a, const face& b);
65 inline Istream& operator>>(Istream&, face&);
66 
67 /*---------------------------------------------------------------------------*\
68  Class face Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 class face
72 :
73  public labelList
74 {
75  // Private Member Functions
76 
77  //- Edge to the right of face vertex i
78  inline label right(const label i) const;
79 
80  //- Edge to the left of face vertex i
81  inline label left(const label i) const;
82 
83  //- Construct list of edge vectors for face
84  tmp<vectorField> calcEdges
85  (
86  const pointField& points
87  ) const;
88 
89  //- Cos between neighbouring edges
90  scalar edgeCos
91  (
92  const vectorField& edges,
93  const label index
94  ) const;
95 
96  //- Find index of largest internal angle on face
97  label mostConcaveAngle
98  (
99  const pointField& points,
100  const vectorField& edges,
101  scalar& edgeCos
102  ) const;
103 
104  //- Enumeration listing the modes for split()
105  enum splitMode
106  {
107  COUNTTRIANGLE, // count if split into triangles
108  COUNTQUAD, // count if split into triangles&quads
109  SPLITTRIANGLE, // split into triangles
110  SPLITQUAD // split into triangles&quads
111  };
112 
113  //- Split face into triangles or triangles&quads.
114  // Stores results quadFaces[quadI], triFaces[triI]
115  // Returns number of new faces created
116  label split
117  (
118  const splitMode mode,
119  const pointField& points,
120  label& triI,
121  label& quadI,
122  faceList& triFaces,
123  faceList& quadFaces
124  ) const;
125 
126 
127 public:
128 
129  // Static data members
130 
131  static const char* const typeName;
132 
133 
134  // Constructors
135 
136  //- Construct null
137  inline face();
138 
139  //- Construct given size
140  explicit inline face(label);
141 
142  //- Construct from list of labels
143  explicit inline face(const UList<label>&);
144 
145  //- Construct from list of labels
146  explicit inline face(const labelList&);
147 
148  //- Construct by transferring the parameter contents
149  explicit inline face(const Xfer<labelList>&);
150 
151  //- Copy construct from triFace
152  face(const triFace&);
153 
154  //- Construct from Istream
155  inline face(Istream&);
156 
157 
158  // Member Functions
159 
160  //- Collapse face by removing duplicate point labels
161  // return the collapsed size
162  label collapse();
163 
164  //- Return the points corresponding to this face
165  inline pointField points(const pointField& meshPoints) const;
166 
167  //- Centre point of face
168  point centre(const pointField&) const;
169 
170  //- Calculate average value at centroid of face
171  template<class Type>
172  Type average(const pointField&, const Field<Type>&) const;
173 
174  //- Scalar magnitude
175  inline scalar mag(const pointField&) const;
176 
177  //- Vector normal; magnitude is equal to area of face
178  vector normal(const pointField&) const;
179 
180  //- Return face with reverse direction
181  face reverseFace() const;
182 
183  //- Navigation through face vertices
184 
185  //- Which vertex on face (face index given a global index)
186  label which(const label globalIndex) const;
187 
188  //- Next vertex on face
189  inline label nextLabel(const label i) const;
190 
191  //- Previous vertex on face
192  inline label prevLabel(const label i) const;
193 
194 
195  //- Return the volume swept out by the face when its points move
196  scalar sweptVol
197  (
198  const pointField& oldPoints,
199  const pointField& newPoints
200  ) const;
201 
202  //- Return potential intersection with face with a ray starting
203  // at p, direction n (does not need to be normalized)
204  // Does face-center decomposition and returns triangle intersection
205  // point closest to p. Face-center is calculated from point average.
206  // For a hit, the distance is signed. Positive number
207  // represents the point in front of triangle
208  // In case of miss the point is the nearest point on the face
209  // and the distance is the distance between the intersection point
210  // and the original point.
211  // The half-ray or full-ray intersection and the contact
212  // sphere adjustment of the projection vector is set by the
213  // intersection parameters
214  pointHit ray
215  (
216  const point& p,
217  const vector& n,
218  const pointField& meshPoints,
221  ) const;
222 
223  //- Fast intersection with a ray.
224  // Does face-center decomposition and returns triangle intersection
225  // point closest to p. See triangle::intersection for details.
227  (
228  const point& p,
229  const vector& q,
230  const point& ctr,
231  const pointField& meshPoints,
232  const intersection::algorithm alg,
233  const scalar tol = 0.0
234  ) const;
235 
236  //- Return nearest point to face
238  (
239  const point& p,
240  const pointField& meshPoints
241  ) const;
242 
243  //- Return contact sphere diameter
244  scalar contactSphereDiameter
245  (
246  const point& p,
247  const vector& n,
248  const pointField& meshPoints
249  ) const;
250 
251  //- Return area in contact, given the displacement in vertices
252  scalar areaInContact
253  (
254  const pointField& points,
255  const scalarField& v
256  ) const;
257 
258  //- Return number of edges
259  inline label nEdges() const;
260 
261  //- Return edges in face point ordering, i.e. edges()[0] is edge
262  // between [0] and [1]
263  edgeList edges() const;
264 
265  //- Return n-th face edge
266  inline edge faceEdge(const label n) const;
267 
268  //- Return the edge direction on the face
269  // - 0: edge not found on the face
270  // - +1: forward (counter-clockwise) on the face
271  // - -1: reverse (clockwise) on the face
272  int edgeDirection(const edge&) const;
273 
274  // Face splitting utilities
275 
276  //- Number of triangles after splitting
277  inline label nTriangles() const;
278 
279  //- Number of triangles after splitting
280  label nTriangles(const pointField& points) const;
281 
282  //- Split into triangles using existing points.
283  // Result in triFaces[triI..triI+nTri].
284  // Splits intelligently to maximize triangle quality.
285  // Returns number of faces created.
286  label triangles
287  (
288  const pointField& points,
289  label& triI,
290  faceList& triFaces
291  ) const;
292 
293  //- Split into triangles using existing points.
294  // Append to DynamicList.
295  // Returns number of faces created.
296  template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
297  label triangles
298  (
299  const pointField& points,
301  ) const;
302 
303  //- Number of triangles and quads after splitting
304  // Returns the sum of both
305  label nTrianglesQuads
306  (
307  const pointField& points,
308  label& nTris,
309  label& nQuads
310  ) const;
311 
312  //- Split into triangles and quads.
313  // Results in triFaces (starting at triI) and quadFaces
314  // (starting at quadI).
315  // Returns number of new faces created.
316  label trianglesQuads
317  (
318  const pointField& points,
319  label& triI,
320  label& quadI,
321  faceList& triFaces,
322  faceList& quadFaces
323  ) const;
324 
325  //- compare faces
326  // 0: different
327  // +1: identical
328  // -1: same face, but different orientation
329  static int compare(const face&, const face&);
330 
331 
332  // Friend Operators
333 
334  friend bool operator==(const face& a, const face& b);
335  friend bool operator!=(const face& a, const face& b);
336 
337 
338  // Istream Operator
339 
340  friend Istream& operator>>(Istream&, face&);
341 };
342 
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 } // End namespace Foam
347 
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349 
350 #include "faceI.H"
351 
352 #ifdef NoRepository
353 # include "faceTemplates.C"
354 #endif
355 
356 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 
358 #endif
359 
360 // ************************ vim: set sw=4 sts=4 et: ************************ //