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 | Copyright (C) 2017 OpenFOAM Foundation
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 "cut.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 //- Modify a uniform operation for reordering a tri (does nothing)
36 template<class Type>
37 inline const cut::uniformOp<Type>& triReorder
38 (
39  const cut::uniformOp<Type>& x,
40  const FixedList<label, 3>&
41 )
42 {
43  return x;
44 }
45 
46 
47 //- Modify a uniform operation for cutting a tri from a tri (does nothing)
48 template<class Type>
49 inline const cut::uniformOp<Type>& triCutTri
50 (
51  const cut::uniformOp<Type>& x,
52  const Pair<scalar>&
53 )
54 {
55  return x;
56 }
57 
58 
59 //- Modify a uniform operation for cutting a quad from a tri (does nothing)
60 template<class Type>
61 inline const cut::uniformOp<Type>& triCutQuad
62 (
63  const cut::uniformOp<Type>& x,
64  const Pair<scalar>&
65 )
66 {
67  return x;
68 }
69 
70 
71 //- Modify a uniform operation for reordering a tet (does nothing)
72 template<class Type>
73 inline const cut::uniformOp<Type>& tetReorder
74 (
75  const cut::uniformOp<Type>& x,
76  const FixedList<label, 4>&
77 )
78 {
79  return x;
80 }
81 
82 
83 //- Modify a uniform operation for cutting a tet from a tet (does nothing)
84 template<class Type>
85 inline const cut::uniformOp<Type>& tetCutTet
86 (
87  const cut::uniformOp<Type>& x,
89 )
90 {
91  return x;
92 }
93 
94 
95 //- Modify a uniform operation for cutting prism0 from a tet (does nothing)
96 template<class Type>
98 (
99  const cut::uniformOp<Type>& x,
100  const FixedList<scalar, 3>&
101 )
102 {
103  return x;
104 }
105 
106 
107 //- Modify a uniform operation for cutting prism01 from a tet (does nothing)
108 template<class Type>
110 (
111  const cut::uniformOp<Type>& x,
112  const FixedList<scalar, 4>&
113 )
114 {
115  return x;
116 }
117 
118 
119 //- Modify a uniform operation for cutting prism23 from a tet (does nothing)
120 template<class Type>
122 (
123  const cut::uniformOp<Type>& x,
124  const FixedList<scalar, 4>&
125 )
126 {
127  return x;
128 }
129 
130 
131 //- Modify a fixed list for reordering a tri (does nothing)
132 template<class Type, unsigned Size>
134 (
135  const FixedList<Type, Size>& x,
136  const FixedList<label, 3>& indices
137 )
138 {
139  FixedList<Type, 3> result;
140  for (unsigned i = 0; i < 3; ++ i)
141  {
142  result[i] = x[indices[i]];
143  }
144  return result;
145 }
146 
147 
148 //- Modify a list for cutting a tri from a tri
149 template<class Type>
151 (
152  const FixedList<Type, 3>& x,
153  const Pair<scalar>& f
154 )
155 {
156  FixedList<Type, 3> result;
157  result[0] = x[0];
158  for (label i = 0; i < 2; ++ i)
159  {
160  result[i+1] = x[0] + f[i]*(x[i+1] - x[0]);
161  }
162  return result;
163 }
164 
165 
166 //- Modify a list for cutting a quad from a tri
167 template<class Type>
169 (
170  const FixedList<Type, 3>& x,
171  const Pair<scalar>& f
172 )
173 {
174  FixedList<Type, 4> result;
175  for (label i = 0; i < 2; ++ i)
176  {
177  result[i] = x[i+1];
178  result[3-i] = x[0] + f[i]*(x[i+1] - x[0]);
179  }
180  return result;
181 }
182 
183 
184 //- Modify a fixed list for reordering a tet (does nothing)
185 template<class Type, unsigned Size>
187 (
188  const FixedList<Type, Size>& x,
189  const FixedList<label, 4>& indices
190 )
191 {
192  FixedList<Type, 4> result;
193  for (unsigned i = 0; i < 4; ++ i)
194  {
195  result[i] = x[indices[i]];
196  }
197  return result;
198 }
199 
200 
201 //- Modify a list for cutting a tet from a tet
202 template<class Type>
204 (
205  const FixedList<Type, 4>& x,
206  const FixedList<scalar, 3>& f
207 )
208 {
209  FixedList<Type, 4> result;
210  result[0] = x[0];
211  for (label i = 0; i < 3; ++ i)
212  {
213  result[i+1] = x[0] + f[i]*(x[i+1] - x[0]);
214  }
215  return result;
216 }
217 
218 
219 //- Modify a list for cutting prism0 from a tet
220 template<class Type>
222 (
223  const FixedList<Type, 4>& x,
224  const FixedList<scalar, 3>& f
225 )
226 {
227  FixedList<Type, 6> result;
228  for (label i = 0; i < 3; ++ i)
229  {
230  result[i] = x[0] + f[i]*(x[i+1] - x[0]);
231  result[i+3] = x[i+1];
232  }
233  return result;
234 }
235 
236 
237 //- Modify a list for cutting prism01 from a tet
238 template<class Type>
240 (
241  const FixedList<Type, 4>& x,
242  const FixedList<scalar, 4>& f
243 )
244 {
245  FixedList<Type, 6> result;
246  for (label i = 0; i < 2; ++ i)
247  {
248  result[3*i] = x[i];
249  for (label j = 0; j < 2; ++ j)
250  {
251  result[3*i+j+1] = x[i] + f[2*i+j]*(x[j+2] - x[i]);
252  }
253  }
254 
255  return result;
256 }
257 
258 
259 //- Modify a list for cutting prism23 from a tet
260 template<class Type>
262 (
263  const FixedList<Type, 4>& x,
264  const FixedList<scalar, 4>& f
265 )
266 {
267  FixedList<Type, 6> result = tetCutPrism01(x, f);
268  result[0] = x[2];
269  result[3] = x[3];
270  Swap(result[2], result[4]);
271  return result;
272 }
273 
274 
275 //- Cut a tri from a tri and apply an operation to the result. The cut is made
276 // along the two edges connected to vertex 0, and the cut locations are given
277 // as factors along these edges. The result is the side connected to vertex 0.
278 template<class Op>
279 inline typename Op::result triCutTri
280 (
281  const Op& op,
282  const FixedList<point, 3>& p,
283  const Pair<scalar>& f
284 )
285 {
286  return Op(triCutTri(op, f))(triCutTri(p, f));
287 }
288 
289 
290 //- Apply an operation to a quad. Splits the quad into two tris.
291 template<class Op, class OpData>
292 inline typename Op::result quadOp
293 (
294  const OpData& opData,
295  const FixedList<point, 4>& p
296 )
297 {
298  static const FixedList<FixedList<label, 3>, 2> i =
299  {{0, 1, 2}, {0, 2, 3}};
300  return
301  Op(triReorder(opData, i[0]))(triReorder(p, i[0]))
302  + Op(triReorder(opData, i[1]))(triReorder(p, i[1]));
303 }
304 
305 
306 //- Cut a quad from a tri and apply an operation to the result. The cuts are
307 // the same as for triCutTri. The result is the side connected to vertices 1
308 // and 2.
309 template<class Op>
310 inline typename Op::result triCutQuad
311 (
312  const Op& op,
313  const FixedList<point, 3>& p,
314  const FixedList<scalar, 2>& f
315 )
316 {
317  return quadOp<Op>(triCutQuad(op, f), triCutQuad(p, f));
318 }
319 
320 
321 //- Cut a tet from a tet and apply an operation to the result. The cut is made
322 // along the three edges connected to vertex 0, and the cut locations are given
323 // as factors along these edges. The result is the side connected to vertex 0.
324 template<class Op>
325 inline typename Op::result tetCutTet
326 (
327  const Op& op,
328  const FixedList<point, 4>& p,
329  const FixedList<scalar, 3>& f
330 )
331 {
332  return Op(tetCutTet(op, f))(tetCutTet(p, f));
333 }
334 
335 
336 //- Apply an operation to a prism. Splits the prism into three tets.
337 template<class Op, class OpData>
338 inline typename Op::result prismOp
339 (
340  const OpData& opData,
341  const FixedList<point, 6>& p
342 )
343 {
344  static const FixedList<FixedList<label, 4>, 3> i =
345  {{0, 1, 2, 4}, {0, 2, 5, 4}, {0, 4, 5, 3}};
346  return
347  Op(tetReorder(opData, i[0]))(tetReorder(p, i[0]))
348  + Op(tetReorder(opData, i[1]))(tetReorder(p, i[1]))
349  + Op(tetReorder(opData, i[2]))(tetReorder(p, i[2]));
350 }
351 
352 
353 //- Cut a prism from a tet and apply an operation to the result. The cuts are
354 // the same as for tetCutTet. The result is the side connected to vertices 1,
355 // 2 and 3.
356 template<class Op>
357 inline typename Op::result tetCutPrism0
358 (
359  const Op& op,
360  const FixedList<point, 4>& p,
361  const FixedList<scalar, 3>& f
362 )
363 {
364  return prismOp<Op>(tetCutPrism0(op, f), tetCutPrism0(p, f));
365 }
366 
367 
368 //- Cut a prism from a tet and apply an operation to the result. The cut is made
369 // along four edges, not edges 01 or 23, and the cut locations are given as
370 // factors along these edges. The result is the side connected to edge 01.
371 template<class Op>
372 inline typename Op::result tetCutPrism01
373 (
374  const Op& op,
375  const FixedList<point, 4>& p,
376  const FixedList<scalar, 4>& f
377 )
378 {
379  return prismOp<Op>(tetCutPrism01(op, f), tetCutPrism01(p, f));
380 }
381 
382 
383 //- Cut a prism from a tet and apply an operation to the result. The cuts are
384 // the same as for tetCutPrism01. The result is the side connected to edge 23.
385 template<class Op>
386 inline typename Op::result tetCutPrism23
387 (
388  const Op& op,
389  const FixedList<point, 4>& p,
390  const FixedList<scalar, 4>& f
391 )
392 {
393  return prismOp<Op>(tetCutPrism23(op, f), tetCutPrism23(p, f));
394 }
395 
396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 
398 } // End namespace Foam
399 
400 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
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:339
#define Op(opName, op)
Definition: ops.H:100
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:98
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:50
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:122
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:62
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
void Swap(T &a, T &b)
Definition: Swap.H:43
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:293
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:110
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:74
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:38
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:86
Namespace for OpenFOAM.