triFace.H 8.25 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
6
7
8
9
10
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
15
16
17
18
19
20
21

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    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
25
26
27

Class
    Foam::triFace

Description
28
29
30
31
32
    A triangular face using a FixedList of labels corresponding to mesh
    vertices.

SeeAlso
    Foam::face, Foam::triangle
33
34
35

SourceFiles
    triFaceI.H
36
    triFaceTemplates.C
37
38
39
40
41
42
43
44
45
46
47
48

\*---------------------------------------------------------------------------*/

#ifndef triFace_H
#define triFace_H

#include "FixedList.H"
#include "edgeList.H"
#include "pointHit.H"
#include "intersection.H"
#include "pointField.H"
#include "triPointRef.H"
mattijs's avatar
mattijs committed
49
#include "ListListOps.H"
50
51
52
53
54
55
56
57

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

// Forward declaration of friend functions and operators

58
class face;
59
class triFace;
60

61
62
63
64
65
inline bool operator==(const triFace&, const triFace&);
inline bool operator!=(const triFace&, const triFace&);


/*---------------------------------------------------------------------------*\
66
                          Class triFace Declaration
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
\*---------------------------------------------------------------------------*/

class triFace
:
    public FixedList<label, 3>
{

public:

    // Constructors

        //- Construct null
        inline triFace();

        //- Construct from three point labels
        inline triFace
        (
            const label a,
            const label b,
            const label c
        );

89
90
        //- Construct from a list of labels
        explicit inline triFace(const labelUList&);
91

92
93
94
95
96
97
        //- Construct from Istream
        inline triFace(Istream&);


    // Member Functions

98
99
100
101
        //- Collapse face by removing duplicate point labels
        //  return the collapsed size, set collapsed point labels to -1
        inline label collapse();

102
103
104
105
        //- Flip the face in-place.
        //  The starting points of the original and flipped face are identical.
        inline void flip();

106
        //- Return the points corresponding to this face
107
        inline pointField points(const pointField&) const;
108

109
110
        //- Return triangle as a face
        inline face triFaceFace() const;
111

112
113
        //- Return the triangle
        inline triPointRef tri(const pointField&) const;
114

115
116
        //- Return centre (centroid)
        inline point centre(const pointField&) const;
117

118
119
120
        //- Calculate average value at centroid of face
        template<class Type>
        Type average(const pointField&, const Field<Type>&) const;
121

122
        //- Magnitude of face area
123
        inline scalar mag(const pointField&) const;
124

125
        //- Vector normal; magnitude is equal to area of face
126
        inline vector normal(const pointField&) const;
127

128
129
        //- Number of triangles after splitting
        inline label nTriangles() const;
130

131
        //- Return face with reverse direction
132
        //  The starting points of the original and reverse face are identical.
133
        inline triFace reverseFace() const;
134

135
136
137
138
139
140
        //- Return swept-volume
        inline scalar sweptVol
        (
            const pointField& oldPoints,
            const pointField& newPoints
        ) const;
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
        //- Return the inertia tensor, with optional reference
        //  point and density specification
        inline tensor inertia
        (
            const pointField&,
            const point& refPt = vector::zero,
            scalar density = 1.0
        ) const;

        //- Return point intersection with a ray starting at p,
        //  with direction q.
        inline pointHit ray
        (
            const point& p,
            const vector& q,
            const pointField& points,
            const intersection::algorithm = intersection::FULL_RAY,
            const intersection::direction dir = intersection::VECTOR
        ) const;

        //- Fast intersection with a ray.
        inline pointHit intersection
        (
            const point& p,
            const vector& q,
            const pointField& points,
            const intersection::algorithm alg,
            const scalar tol = 0.0
        ) const;

172
173
174
175
176
177
178
179
180
181
        inline pointHit intersection
        (
            const point& p,
            const vector& q,
            const point& ctr,
            const pointField& points,
            const intersection::algorithm alg,
            const scalar tol = 0.0
        ) const;

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
        //- Return nearest point to face
        inline pointHit nearestPoint
        (
            const point& p,
            const pointField& points
        ) const;


        //- Return nearest point to face and classify it:
        //  + near point (nearType=POINT, nearLabel=0, 1, 2)
        //  + near edge (nearType=EDGE, nearLabel=0, 1, 2)
        //    Note: edges are counted from starting vertex so
        //    e.g. edge n is from f[n] to f[0], where the face has n + 1
        //    points
        inline pointHit nearestPointClassify
        (
            const point& p,
            const pointField& points,
            label& nearType,
            label& nearLabel
        ) const;
Mark Olesen's avatar
Mark Olesen committed
203

204
205
        //- Return number of edges
        inline label nEdges() const;
206

207
208
209
        //- Return edges in face point ordering,
        //  i.e. edges()[0] is edge between [0] and [1]
        inline edgeList edges() const;
210

211
212
        //- Return n-th face edge
        inline edge faceEdge(const label n) const;
213

214
        //- Return the edge direction on the face
215
        //  Returns:
216
217
218
219
        //  - +1: forward (counter-clockwise) on the face
        //  - -1: reverse (clockwise) on the face
        //  -  0: edge not found on the face
        inline int edgeDirection(const edge&) const;
220

221
        //- compare triFaces
222
        //  Returns:
223
224
225
226
        //  -  0: different
        //  - +1: identical
        //  - -1: same face, but different orientation
        static inline int compare(const triFace&, const triFace&);
227
228
229

    // Friend Operators

230
231
        inline friend bool operator==(const triFace&, const triFace&);
        inline friend bool operator!=(const triFace&, const triFace&);
232
233
234
};


235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
//- Hash specialization for hashing triFace - a commutative hash value.
//  Hash incrementally.
template<>
inline unsigned Hash<triFace>::operator()(const triFace& t, unsigned seed) const
{
    // Fortunately we don't need this very often
    const uLabel t0(t[0]);
    const uLabel t1(t[1]);
    const uLabel t2(t[2]);

    const uLabel val = (t0*t1*t2 + t0+t1+t2);

    return Hash<uLabel>()(val, seed);
}


//- Hash specialization for hashing triFace - a commutative hash value.
252
template<>
Mark Olesen's avatar
Mark Olesen committed
253
inline unsigned Hash<triFace>::operator()(const triFace& t) const
254
{
255
    return Hash<triFace>::operator()(t, 0);
256
257
}

258

mattijs's avatar
mattijs committed
259
260
261
template<>
inline bool contiguous<triFace>()  {return true;}

262

mattijs's avatar
mattijs committed
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//- Hash specialization to offset faces in ListListOps::combineOffset
template<>
class offsetOp<triFace>
{

public:

    inline triFace operator()
    (
        const triFace& x,
        const label offset
    ) const
    {
        triFace result(x);

        forAll(x, xI)
        {
            result[xI] = x[xI] + offset;
        }
        return result;
    }
};


287
288
289
290
291
292
293
294
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "triFaceI.H"

295
296
297
298
#ifdef NoRepository
#   include "triFaceTemplates.C"
#endif

299
300
301
302
303
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //