cut.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2017-2020 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 Description:
25  Functions which cut triangles and tetrahedra. Generic operations are
26  applied to each half of a cut.
27 
28 SourceFiles:
29  cutI.H
30  cutTemplates.C
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef cut_H
35 #define cut_H
36 
37 #include "FixedList.H"
38 #include "nil.H"
39 #include "plane.H"
40 #include "tetPointRef.H"
41 #include "triPointRef.H"
42 #include "zero.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 namespace cut
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class uniformOp Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 template<class Type>
56 class uniformOp
57 {
58  //- Data
59  Type data_;
60 
61 
62 public:
63 
64  // Constructors
65 
66  //- Construct null
68  {}
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 
91 class noOp
92 :
93  public uniformOp<nil>
94 {
95 public:
96 
97  // Typedefs
98 
99  //- Result type
100  typedef zero result;
101 
102 
103  // Constructors
104 
105  //- Construct null
107  {}
108 
109  //- Construct from base
110  noOp(const uniformOp<nil>& op)
111  :
112  uniformOp<nil>(op)
113  {}
114 
115 
116  // Member Operators
117 
118  //- Operate on nothing
119  result operator()() const
120  {
121  return result();
122  }
123 
124  //- Operate on a triangle or tetrahedron
125  template<class Type, unsigned Size>
126  result operator()(const FixedList<Type, Size>& p) const
127  {
128  return result();
129  }
130 };
131 
132 
133 /*---------------------------------------------------------------------------*\
134  Class areaOp Declaration
135 \*---------------------------------------------------------------------------*/
136 
137 class areaOp
138 :
139  public uniformOp<nil>
140 {
141 public:
142 
143  // Typedefs
144 
145  //- Result type
146  typedef vector result;
147 
148 
149  // Constructors
150 
151  //- Construct null
153  {}
154 
155  //- Construct from base
157  :
158  uniformOp<nil>(op)
159  {}
160 
161 
162  // Member Operators
163 
164  //- Operate on nothing
165  result operator()() const
166  {
167  return vector::zero;
168  }
169 
170  //- Operate on a triangle
171  result operator()(const FixedList<point, 3>& p) const
172  {
173  return result(triPointRef(p[0], p[1], p[2]).area());
174  }
175 };
176 
177 
178 /*---------------------------------------------------------------------------*\
179  Class areaMagOp Declaration
180 \*---------------------------------------------------------------------------*/
181 
183 :
184  public uniformOp<nil>
185 {
186 public:
187 
188  // Typedefs
189 
190  //- Result type
191  typedef scalar result;
192 
193 
194  // Constructors
195 
196  //- Construct null
198  {}
199 
200  //- Construct from base
202  :
203  uniformOp<nil>(op)
204  {}
205 
206 
207  // Member Operators
208 
209  //- Operate on nothing
210  result operator()() const
211  {
212  return 0;
213  }
214 
215  //- Operate on a triangle
216  result operator()(const FixedList<point, 3>& p) const
217  {
218  return result(triPointRef(p[0], p[1], p[2]).mag());
219  }
220 };
221 
222 
223 /*---------------------------------------------------------------------------*\
224  Class volumeOp Declaration
225 \*---------------------------------------------------------------------------*/
226 
227 class volumeOp
228 :
229  public uniformOp<nil>
230 {
231 public:
232 
233  // Typedefs
234 
235  //- Result type
236  typedef scalar result;
237 
238 
239  // Constructors
240 
241  //- Construct null
243  {}
244 
245  //- Construct from base
247  :
248  uniformOp<nil>(op)
249  {}
250 
251 
252  // Member Operators
253 
254  //- Operate on nothing
255  result operator()() const
256  {
257  return 0;
258  }
259 
260  //- Operate on a tetrahedron
261  result operator()(const FixedList<point, 4>& p) const
262  {
263  return result(tetPointRef(p[0], p[1], p[2], p[3]).mag());
264  }
265 };
266 
267 
268 /*---------------------------------------------------------------------------*\
269  Class areaIntegrateOp Declaration
270 \*---------------------------------------------------------------------------*/
271 
272 template<class Type>
274 :
275  public FixedList<Type, 3>
276 {
277 public:
278 
279  // Typedefs
280 
281  //- Result type
283 
284 
285  // Constructors
286 
287  //- Construct from base
289  :
290  FixedList<Type, 3>(x)
291  {}
292 
293 
294  // Member Operators
295 
296  //- Operate on nothing
297  result operator()() const
298  {
299  return pTraits<result>::zero;
300  }
301 
302  //- Operate on a triangle
303  result operator()(const FixedList<point, 3>& p) const
304  {
305  const FixedList<Type, 3>& x = *this;
306  return result(areaOp()(p)*(x[0] + x[1] + x[2])/3);
307  }
308 };
309 
310 
311 /*---------------------------------------------------------------------------*\
312  Class areaMagIntegrateOp Declaration
313 \*---------------------------------------------------------------------------*/
314 
315 template<class Type>
317 :
318  public FixedList<Type, 3>
319 {
320 public:
321 
322  // Typedefs
323 
324  //- Result type
325  typedef Type result;
326 
327 
328  // Constructors
329 
330  //- Construct from base
332  :
333  FixedList<Type, 3>(x)
334  {}
335 
336 
337  // Member Operators
338 
339  //- Operate on nothing
340  result operator()() const
341  {
342  return pTraits<result>::zero;
343  }
344 
345  //- Operate on a triangle
346  result operator()(const FixedList<point, 3>& p) const
347  {
348  const FixedList<Type, 3>& x = *this;
349  return result(areaMagOp()(p)*(x[0] + x[1] + x[2])/3);
350  }
351 };
352 
353 
354 /*---------------------------------------------------------------------------*\
355  Class volumeIntegrateOp Declaration
356 \*---------------------------------------------------------------------------*/
357 
358 template<class Type>
360 :
361  public FixedList<Type, 4>
362 {
363 public:
364 
365  // Typedefs
366 
367  //- Result type
368  typedef Type result;
369 
370 
371  // Constructors
372 
373  //- Construct from base
375  :
376  FixedList<Type, 4>(x)
377  {}
378 
379 
380  // Member Operators
381 
382  //- Operate on nothing
383  result operator()() const
384  {
385  return pTraits<result>::zero;
386  }
387 
388  //- Operate on a tetrahedron
389  result operator()(const FixedList<point, 4>& p) const
390  {
391  const FixedList<Type, 4>& x = *this;
392  return result(volumeOp()(p)*(x[0] + x[1] + x[2] + x[3])/4);
393  }
394 };
395 
396 
397 /*---------------------------------------------------------------------------*\
398  Class listOp Declaration
399 \*---------------------------------------------------------------------------*/
400 
401 template<class Type, unsigned Size>
402 class listOp
403 :
404  public uniformOp<nil>
405 {
406 public:
407 
408  // Classes
409 
410  //- Result class
411  class result
412  :
413  public DynamicList<FixedList<Type, Size>>
414  {
415  public:
416 
417  // Constructors
418 
419  //- Construct from a single element
421  :
422  DynamicList<FixedList<Type, Size>>(1, x)
423  {}
424 
425 
426  // Member Operators
427 
428  //- Add together two lists
429  result operator+(const result& x) const
430  {
431  result r(*this);
432  r.append(x);
433  return r;
434  }
435  };
436 
437 
438  // Constructors
439 
440  //- Construct null
442  {}
443 
444  //- Construct from base
446  :
447  uniformOp<nil>(op)
448  {}
449 
450 
451  // Member Operators
452 
453  //- Operate on nothing
455  {
456  return result();
457  }
458 
459  //- Operate on a triangle or tetrahedron
461  {
462  return result(p);
463  }
464 };
465 
466 
468 
469 
471 
472 
473 /*---------------------------------------------------------------------------*\
474  Class appendOp Declaration
475 \*---------------------------------------------------------------------------*/
476 
477 template<class Container>
478 class appendOp
479 :
480  public uniformOp<Container&>
481 {
482 public:
483 
484  // Typedefs
485 
486  //- Result type
487  typedef zero result;
488 
489 
490  // Constructors
491 
492  //- Construct from a container reference
493  appendOp(Container& x)
494  :
495  uniformOp<Container&>(x)
496  {}
497 
498  //- Construct from base
500  :
501  uniformOp<Container&>(op)
502  {}
503 
504 
505  // Member Operators
506 
507  //- Operate on nothing
508  result operator()() const
509  {
510  return result();
511  }
512 
513  //- Operate on a triangle or tetrahedron
514  template<class Type, unsigned Size>
515  result operator()(const FixedList<Type, Size>& p) const
516  {
517  this->data().append(p);
518  return result();
519  }
520 };
521 
522 
523 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
524 
525 //- Trait to determine the result of the addition of two operations
526 template<class AheadOp, class BehindOp>
528 
529 template<class Op>
531 {
532 public:
533 
534  typedef typename Op::result type;
535 };
536 
537 template<>
539 {
540 public:
541 
542  typedef typename noOp::result type;
543 };
544 
545 template<class Op>
547 {
548 public:
549 
550  typedef typename Op::result type;
551 };
552 
553 template<class Op>
555 {
556 public:
557 
558  typedef typename Op::result type;
559 };
560 
561 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
562 
563 } // End namespace cut
564 
565 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
566 
567 //- Cut a triangle along the zero plane defined by the given levels. Templated
568 // on aboveOp and belowOp; the operations applied to the regions on either side
569 // of the cut.
570 template<class Point, class AboveOp, class BelowOp>
572 (
573  const FixedList<Point, 3>& tri,
574  const FixedList<scalar, 3>& level,
575  const AboveOp& aboveOp,
576  const BelowOp& belowOp
577 );
578 
579 //- As above, but with a plane specifying the location of the cut
580 template<class AboveOp, class BelowOp>
582 (
583  const FixedList<point, 3>& tri,
584  const plane& s,
585  const AboveOp& aboveOp,
586  const BelowOp& belowOp
587 );
588 
589 //- As triCut, but for a tetrahedron.
590 template<class Point, class AboveOp, class BelowOp>
592 (
593  const FixedList<Point, 4>& tet,
594  const FixedList<scalar, 4>& level,
595  const AboveOp& aboveOp,
596  const BelowOp& belowOp
597 );
598 
599 //- As above, but with a plane specifying the location of the cut
600 template<class AboveOp, class BelowOp>
602 (
603  const FixedList<point, 4>& tet,
604  const plane& s,
605  const AboveOp& aboveOp,
606  const BelowOp& belowOp
607 );
608 
609 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
610 
611 } // End namespace Foam
612 
613 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
614 
615 #include "cutI.H"
616 
617 #ifdef NoRepository
618  #include "cutTemplates.C"
619 #endif
620 
621 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
622 
623 #endif
624 
625 // ************************************************************************* //
areaMagIntegrateOp(const FixedList< Type, 3 > &x)
Construct from base.
Definition: cut.H:331
result operator()(const FixedList< point, 4 > &p) const
Operate on a tetrahedron.
Definition: cut.H:261
appendOp(const uniformOp< Container &> &op)
Construct from base.
Definition: cut.H:499
tetrahedron< point, const point & > tetPointRef
Definition: tetPointRef.H:44
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:54
Trait to determine the result of the addition of two operations.
Definition: cut.H:527
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition: cut.H:346
vector result
Result type.
Definition: cut.H:146
listOp(const uniformOp< nil > &op)
Construct from base.
Definition: cut.H:445
Type result
Result type.
Definition: cut.H:325
outerProduct< Type, vector >::type result
Result type.
Definition: cut.H:282
Traits class for primitives.
Definition: pTraits.H:50
#define Op(opName, op)
Definition: ops.H:101
appendOp(Container &x)
Construct from a container reference.
Definition: cut.H:493
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
Type data() const
Access the data.
Definition: cut.H:80
result operator()() const
Operate on nothing.
Definition: cut.H:454
uniformOp(Type data)
Construct from data.
Definition: cut.H:71
result operator()(const FixedList< Type, Size > &p) const
Operate on a triangle or tetrahedron.
Definition: cut.H:126
listOp< point, 3 > listTriOp
Definition: cut.H:467
result operator()() const
Operate on nothing.
Definition: cut.H:119
result operator()(const FixedList< Type, Size > &p) const
Operate on a triangle or tetrahedron.
Definition: cut.H:515
scalar result
Result type.
Definition: cut.H:236
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
volumeOp(const uniformOp< nil > &op)
Construct from base.
Definition: cut.H:246
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
result operator()() const
Operate on nothing.
Definition: cut.H:210
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. Templated.
noOp(const uniformOp< nil > &op)
Construct from base.
Definition: cut.H:110
result(const FixedList< Type, Size > &x)
Construct from a single element.
Definition: cut.H:420
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
zero result
Result type.
Definition: cut.H:100
result operator()() const
Operate on nothing.
Definition: cut.H:508
result operator+(const result &x) const
Add together two lists.
Definition: cut.H:429
result operator()() const
Operate on nothing.
Definition: cut.H:255
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition: cut.H:303
areaIntegrateOp(const FixedList< Type, 3 > &x)
Construct from base.
Definition: cut.H:288
scalar result
Result type.
Definition: cut.H:191
Database for solution and other reduced data.
Definition: data.H:51
areaMagOp(const uniformOp< nil > &op)
Construct from base.
Definition: cut.H:201
listOp< point, 4 > listTetOp
Definition: cut.H:470
uniformOp()
Construct null.
Definition: cut.H:67
volumeIntegrateOp(const FixedList< Type, 4 > &x)
Construct from base.
Definition: cut.H:374
result operator()() const
Operate on nothing.
Definition: cut.H:383
zero result
Result type.
Definition: cut.H:487
result operator()(const FixedList< point, 4 > &p) const
Operate on a tetrahedron.
Definition: cut.H:389
result operator()() const
Operate on nothing.
Definition: cut.H:340
listOp()
Construct null.
Definition: cut.H:441
triangle< point, const point & > triPointRef
Definition: triPointRef.H:44
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition: cut.H:171
areaOp()
Construct null.
Definition: cut.H:152
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
dimensioned< scalar > mag(const dimensioned< Type > &)
result operator()() const
Operate on nothing.
Definition: cut.H:165
volScalarField & p
result operator()(const FixedList< Type, Size > &p) const
Operate on a triangle or tetrahedron.
Definition: cut.H:460
areaOp(const uniformOp< nil > &op)
Construct from base.
Definition: cut.H:156
Result class.
Definition: cut.H:411
noOp()
Construct null.
Definition: cut.H:106
result operator()() const
Operate on nothing.
Definition: cut.H:297
Type result
Result type.
Definition: cut.H:368
Namespace for OpenFOAM.
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.
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition: cut.H:216
volumeOp()
Construct null.
Definition: cut.H:242
A zero-sized class without any storage. Used, for example, in HashSet.
Definition: nil.H:58
areaMagOp()
Construct null.
Definition: cut.H:197