Loading...
Searching...
No Matches
cut.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
26Description
27 Functions for cutting triangles and tetrahedra.
28 Generic operations are applied to each half of a cut.
29
30SourceFiles
31 cutI.H
32 cutTemplates.C
33
34\*---------------------------------------------------------------------------*/
35
36#ifndef Foam_cut_H
37#define Foam_cut_H
38
39#include "plane.H"
40#include "FixedList.H"
41#include "tetrahedron.H"
42#include "triangle.H"
43#include "zero.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49namespace cut
50{
51
52/*---------------------------------------------------------------------------*\
53 Class uniformOp Declaration
54\*---------------------------------------------------------------------------*/
55
56template<class Type>
57class uniformOp
58{
59 //- Data
60 Type data_;
61
62
63public:
64
65 // Constructors
66
67 //- Default construct
68 uniformOp() = default;
69
70 //- Construct from data
71 uniformOp(Type data)
72 :
73 data_(data)
74 {}
75
76
77 // Member Functions
78
79 //- Access the data
80 Type data() const
81 {
82 return data_;
83 }
84};
85
86
87/*---------------------------------------------------------------------------*\
88 Class noOp Declaration
89\*---------------------------------------------------------------------------*/
90
91class noOp
92:
93 public uniformOp<Foam::zero>
94{
95public:
96
97 // Typedefs
98
99 //- Result type
100 typedef zero result;
101
102
103 // Constructors
104
105 //- Default construct
106 noOp() = default;
107
108 //- Construct from base
109 noOp(const uniformOp<Foam::zero>& op)
110 :
111 uniformOp<Foam::zero>(op)
112 {}
113
115 // Member Operators
116
117 //- Operate on nothing
118 result operator()() const
120 return result();
121 }
122
123 //- Operate on a triangle or tetrahedron
124 template<unsigned N>
126 {
127 return result();
128 }
129};
131
132/*---------------------------------------------------------------------------*\
133 Class areaOp Declaration
134\*---------------------------------------------------------------------------*/
135
136class areaOp
137:
138 public uniformOp<Foam::zero>
140public:
141
142 // Typedefs
143
144 //- Result type
145 typedef vector result;
146
147
148 // Constructors
149
150 //- Default construct
151 areaOp() = default;
152
153 //- Construct from base
155 :
156 uniformOp<Foam::zero>(op)
157 {}
158
159
160 // Member Operators
162 //- Operate on nothing
163 result operator()() const
164 {
165 return vector::zero;
166 }
167
168 //- Operate on a triangle
170 {
171 return result(triPointRef::areaNormal(p[0], p[1], p[2]));
172 }
173};
175
176/*---------------------------------------------------------------------------*\
177 Class volumeOp Declaration
178\*---------------------------------------------------------------------------*/
179
180class volumeOp
181:
182 public uniformOp<Foam::zero>
183{
184public:
186 // Typedefs
187
188 //- Result type
189 typedef scalar result;
190
191
192 // Constructors
194 //- Default construct
195 volumeOp() = default;
196
197 //- Construct from base
199 :
200 uniformOp<Foam::zero>(op)
201 {}
202
203
204 // Member Operators
205
206 //- Operate on nothing
207 result operator()() const
208 {
209 return 0;
210 }
211
212 //- Operate on a tetrahedron
214 {
215 return result(tetPointRef(p[0], p[1], p[2], p[3]).mag());
216 }
217};
218
219
220/*---------------------------------------------------------------------------*\
221 Class areaIntegrateOp Declaration
222\*---------------------------------------------------------------------------*/
224template<class Type>
225class areaIntegrateOp
226:
227 public FixedList<Type, 3>
229public:
230
231 // Typedefs
232
233 //- Result type
235
236
237 // Constructors
238
239 //- Construct from base
241 :
242 FixedList<Type, 3>(x)
243 {}
244
245
246 // Member Operators
248 //- Operate on nothing
249 result operator()() const
250 {
252 }
253
254 //- Operate on a triangle
256 {
257 const FixedList<Type, 3>& x = *this;
258 return result(areaOp()(p)*(x[0] + x[1] + x[2])/3);
260};
261
262
263/*---------------------------------------------------------------------------*\
264 Class volumeIntegrateOp Declaration
265\*---------------------------------------------------------------------------*/
266
267template<class Type>
268class volumeIntegrateOp
269:
270 public FixedList<Type, 4>
271{
272public:
273
274 // Typedefs
275
276 //- Result type
277 typedef Type result;
279
280 // Constructors
281
282 //- Construct from base
284 :
285 FixedList<Type, 4>(x)
286 {}
287
288
289 // Member Operators
290
291 //- Operate on nothing
292 result operator()() const
293 {
295 }
296
297 //- Operate on a tetrahedron
299 {
300 const FixedList<Type, 4>& x = *this;
301 return result(volumeOp()(p)*(x[0] + x[1] + x[2] + x[3])/4);
302 }
303};
304
305
306/*---------------------------------------------------------------------------*\
307 Class listOp Declaration
308\*---------------------------------------------------------------------------*/
309
310template<unsigned N>
311class listOp
312:
313 public uniformOp<Foam::zero>
314{
315public:
316
317 // Classes
318
319 //- Result class
320 class result
322 public DynamicList<FixedList<point, N>>
323 {
324 public:
325
326 // Constructors
327
328 //- Construct from a single element
330 :
332 {}
333
334
335 // Member Operators
336
337 //- Add together two lists
338 result operator+(const result& x) const
339 {
340 result r(*this);
341 r.append(x);
342 return r;
343 }
344 };
345
346
347 // Constructors
349 //- Default construct
350 listOp() = default;
351
352 //- Construct from base
354 :
355 uniformOp<Foam::zero>(op)
356 {}
357
358
359 // Member Operators
360
361 //- Operate on nothing
362 result operator()() const
363 {
364 return result();
365 }
366
367 //- Operate on a triangle or tetrahedron
368 result operator()(const FixedList<point, N>& p) const
369 {
370 return result(p);
371 }
373
374
375typedef listOp<3> listTriOp;
376typedef listOp<4> listTetOp;
377
378
379/*---------------------------------------------------------------------------*\
380 Class appendOp Declaration
381\*---------------------------------------------------------------------------*/
382
383template<class Container>
384class appendOp
385:
386 public uniformOp<Container&>
387{
388public:
389
390 // Typedefs
391
392 //- Result type
393 typedef zero result;
395
396 // Constructors
397
398 //- Construct from a container reference
399 appendOp(Container& x)
400 :
401 uniformOp<Container&>(x)
402 {}
403
404 //- Construct from base
406 :
407 uniformOp<Container&>(op)
408 {}
409
410
411 // Member Operators
412
413 //- Operate on nothing
414 result operator()() const
415 {
416 return result();
417 }
418
419 //- Operate on a triangle or tetrahedron
420 template<unsigned N>
422 {
423 this->data().append(p);
424 return result();
425 }
426};
427
428
429// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
430
431//- Trait to determine the result of the addition of two operations
432template<class AheadOp, class BehindOp> class opAddResult;
433
434template<class Op>
435class opAddResult<Op, Op>
436{
437public:
438
439 typedef typename Op::result type;
441
442template<>
443class opAddResult<noOp, noOp>
444{
445public:
446
447 typedef typename noOp::result type;
449
450template<class Op>
451class opAddResult<noOp, Op>
452{
453public:
454
455 typedef typename Op::result type;
456};
457
458template<class Op>
460{
461public:
462
463 typedef typename Op::result type;
464};
465
466// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
468} // End namespace cut
469
470// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
471
472//- Cut a triangle along the zero plane defined by the given levels.
473// Templated on aboveOp and belowOp; the operations applied to the regions
474// on either side of the cut.
475template<class AboveOp, class BelowOp>
477(
478 const FixedList<point, 3>& tri,
479 const FixedList<scalar, 3>& level,
480 const AboveOp& aboveOp,
481 const BelowOp& belowOp
482);
483
484//- As above, but with a plane specifying the location of the cut
485template<class AboveOp, class BelowOp>
487(
488 const FixedList<point, 3>& tri,
489 const plane& pln,
490 const AboveOp& aboveOp,
491 const BelowOp& belowOp
492);
493
494//- As triCut, but for a tetrahedron.
495template<class AboveOp, class BelowOp>
497(
498 const FixedList<point, 4>& tet,
499 const FixedList<scalar, 4>& level,
500 const AboveOp& aboveOp,
501 const BelowOp& belowOp
502);
503
504//- As above, but with a plane specifying the location of the cut
505template<class AboveOp, class BelowOp>
507(
509 const plane& pln,
510 const AboveOp& aboveOp,
511 const BelowOp& belowOp
512);
513
514// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
516} // End namespace Foam
517
518// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
520#include "cutI.H"
521
522#ifdef NoRepository
523 #include "cutTemplates.C"
524#endif
525
526// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
528#endif
529
530// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void append(const T &val)
Copy append an element to the end of this list.
A 1D vector of objects of type <T> with a fixed length <N>.
Definition FixedList.H:73
static const Form zero
zero result
Result type.
Definition cut.H:459
appendOp(const uniformOp< Container & > &op)
Construct from base.
Definition cut.H:475
result operator()() const
Operate on nothing.
Definition cut.H:486
appendOp(Container &x)
Construct from a container reference.
Definition cut.H:467
result operator()(const FixedList< point, N > &p) const
Operate on a triangle or tetrahedron.
Definition cut.H:495
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition cut.H:297
result operator()() const
Operate on nothing.
Definition cut.H:289
outerProduct< Type, vector >::type result
Result type.
Definition cut.H:270
areaIntegrateOp(const FixedList< Type, 3 > &x)
Construct from base.
Definition cut.H:278
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition cut.H:193
areaOp()=default
Default construct.
result operator()() const
Operate on nothing.
Definition cut.H:185
vector result
Result type.
Definition cut.H:161
areaOp(const uniformOp< Foam::zero > &op)
Construct from base.
Definition cut.H:174
Result class.
Definition cut.H:375
result(const FixedList< point, N > &x)
Construct from a single element.
Definition cut.H:383
result operator+(const result &x) const
Add together two lists.
Definition cut.H:394
listOp()=default
Default construct.
result operator()() const
Operate on nothing.
Definition cut.H:424
listOp(const uniformOp< Foam::zero > &op)
Construct from base.
Definition cut.H:413
result operator()(const FixedList< point, N > &p) const
Operate on a triangle or tetrahedron.
Definition cut.H:432
zero result
Result type.
Definition cut.H:106
noOp()=default
Default construct.
result operator()() const
Operate on nothing.
Definition cut.H:130
noOp(const uniformOp< Foam::zero > &op)
Construct from base.
Definition cut.H:119
result operator()(const FixedList< point, N > &p) const
Operate on a triangle or tetrahedron.
Definition cut.H:139
Trait to determine the result of the addition of two operations.
Definition cut.H:508
Type data() const
Access the data.
Definition cut.H:84
uniformOp(Type data)
Construct from data.
Definition cut.H:73
uniformOp()=default
Default construct.
volumeIntegrateOp(const FixedList< Type, 4 > &x)
Construct from base.
Definition cut.H:329
result operator()() const
Operate on nothing.
Definition cut.H:340
Type result
Result type.
Definition cut.H:321
result operator()(const FixedList< point, 4 > &p) const
Operate on a tetrahedron.
Definition cut.H:348
scalar result
Result type.
Definition cut.H:215
result operator()() const
Operate on nothing.
Definition cut.H:239
result operator()(const FixedList< point, 4 > &p) const
Operate on a tetrahedron.
Definition cut.H:247
volumeOp()=default
Default construct.
volumeOp(const uniformOp< Foam::zero > &op)
Construct from base.
Definition cut.H:228
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank)>::type type
Definition products.H:118
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition plane.H:91
static vector areaNormal(const point &p0, const point &p1, const point &p2)
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
volScalarField & p
listOp< 4 > listTetOp
Definition cut.H:440
listOp< 3 > listTriOp
Definition cut.H:439
Namespace for OpenFOAM.
tetrahedron< point, const point & > tetPointRef
A tetrahedron using referred points.
Definition tetrahedron.H:72
cut::opAddResult< AboveOp, BelowOp >::type triCut(const FixedList< point, 3 > &tri, const FixedList< scalar, 3 > &level, const AboveOp &aboveOp, const BelowOp &belowOp)
Cut a triangle along the zero plane defined by the given levels.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
vector point
Point is a vector.
Definition point.H:37
cut::opAddResult< AboveOp, BelowOp >::type tetCut(const FixedList< point, 4 > &tet, const FixedList< scalar, 4 > &level, const AboveOp &aboveOp, const BelowOp &belowOp)
As triCut, but for a tetrahedron.
Vector< scalar > vector
Definition vector.H:57
#define Op(opName, op)
Definition ops.H:99
Same as Foam::identityOp. Should never be specialized.
Definition flipOp.H:53
const Vector< label > N(dict.get< Vector< label > >("N"))