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 cut_H
37#define cut_H
38
39#include "plane.H"
40#include "FixedList.H"
41#include "tetPointRef.H"
42#include "triPointRef.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>
58{
59 //- Data
60 Type data_;
61
62
63public:
64
65 // Constructors
66
67 //- Default construct
68 uniformOp() = default;
69
70 //- Construct from 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<zero::null>
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
110 :
111 uniformOp<zero::null>(op)
112 {}
113
114
115 // Member Operators
116
117 //- Operate on nothing
119 {
120 return result();
121 }
122
123 //- Operate on a triangle or tetrahedron
124 template<unsigned N>
126 {
127 return result();
128 }
129};
130
131
132/*---------------------------------------------------------------------------*\
133 Class areaOp Declaration
134\*---------------------------------------------------------------------------*/
135
137:
138 public uniformOp<zero::null>
139{
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<zero::null>(op)
157 {}
158
159
160 // Member Operators
161
162 //- Operate on nothing
164 {
165 return vector::zero;
166 }
167
168 //- Operate on a triangle
170 {
171 return result(triPointRef(p[0], p[1], p[2]).areaNormal());
172 }
173};
174
175
176/*---------------------------------------------------------------------------*\
177 Class volumeOp Declaration
178\*---------------------------------------------------------------------------*/
179
181:
182 public uniformOp<zero::null>
183{
184public:
185
186 // Typedefs
187
188 //- Result type
189 typedef scalar result;
190
191
192 // Constructors
193
194 //- Default construct
195 volumeOp() = default;
196
197 //- Construct from base
199 :
200 uniformOp<zero::null>(op)
201 {}
202
203
204 // Member Operators
205
206 //- Operate on nothing
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\*---------------------------------------------------------------------------*/
223
224template<class Type>
226:
227 public FixedList<Type, 3>
228{
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
247
248 //- Operate on nothing
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);
259 }
260};
261
262
263/*---------------------------------------------------------------------------*\
264 Class volumeIntegrateOp Declaration
265\*---------------------------------------------------------------------------*/
266
267template<class Type>
269:
270 public FixedList<Type, 4>
271{
272public:
273
274 // Typedefs
275
276 //- Result type
277 typedef Type result;
278
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
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>
312:
313 public uniformOp<zero::null>
314{
315public:
316
317 // Classes
318
319 //- Result class
320 class result
321 :
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
348
349 //- Default construct
350 listOp() = default;
351
352 //- Construct from base
354 :
355 uniformOp<zero::null>(op)
356 {}
357
358
359 // Member Operators
360
361 //- Operate on nothing
363 {
364 return result();
365 }
366
367 //- Operate on a triangle or tetrahedron
369 {
370 return result(p);
371 }
372};
373
374
377
378
379/*---------------------------------------------------------------------------*\
380 Class appendOp Declaration
381\*---------------------------------------------------------------------------*/
382
383template<class Container>
385:
386 public uniformOp<Container&>
387{
388public:
389
390 // Typedefs
391
392 //- Result type
393 typedef zero result;
394
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
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>
436{
437public:
438
439 typedef typename Op::result type;
440};
441
442template<>
444{
445public:
446
447 typedef typename noOp::result type;
448};
449
450template<class 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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
467
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(
508 const FixedList<point, 4>& tet,
509 const plane& pln,
510 const AboveOp& aboveOp,
511 const BelowOp& belowOp
512);
513
514// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
515
516} // End namespace Foam
517
518// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
519
520#include "cutI.H"
521
522#ifdef NoRepository
523 #include "cutTemplates.C"
524#endif
525
526// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
527
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:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
zero result
Result type.
Definition: cut.H:393
appendOp(const uniformOp< Container & > &op)
Construct from base.
Definition: cut.H:405
result operator()() const
Operate on nothing.
Definition: cut.H:414
appendOp(Container &x)
Construct from a container reference.
Definition: cut.H:399
result operator()(const FixedList< point, N > &p) const
Operate on a triangle or tetrahedron.
Definition: cut.H:421
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition: cut.H:255
result operator()() const
Operate on nothing.
Definition: cut.H:249
outerProduct< Type, vector >::type result
Result type.
Definition: cut.H:234
areaIntegrateOp(const FixedList< Type, 3 > &x)
Construct from base.
Definition: cut.H:240
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition: cut.H:169
areaOp()=default
Default construct.
result operator()() const
Operate on nothing.
Definition: cut.H:163
areaOp(const uniformOp< zero::null > &op)
Construct from base.
Definition: cut.H:154
vector result
Result type.
Definition: cut.H:145
Result class.
Definition: cut.H:323
result(const FixedList< point, N > &x)
Construct from a single element.
Definition: cut.H:329
result operator+(const result &x) const
Add together two lists.
Definition: cut.H:338
listOp()=default
Default construct.
result operator()() const
Operate on nothing.
Definition: cut.H:362
listOp(const uniformOp< zero::null > &op)
Construct from base.
Definition: cut.H:353
result operator()(const FixedList< point, N > &p) const
Operate on a triangle or tetrahedron.
Definition: cut.H:368
zero result
Result type.
Definition: cut.H:100
noOp()=default
Default construct.
noOp(const uniformOp< zero::null > &op)
Construct from base.
Definition: cut.H:109
result operator()() const
Operate on nothing.
Definition: cut.H:118
result operator()(const FixedList< point, N > &p) const
Operate on a triangle or tetrahedron.
Definition: cut.H:125
Trait to determine the result of the addition of two operations.
Definition: cut.H:432
Type data() const
Access the data.
Definition: cut.H:80
uniformOp(Type data)
Construct from data.
Definition: cut.H:71
uniformOp()=default
Default construct.
volumeIntegrateOp(const FixedList< Type, 4 > &x)
Construct from base.
Definition: cut.H:283
result operator()() const
Operate on nothing.
Definition: cut.H:292
Type result
Result type.
Definition: cut.H:277
result operator()(const FixedList< point, 4 > &p) const
Operate on a tetrahedron.
Definition: cut.H:298
scalar result
Result type.
Definition: cut.H:189
result operator()() const
Operate on nothing.
Definition: cut.H:207
result operator()(const FixedList< point, 4 > &p) const
Operate on a tetrahedron.
Definition: cut.H:213
volumeOp()=default
Default construct.
volumeOp(const uniformOp< zero::null > &op)
Construct from base.
Definition: cut.H:198
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition: plane.H:95
Patchify triangles based on orientation w.r.t other (triangulated or triangulatable) surfaces.
type
Volume classification types.
Definition: volumeType.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
volScalarField & p
listOp< 4 > listTetOp
Definition: cut.H:376
listOp< 3 > listTriOp
Definition: cut.H:375
Namespace for OpenFOAM.
tetrahedron< point, const point & > tetPointRef
A tetrahedron using referred points.
Definition: tetPointRef.H:47
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)
triangle< point, const point & > triPointRef
A triangle using referred points.
Definition: triangle.H:71
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.
#define Op(opName, op)
Definition: ops.H:112
A non-counting (dummy) refCount.
Definition: refCount.H:59
const Vector< label > N(dict.get< Vector< label > >("N"))