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 triangular face using a FixedList of labels corresponding to mesh
32 Foam::face, Foam::triangle
38 \*---------------------------------------------------------------------------*/
43 #include "FixedList.H"
46 #include "intersection.H"
47 #include "pointField.H"
48 #include "triPointRef.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 // Forward declaration of friend functions and operators
60 inline bool operator==(const triFace&, const triFace&);
61 inline bool operator!=(const triFace&, const triFace&);
64 /*---------------------------------------------------------------------------*\
65 Class triFace Declaration
66 \*---------------------------------------------------------------------------*/
70 public FixedList<label, 3>
80 //- Construct from three point labels
88 //- Construct from a list of labels
89 explicit inline triFace(const labelUList&);
91 //- Construct from Istream
92 inline triFace(Istream&);
97 //- Collapse face by removing duplicate point labels
98 // return the collapsed size, set collapsed point labels to -1
99 inline label collapse();
101 //- Flip the face in-place.
102 // The starting points of the original and flipped face are identical.
105 //- Return the points corresponding to this face
106 inline pointField points(const pointField&) const;
108 //- Return triangle as a face
109 inline face triFaceFace() const;
111 //- Return the triangle
112 inline triPointRef tri(const pointField&) const;
114 //- Return centre (centroid)
115 inline point centre(const pointField&) const;
117 //- Calculate average value at centroid of face
119 Type average(const pointField&, const Field<Type>&) const;
121 //- Magnitude of face area
122 inline scalar mag(const pointField&) const;
124 //- Vector normal; magnitude is equal to area of face
125 inline vector normal(const pointField&) const;
127 //- Number of triangles after splitting
128 inline label nTriangles() const;
130 //- Return face with reverse direction
131 // The starting points of the original and reverse face are identical.
132 inline triFace reverseFace() const;
134 //- Return swept-volume
135 inline scalar sweptVol
137 const pointField& oldPoints,
138 const pointField& newPoints
141 //- Return the inertia tensor, with optional reference
142 // point and density specification
143 inline tensor inertia
146 const point& refPt = vector::zero,
150 //- Return point intersection with a ray starting at p,
156 const pointField& points,
157 const intersection::algorithm = intersection::FULL_RAY,
158 const intersection::direction dir = intersection::VECTOR
161 //- Fast intersection with a ray.
162 inline pointHit intersection
166 const pointField& points,
167 const intersection::algorithm alg,
168 const scalar tol = 0.0
171 //- Return nearest point to face
172 inline pointHit nearestPoint
175 const pointField& points
179 //- Return nearest point to face and classify it:
180 // + near point (nearType=POINT, nearLabel=0, 1, 2)
181 // + near edge (nearType=EDGE, nearLabel=0, 1, 2)
182 // Note: edges are counted from starting vertex so
183 // e.g. edge n is from f[n] to f[0], where the face has n + 1
185 inline pointHit nearestPointClassify
188 const pointField& points,
193 //- Return number of edges
194 inline label nEdges() const;
196 //- Return edges in face point ordering,
197 // i.e. edges()[0] is edge between [0] and [1]
198 inline edgeList edges() const;
200 //- Return n-th face edge
201 inline edge faceEdge(const label n) const;
203 //- Return the edge direction on the face
205 // - +1: forward (counter-clockwise) on the face
206 // - -1: reverse (clockwise) on the face
207 // - 0: edge not found on the face
208 inline int edgeDirection(const edge&) const;
214 // - -1: same face, but different orientation
215 static inline int compare(const triFace&, const triFace&);
219 inline friend bool operator==(const triFace&, const triFace&);
220 inline friend bool operator!=(const triFace&, const triFace&);
224 //- Hash specialization for hashing triFace - a commutative hash value.
225 // Hash incrementally.
227 inline unsigned Hash<triFace>::operator()(const triFace& t, unsigned seed) const
229 // Fortunately we don't need this very often
230 const uLabel t0(t[0]);
231 const uLabel t1(t[1]);
232 const uLabel t2(t[2]);
234 const uLabel val = (t0*t1*t2 + t0+t1+t2);
236 return Hash<uLabel>()(val, seed);
240 //- Hash specialization for hashing triFace - a commutative hash value.
242 inline unsigned Hash<triFace>::operator()(const triFace& t) const
244 return Hash<triFace>::operator()(t, 0);
249 inline bool contiguous<triFace>() {return true;}
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 } // End namespace Foam
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 #include "triFaceI.H"
261 # include "triFaceTemplates.C"
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 // ************************************************************************* //