FreeFOAM The Cross-Platform CFD Toolkit
triFaceI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include <OpenFOAM/IOstreams.H>
27 #include <OpenFOAM/face.H>
28 #include <OpenFOAM/triPointRef.H>
29 
30 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
31 
32 inline int Foam::triFace::compare(const triFace& a, const triFace& b)
33 {
34  if
35  (
36  (a[0] == b[0] && a[1] == b[1] && a[2] == b[2])
37  || (a[0] == b[1] && a[1] == b[2] && a[2] == b[0])
38  || (a[0] == b[2] && a[1] == b[0] && a[2] == b[1])
39  )
40  {
41  // identical
42  return 1;
43  }
44  else if
45  (
46  (a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
47  || (a[0] == b[1] && a[1] == b[0] && a[2] == b[2])
48  || (a[0] == b[0] && a[1] == b[2] && a[2] == b[1])
49  )
50  {
51  // same face, but reversed orientation
52  return -1;
53  }
54  else
55  {
56  return 0;
57  }
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
64 {}
65 
66 
68 (
69  const label a,
70  const label b,
71  const label c
72 )
73 {
74  operator[](0) = a;
75  operator[](1) = b;
76  operator[](2) = c;
77 }
78 
79 
81 :
82  FixedList<label, 3>(lst)
83 {}
84 
85 
87 :
88  FixedList<label, 3>(is)
89 {}
90 
91 
92 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 
94 inline Foam::label Foam::triFace::collapse()
95 {
96  // we cannot resize a FixedList, so mark duplicates with '-1'
97  // (the lower vertex is retained)
98  // catch any '-1' (eg, if called twice)
99 
100  label n = 3;
101  if (operator[](0) == operator[](1) || operator[](1) == -1)
102  {
103  operator[](1) = -1;
104  n--;
105  }
106  else if (operator[](1) == operator[](2) || operator[](2) == -1)
107  {
108  operator[](2) = -1;
109  n--;
110  }
111  if (operator[](0) == operator[](2))
112  {
113  operator[](2) = -1;
114  n--;
115  }
116 
117  return n;
118 }
119 
120 
122 {
123  pointField p(3);
124 
125  p[0] = points[operator[](0)];
126  p[1] = points[operator[](1)];
127  p[2] = points[operator[](2)];
128 
129  return p;
130 }
131 
132 
134 {
135  Foam::face f(3);
136 
137  f[0] = operator[](0);
138  f[1] = operator[](1);
139  f[2] = operator[](2);
140 
141  return f;
142 }
143 
144 
145 inline Foam::label Foam::triFace::nEdges() const
146 {
147  return 3;
148 }
149 
150 
152 {
153  edgeList e(3);
154 
155  e[0].start() = operator[](0);
156  e[0].end() = operator[](1);
157 
158  e[1].start() = operator[](1);
159  e[1].end() = operator[](2);
160 
161  e[2].start() = operator[](2);
162  e[2].end() = operator[](0);
163 
164  return e;
165 }
166 
167 
168 // return
169 // - +1: forward (counter-clockwise) on the face
170 // - -1: reverse (clockwise) on the face
171 // - 0: edge not found on the face
172 inline int Foam::triFace::edgeDirection(const edge& e) const
173 {
174  if
175  (
176  (operator[](0) == e.start() && operator[](1) == e.end())
177  || (operator[](1) == e.start() && operator[](2) == e.end())
178  || (operator[](2) == e.start() && operator[](0) == e.end())
179  )
180  {
181  return 1;
182  }
183  else if
184  (
185  (operator[](0) == e.end() && operator[](1) == e.start())
186  || (operator[](1) == e.end() && operator[](2) == e.start())
187  || (operator[](2) == e.end() && operator[](0) == e.start())
188  )
189  {
190  return -1;
191  }
192  else
193  {
194  return 0;
195  }
196 }
197 
198 
200 {
201  return (1.0/3.0)*
202  (
203  points[operator[](0)]
204  + points[operator[](1)]
205  + points[operator[](2)]
206  );
207 }
208 
209 
210 inline Foam::scalar Foam::triFace::mag(const pointField& points) const
211 {
212  return ::Foam::mag(normal(points));
213 }
214 
215 // could also delegate to triPointRef(...).normal()
217 {
218  return 0.5*
219  (
220  (points[operator[](1)] - points[operator[](0)])
221  ^(points[operator[](2)] - points[operator[](0)])
222  );
223 }
224 
225 
226 inline Foam::label Foam::triFace::nTriangles() const
227 {
228  return 1;
229 }
230 
231 
233 {
234  // The starting points of the original and reverse face are identical.
235  return triFace(operator[](0), operator[](2), operator[](1));
236 }
237 
238 
239 inline Foam::scalar Foam::triFace::sweptVol
240 (
241  const pointField& opts,
242  const pointField& npts
243 ) const
244 {
245  return (1.0/6.0)*
246  (
247  (
248  (npts[operator[](0)] - opts[operator[](0)])
249  & (
250  (opts[operator[](1)] - opts[operator[](0)])
251  ^ (opts[operator[](2)] - opts[operator[](0)])
252  )
253  )
254  + (
255  (npts[operator[](1)] - opts[operator[](1)])
256  & (
257  (opts[operator[](2)] - opts[operator[](1)])
258  ^ (npts[operator[](0)] - opts[operator[](1)])
259  )
260  )
261  + (
262  (opts[operator[](2)] - npts[operator[](2)])
263  & (
264  (npts[operator[](1)] - npts[operator[](2)])
265  ^ (npts[operator[](0)] - npts[operator[](2)])
266  )
267  )
268  );
269 }
270 
271 
273 (
274  const point& p,
275  const vector& q,
276  const pointField& points,
277  const intersection::algorithm alg,
278  const intersection::direction dir
279 ) const
280 {
281  return triPointRef
282  (
283  points[operator[](0)],
284  points[operator[](1)],
285  points[operator[](2)]
286  ).ray(p, q, alg, dir);
287 }
288 
289 
291 {
292  return triPointRef
293  (
294  points[operator[](0)],
295  points[operator[](1)],
296  points[operator[](2)]
297  );
298 }
299 
300 
301 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
302 
303 inline bool Foam::operator==(const triFace& a, const triFace& b)
304 {
305  return triFace::compare(a,b) != 0;
306 }
307 
308 
309 inline bool Foam::operator!=(const triFace& a, const triFace& b)
310 {
311  return triFace::compare(a,b) == 0;
312 }
313 
314 
315 // ************************ vim: set sw=4 sts=4 et: ************************ //