tetrahedron.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) 2011-2023 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 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef tetrahedron_H
39 #define tetrahedron_H
40 
41 #include "point.H"
42 #include "primitiveFieldsFwd.H"
43 #include "pointHit.H"
44 #include "Random.H"
45 #include "FixedList.H"
46 #include "UList.H"
47 #include "triPointRef.H"
48 #include "boundBox.H"
49 #include "barycentric.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 class Istream;
57 class Ostream;
58 
59 // Forward declaration of friend functions and operators
60 
61 template<class Point, class PointRef> class tetrahedron;
62 
63 template<class Point, class PointRef>
64 inline Istream& operator>>
65 (
66  Istream&,
68 );
69 
70 template<class Point, class PointRef>
71 inline Ostream& operator<<
72 (
73  Ostream&,
75 );
76 
77 /*---------------------------------------------------------------------------*\
78  Class tetrahedron Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 template<class Point, class PointRef>
82 class tetrahedron
83 {
84  // Private Data
85 
86  PointRef a_, b_, c_, d_;
87 
88 
89 public:
90 
91  // Member constants
92 
93  enum
94  {
95  nVertices = 4, // Number of vertices in tetrahedron
96  nEdges = 6 // Number of edges in tetrahedron
97  };
98 
99 
100  // Constructors
101 
102  //- Construct from points
103  inline tetrahedron
104  (
105  const Point& a,
106  const Point& b,
107  const Point& c,
108  const Point& d
109  );
110 
111  //- Construct from four points in the list of points
112  inline tetrahedron
113  (
114  const UList<Point>&,
115  const FixedList<label, 4>& indices
116  );
117 
118  //- Construct from Istream
119  inline tetrahedron(Istream&);
120 
121 
122  // Member Functions
123 
124  // Access
125 
126  //- Return vertices
127  inline const Point& a() const;
128 
129  inline const Point& b() const;
130 
131  inline const Point& c() const;
132 
133  inline const Point& d() const;
134 
135  //- Return i-th face
136  inline triPointRef tri(const label facei) const;
137 
138  // Properties
139 
140  //- Return face normal
141  inline vector Sa() const;
142 
143  inline vector Sb() const;
144 
145  inline vector Sc() const;
146 
147  inline vector Sd() const;
148 
149  //- Return centre (centroid)
150  inline Point centre() const;
151 
152  //- Return volume
153  inline scalar mag() const;
154 
155  //- Return the circum centre and radius
156  inline Tuple2<Point, scalar> circumSphere() const;
157 
158  //- Return quality: Ratio of tetrahedron and circum-sphere
159  // volume, scaled so that a regular tetrahedron has a
160  // quality of 1
161  inline scalar quality() const;
162 
163  //- Return a random point in the tetrahedron from a
164  // uniform distribution
165  inline Point randomPoint(Random& rndGen) const;
166 
167  //- Calculate the point from the given barycentric coordinates.
168  inline Point barycentricToPoint(const barycentric& bary) const;
169 
170  //- Calculate the barycentric coordinates from the given point
171  inline barycentric pointToBarycentric(const point& pt) const;
172 
173  //- Calculate the barycentric coordinates from the given point.
174  // Returns the determinant.
175  inline scalar pointToBarycentric
176  (
177  const point& pt,
178  barycentric& bary
179  ) const;
180 
181  //- Return nearest point to p on tetrahedron. Is p itself
182  // if inside.
183  inline pointHit nearestPoint(const point& p) const;
184 
185  //- Return true if point is inside tetrahedron
186  inline bool inside(const point& pt) const;
187 
188  //- Calculate the bounding box
189  inline boundBox bounds() const;
190 
191 
192  // IOstream Operators
193 
194  friend Istream& operator>> <Point, PointRef>
195  (
196  Istream&,
197  tetrahedron&
198  );
199 
200  friend Ostream& operator<< <Point, PointRef>
201  (
202  Ostream&,
203  const tetrahedron&
204  );
205 };
206 
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 } // End namespace Foam
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 #include "tetrahedronI.H"
215 
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217 
218 #endif
219 
220 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Random number generator.
Definition: Random.H:58
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:63
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:59
A tetrahedron primitive.
Definition: tetrahedron.H:82
barycentric pointToBarycentric(const point &pt) const
Calculate the barycentric coordinates from the given point.
Definition: tetrahedronI.H:238
vector Sd() const
Definition: tetrahedronI.H:156
triPointRef tri(const label facei) const
Return i-th face.
Definition: tetrahedronI.H:101
boundBox bounds() const
Calculate the bounding box.
Definition: tetrahedronI.H:463
const Point & a() const
Return vertices.
Definition: tetrahedronI.H:72
Point centre() const
Return centre (centroid)
Definition: tetrahedronI.H:163
vector Sc() const
Definition: tetrahedronI.H:149
bool inside(const point &pt) const
Return true if point is inside tetrahedron.
Definition: tetrahedronI.H:387
vector Sb() const
Definition: tetrahedronI.H:142
Tuple2< Point, scalar > circumSphere() const
Return the circum centre and radius.
Definition: tetrahedronI.H:178
const Point & c() const
Definition: tetrahedronI.H:86
scalar mag() const
Return volume.
Definition: tetrahedronI.H:170
pointHit nearestPoint(const point &p) const
Return nearest point to p on tetrahedron. Is p itself.
Definition: tetrahedronI.H:293
Point randomPoint(Random &rndGen) const
Return a random point in the tetrahedron from a.
Definition: tetrahedronI.H:218
Point barycentricToPoint(const barycentric &bary) const
Calculate the point from the given barycentric coordinates.
Definition: tetrahedronI.H:228
tetrahedron(const Point &a, const Point &b, const Point &c, const Point &d)
Construct from points.
Definition: tetrahedronI.H:34
const Point & b() const
Definition: tetrahedronI.H:79
scalar quality() const
Return quality: Ratio of tetrahedron and circum-sphere.
Definition: tetrahedronI.H:208
const Point & d() const
Definition: tetrahedronI.H:93
vector Sa() const
Return face normal.
Definition: tetrahedronI.H:135
A triangle primitive used to calculate face areas and swept volumes.
Definition: triangle.H:80
Namespace for OpenFOAM.
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
Forward declarations of the specialisations of Field<T> for scalar, vector and tensor.
volScalarField & p
Random rndGen(label(0))