cutI.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "cut.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 //- Modify a uniform operation for reordering a tri (does nothing)
38 template<class Type>
39 inline const cut::uniformOp<Type>& triReorder
40 (
41  const cut::uniformOp<Type>& x,
42  const FixedList<label, 3>&
43 )
44 {
45  return x;
46 }
47 
48 
49 //- Modify a uniform operation for cutting a tri from a tri (does nothing)
50 template<class Type>
51 inline const cut::uniformOp<Type>& triCutTri
52 (
53  const cut::uniformOp<Type>& x,
54  const Pair<scalar>&
55 )
56 {
57  return x;
58 }
59 
60 
61 //- Modify a uniform operation for cutting a quad from a tri (does nothing)
62 template<class Type>
63 inline const cut::uniformOp<Type>& triCutQuad
64 (
65  const cut::uniformOp<Type>& x,
66  const Pair<scalar>&
67 )
68 {
69  return x;
70 }
71 
72 
73 //- Modify a uniform operation for reordering a tet (does nothing)
74 template<class Type>
75 inline const cut::uniformOp<Type>& tetReorder
76 (
77  const cut::uniformOp<Type>& x,
78  const FixedList<label, 4>&
79 )
80 {
81  return x;
82 }
83 
84 
85 //- Modify a uniform operation for cutting a tet from a tet (does nothing)
86 template<class Type>
87 inline const cut::uniformOp<Type>& tetCutTet
88 (
89  const cut::uniformOp<Type>& x,
91 )
92 {
93  return x;
94 }
95 
96 
97 //- Modify a uniform operation for cutting prism0 from a tet (does nothing)
98 template<class Type>
99 inline const cut::uniformOp<Type>& tetCutPrism0
100 (
101  const cut::uniformOp<Type>& x,
102  const FixedList<scalar, 3>&
103 )
104 {
105  return x;
106 }
107 
108 
109 //- Modify a uniform operation for cutting prism01 from a tet (does nothing)
110 template<class Type>
111 inline const cut::uniformOp<Type>& tetCutPrism01
112 (
113  const cut::uniformOp<Type>& x,
114  const FixedList<scalar, 4>&
115 )
116 {
117  return x;
118 }
119 
120 
121 //- Modify a uniform operation for cutting prism23 from a tet (does nothing)
122 template<class Type>
123 inline const cut::uniformOp<Type>& tetCutPrism23
124 (
125  const cut::uniformOp<Type>& x,
126  const FixedList<scalar, 4>&
127 )
128 {
129  return x;
130 }
131 
132 
133 //- Modify a fixed list for reordering a tri (does nothing)
134 template<class Type, unsigned N>
135 inline FixedList<Type, 3> triReorder
136 (
137  const FixedList<Type, N>& x,
138  const FixedList<label, 3>& indices
139 )
140 {
141  FixedList<Type, 3> result;
142  for (unsigned i = 0; i < 3; ++ i)
143  {
144  result[i] = x[indices[i]];
145  }
146  return result;
147 }
148 
149 
150 //- Modify a list for cutting a tri from a tri
151 template<class Type>
152 inline FixedList<Type, 3> triCutTri
153 (
154  const FixedList<Type, 3>& x,
155  const Pair<scalar>& f
156 )
157 {
158  FixedList<Type, 3> result;
159  result[0] = x[0];
160  for (label i = 0; i < 2; ++ i)
161  {
162  result[i+1] = x[0] + f[i]*(x[i+1] - x[0]);
163  }
164  return result;
165 }
166 
167 
168 //- Modify a list for cutting a quad from a tri
169 template<class Type>
170 inline FixedList<Type, 4> triCutQuad
171 (
172  const FixedList<Type, 3>& x,
173  const Pair<scalar>& f
174 )
175 {
176  FixedList<Type, 4> result;
177  for (label i = 0; i < 2; ++ i)
178  {
179  result[i] = x[i+1];
180  result[3-i] = x[0] + f[i]*(x[i+1] - x[0]);
181  }
182  return result;
183 }
184 
185 
186 //- Modify a fixed list for reordering a tet (does nothing)
187 template<class Type, unsigned N>
188 inline FixedList<Type, 4> tetReorder
189 (
190  const FixedList<Type, N>& x,
191  const FixedList<label, 4>& indices
192 )
193 {
194  FixedList<Type, 4> result;
195  for (unsigned i = 0; i < 4; ++ i)
196  {
197  result[i] = x[indices[i]];
198  }
199  return result;
200 }
201 
202 
203 //- Modify a list for cutting a tet from a tet
204 template<class Type>
205 inline FixedList<Type, 4> tetCutTet
206 (
207  const FixedList<Type, 4>& x,
208  const FixedList<scalar, 3>& f
209 )
210 {
211  FixedList<Type, 4> result;
212  result[0] = x[0];
213  for (label i = 0; i < 3; ++ i)
214  {
215  result[i+1] = x[0] + f[i]*(x[i+1] - x[0]);
216  }
217  return result;
218 }
219 
220 
221 //- Modify a list for cutting prism0 from a tet
222 template<class Type>
223 inline FixedList<Type, 6> tetCutPrism0
224 (
225  const FixedList<Type, 4>& x,
226  const FixedList<scalar, 3>& f
227 )
228 {
229  FixedList<Type, 6> result;
230  for (label i = 0; i < 3; ++ i)
231  {
232  result[i] = x[0] + f[i]*(x[i+1] - x[0]);
233  result[i+3] = x[i+1];
234  }
235  return result;
236 }
237 
238 
239 //- Modify a list for cutting prism01 from a tet
240 template<class Type>
241 inline FixedList<Type, 6> tetCutPrism01
242 (
243  const FixedList<Type, 4>& x,
244  const FixedList<scalar, 4>& f
245 )
246 {
247  FixedList<Type, 6> result;
248  for (label i = 0; i < 2; ++ i)
249  {
250  result[3*i] = x[i];
251  for (label j = 0; j < 2; ++ j)
252  {
253  result[3*i+j+1] = x[i] + f[2*i+j]*(x[j+2] - x[i]);
254  }
255  }
256 
257  return result;
258 }
259 
260 
261 //- Modify a list for cutting prism23 from a tet
262 template<class Type>
263 inline FixedList<Type, 6> tetCutPrism23
264 (
265  const FixedList<Type, 4>& x,
266  const FixedList<scalar, 4>& f
267 )
268 {
269  FixedList<Type, 6> result = tetCutPrism01(x, f);
270  result[0] = x[2];
271  result[3] = x[3];
272  Swap(result[2], result[4]);
273  return result;
274 }
275 
276 
277 //- Cut a tri from a tri and apply an operation to the result. The cut is made
278 // along the two edges connected to vertex 0, and the cut locations are given
279 // as factors along these edges. The result is the side connected to vertex 0.
280 template<class Op>
281 inline typename Op::result triCutTri
282 (
283  const Op& op,
284  const FixedList<point, 3>& p,
285  const Pair<scalar>& f
286 )
287 {
288  return Op(triCutTri(op, f))(triCutTri(p, f));
289 }
290 
291 
292 //- Apply an operation to a quad. Splits the quad into two tris.
293 template<class Op, class OpData>
294 inline typename Op::result quadOp
295 (
296  const OpData& opData,
297  const FixedList<point, 4>& p
298 )
299 {
300  static const FixedList<FixedList<label, 3>, 2> i =
301  {{0, 1, 2}, {0, 2, 3}};
302  return
303  Op(triReorder(opData, i[0]))(triReorder(p, i[0]))
304  + Op(triReorder(opData, i[1]))(triReorder(p, i[1]));
305 }
306 
307 
308 //- Cut a quad from a tri and apply an operation to the result. The cuts are
309 // the same as for triCutTri. The result is the side connected to vertices 1
310 // and 2.
311 template<class Op>
312 inline typename Op::result triCutQuad
313 (
314  const Op& op,
315  const FixedList<point, 3>& p,
316  const FixedList<scalar, 2>& f
317 )
318 {
319  return quadOp<Op>(triCutQuad(op, f), triCutQuad(p, f));
320 }
321 
322 
323 //- Cut a tet from a tet and apply an operation to the result. The cut is made
324 // along the three edges connected to vertex 0, and the cut locations are given
325 // as factors along these edges. The result is the side connected to vertex 0.
326 template<class Op>
327 inline typename Op::result tetCutTet
328 (
329  const Op& op,
330  const FixedList<point, 4>& p,
331  const FixedList<scalar, 3>& f
332 )
333 {
334  return Op(tetCutTet(op, f))(tetCutTet(p, f));
335 }
336 
337 
338 //- Apply an operation to a prism. Splits the prism into three tets.
339 template<class Op, class OpData>
340 inline typename Op::result prismOp
341 (
342  const OpData& opData,
343  const FixedList<point, 6>& p
344 )
345 {
346  static const FixedList<FixedList<label, 4>, 3> i =
347  {{0, 1, 2, 4}, {0, 2, 5, 4}, {0, 4, 5, 3}};
348  return
349  Op(tetReorder(opData, i[0]))(tetReorder(p, i[0]))
350  + Op(tetReorder(opData, i[1]))(tetReorder(p, i[1]))
351  + Op(tetReorder(opData, i[2]))(tetReorder(p, i[2]));
352 }
353 
354 
355 //- Cut a prism from a tet and apply an operation to the result. The cuts are
356 // the same as for tetCutTet. The result is the side connected to vertices 1,
357 // 2 and 3.
358 template<class Op>
359 inline typename Op::result tetCutPrism0
360 (
361  const Op& op,
362  const FixedList<point, 4>& p,
363  const FixedList<scalar, 3>& f
364 )
365 {
366  return prismOp<Op>(tetCutPrism0(op, f), tetCutPrism0(p, f));
367 }
368 
369 
370 //- Cut a prism from a tet and apply an operation to the result. The cut is made
371 // along four edges, not edges 01 or 23, and the cut locations are given as
372 // factors along these edges. The result is the side connected to edge 01.
373 template<class Op>
374 inline typename Op::result tetCutPrism01
375 (
376  const Op& op,
377  const FixedList<point, 4>& p,
378  const FixedList<scalar, 4>& f
379 )
380 {
381  return prismOp<Op>(tetCutPrism01(op, f), tetCutPrism01(p, f));
382 }
383 
384 
385 //- Cut a prism from a tet and apply an operation to the result. The cuts are
386 // the same as for tetCutPrism01. The result is the side connected to edge 23.
387 template<class Op>
388 inline typename Op::result tetCutPrism23
389 (
390  const Op& op,
391  const FixedList<point, 4>& p,
392  const FixedList<scalar, 4>& f
393 )
394 {
395  return prismOp<Op>(tetCutPrism23(op, f), tetCutPrism23(p, f));
396 }
397 
398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
399 
400 } // End namespace Foam
401 
402 // ************************************************************************* //
Foam::triCutTri
const cut::uniformOp< Type > & triCutTri(const cut::uniformOp< Type > &x, const Pair< scalar > &)
Modify a uniform operation for cutting a tri from a tri (does nothing)
Definition: cutI.H:52
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Swap
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Definition: DynamicList.H:429
Foam::tetCutTet
const cut::uniformOp< Type > & tetCutTet(const cut::uniformOp< Type > &x, const FixedList< scalar, 3 > &)
Modify a uniform operation for cutting a tet from a tet (does nothing)
Definition: cutI.H:88
Foam::quadOp
Op::result quadOp(const OpData &opData, const FixedList< point, 4 > &p)
Apply an operation to a quad. Splits the quad into two tris.
Definition: cutI.H:295
Foam::tetCutPrism23
const cut::uniformOp< Type > & tetCutPrism23(const cut::uniformOp< Type > &x, const FixedList< scalar, 4 > &)
Modify a uniform operation for cutting prism23 from a tet (does nothing)
Definition: cutI.H:124
Foam::tetReorder
const cut::uniformOp< Type > & tetReorder(const cut::uniformOp< Type > &x, const FixedList< label, 4 > &)
Modify a uniform operation for reordering a tet (does nothing)
Definition: cutI.H:76
Foam::tetCutPrism01
const cut::uniformOp< Type > & tetCutPrism01(const cut::uniformOp< Type > &x, const FixedList< scalar, 4 > &)
Modify a uniform operation for cutting prism01 from a tet (does nothing)
Definition: cutI.H:112
cut.H
Functions for cutting triangles and tetrahedra. Generic operations are applied to each half of a cut.
Foam::tetCutPrism0
const cut::uniformOp< Type > & tetCutPrism0(const cut::uniformOp< Type > &x, const FixedList< scalar, 3 > &)
Modify a uniform operation for cutting prism0 from a tet (does nothing)
Definition: cutI.H:100
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::prismOp
Op::result prismOp(const OpData &opData, const FixedList< point, 6 > &p)
Apply an operation to a prism. Splits the prism into three tets.
Definition: cutI.H:341
Foam::triReorder
const cut::uniformOp< Type > & triReorder(const cut::uniformOp< Type > &x, const FixedList< label, 3 > &)
Modify a uniform operation for reordering a tri (does nothing)
Definition: cutI.H:40
Foam::triCutQuad
const cut::uniformOp< Type > & triCutQuad(const cut::uniformOp< Type > &x, const Pair< scalar > &)
Modify a uniform operation for cutting a quad from a tri (does nothing)
Definition: cutI.H:64
Foam::Pair< scalar >
f
labelList f(nPoints)
Foam::FixedList< label, 3 >
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::cut::uniformOp
Definition: cut.H:57
Op
#define Op(opName, op)
Definition: ops.H:112