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