1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 A face is a list of labels corresponding to mesh vertices.
41 \*---------------------------------------------------------------------------*/
46 #include "pointField.H"
47 #include "labelList.H"
49 #include "vectorField.H"
50 #include "faceListFwd.H"
51 #include "intersection.H"
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 // Forward declaration of friend functions and operators
64 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
67 inline bool operator==(const face& a, const face& b);
68 inline bool operator!=(const face& a, const face& b);
69 inline Istream& operator>>(Istream&, face&);
71 /*---------------------------------------------------------------------------*\
72 Class face Declaration
73 \*---------------------------------------------------------------------------*/
79 // Private Member Functions
81 //- Edge to the right of face vertex i
82 inline label right(const label i) const;
84 //- Edge to the left of face vertex i
85 inline label left(const label i) const;
87 //- Construct list of edge vectors for face
88 tmp<vectorField> calcEdges
90 const pointField& points
93 //- Cos between neighbouring edges
96 const vectorField& edges,
100 //- Find index of largest internal angle on face
101 label mostConcaveAngle
103 const pointField& points,
104 const vectorField& edges,
108 //- Enumeration listing the modes for split()
111 COUNTTRIANGLE, // count if split into triangles
112 COUNTQUAD, // count if split into triangles&quads
113 SPLITTRIANGLE, // split into triangles
114 SPLITQUAD // split into triangles&quads
117 //- Split face into triangles or triangles&quads.
118 // Stores results quadFaces[quadI], triFaces[triI]
119 // Returns number of new faces created
122 const splitMode mode,
123 const pointField& points,
133 //- Return types for classify
137 POINT, // Close to point
138 EDGE // Close to edge
141 // Static data members
143 static const char* const typeName;
151 //- Construct given size
152 explicit inline face(label);
154 //- Construct from list of labels
155 explicit inline face(const labelUList&);
157 //- Construct from list of labels
158 explicit inline face(const labelList&);
160 //- Construct by transferring the parameter contents
161 explicit inline face(const Xfer<labelList>&);
163 //- Copy construct from triFace
164 face(const triFace&);
166 //- Construct from Istream
167 inline face(Istream&);
172 //- Collapse face by removing duplicate point labels
173 // return the collapsed size
176 //- Flip the face in-place.
177 // The starting points of the original and flipped face are identical.
180 //- Return the points corresponding to this face
181 inline pointField points(const pointField&) const;
183 //- Centre point of face
184 point centre(const pointField&) const;
186 //- Calculate average value at centroid of face
188 Type average(const pointField&, const Field<Type>&) const;
190 //- Magnitude of face area
191 inline scalar mag(const pointField&) const;
193 //- Vector normal; magnitude is equal to area of face
194 vector normal(const pointField&) const;
196 //- Return face with reverse direction
197 // The starting points of the original and reverse face are identical.
198 face reverseFace() const;
200 //- Navigation through face vertices
202 //- Which vertex on face (face index given a global index)
203 // returns -1 if not found
204 label which(const label globalIndex) const;
206 //- Next vertex on face
207 inline label nextLabel(const label i) const;
209 //- Previous vertex on face
210 inline label prevLabel(const label i) const;
213 //- Return the volume swept out by the face when its points move
216 const pointField& oldPoints,
217 const pointField& newPoints
220 //- Return the inertia tensor, with optional reference
221 // point and density specification
225 const point& refPt = vector::zero,
229 //- Return potential intersection with face with a ray starting
230 // at p, direction n (does not need to be normalized)
231 // Does face-centre decomposition and returns triangle intersection
232 // point closest to p. Face-centre is calculated from point average.
233 // For a hit, the distance is signed. Positive number
234 // represents the point in front of triangle
235 // In case of miss the point is the nearest point on the face
236 // and the distance is the distance between the intersection point
237 // and the original point.
238 // The half-ray or full-ray intersection and the contact
239 // sphere adjustment of the projection vector is set by the
240 // intersection parameters
246 const intersection::algorithm alg = intersection::FULL_RAY,
247 const intersection::direction dir = intersection::VECTOR
250 //- Fast intersection with a ray.
251 // Does face-centre decomposition and returns triangle intersection
252 // point closest to p. See triangle::intersection for details.
253 pointHit intersection
259 const intersection::algorithm alg,
260 const scalar tol = 0.0
263 //- Return nearest point to face
264 pointHit nearestPoint
270 //- Return nearest point to face and classify it:
271 // + near point (nearType=POINT, nearLabel=0, 1, 2)
272 // + near edge (nearType=EDGE, nearLabel=0, 1, 2)
273 // Note: edges are counted from starting vertex so
274 // e.g. edge n is from f[n] to f[0], where the face has n + 1
276 pointHit nearestPointClassify
284 //- Return contact sphere diameter
285 scalar contactSphereDiameter
292 //- Return area in contact, given the displacement in vertices
299 //- Return number of edges
300 inline label nEdges() const;
302 //- Return edges in face point ordering,
303 // i.e. edges()[0] is edge between [0] and [1]
304 edgeList edges() const;
306 //- Return n-th face edge
307 inline edge faceEdge(const label n) const;
309 //- Return the edge direction on the face
311 // - 0: edge not found on the face
312 // - +1: forward (counter-clockwise) on the face
313 // - -1: reverse (clockwise) on the face
314 int edgeDirection(const edge&) const;
316 // Face splitting utilities
318 //- Number of triangles after splitting
319 inline label nTriangles() const;
321 //- Number of triangles after splitting
322 label nTriangles(const pointField& points) const;
324 //- Split into triangles using existing points.
325 // Result in triFaces[triI..triI+nTri].
326 // Splits intelligently to maximize triangle quality.
327 // Returns number of faces created.
330 const pointField& points,
335 //- Split into triangles using existing points.
336 // Append to DynamicList.
337 // Returns number of faces created.
338 template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
341 const pointField& points,
342 DynamicList<face, SizeInc, SizeMult, SizeDiv>& triFaces
345 //- Number of triangles and quads after splitting
346 // Returns the sum of both
347 label nTrianglesQuads
349 const pointField& points,
354 //- Split into triangles and quads.
355 // Results in triFaces (starting at triI) and quadFaces
356 // (starting at quadI).
357 // Returns number of new faces created.
360 const pointField& points,
370 // -1: same face, but different orientation
371 static int compare(const face&, const face&);
376 friend bool operator==(const face& a, const face& b);
377 friend bool operator!=(const face& a, const face& b);
382 friend Istream& operator>>(Istream&, face&);
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 } // End namespace Foam
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395 # include "faceTemplates.C"
398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
402 // ************************************************************************* //