TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Tetraedre.h
1/****************************************************************************
2* Copyright (c) 2024, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef Tetraedre_included
17#define Tetraedre_included
18
19#include <Elem_geom_base.h>
20#include <Linear_algebra_tools.h>
21
22/*! @brief Tetraedre class — represents the tetrahedral geometric element.
23 *
24 * A tetrahedron is a polyhedron with 4 faces, 4 vertices and
25 * a single face type having 3 vertices per face.
26 *
27 * @sa Elem_geom_base Elem_geom, This element is usable in 3D
28 */
29template <typename _SIZE_>
31{
32
33 Declare_instanciable_32_64(Tetraedre_32_64);
34
35public :
36 using int_t = _SIZE_;
37 using IntTab_t = IntTab_T<_SIZE_>;
38 using SmallArrOfTID_t = SmallArrOfTID_T<_SIZE_>;
39 using DoubleVect_t = DoubleVect_T<_SIZE_>;
40 using DoubleTab_t = DoubleTab_T<_SIZE_>;
42
43
44 inline int face_sommet(int i, int j) const override;
45 inline int face_sommet0(int i) const;
46 inline int face_sommet1(int i) const;
47 inline int face_sommet2(int i) const;
48 inline int face_sommet3(int i) const;
49 inline int nb_som() const override { return 4; }
50 inline int nb_faces(int=0) const override;
51 inline int nb_som_face(int=0) const override;
52 inline bool est_structure() const override { return false; }
53 const Nom& nom_lml() const override;
54 int contient(const ArrOfDouble& pos, int_t elem) const override;
55 int contient(const SmallArrOfTID_t& soms, int_t elem) const override;
56 inline Type_Face type_face(int=0) const override;
57 void calculer_volumes(DoubleVect_t& vols) const override;
58 void calculer_normales(const IntTab_t& faces_sommets , DoubleTab_t& face_normales) const override;
59
60 int get_tab_faces_sommets_locaux(IntTab& faces_som_local) const override;
61 void get_tab_aretes_sommets_locaux(IntTab& aretes_som_local) const override;
62
63 static inline void matrice_base_tetraedre(const IntTab& polys,
64 const DoubleTab& coords,
65 int num_elem,
66 Matrice33& m,
67 Vecteur3& origine);
68 static inline void matrice_base_tetraedre(const IntTab& polys,
69 const DoubleTab& coords,
70 int num_elem,
71 Matrice33& m);
72// static double coord_bary(const IntTab& polys,
73// const DoubleTab& coords,
74// const Vecteur3& point,
75// int le_poly,
76// Vecteur3& coord_bary,
77// double epsilon = 0.);
78
79protected:
80 // Members herited from top classes:
82 using Elem_geom_base_32_64<_SIZE_>::mon_dom;
83
84};
85
86
87/*! @brief Returns the index of the j-th vertex of the i-th face of the element.
88 *
89 * @param (int i) a face index
90 * @param (int j) a vertex index
91 * @return (int) the index of the j-th vertex of the i-th face
92 */
93template <typename _SIZE_>
94inline int Tetraedre_32_64<_SIZE_>::face_sommet(int i, int j) const
95{
96 assert(i<4);
97 switch(i)
98 {
99 case 0:
100 return face_sommet0(j);
101 case 1:
102 return face_sommet1(j);
103 case 2:
104 return face_sommet2(j);
105 case 3:
106 return face_sommet3(j);
107 default :
108 return -1;
109 }
110}
111
112
113/*! @brief Returns the number of faces of the specified type that the geometric element has.
114 *
115 * @param (int i) the face type
116 * @return (int) the number of faces of type i
117 */
118template <typename _SIZE_>
120{
121 assert(i==0);
122 return 4;
123}
124
125
126/*! @brief Returns the number of vertices of faces of the specified type.
127 *
128 * @param (int i) the face type
129 * @return (int) the number of vertices of faces of type i
130 */
131template <typename _SIZE_>
133{
134 assert(i==0);
135 return 3;
136}
137
138
139/*! @brief Returns the index of the i-th vertex of face 0.
140 *
141 * @param (int i) the vertex index to return
142 * @return (int) the index of the i-th vertex of face 0
143 */
144template <typename _SIZE_>
146{
147 //face_sommet0(0)=1;
148 //face_sommet0(1)=2;
149 //face_sommet0(2)=3;
150 assert(i>=0);
151 assert(i<3);
152 return (i+1);
153}
154
155
156/*! @brief Returns the index of the i-th vertex of face 1.
157 *
158 * @param (int i) the vertex index to return
159 * @return (int) the index of the i-th vertex of face 1
160 */
161template <typename _SIZE_>
163{
164 //face_sommet0(0)=2;
165 //face_sommet1(1)=3;
166 //face_sommet2(2)=0;
167 assert(i>=0);
168 assert(i<3);
169 return (i+2)%4;
170}
171
172
173/*! @brief Returns the index of the i-th vertex of face 2.
174 *
175 * @param (int i) the vertex index to return
176 * @return (int) the index of the i-th vertex of face 2
177 */
178template <typename _SIZE_>
180{
181 //face_sommet2(0)=3;
182 //face_sommet2(1)=0;
183 //face_sommet2(2)=1;
184 assert(i>=0);
185 assert(i<3);
186 return (i+3)%4;
187}
188
189
190/*! @brief Returns the index of the i-th vertex of face 3.
191 *
192 * @param (int i) the vertex index to return
193 * @return (int) the index of the i-th vertex of face 3
194 */
195template <typename _SIZE_>
197{
198 //face_sommet2(0)=0;
199 //face_sommet2(1)=1;
200 //face_sommet2(2)=2;
201 assert(i>=0);
202 assert(i<3);
203 return (i);
204}
205
206
207/*! @brief Returns the i-th face type.
208 *
209 * A tetrahedron has only one face type.
210 *
211 * @param (int i) the rank of the face type to return
212 * @return (Type_Face) a face type
213 */
214template <typename _SIZE_>
215inline Type_Face Tetraedre_32_64<_SIZE_>::type_face(int i) const
216{
217 assert(i==0);
218 return Type_Face::triangle_3D;
219}
220
221/*! @brief Fills matrix m with the three basis vectors of the requested tetrahedron (the first vertex of the tetra is taken as origin).
222 *
223 * polys is the array of domain elements, coords the coordinate array,
224 * num_elem the index of the tetrahedron to compute.
225 * m is filled with the matrix m(i,j) = coord(polys(num_elem, j+1), i) - coord(polys(num_elem, 0), i)
226 *
227 */
228template <typename _SIZE_>
230 const DoubleTab& coords,
231 int num_elem,
232 Matrice33& m)
233{
234 const int som0 = polys(num_elem, 0);
235 const int som1 = polys(num_elem, 1);
236 const int som2 = polys(num_elem, 2);
237 const int som3 = polys(num_elem, 3);
238 const double x0 = coords(som0, 0);
239 const double y0 = coords(som0, 1);
240 const double z0 = coords(som0, 2);
241 // Matrix of the three basis vectors of the tetra (origin at vertex 0)
242 m(0,0) = coords(som1,0) - x0;
243 m(1,0) = coords(som1,1) - y0;
244 m(2,0) = coords(som1,2) - z0;
245 m(0,1) = coords(som2,0) - x0;
246 m(1,1) = coords(som2,1) - y0;
247 m(2,1) = coords(som2,2) - z0;
248 m(0,2) = coords(som3,0) - x0;
249 m(1,2) = coords(som3,1) - y0;
250 m(2,2) = coords(som3,2) - z0;
251}
252
253/*! @brief Same as the previous overload, but also fills "origine" with the coordinates of the first vertex.
254 *
255 */
256template <typename _SIZE_>
258 const DoubleTab& coords,
259 int num_elem,
260 Matrice33& m,
261 Vecteur3& origine)
262{
263 const int som0 = polys(num_elem, 0);
264 const int som1 = polys(num_elem, 1);
265 const int som2 = polys(num_elem, 2);
266 const int som3 = polys(num_elem, 3);
267 const double x0 = coords(som0, 0);
268 const double y0 = coords(som0, 1);
269 const double z0 = coords(som0, 2);
270 // Matrix of the three basis vectors of the tetra (origin at vertex 0)
271 m(0,0) = coords(som1,0) - x0;
272 m(1,0) = coords(som1,1) - y0;
273 m(2,0) = coords(som1,2) - z0;
274 m(0,1) = coords(som2,0) - x0;
275 m(1,1) = coords(som2,1) - y0;
276 m(2,1) = coords(som2,2) - z0;
277 m(0,2) = coords(som3,0) - x0;
278 m(1,2) = coords(som3,1) - y0;
279 m(2,2) = coords(som3,2) - z0;
280 origine[0] = x0;
281 origine[1] = y0;
282 origine[2] = z0;
283}
284
285
286using Tetraedre = Tetraedre_32_64<int>;
287using Tetraedre_64 = Tetraedre_32_64<trustIdType>;
288
289#endif
class Domaine_32_64 A Domain is a mesh composed of a set of geometric elements of the same type.
Definition Domaine.h:62
Class Elem_geom_base This class is the base class for the definition of elements.
A 3x3 matrix.
Definition Matrice33.h:28
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
static int dimension
Definition Objet_U.h:94
Tetraedre class — represents the tetrahedral geometric element.
Definition Tetraedre.h:31
static void matrice_base_tetraedre(const IntTab &polys, const DoubleTab &coords, int num_elem, Matrice33 &m, Vecteur3 &origine)
Same as the previous overload, but also fills "origine" with the coordinates of the first vertex.
Definition Tetraedre.h:257
Type_Face type_face(int=0) const override
Returns the i-th face type.
Definition Tetraedre.h:215
void calculer_volumes(DoubleVect_t &vols) const override
Computes the volumes of the elements of the associated domain.
int contient(const SmallArrOfTID_t &soms, int_t elem) const override
Returns 1 if the vertices specified by "som" are the vertices of element "element".
int contient(const ArrOfDouble &pos, int_t elem) const override
Returns 1 if element "ielem" of the domain associated with this geometric element contains the point ...
int face_sommet3(int i) const
Returns the index of the i-th vertex of face 3.
Definition Tetraedre.h:196
int nb_som_face(int=0) const override
Returns the number of vertices of faces of the specified type.
Definition Tetraedre.h:132
static void matrice_base_tetraedre(const IntTab &polys, const DoubleTab &coords, int num_elem, Matrice33 &m)
Fills matrix m with the three basis vectors of the requested tetrahedron (the first vertex of the tet...
Definition Tetraedre.h:229
Domaine_32_64< _SIZE_ > Domaine_t
Definition Tetraedre.h:41
int face_sommet2(int i) const
Returns the index of the i-th vertex of face 2.
Definition Tetraedre.h:179
int get_tab_faces_sommets_locaux(IntTab &faces_som_local) const override
See ElemGeomBase::get_tab_faces_sommets_locaux.
int nb_som() const override
Nb of vertices for the element.
Definition Tetraedre.h:49
bool est_structure() const override
Definition Tetraedre.h:52
int face_sommet(int i, int j) const override
Returns the index of the j-th vertex of the i-th face of the element.
Definition Tetraedre.h:94
IntTab_T< _SIZE_ > IntTab_t
Definition Tetraedre.h:37
int face_sommet1(int i) const
Returns the index of the i-th vertex of face 1.
Definition Tetraedre.h:162
void get_tab_aretes_sommets_locaux(IntTab &aretes_som_local) const override
Same as Elem_geom_base::get_tab_faces_sommets_locaux but for edges: aretes_som_local.
const Nom & nom_lml() const override
Returns the LML name of a tetrahedron = "TETRA4".
Definition Tetraedre.cpp:50
DoubleTab_T< _SIZE_ > DoubleTab_t
Definition Tetraedre.h:40
SmallArrOfTID_T< _SIZE_ > SmallArrOfTID_t
Definition Tetraedre.h:38
int face_sommet0(int i) const
Returns the index of the i-th vertex of face 0.
Definition Tetraedre.h:145
DoubleVect_T< _SIZE_ > DoubleVect_t
Definition Tetraedre.h:39
void calculer_normales(const IntTab_t &faces_sommets, DoubleTab_t &face_normales) const override
Computes the face normals of the elements of the associated domain.
int nb_faces(int=0) const override
Returns the number of faces of the specified type that the geometric element has.
Definition Tetraedre.h:119