initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / meshes / meshShapes / triFace / triFaceI.H
blob2bced4ccf2d42180714357d2ff2782f568590d44
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "IOstreams.H"
28 #include "face.H"
29 #include "triPointRef.H"
31 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
33 inline int Foam::triFace::compare(const triFace& a, const triFace& b)
35     if
36     (
37         (a[0] == b[0] && a[1] == b[1] && a[2] == b[2])
38      || (a[0] == b[1] && a[1] == b[2] && a[2] == b[0])
39      || (a[0] == b[2] && a[1] == b[0] && a[2] == b[1])
40     )
41     {
42         // identical
43         return 1;
44     }
45     else if
46     (
47         (a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
48      || (a[0] == b[1] && a[1] == b[0] && a[2] == b[2])
49      || (a[0] == b[0] && a[1] == b[2] && a[2] == b[1])
50     )
51     {
52         // same face, but reversed orientation
53         return -1;
54     }
55     else
56     {
57         return 0;
58     }
62 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
64 inline Foam::triFace::triFace()
68 inline Foam::triFace::triFace
70     const label a,
71     const label b,
72     const label c
75     operator[](0) = a;
76     operator[](1) = b;
77     operator[](2) = c;
81 inline Foam::triFace::triFace(const UList<label>& l)
83     FixedList<label, 3>(l)
87 inline Foam::triFace::triFace(Istream& is)
89     FixedList<label, 3>(is)
93 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
95 inline Foam::label Foam::triFace::collapse()
97     // we cannot resize a FixedList, so mark duplicates with '-1'
98     // (the lower vertex is retained)
99     // catch any '-1' - ie, if called twice
101     label n = 3;
102     if (operator[](0) == operator[](1) || operator[](1) == -1)
103     {
104         operator[](1) = -1;
105         n--;
106     }
107     else if (operator[](1) == operator[](2) || operator[](2) == -1)
108     {
109         operator[](2) = -1;
110         n--;
111     }
112     if (operator[](0) == operator[](2))
113     {
114         operator[](2) = -1;
115         n--;
116     }
118     return n;
122 inline Foam::pointField Foam::triFace::points(const pointField& points) const
124     pointField p(3);
126     p[0] = points[operator[](0)];
127     p[1] = points[operator[](1)];
128     p[2] = points[operator[](2)];
130     return p;
134 inline Foam::face Foam::triFace::triFaceFace() const
136     face f(3);
138     f[0] = operator[](0);
139     f[1] = operator[](1);
140     f[2] = operator[](2);
142     return f;
146 inline Foam::label Foam::triFace::nEdges() const
148     return 3;
152 inline Foam::edgeList Foam::triFace::edges() const
154     edgeList e(3);
156     e[0].start() = operator[](0);
157     e[0].end() = operator[](1);
159     e[1].start() = operator[](1);
160     e[1].end() = operator[](2);
162     e[2].start() = operator[](2);
163     e[2].end() = operator[](0);
165     return e;
169 // return
170 //  - +1: forward (counter-clockwise) on the face
171 //  - -1: reverse (clockwise) on the face
172 //  -  0: edge not found on the face
173 inline int Foam::triFace::edgeDirection(const edge& e) const
175     if
176     (
177         (operator[](0) == e.start() && operator[](1) == e.end())
178      || (operator[](1) == e.start() && operator[](2) == e.end())
179      || (operator[](2) == e.start() && operator[](0) == e.end())
180     )
181     {
182         return 1;
183     }
184     else if
185     (
186         (operator[](0) == e.end() && operator[](1) == e.start())
187      || (operator[](1) == e.end() && operator[](2) == e.start())
188      || (operator[](2) == e.end() && operator[](0) == e.start())
189     )
190     {
191         return -1;
192     }
193     else
194     {
195         return 0;
196     }
200 inline Foam::point Foam::triFace::centre(const pointField& points) const
202     return (1.0/3.0)*
203     (
204         points[operator[](0)]
205       + points[operator[](1)]
206       + points[operator[](2)]
207     );
211 inline Foam::scalar Foam::triFace::mag(const pointField& points) const
213     return ::Foam::mag(normal(points));
217 inline Foam::vector Foam::triFace::normal(const pointField& points) const
219     return 0.5*
220     (
221         (points[operator[](1)] - points[operator[](0)])
222        ^(points[operator[](2)] - points[operator[](0)])
223     );
227 inline Foam::scalar Foam::triFace::sweptVol
229     const pointField& opts,
230     const pointField& npts
231 ) const
233     return (1.0/6.0)*
234     (
235         (
236             (npts[operator[](0)] - opts[operator[](0)])
237           & (
238                 (opts[operator[](1)] - opts[operator[](0)])
239               ^ (opts[operator[](2)] - opts[operator[](0)])
240             )
241         )
242       + (
243             (npts[operator[](1)] - opts[operator[](1)])
244           & (
245                 (opts[operator[](2)] - opts[operator[](1)])
246               ^ (npts[operator[](0)] - opts[operator[](1)])
247             )
248         )
249       + (
250             (opts[operator[](2)] - npts[operator[](2)])
251           & (
252                 (npts[operator[](1)] - npts[operator[](2)])
253               ^ (npts[operator[](0)] - npts[operator[](2)])
254             )
255         )
256     );
260 inline Foam::pointHit Foam::triFace::ray
262     const point& p,
263     const vector& q,
264     const pointField& points,
265     const intersection::algorithm alg,
266     const intersection::direction dir
267 ) const
269     return triPointRef
270     (
271         points[operator[](0)],
272         points[operator[](1)],
273         points[operator[](2)]
274     ).ray(p, q, alg, dir);
278 inline Foam::triPointRef Foam::triFace::tri(const pointField& points) const
280     return triPointRef
281     (
282         points[operator[](0)],
283         points[operator[](1)],
284         points[operator[](2)]
285     );
289 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
291 inline bool Foam::operator==(const triFace& a, const triFace& b)
293     return triFace::compare(a,b) != 0;
297 inline bool Foam::operator!=(const triFace& a, const triFace& b)
299     return triFace::compare(a,b) == 0;
303 // ************************************************************************* //