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