tetrahedron.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 | Copyright (C) 2011-2017 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 Class
25  Foam::tetrahedron
26 
27 Description
28  A tetrahedron primitive.
29 
30  Ordering of edges needs to be the same for a tetrahedron
31  class, a tetrahedron cell shape model and a tetCell.
32 
33 SourceFiles
34  tetrahedronI.H
35  tetrahedron.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef tetrahedron_H
40 #define tetrahedron_H
41 
42 #include "point.H"
43 #include "primitiveFieldsFwd.H"
44 #include "pointHit.H"
45 #include "cachedRandom.H"
46 #include "Random.H"
47 #include "FixedList.H"
48 #include "UList.H"
49 #include "triPointRef.H"
50 #include "boundBox.H"
51 #include "barycentric.H"
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 class Istream;
59 class Ostream;
60 
61 // Forward declaration of friend functions and operators
62 
63 template<class Point, class PointRef> class tetrahedron;
64 
65 template<class Point, class PointRef>
66 inline Istream& operator>>
67 (
68  Istream&,
70 );
71 
72 template<class Point, class PointRef>
73 inline Ostream& operator<<
74 (
75  Ostream&,
77 );
78 
79 /*---------------------------------------------------------------------------*\
80  class tetrahedron Declaration
81 \*---------------------------------------------------------------------------*/
82 
83 template<class Point, class PointRef>
84 class tetrahedron
85 {
86 private:
87 
88  // Private data
89 
90  PointRef a_, b_, c_, d_;
91 
92 
93 public:
94 
95  // Member constants
96 
97  enum
98  {
99  nVertices = 4, // Number of vertices in tetrahedron
100  nEdges = 6 // Number of edges in tetrahedron
101  };
102 
103 
104  // Constructors
105 
106  //- Construct from points
107  inline tetrahedron
108  (
109  const Point& a,
110  const Point& b,
111  const Point& c,
112  const Point& d
113  );
114 
115  //- Construct from four points in the list of points
116  inline tetrahedron
117  (
118  const UList<Point>&,
119  const FixedList<label, 4>& indices
120  );
121 
122  //- Construct from Istream
123  inline tetrahedron(Istream&);
124 
125 
126  // Member Functions
127 
128  // Access
129 
130  //- Return vertices
131  inline const Point& a() const;
132 
133  inline const Point& b() const;
134 
135  inline const Point& c() const;
136 
137  inline const Point& d() const;
138 
139  //- Return i-th face
140  inline triPointRef tri(const label facei) const;
141 
142  // Properties
143 
144  //- Return face normal
145  inline vector Sa() const;
146 
147  inline vector Sb() const;
148 
149  inline vector Sc() const;
150 
151  inline vector Sd() const;
152 
153  //- Return centre (centroid)
154  inline Point centre() const;
155 
156  //- Return volume
157  inline scalar mag() const;
158 
159  //- Return circum-centre
160  inline Point circumCentre() const;
161 
162  //- Return circum-radius
163  inline scalar circumRadius() const;
164 
165  //- Return quality: Ratio of tetrahedron and circum-sphere
166  // volume, scaled so that a regular tetrahedron has a
167  // quality of 1
168  inline scalar quality() const;
169 
170  //- Return a random point in the tetrahedron from a
171  // uniform distribution
172  inline Point randomPoint(Random& rndGen) const;
173 
174  //- Return a random point in the tetrahedron from a
175  // uniform distribution
176  inline Point randomPoint(cachedRandom& rndGen) const;
177 
178  //- Calculate the point from the given barycentric coordinates.
179  inline Point barycentricToPoint(const barycentric& bary) const;
180 
181  //- Calculate the barycentric coordinates from the given point
182  inline barycentric pointToBarycentric(const point& pt) const;
183 
184  //- Calculate the barycentric coordinates from the given point.
185  // Returns the determinant.
186  inline scalar pointToBarycentric
187  (
188  const point& pt,
189  barycentric& bary
190  ) const;
191 
192  //- Return nearest point to p on tetrahedron. Is p itself
193  // if inside.
194  inline pointHit nearestPoint(const point& p) const;
195 
196  //- Return true if point is inside tetrahedron
197  inline bool inside(const point& pt) const;
198 
199  //- Return (min)containment sphere, i.e. the smallest sphere with
200  // all points inside. Returns pointHit with:
201  // - hit : if sphere is equal to circumsphere
202  // (biggest sphere)
203  // - point : centre of sphere
204  // - distance : radius of sphere
205  // - eligiblemiss: false
206  // Tol (small compared to 1, e.g. 1e-9) is used to determine
207  // whether point is inside: mag(pt - ctr) < (1+tol)*radius.
208  pointHit containmentSphere(const scalar tol) const;
209 
210  //- Fill buffer with shape function products
211  void gradNiSquared(scalarField& buffer) const;
212 
213  void gradNiDotGradNj(scalarField& buffer) const;
214 
215  void gradNiGradNi(tensorField& buffer) const;
216 
217  void gradNiGradNj(tensorField& buffer) const;
218 
219  //- Calculate the bounding box
220  boundBox bounds() const;
221 
222 
223  // IOstream operators
224 
225  friend Istream& operator>> <Point, PointRef>
226  (
227  Istream&,
228  tetrahedron&
229  );
230 
231  friend Ostream& operator<< <Point, PointRef>
232  (
233  Ostream&,
234  const tetrahedron&
235  );
236 };
237 
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 } // End namespace Foam
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 #include "tetrahedronI.H"
246 
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 
249 #ifdef NoRepository
250  #include "tetrahedron.C"
251 #endif
252 
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 
255 #endif
256 
257 // ************************************************************************* //
A tetrahedron primitive.
Definition: tetrahedron.H:62
A triangle primitive used to calculate face normals and swept volumes.
Definition: triangle.H:58
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
pointHit containmentSphere(const scalar tol) const
Return (min)containment sphere, i.e. the smallest sphere with.
Definition: tetrahedron.C:34
scalar circumRadius() const
Return circum-radius.
Definition: tetrahedronI.H:204
tetrahedron(const Point &a, const Point &b, const Point &c, const Point &d)
Construct from points.
Definition: tetrahedronI.H:34
Point circumCentre() const
Return circum-centre.
Definition: tetrahedronI.H:177
const Point & c() const
Definition: tetrahedronI.H:86
vector Sd() const
Definition: tetrahedronI.H:156
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void gradNiSquared(scalarField &buffer) const
Fill buffer with shape function products.
Definition: tetrahedron.C:246
const Point & a() const
Return vertices.
Definition: tetrahedronI.H:72
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
Random number generator.
Definition: cachedRandom.H:63
Point barycentricToPoint(const barycentric &bary) const
Calculate the point from the given barycentric coordinates.
Definition: tetrahedronI.H:264
const Point & d() const
Definition: tetrahedronI.H:93
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
const Point & b() const
Definition: tetrahedronI.H:79
scalar quality() const
Return quality: Ratio of tetrahedron and circum-sphere.
Definition: tetrahedronI.H:230
void gradNiGradNi(tensorField &buffer) const
Definition: tetrahedron.C:297
vector Sb() const
Definition: tetrahedronI.H:142
scalar mag() const
Return volume.
Definition: tetrahedronI.H:170
cachedRandom rndGen(label(0), -1)
vector Sa() const
Return face normal.
Definition: tetrahedronI.H:135
Point centre() const
Return centre (centroid)
Definition: tetrahedronI.H:163
bool inside(const point &pt) const
Return true if point is inside tetrahedron.
Definition: tetrahedronI.H:423
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
Simple random number generator.
Definition: Random.H:49
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
triPointRef tri(const label facei) const
Return i-th face.
Definition: tetrahedronI.H:101
boundBox bounds() const
Calculate the bounding box.
Definition: tetrahedron.C:340
barycentric pointToBarycentric(const point &pt) const
Calculate the barycentric coordinates from the given point.
Definition: tetrahedronI.H:274
void gradNiGradNj(tensorField &buffer) const
Definition: tetrahedron.C:315
pointHit nearestPoint(const point &p) const
Return nearest point to p on tetrahedron. Is p itself.
Definition: tetrahedronI.H:329
void gradNiDotGradNj(scalarField &buffer) const
Definition: tetrahedron.C:267
Point randomPoint(Random &rndGen) const
Return a random point in the tetrahedron from a.
Definition: tetrahedronI.H:244
volScalarField & p
vector Sc() const
Definition: tetrahedronI.H:149
Namespace for OpenFOAM.