1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 A tetrahedron primitive.
30 Ordering of edges needs to be the same for a tetrahedron
31 class, a tetrahedron cell shape model and a tetCell.
37 \*---------------------------------------------------------------------------*/
43 #include "primitiveFieldsFwd.H"
45 #include "cachedRandom.H"
47 #include "FixedList.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 // Forward declaration of friend functions and operators
60 template<class Point, class PointRef> class tetrahedron;
62 template<class Point, class PointRef>
63 inline Istream& operator>>
66 tetrahedron<Point, PointRef>&
69 template<class Point, class PointRef>
70 inline Ostream& operator<<
73 const tetrahedron<Point, PointRef>&
77 /*---------------------------------------------------------------------------*\
78 class tetrahedron Declaration
79 \*---------------------------------------------------------------------------*/
81 template<class Point, class PointRef>
86 PointRef a_, b_, c_, d_;
95 nVertices = 4, // Number of vertices in tetrahedron
96 nEdges = 6 // Number of edges in tetrahedron
102 //- Construct from points
111 //- Construct from four points in the list of points
115 const FixedList<label, 4>& indices
118 //- Construct from Istream
119 inline tetrahedron(Istream&);
127 inline const Point& a() const;
129 inline const Point& b() const;
131 inline const Point& c() const;
133 inline const Point& d() const;
138 //- Return face normal
139 inline vector Sa() const;
141 inline vector Sb() const;
143 inline vector Sc() const;
145 inline vector Sd() const;
147 //- Return centre (centroid)
148 inline Point centre() const;
151 inline scalar mag() const;
153 //- Return circum-centre
154 inline Point circumCentre() const;
156 //- Return circum-radius
157 inline scalar circumRadius() const;
159 //- Return quality: Ratio of tetrahedron and circum-sphere
160 // volume, scaled so that a regular tetrahedron has a
162 inline scalar quality() const;
164 //- Return a random point in the tetrahedron from a
165 // uniform distribution
166 inline Point randomPoint(Random& rndGen) const;
168 //- Return a random point in the tetrahedron from a
169 // uniform distribution
170 inline Point randomPoint(cachedRandom& rndGen) const;
172 //- Calculate the barycentric coordinates of the given
173 // point, in the same order as a, b, c, d. Returns the
174 // determinant of the solution.
175 inline scalar barycentric
181 //- Return nearest point to p on tetrahedron
182 inline pointHit nearestPoint(const point& p) const;
184 //- Return true if point is inside tetrahedron
185 inline bool inside(const point& pt) const;
187 //- Return (min)containment sphere, i.e. the smallest sphere with
188 // all points inside. Returns pointHit with:
189 // - hit : if sphere is equal to circumsphere
191 // - point : centre of sphere
192 // - distance : radius of sphere
193 // - eligiblemiss: false
194 // Tol (small compared to 1, e.g. 1E-9) is used to determine
195 // whether point is inside: mag(pt - ctr) < (1+tol)*radius.
196 pointHit containmentSphere(const scalar tol) const;
198 //- Fill buffer with shape function products
199 void gradNiSquared(scalarField& buffer) const;
201 void gradNiDotGradNj(scalarField& buffer) const;
203 void gradNiGradNi(tensorField& buffer) const;
205 void gradNiGradNj(tensorField& buffer) const;
208 // IOstream operators
210 friend Istream& operator>> <Point, PointRef>
216 friend Ostream& operator<< <Point, PointRef>
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 } // End namespace Foam
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 #include "tetrahedronI.H"
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 # include "tetrahedron.C"
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 // ************************************************************************* //