triFaceI.H 6.97 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    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 2 of the License, or (at your
    option) any later version.

    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
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

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

#include "IOstreams.H"
#include "face.H"
#include "triPointRef.H"

31
32
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //

33
inline int Foam::triFace::compare(const triFace& a, const triFace& b)
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{
    if
    (
        (a[0] == b[0] && a[1] == b[1] && a[2] == b[2])
     || (a[0] == b[1] && a[1] == b[2] && a[2] == b[0])
     || (a[0] == b[2] && a[1] == b[0] && a[2] == b[1])
    )
    {
        // identical
        return 1;
    }
    else if
    (
        (a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
     || (a[0] == b[1] && a[1] == b[0] && a[2] == b[2])
     || (a[0] == b[0] && a[1] == b[2] && a[2] == b[1])
    )
    {
        // same face, but reversed orientation
        return -1;
    }
    else
    {
        return 0;
    }
}

61

62
63
// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

64
inline Foam::triFace::triFace()
65
66
67
{}


68
inline Foam::triFace::triFace
69
70
71
72
73
74
75
76
77
78
79
(
    const label a,
    const label b,
    const label c
)
{
    operator[](0) = a;
    operator[](1) = b;
    operator[](2) = c;
}

80

81
inline Foam::triFace::triFace(const UList<label>& lst)
82
:
83
    FixedList<label, 3>(lst)
84
85
{}

86

87
inline Foam::triFace::triFace(Istream& is)
88
89
90
91
92
93
94
:
    FixedList<label, 3>(is)
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

95
96
97
98
inline Foam::label Foam::triFace::collapse()
{
    // we cannot resize a FixedList, so mark duplicates with '-1'
    // (the lower vertex is retained)
99
    // catch any '-1' (eg, if called twice)
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

    label n = 3;
    if (operator[](0) == operator[](1) || operator[](1) == -1)
    {
        operator[](1) = -1;
        n--;
    }
    else if (operator[](1) == operator[](2) || operator[](2) == -1)
    {
        operator[](2) = -1;
        n--;
    }
    if (operator[](0) == operator[](2))
    {
        operator[](2) = -1;
        n--;
    }

    return n;
}


122
inline Foam::pointField Foam::triFace::points(const pointField& points) const
123
124
125
126
127
128
129
130
131
132
133
{
    pointField p(3);

    p[0] = points[operator[](0)];
    p[1] = points[operator[](1)];
    p[2] = points[operator[](2)];

    return p;
}


134
inline Foam::face Foam::triFace::triFaceFace() const
135
136
137
138
139
140
141
142
143
144
145
{
    face f(3);

    f[0] = operator[](0);
    f[1] = operator[](1);
    f[2] = operator[](2);

    return f;
}


146
inline Foam::label Foam::triFace::nEdges() const
147
148
149
150
151
{
    return 3;
}


152
inline Foam::edgeList Foam::triFace::edges() const
153
154
155
156
{
    edgeList e(3);

    e[0].start() = operator[](0);
157
    e[0].end()   = operator[](1);
158
159

    e[1].start() = operator[](1);
160
    e[1].end()   = operator[](2);
161
162

    e[2].start() = operator[](2);
163
    e[2].end()   = operator[](0);
164
165
166
167
168

    return e;
}


169
170
171
172
// return
//  - +1: forward (counter-clockwise) on the face
//  - -1: reverse (clockwise) on the face
//  -  0: edge not found on the face
173
inline int Foam::triFace::edgeDirection(const edge& e) const
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
{
    if
    (
        (operator[](0) == e.start() && operator[](1) == e.end())
     || (operator[](1) == e.start() && operator[](2) == e.end())
     || (operator[](2) == e.start() && operator[](0) == e.end())
    )
    {
        return 1;
    }
    else if
    (
        (operator[](0) == e.end() && operator[](1) == e.start())
     || (operator[](1) == e.end() && operator[](2) == e.start())
     || (operator[](2) == e.end() && operator[](0) == e.start())
    )
    {
        return -1;
    }
    else
    {
        return 0;
    }
}


200
inline Foam::point Foam::triFace::centre(const pointField& points) const
201
202
203
204
205
206
207
208
209
210
{
    return (1.0/3.0)*
    (
        points[operator[](0)]
      + points[operator[](1)]
      + points[operator[](2)]
    );
}


211
inline Foam::scalar Foam::triFace::mag(const pointField& points) const
212
213
214
215
{
    return ::Foam::mag(normal(points));
}

216
// could also delegate to triPointRef(...).normal()
217
inline Foam::vector Foam::triFace::normal(const pointField& points) const
218
219
220
221
222
223
224
225
226
{
    return 0.5*
    (
        (points[operator[](1)] - points[operator[](0)])
       ^(points[operator[](2)] - points[operator[](0)])
    );
}


227
228
229
230
231
232
233
inline Foam::triFace Foam::triFace::reverseFace() const
{
    // The starting points of the original and reverse face are identical.
    return triFace(operator[](0), operator[](2), operator[](1));
}


234
inline Foam::scalar Foam::triFace::sweptVol
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
(
    const pointField& opts,
    const pointField& npts
) const
{
    return (1.0/6.0)*
    (
        (
            (npts[operator[](0)] - opts[operator[](0)])
          & (
                (opts[operator[](1)] - opts[operator[](0)])
              ^ (opts[operator[](2)] - opts[operator[](0)])
            )
        )
      + (
            (npts[operator[](1)] - opts[operator[](1)])
          & (
                (opts[operator[](2)] - opts[operator[](1)])
              ^ (npts[operator[](0)] - opts[operator[](1)])
            )
        )
      + (
            (opts[operator[](2)] - npts[operator[](2)])
          & (
                (npts[operator[](1)] - npts[operator[](2)])
              ^ (npts[operator[](0)] - npts[operator[](2)])
            )
        )
    );
}


267
inline Foam::pointHit Foam::triFace::ray
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
(
    const point& p,
    const vector& q,
    const pointField& points,
    const intersection::algorithm alg,
    const intersection::direction dir
) const
{
    return triPointRef
    (
        points[operator[](0)],
        points[operator[](1)],
        points[operator[](2)]
    ).ray(p, q, alg, dir);
}


285
inline Foam::triPointRef Foam::triFace::tri(const pointField& points) const
286
287
288
289
290
291
292
293
294
295
296
297
{
    return triPointRef
    (
        points[operator[](0)],
        points[operator[](1)],
        points[operator[](2)]
    );
}


// * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //

298
inline bool Foam::operator==(const triFace& a, const triFace& b)
299
{
300
    return triFace::compare(a,b) != 0;
301
302
303
}


304
inline bool Foam::operator!=(const triFace& a, const triFace& b)
305
{
306
    return triFace::compare(a,b) == 0;
307
308
309
310
}


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