TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Hexaedre.cpp
1/****************************************************************************
2* Copyright (c) 2025, 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#include <Hexaedre.h>
17#include <Domaine.h>
18
19// Vertex and face numbering convention
20// sommets faces 5(face z=1)
21// 6------7 *------*
22// /| /| /| 4 /|
23// 2------3 | *------* |
24// | | | | |0| |3|
25// | 4----|-5 | *----|-*
26// |/ |/ |/ 1 |/
27// 0------1 *------*
28// 2(face z=0)
29static int faces_sommets_hexa[6][4] =
30{
31 { 0, 2, 4, 6 },
32 { 0, 1, 4, 5 },
33 { 0, 1, 2, 3 },
34 { 1, 3, 5, 7 },
35 { 2, 3, 6, 7 },
36 { 4, 5, 6, 7 }
37};
38
39Implemente_instanciable_32_64(Hexaedre_32_64,"Hexaedre",Elem_geom_base_32_64<_T_>);
40
41
42/*! @brief Does nothing.
43 *
44 * @param s An output stream.
45 * @return The output stream.
46 */
47template <typename _SIZE_>
49{
50 return s;
51}
52
53
54/*! @brief Does nothing.
55 *
56 * @param s An input stream.
57 * @return The input stream.
58 */
59template <typename _SIZE_>
61{
62 return s;
63}
64
65/*! @brief Reorders the vertices of the hexahedron.
66 */
67template <typename _SIZE_>
69{
70 if (this->reordonner_elem()==-1)
71 {
72 Cerr << "This mesh is not composed of regular hexahedra\n";
73 Cerr << "This seems to be VEF hexahedra (Hexaedre_VEF)\n";
74 Cerr << "Check your mesh." << finl;
76 }
77}
78
79/*! @brief Reorders the vertices of the hexahedron element.
80 *
81 * @return 0 on success, -1 if the mesh is not composed of regular hexahedra.
82 */
83template <typename _SIZE_>
85{
86 Domaine_t& domaine = this->mon_dom.valeur();
87 const DoubleTab_t& dom_coord = domaine.les_sommets();
88 IntTab_t& elem = domaine.les_elems();
89 SmallArrOfTID_t S(8);
90 SmallArrOfTID_t NS(8);
91 double coord[8][3];
92 double xmin[3];
93 const int_t nb_elem = domaine.nb_elem();
94 const int delta[3] = {1, 2, 4};
95 trustIdType changed_count = 0;
96
97 for (int_t num_poly = 0; num_poly < nb_elem; num_poly++)
98 {
99 xmin[0] = xmin[1] = xmin[2] = 1e40;
100 for(int i=0; i<8; i++)
101 {
102 int_t s = elem(num_poly,i);
103 S[i] = s;
104 NS[i] = -1;
105 for(int j=0; j<3; j++)
106 {
107 double x = dom_coord(s, j);
108 coord[i][j] = x;
109 if (x < xmin[j])
110 xmin[j] = x;
111 }
112 }
113
114 // For each vertex, find its rank within the element
115 // based on its coordinates
116 for (int i=0; i<8; i++)
117 {
118 int num_sommet = 0;
119 for (int j=0; j<3; j++)
120 {
121 double x = coord[i][j];
122 if (!est_egal(x, xmin[j]))
123 num_sommet += delta[j];
124 }
125 if (NS[num_sommet] == -1)
126 NS[num_sommet] = S[i];
127 else
128 return -1;
129 }
130 // Is this a regular hexahedron?
131 if (min_array(NS)==-1)
132 return -1;
133 // Have all vertices been found?
134 int updated = 0;
135 for(int i=0; i<8; i++)
136 {
137 if (S[i] != NS[i])
138 updated = 1;
139 elem(num_poly, i) = NS[i];
140 }
141 if (updated)
142 changed_count++;
143 }
144 changed_count = Process::mp_sum(changed_count);
146 Cerr << "Hexaedre_32_64<_SIZE_>::reordonner : " << changed_count << " elements reversed" << finl;
147 return 0;
148}
149
150/*! @brief Returns the LML name of a hexahedron = "VOXEL8".
151 *
152 * @return Always equal to "VOXEL8".
153 */
154template <typename _SIZE_>
156{
157 static Nom nom="VOXEL8";
158 return nom;
159}
160
161
162/*! @brief Returns 1 if element "element" of the domain associated with this geometric element contains the point
163 *
164 * with coordinates specified by the parameter "pos". Returns 0 otherwise.
165 *
166 * @param pos Coordinates of the point to locate.
167 * @param element Index of the domain element in which to search for the point.
168 * @return 1 if the specified point belongs to element "element", 0 otherwise.
169 */
170template <typename _SIZE_>
171int Hexaedre_32_64<_SIZE_>::contient(const ArrOfDouble& pos, int_t element ) const
172{
173 assert(pos.size_array()==3);
174 const Domaine_t& dom=this->mon_dom.valeur();
175 int_t som0 = dom.sommet_elem(element,0),
176 som7 = dom.sommet_elem(element,7);
177 if ( inf_ou_egal(dom.coord(som0,0),pos[0]) && inf_ou_egal(pos[0],dom.coord(som7,0))
178 && inf_ou_egal(dom.coord(som0,1),pos[1]) && inf_ou_egal(pos[1],dom.coord(som7,1))
179 && inf_ou_egal(dom.coord(som0,2),pos[2]) && inf_ou_egal(pos[2],dom.coord(som7,2)) )
180 return 1;
181 else
182 return 0;
183}
184
185
186/*! @brief Returns 1 if the vertices specified by parameter "som" are the vertices of element "element"
187 *
188 * in the domain associated with this geometric element. Returns 0 otherwise.
189 *
190 * @param som Vertex indices to compare with those of element "element".
191 * @param element Index of the domain element whose vertices are to be compared.
192 * @return 1 if the specified vertices are those of the given element, 0 otherwise.
193 */
194template <typename _SIZE_>
196{
197 const Domaine_t& domaine=this->mon_dom.valeur();
198 if((domaine.sommet_elem(element,0)==som[0])&&
199 (domaine.sommet_elem(element,1)==som[1])&&
200 (domaine.sommet_elem(element,2)==som[2])&&
201 (domaine.sommet_elem(element,3)==som[3])&&
202 (domaine.sommet_elem(element,4)==som[4])&&
203 (domaine.sommet_elem(element,5)==som[5])&&
204 (domaine.sommet_elem(element,6)==som[6])&&
205 (domaine.sommet_elem(element,7)==som[7]))
206 return 1;
207 else
208 return 0;
209}
210
211/*! @brief Computes the volumes of the elements of the associated domain.
212 *
213 * @param volumes Vector to fill with the volumes of domain elements.
214 */
215template <typename _SIZE_>
217{
218 const Domaine_t& domaine=this->mon_dom.valeur();
219 double dx,dy,dz;
220 int_t S1,S2,S3,S4;
221
222 int_t size_tot = domaine.nb_elem_tot();
223 assert(volumes.size_totale()==size_tot);
224 for (int_t num_poly=0; num_poly<size_tot; num_poly++)
225 {
226 S1 = domaine.sommet_elem(num_poly,0);
227 S2 = domaine.sommet_elem(num_poly,1);
228 S3 = domaine.sommet_elem(num_poly,2);
229 S4 = domaine.sommet_elem(num_poly,4);
230 dx = domaine.coord(S2,0) - domaine.coord(S1,0);
231 dy = domaine.coord(S3,1) - domaine.coord(S1,1);
232 dz = domaine.coord(S4,2) - domaine.coord(S1,2);
233 volumes[num_poly]= dx*dy*dz;
234 }
235}
236
237/*! @brief Computes the face normals of the elements of the associated domain.
238 *
239 * @param Face_sommets Vertex indices of the faces in the domain vertex list.
240 * @param face_normales Output array to fill with face normals.
241 */
242template <typename _SIZE_>
243void Hexaedre_32_64<_SIZE_>::calculer_normales(const IntTab_t& Face_sommets, DoubleTab_t& face_normales) const
244{
245 const Domaine_t& domaine_geom = this->mon_dom.valeur();
246 const DoubleTab_t& les_coords = domaine_geom.coord_sommets();
247 int_t nbfaces = Face_sommets.dimension(0);
248 double x1,y1,z1,x2,y2,z2;
249 int_t n0,n1,n2;
250 for (int numface=0; numface<nbfaces; numface++)
251 {
252
253 n0 = Face_sommets(numface,0);
254 n1 = Face_sommets(numface,1);
255 n2 = Face_sommets(numface,2);
256
257 x1 = les_coords(n0,0) - les_coords(n1,0);
258 y1 = les_coords(n0,1) - les_coords(n1,1);
259 z1 = les_coords(n0,2) - les_coords(n1,2);
260
261 x2 = les_coords(n2,0) - les_coords(n1,0);
262 y2 = les_coords(n2,1) - les_coords(n1,1);
263 z2 = les_coords(n2,2) - les_coords(n1,2);
264
265 face_normales(numface,0) = (y1*z2 - y2*z1);
266 face_normales(numface,1) = (-x1*z2 + x2*z1);
267 face_normales(numface,2) = (x1*y2 - x2*y1);
268 }
269}
270
271
272/*! @brief See ElemGeomBase::get_tab_faces_sommets_locaux.
273 *
274 */
275template <typename _SIZE_>
277{
278 faces_som_local.resize(6,4);
279 for (int i=0; i<6; i++)
280 for (int j=0; j<4; j++)
281 faces_som_local(i,j) = faces_sommets_hexa[i][j];
282 return 1;
283}
284
285/*! @brief Returns the index of the j-th vertex of the i-th face of the element.
286 *
287 * @param (int i) a face index
288 * @param (int j) a vertex index
289 * @return (int) the index of the j-th vertex of the i-th face
290 */
291template <typename _SIZE_>
293{
294 assert(i<6);
295 switch(i)
296 {
297 case 0:
298 return face_sommet0(j);
299 case 1:
300 return face_sommet1(j);
301 case 2:
302 return face_sommet2(j);
303 case 3:
304 return face_sommet3(j);
305 case 4:
306 return face_sommet4(j);
307 case 5:
308 return face_sommet5(j);
309 default :
310 return -1;
311 }
312}
313
314
315template class Hexaedre_32_64<int>;
316#if INT_is_64_ == 2
317template class Hexaedre_32_64<trustIdType>;
318#endif
319
const DoubleTab_t & coord_sommets() const
Definition Domaine.h:112
double coord(int_t i, int j) const
Definition Domaine.h:110
int_t sommet_elem(int_t i, int j) const
Returns the (global) number of the j-th vertex of the i-th element.
Definition Domaine.h:136
Class Elem_geom_base This class is the base class for the definition of elements.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Class Hexaedre: represents a geometric element with 6 faces, 8 vertices, and.
Definition Hexaedre.h:29
int reordonner_elem()
Reorders the vertices of the hexahedron element.
Definition Hexaedre.cpp:84
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.
Definition Hexaedre.cpp:243
int contient(const ArrOfDouble &pos, int_t elem) const override
Returns 1 if element "element" of the domain associated with this geometric element contains the poin...
Definition Hexaedre.cpp:171
DoubleVect_T< _SIZE_ > DoubleVect_t
Definition Hexaedre.h:37
int face_sommet1(int i) const
Returns the index of the i-th vertex of face 1.
Definition Hexaedre.h:114
_SIZE_ int_t
Definition Hexaedre.h:34
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 Hexaedre.cpp:292
int face_sommet2(int i) const
Returns the index of the i-th vertex of face 2.
Definition Hexaedre.h:132
int face_sommet0(int i) const
Returns the index of the i-th vertex of face 0.
Definition Hexaedre.h:96
void calculer_volumes(DoubleVect_t &vols) const override
Computes the volumes of the elements of the associated domain.
Definition Hexaedre.cpp:216
int face_sommet4(int i) const
Returns the index of the i-th vertex of face 4.
Definition Hexaedre.h:168
int get_tab_faces_sommets_locaux(IntTab &faces_som_local) const override
See ElemGeomBase::get_tab_faces_sommets_locaux.
Definition Hexaedre.cpp:276
Domaine_32_64< _SIZE_ > Domaine_t
Definition Hexaedre.h:39
const Nom & nom_lml() const override
Returns the LML name of a hexahedron = "VOXEL8".
Definition Hexaedre.cpp:155
int face_sommet5(int i) const
Returns the index of the i-th vertex of face 5.
Definition Hexaedre.h:186
void reordonner() override
Reorders the vertices of the hexahedron.
Definition Hexaedre.cpp:68
SmallArrOfTID_T< _SIZE_ > SmallArrOfTID_t
Definition Hexaedre.h:36
DoubleTab_T< _SIZE_ > DoubleTab_t
Definition Hexaedre.h:38
int face_sommet3(int i) const
Returns the index of the i-th vertex of face 3.
Definition Hexaedre.h:150
IntTab_T< _SIZE_ > IntTab_t
Definition Hexaedre.h:35
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
static double mp_sum(double)
Computes the sum of x over all processors in the current group.
Definition Process.cpp:145
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
Definition Process.cpp:82
Base class for output streams.
Definition Sortie.h:52
_SIZE_ size_array() const
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61