cutTriTet.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-2022 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  cutTriTetI.H
30  cutTriTetTemplates.C
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef cutTriTet_H
35 #define cutTriTet_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 cutTriTet
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
120  {
121  return result();
122  }
123 
124  //- Operate on a triangle or tetrahedron
125  template<class Type, unsigned Size>
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
166  {
167  return vector::zero;
168  }
169 
170  //- Operate on a triangle
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
211  {
212  return 0;
213  }
214 
215  //- Operate on a triangle
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
256  {
257  return 0;
258  }
259 
260  //- Operate on a tetrahedron
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
298  {
299  return pTraits<result>::zero;
300  }
301 
302  //- Operate on a triangle
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
341  {
342  return pTraits<result>::zero;
343  }
344 
345  //- Operate on a triangle
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
384  {
385  return pTraits<result>::zero;
386  }
387 
388  //- Operate on a tetrahedron
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
509  {
510  return result();
511  }
512 
513  //- Operate on a triangle or tetrahedron
514  template<class Type, unsigned Size>
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 cutTriTet
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 "cutTriTetI.H"
616 
617 #ifdef NoRepository
618  #include "cutTriTetTemplates.C"
619 #endif
620 
621 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
622 
623 #endif
624 
625 // ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:78
static const Form zero
Definition: VectorSpace.H:113
zero result
Result type.
Definition: cutTriTet.H:487
appendOp(const uniformOp< Container & > &op)
Construct from base.
Definition: cutTriTet.H:499
result operator()() const
Operate on nothing.
Definition: cutTriTet.H:508
appendOp(Container &x)
Construct from a container reference.
Definition: cutTriTet.H:493
result operator()(const FixedList< Type, Size > &p) const
Operate on a triangle or tetrahedron.
Definition: cutTriTet.H:515
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition: cutTriTet.H:303
outerProduct< Type, vector >::type result
Result type.
Definition: cutTriTet.H:282
result operator()() const
Operate on nothing.
Definition: cutTriTet.H:297
areaIntegrateOp(const FixedList< Type, 3 > &x)
Construct from base.
Definition: cutTriTet.H:288
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition: cutTriTet.H:346
areaMagIntegrateOp(const FixedList< Type, 3 > &x)
Construct from base.
Definition: cutTriTet.H:331
result operator()() const
Operate on nothing.
Definition: cutTriTet.H:340
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition: cutTriTet.H:216
scalar result
Result type.
Definition: cutTriTet.H:191
result operator()() const
Operate on nothing.
Definition: cutTriTet.H:210
areaMagOp()
Construct null.
Definition: cutTriTet.H:197
areaMagOp(const uniformOp< nil > &op)
Construct from base.
Definition: cutTriTet.H:201
result operator()(const FixedList< point, 3 > &p) const
Operate on a triangle.
Definition: cutTriTet.H:171
result operator()() const
Operate on nothing.
Definition: cutTriTet.H:165
vector result
Result type.
Definition: cutTriTet.H:146
areaOp(const uniformOp< nil > &op)
Construct from base.
Definition: cutTriTet.H:156
areaOp()
Construct null.
Definition: cutTriTet.H:152
result(const FixedList< Type, Size > &x)
Construct from a single element.
Definition: cutTriTet.H:420
result operator+(const result &x) const
Add together two lists.
Definition: cutTriTet.H:429
result operator()() const
Operate on nothing.
Definition: cutTriTet.H:454
listOp(const uniformOp< nil > &op)
Construct from base.
Definition: cutTriTet.H:445
listOp()
Construct null.
Definition: cutTriTet.H:441
result operator()(const FixedList< Type, Size > &p) const
Operate on a triangle or tetrahedron.
Definition: cutTriTet.H:460
zero result
Result type.
Definition: cutTriTet.H:100
result operator()() const
Operate on nothing.
Definition: cutTriTet.H:119
noOp(const uniformOp< nil > &op)
Construct from base.
Definition: cutTriTet.H:110
result operator()(const FixedList< Type, Size > &p) const
Operate on a triangle or tetrahedron.
Definition: cutTriTet.H:126
noOp()
Construct null.
Definition: cutTriTet.H:106
Trait to determine the result of the addition of two operations.
Definition: cutTriTet.H:527
Type data() const
Access the data.
Definition: cutTriTet.H:80
uniformOp(Type data)
Construct from data.
Definition: cutTriTet.H:71
uniformOp()
Construct null.
Definition: cutTriTet.H:67
volumeIntegrateOp(const FixedList< Type, 4 > &x)
Construct from base.
Definition: cutTriTet.H:374
result operator()() const
Operate on nothing.
Definition: cutTriTet.H:383
result operator()(const FixedList< point, 4 > &p) const
Operate on a tetrahedron.
Definition: cutTriTet.H:389
scalar result
Result type.
Definition: cutTriTet.H:236
result operator()() const
Operate on nothing.
Definition: cutTriTet.H:255
volumeOp(const uniformOp< nil > &op)
Construct from base.
Definition: cutTriTet.H:246
result operator()(const FixedList< point, 4 > &p) const
Operate on a tetrahedron.
Definition: cutTriTet.H:261
volumeOp()
Construct null.
Definition: cutTriTet.H:242
Database for solution and other reduced data.
Definition: data.H:54
A zero-sized class without any storage. Used, for example, in HashSet.
Definition: nil.H:59
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
Traits class for primitives.
Definition: pTraits.H:53
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:61
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
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.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
listOp< point, 4 > listTetOp
Definition: cutTriTet.H:470
listOp< point, 3 > listTriOp
Definition: cutTriTet.H:467
Namespace for OpenFOAM.
dimensioned< scalar > mag(const dimensioned< Type > &)
cutTriTet::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.
triangle< point, const point & > triPointRef
Definition: triPointRef.H:44
cutTriTet::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.
tetrahedron< point, const point & > tetPointRef
Definition: tetPointRef.H:44
#define Op(opName, op)
Definition: ops.H:100
volScalarField & p