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-------------------------------------------------------------------------------
10License
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
32namespace Foam
33{
34
35// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36
37//- Modify a uniform operation for reordering a tri (does nothing)
38template<class Type>
40(
43)
44{
45 return x;
46}
47
48
49//- Modify a uniform operation for cutting a tri from a tri (does nothing)
50template<class Type>
52(
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)
62template<class Type>
64(
66 const Pair<scalar>&
67)
68{
69 return x;
70}
71
72
73//- Modify a uniform operation for reordering a tet (does nothing)
74template<class Type>
76(
79)
80{
81 return x;
82}
83
84
85//- Modify a uniform operation for cutting a tet from a tet (does nothing)
86template<class Type>
88(
91)
92{
93 return x;
94}
95
96
97//- Modify a uniform operation for cutting prism0 from a tet (does nothing)
98template<class Type>
100(
101 const cut::uniformOp<Type>& x,
103)
104{
105 return x;
106}
107
108
109//- Modify a uniform operation for cutting prism01 from a tet (does nothing)
110template<class Type>
112(
113 const cut::uniformOp<Type>& x,
115)
116{
117 return x;
118}
119
120
121//- Modify a uniform operation for cutting prism23 from a tet (does nothing)
122template<class Type>
124(
125 const cut::uniformOp<Type>& x,
127)
128{
129 return x;
130}
131
132
133//- Modify a fixed list for reordering a tri (does nothing)
134template<class Type, unsigned N>
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
151template<class Type>
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
169template<class Type>
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)
187template<class Type, unsigned N>
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
204template<class Type>
206(
207 const FixedList<Type, 4>& x,
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
222template<class Type>
224(
225 const FixedList<Type, 4>& x,
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
240template<class Type>
242(
243 const FixedList<Type, 4>& x,
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
262template<class Type>
264(
265 const FixedList<Type, 4>& x,
267)
268{
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.
280template<class Op>
281inline 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.
293template<class Op, class OpData>
294inline typename Op::result quadOp
295(
296 const OpData& opData,
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.
311template<class Op>
312inline typename Op::result triCutQuad
313(
314 const Op& op,
315 const FixedList<point, 3>& p,
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.
326template<class Op>
327inline typename Op::result tetCutTet
328(
329 const Op& op,
330 const FixedList<point, 4>& p,
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.
339template<class Op, class OpData>
340inline typename Op::result prismOp
341(
342 const OpData& opData,
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.
358template<class Op>
359inline typename Op::result tetCutPrism0
360(
361 const Op& op,
362 const FixedList<point, 4>& p,
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.
373template<class Op>
374inline typename Op::result tetCutPrism01
375(
376 const Op& op,
377 const FixedList<point, 4>& p,
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.
387template<class Op>
388inline typename Op::result tetCutPrism23
389(
390 const Op& op,
391 const FixedList<point, 4>& p,
393)
394{
395 return prismOp<Op>(tetCutPrism23(op, f), tetCutPrism23(p, f));
396}
397
398// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
399
400} // End namespace Foam
401
402// ************************************************************************* //
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:69
volScalarField & p
Namespace for OpenFOAM.
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
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
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
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
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Definition: DynamicList.H:408
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
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
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
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
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
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
#define Op(opName, op)
Definition: ops.H:112
labelList f(nPoints)
Functions for cutting triangles and tetrahedra. Generic operations are applied to each half of a cut.