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 Foam_cut_H
37 #define Foam_cut_H
38 
39 #include "plane.H"
40 #include "FixedList.H"
41 #include "tetrahedron.H"
42 #include "triangle.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  //- Default construct
68  uniformOp() = default;
69 
70  //- Construct from data
71  uniformOp(Type 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<Foam::zero>
94 {
95 public:
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
109  noOp(const uniformOp<Foam::zero>& op)
110  :
111  uniformOp<Foam::zero>(op)
112  {}
113 
114 
115  // Member Operators
116 
117  //- Operate on nothing
118  result operator()() const
119  {
120  return result();
121  }
122 
123  //- Operate on a triangle or tetrahedron
124  template<unsigned N>
125  result operator()(const FixedList<point, N>& p) const
126  {
127  return result();
128  }
129 };
131 
132 /*---------------------------------------------------------------------------*\
133  Class areaOp Declaration
134 \*---------------------------------------------------------------------------*/
135 
136 class areaOp
137 :
138  public uniformOp<Foam::zero>
139 {
140 public:
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
154  areaOp(const uniformOp<Foam::zero>& op)
155  :
156  uniformOp<Foam::zero>(op)
157  {}
158 
159 
160  // Member Operators
162  //- Operate on nothing
163  result operator()() const
164  {
165  return vector::zero;
166  }
167 
168  //- Operate on a triangle
169  result operator()(const FixedList<point, 3>& p) const
170  {
171  return result(triPointRef::areaNormal(p[0], p[1], p[2]));
172  }
173 };
175 
176 /*---------------------------------------------------------------------------*\
177  Class volumeOp Declaration
178 \*---------------------------------------------------------------------------*/
179 
180 class volumeOp
181 :
182  public uniformOp<Foam::zero>
183 {
184 public:
186  // Typedefs
187 
188  //- Result type
189  typedef scalar result;
190 
191 
192  // Constructors
194  //- Default construct
195  volumeOp() = default;
196 
197  //- Construct from base
199  :
200  uniformOp<Foam::zero>(op)
201  {}
202 
203 
204  // Member Operators
205 
206  //- Operate on nothing
207  result operator()() const
208  {
209  return 0;
210  }
211 
212  //- Operate on a tetrahedron
213  result operator()(const FixedList<point, 4>& p) const
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 
224 template<class Type>
225 class areaIntegrateOp
226 :
227  public FixedList<Type, 3>
228 {
229 public:
230 
231  // Typedefs
232 
233  //- Result type
234  typedef typename outerProduct<Type, vector>::type result;
235 
236 
237  // Constructors
238 
239  //- Construct from base
241  :
242  FixedList<Type, 3>(x)
243  {}
244 
245 
246  // Member Operators
248  //- Operate on nothing
249  result operator()() const
250  {
251  return pTraits<result>::zero;
252  }
253 
254  //- Operate on a triangle
255  result operator()(const FixedList<point, 3>& p) const
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 
267 template<class Type>
268 class volumeIntegrateOp
269 :
270  public FixedList<Type, 4>
271 {
272 public:
273 
274  // Typedefs
275 
276  //- Result type
277  typedef Type result;
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
292  result operator()() const
293  {
294  return pTraits<result>::zero;
295  }
296 
297  //- Operate on a tetrahedron
298  result operator()(const FixedList<point, 4>& p) const
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 
310 template<unsigned N>
311 class listOp
312 :
313  public uniformOp<Foam::zero>
314 {
315 public:
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  :
331  DynamicList<FixedList<point, N>>(1, x)
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
349  //- Default construct
350  listOp() = default;
351 
352  //- Construct from base
353  listOp(const uniformOp<Foam::zero>& op)
354  :
355  uniformOp<Foam::zero>(op)
356  {}
357 
358 
359  // Member Operators
360 
361  //- Operate on nothing
362  result operator()() const
363  {
364  return result();
365  }
366 
367  //- Operate on a triangle or tetrahedron
368  result operator()(const FixedList<point, N>& p) const
369  {
370  return result(p);
371  }
372 };
373 
374 
375 typedef listOp<3> listTriOp;
376 typedef listOp<4> listTetOp;
377 
378 
379 /*---------------------------------------------------------------------------*\
380  Class appendOp Declaration
381 \*---------------------------------------------------------------------------*/
382 
383 template<class Container>
384 class appendOp
385 :
386  public uniformOp<Container&>
387 {
388 public:
389 
390  // Typedefs
391 
392  //- Result type
393  typedef zero result;
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
414  result operator()() const
415  {
416  return result();
417  }
418 
419  //- Operate on a triangle or tetrahedron
420  template<unsigned N>
421  result operator()(const FixedList<point, N>& p) const
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
432 template<class AheadOp, class BehindOp> class opAddResult;
433 
434 template<class Op>
435 class opAddResult<Op, Op>
436 {
437 public:
438 
439  typedef typename Op::result type;
440 };
441 
442 template<>
443 class opAddResult<noOp, noOp>
444 {
445 public:
446 
447  typedef typename noOp::result type;
448 };
449 
450 template<class Op>
451 class opAddResult<noOp, Op>
452 {
453 public:
454 
455  typedef typename Op::result type;
456 };
457 
458 template<class Op>
460 {
461 public:
462 
463  typedef typename Op::result type;
464 };
465 
466 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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.
475 template<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
485 template<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.
495 template<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
505 template<class AboveOp, class BelowOp>
507 (
509  const plane& pln,
510  const AboveOp& aboveOp,
511  const BelowOp& belowOp
512 );
513 
514 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
516 } // End namespace Foam
517 
518 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
520 #include "cutI.H"
521 
522 #ifdef NoRepository
523  #include "cutTemplates.C"
524 #endif
525 
526 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
528 #endif
529 
530 // ************************************************************************* //
volumeOp()=default
Default construct.
listOp< 4 > listTetOp
Definition: cut.H:440
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:107
Trait to determine the result of the addition of two operations.
Definition: cut.H:508
vector result
Result type.
Definition: cut.H:161
tetrahedron< point, const point & > tetPointRef
A tetrahedron using referred points.
Definition: tetrahedron.H:72
outerProduct< Type, vector >::type result
Result type.
Definition: cut.H:270
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
#define Op(opName, op)
Definition: ops.H:101
appendOp(Container &x)
Construct from a container reference.
Definition: cut.H:467
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:118
areaOp()=default
Default construct.
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition: plane.H:90
Type data() const
Access the data.
Definition: cut.H:84
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.
listOp()=default
Default construct.
result operator()() const
Operate on nothing.
Definition: cut.H:424
result(const FixedList< point, N > &x)
Construct from a single element.
Definition: cut.H:383
result operator()() const
Operate on nothing.
Definition: cut.H:130
scalar result
Result type.
Definition: cut.H:215
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
Same as Foam::identityOp. Should never be specialized.
Definition: flipOp.H:52
zero result
Result type.
Definition: cut.H:106
result operator()() const
Operate on nothing.
Definition: cut.H:486
result operator+(const result &x) const
Add together two lists.
Definition: cut.H:394
result operator()() const
Operate on nothing.
Definition: cut.H:239
areaIntegrateOp(const FixedList< Type, 3 > &x)
Construct from base.
Definition: cut.H:278
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
listOp< 3 > listTriOp
Definition: cut.H:439
const Vector< label > N(dict.get< Vector< label >>("N"))
uniformOp()=default
Default construct.
volumeIntegrateOp(const FixedList< Type, 4 > &x)
Construct from base.
Definition: cut.H:329
result operator()() const
Operate on nothing.
Definition: cut.H:340
zero result
Result type.
Definition: cut.H:459
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
result operator()() const
Operate on nothing.
Definition: cut.H:185
volScalarField & p
noOp()=default
Default construct.
Result class.
Definition: cut.H:372
result operator()() const
Operate on nothing.
Definition: cut.H:289
Type result
Result type.
Definition: cut.H:321
Namespace for OpenFOAM.
vector areaNormal() const
The area normal - with magnitude equal to area of triangle.
Definition: triangleI.H:151