TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Aretes.cpp
1/****************************************************************************
2* Copyright (c) 2022, 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 <Aretes.h>
17#include <Domaine_VDF.h>
18
19Implemente_instanciable(Aretes,"Aretes",Objet_U);
20
21
22// printOn et readOn
23
25{
26 s << "Aretes " << finl;
27 s << faces_ << finl;
28 s << type1_ << finl;
29 s << type2_ << finl;
30 return s;
31}
32
34{
35 return s ;
36}
37
38/*! @brief affecte a l'arete numero les faces f1, f2, f3, f4
39 *
40 * l'arete est de type2_ type ou :
41 * type2_ = -1 si arete coin
42 * type2_ = 0 si arete bord
43 * type2_ = 1 si arete mixte
44 * type2_ = 2 si arete interne
45 * l'arete est de type1_ dir ou :
46 * type1_ = 0 si arete XY
47 * type1_ = 1 si arete XZ
48 * type1_ = 2 si arete YZ
49 * En dimension 2 il n'y a que des aretes XY
50 *
51 */
52void Aretes::affecter(int& numero_a, int dir, int type, int nb_face,
53 int f1, int f2, int f3, int f4, const ArrOfInt& est_une_plaque)
54{
55 int nb_plaques = 0;
56 nb_plaques += f1>=0 ? est_une_plaque[f1] : 0;
57 nb_plaques += f2>=0 ? est_une_plaque[f2] : 0;
58 nb_plaques += f3>=0 ? est_une_plaque[f3] : 0;
59 nb_plaques += f4>=0 ? est_une_plaque[f4] : 0;
60 int coin = -1 ;
61 int bord = 0 ;
62 if (type>0)
63 {
64 if (nb_plaques!=0) return;
65 if( (f1<nb_face) || (f2<nb_face) || (f3<nb_face) || (f4<nb_face) )
66 numero_a++;
67 else
68 return;
69 }
70 if (type==bord)
71 {
72 if( (f1<nb_face) || (f2<nb_face) || (f3<nb_face) )
73 numero_a++;
74 else
75 return;
76 }
77 if (type==coin)
78 {
79 if( (f1<nb_face) && (f2<nb_face) && (f3<nb_face) && (f4<nb_face) )
80 numero_a++;
81 else
82 return;
83 }
84
85 faces_(numero_a, 0)=f1;
86 faces_(numero_a, 1)=f2;
87 faces_(numero_a, 2)=f3;
88 faces_(numero_a, 3)=f4;
89 type1_(numero_a)=dir;
90 type2_(numero_a)=type;
91
92 if(type >0)
93 {
94 assert(faces_(numero_a, 0) !=-1);
95 assert(faces_(numero_a, 1) !=-1);
96 assert(faces_(numero_a, 2) !=-1);
97 assert(faces_(numero_a, 3) !=-1);
98 }
99}
100
102{
103 const IntTab& so = domaine.face_sommets();
104 const DoubleTab& co = domaine.domaine().les_sommets();
105 DoubleTab& xa_ = domaine.xa();
106 int i,j,k;
107 int f0=-1,f1=-1,s00,s01,s10,s11;
108 int type;
109 int nb_aretes = faces_.dimension(0);
110 //const IntVect& orient = domaine.orientation();
111 // Calcul des ccordonnees de l'arete
112 if(dimension==2)
113 {
114 xa_.resize(nb_aretes,2);
115 for(i=0; i<nb_aretes; i++)
116 {
117 type = type2_(i);
118 if((type==2)||(type==1)) // arete interne ou mixte
119 {
120 f0 = faces_(i,0);
121 s00 = so(f0,0);
122 s01 = so(f0,1);
123 f1 = faces_(i,1);
124 s10 = so(f1,0);
125 s11 = so(f1,1);
126 if((s00==s10)||(s00==s11))
127 {
128 xa_(i,0) = co(s00,0);
129 xa_(i,1) = co(s00,1);
130 }
131 else if((s01==s10)||(s01==s11))
132 {
133 xa_(i,0) = co(s01,0);
134 xa_(i,1) = co(s01,1);
135 }
136 else
137 {
138 Cerr<<"Erreur on a pas trouve de sommets communs"<<finl;
139 exit();
140 }
141 }
142 else if((type == 0)||(type == -1)) // arete bord ou coin
143 {
144 for(j=0; j<4; j++)
145 {
146 f0=faces_(i,j);
147 if(f0!=-1) break;
148 }
149 assert(j<4);
150 k=j+1;
151 s00 = so(f0,0);
152 s01 = so(f0,1);
153 for(j=k; j<4; j++)
154 {
155 f1=faces_(i,j);
156 if(f1!=-1) break;
157 }
158 assert(j<4);
159 s10 = so(f1,0);
160 s11 = so(f1,1);
161 if((s00==s10)||(s00==s11))
162 {
163 xa_(i,0) = co(s00,0);
164 xa_(i,1) = co(s00,1);
165 }
166 else if((s01==s10)||(s01==s11))
167 {
168 xa_(i,0) = co(s01,0);
169 xa_(i,1) = co(s01,1);
170 }
171 else
172 {
173 Cerr<<"Erreur on a pas trouve de sommets communs"<<finl;
174 exit();
175 }
176 }
177 }
178 }
179 else if(dimension==3)
180 {
181 xa_.resize(nb_aretes,3);
182 for(i=0; i<nb_aretes; i++)
183 {
184 type = type2_(i);
185 if((type==2)||(type==1)) // arete interne ou mixte
186 {
187 f0 = faces_(i,0);
188 f1 = faces_(i,1);
189 int s0,s1,s0j;
190 int deux;
191 for(j=0; j<4; j++)
192 {
193 s0j=so(f0,j);
194 for(k=0; k<4; k++)
195 if(s0j==so(f1,k)) break;
196 if(k<4) break;
197 }
198 assert(j<4);
199 s0 = s0j;
200 deux = j+1;
201 for(j=deux; j<4; j++)
202 {
203 s0j=so(f0,j);
204 for(k=0; k<4; k++)
205 if(s0j==so(f1,k)) break;
206 if(k<4) break;
207 }
208 assert(j<4);
209 s1 = s0j;
210 xa_(i,0) = (co(s0,0)+co(s1,0))/2.0;
211 xa_(i,1) = (co(s0,1)+co(s1,1))/2.0;
212 xa_(i,2) = (co(s0,2)+co(s1,2))/2.0;
213 }
214 else if((type == 0)||(type == -1)) // arete bord ou coin
215 {
216 int f,fdeux;
217 int s0,s1,s0j;
218 int deux;
219 for(f=0; f<4; f++)
220 {
221 f0=faces_(i,f);
222 if(f0!=-1) break;
223 }
224 assert(f<4);
225 fdeux=f+1;
226 for(f=fdeux; f<4; f++)
227 {
228 f1=faces_(i,f);
229 if(f1!=-1) break;
230 }
231 for(j=0; j<4; j++)
232 {
233 s0j=so(f0,j);
234 for(k=0; k<4; k++)
235 if(s0j==so(f1,k)) break;
236 if(k<4) break;
237 }
238 assert(j<4);
239 s0 = s0j;
240 deux = j+1;
241 for(j=deux; j<4; j++)
242 {
243 s0j=so(f0,j);
244 for(k=0; k<4; k++)
245 if(s0j==so(f1,k)) break;
246 if(k<4) break;
247 }
248 assert(j<4);
249 s1 = s0j;
250 xa_(i,0) = (co(s0,0)+co(s1,0))/2.0;
251 xa_(i,1) = (co(s0,1)+co(s1,1))/2.0;
252 xa_(i,2) = (co(s0,2)+co(s1,2))/2.0;
253 }
254 }
255 }
256}
257
258/*! @brief Dimensionne les tableaux.
259 *
260 */
262{
263 faces_.resize(n,4);
264 type1_.resize(n);
265 type2_.resize(n) ;
266}
267
268/*! @brief appelee par trier Echange les aretes a1 et a2
269 *
270 */
271void Aretes::swap(int a1, int a2)
272{
273 int tmp;
274 tmp = faces_(a1, 0);
275 faces_(a1, 0) = faces_(a2, 0);
276 faces_(a2, 0)=tmp;
277 tmp = faces_(a1, 1);
278 faces_(a1, 1) = faces_(a2, 1);
279 faces_(a2, 1)=tmp;
280 tmp = faces_(a1, 2);
281 faces_(a1, 2) = faces_(a2, 2);
282 faces_(a2, 2)=tmp;
283 tmp = faces_(a1, 3);
284 faces_(a1, 3) = faces_(a2, 3);
285 faces_(a2, 3)=tmp;
286 tmp = type1_(a1);
287 type1_(a1)=type1_(a2);
288 type1_(a2)=tmp;
289 tmp = type2_(a1);
290 type2_(a1)=type2_(a2);
291 type2_(a2)=tmp;
292}
293/*! @brief reoordonne le tableaux des aretes avec d'abord les aretes coins (elles n'ont que deux faces)
294 *
295 * puis les aretes bord (elles ont trois faces dont deux de bord)
296 * puis les aretes mixte (elles ont quatre faces dont deux de bord)
297 * puis les aretes_internes (elles ont quatre faces internes)
298 *
299 */
300void Aretes::trier(int& nb_aretes_coin, int& nb_aretes_bord,
301 int& nb_aretes_mixte, int& nb_aretes_interne)
302{
303 //
304 nb_aretes_coin=nb_aretes_bord=nb_aretes_mixte=nb_aretes_interne=0;
305 int coin = -1 ;
306 int bord = 0 ;
307 int mixte = 1 ;
308 int interne = 2 ;
309 int nb_aretes = type1_.size();
310 int courante=0;
311 int arete;
312 while( (courante<nb_aretes)&&(type2_(courante)==coin) )
313 {
314 courante++;
315 nb_aretes_coin++;
316 }
317 for(arete=courante; arete<nb_aretes; arete++)
318 {
319 if(type2_(arete)==coin)
320 {
321 swap(arete, courante);
322 while( (courante<nb_aretes)&&(type2_(courante)==coin) )
323 {
324 courante++;
325 nb_aretes_coin++;
326 }
327 //arete=courante;
328 }
329 }
330 while( (courante<nb_aretes)&&(type2_(courante)==bord) )
331 {
332 courante++;
333 nb_aretes_bord++;
334 }
335 for(arete=courante; arete<nb_aretes; arete++)
336 {
337 if(type2_(arete)==bord)
338 {
339 swap(arete, courante);
340 assert(type2_(courante) == bord);
341 while( (courante<nb_aretes)&&(type2_(courante)==bord) )
342 {
343 courante++;
344 nb_aretes_bord++;
345 }
346 //arete=courante;
347 }
348 }
349 while( (courante<nb_aretes)&&(type2_(courante)==mixte) )
350 {
351 courante++;
352 nb_aretes_mixte++;
353 }
354 for(arete=courante; arete<nb_aretes; arete++)
355 {
356 if(type2_(arete)==mixte)
357 {
358 swap(arete, courante);
359 assert(faces_(courante, 0) !=-1);
360 assert(faces_(courante, 1) !=-1);
361 assert(faces_(courante, 2) !=-1);
362 assert(faces_(courante, 3) !=-1);
363 while( (courante<nb_aretes)&&(type2_(courante)==mixte) )
364 {
365 courante++;
366 nb_aretes_mixte++;
367 }
368 //arete=courante;
369 }
370 }
371 while( (courante<nb_aretes)&&(type2_(courante)==interne) )
372 {
373 courante++;
374 nb_aretes_interne++;
375 }
376 for(arete=courante; arete<nb_aretes; arete++)
377 {
378 if(type2_(arete)==interne)
379 {
380 swap(arete, courante);
381 assert(faces_(courante, 0) !=-1);
382 assert(faces_(courante, 1) !=-1);
383 assert(faces_(courante, 2) !=-1);
384 assert(faces_(courante, 3) !=-1);
385 while( (courante<nb_aretes)&&(type2_(courante)==interne) )
386 {
387 courante++;
388 nb_aretes_interne++;
389 }
390 //arete=courante;
391 }
392 }
393}
394
395void Aretes::trier_pour_debog(int& nb_aretes_coin, int& nb_aretes_bord,
396 int& nb_aretes_mixte, int& nb_aretes_interne,const DoubleTab&
397 xv)
398{
399
400 ArrOfDouble XVref(dimension),XVref2(dimension);
401 int nb_aretes = type1_.size();
402 int arete;
403 for (int boucle=0; boucle<3; boucle++)
404 {
405 int deb=nb_aretes - nb_aretes_interne;
406 int fin=nb_aretes;
407 if (boucle==1)
408 {
409 fin=deb;
410 deb-=nb_aretes_mixte;
411 }
412 else if (boucle==2)
413 {
414 fin=deb;
415 deb-= nb_aretes_bord;
416 }
417 for ( arete=deb; arete<fin; arete++)
418 {
419 if ((boucle==2)&&(type2_(arete)!=0))
420 {
421 Cerr<<"gros pb "<<arete<<finl;
422 exit();
423 }
424 int ref=faces_(arete,0);
425 for (int i=0; i<dimension; i++) XVref[i]=xv(ref,i);
426 int marq=-1;
427 int ref2;
428 for (int arete2=arete; arete2<fin; arete2++)
429 {
430 ref2=faces_(arete2,0);
431 for (int i=0; i<dimension; i++) XVref2[i]=xv(ref2,i);
432 int test=-1;
433 // int testsa=-1;
434 if (dimension==2)
435 {
436 if (sup_strict(XVref2[1],XVref[1])) test=1;
437 else if ((XVref2[1]==XVref[1])&&(sup_strict(XVref2[0],XVref[0]))) test=0;
438 }
439 else if (dimension==3)
440 {
441 if (XVref2[2]>XVref[2]) test=2;
442 else if (XVref2[2]==XVref[2])
443 {
444 if (XVref2[1]>XVref[1]) test=1;
445 else if ((XVref2[1]==XVref[1])&&(XVref2[0]>XVref[0])) test=0;
446 }
447 }
448 if (test!=-1)
449 {
450 marq=arete2;
451 XVref=XVref2;
452 }
453 }
454 if (marq!=-1) swap(arete,marq);
455 }
456 }
457 for (arete=nb_aretes - nb_aretes_interne; arete<nb_aretes*0; arete++)
458 {
459 Cerr <<me()<<" arete "<<arete<<" "<< faces_(arete,0)<<" "<< faces_(arete,1)<<" "<< faces_(arete,2)<<" "<< faces_(arete,3)<<finl;
460 }
461}
void trier_pour_debog(int &, int &, int &, int &, const DoubleTab &)
Definition Aretes.cpp:395
void affecter(int &, int, int, int, int, int, int, int, const ArrOfInt &)
affecte a l'arete numero les faces f1, f2, f3, f4
Definition Aretes.cpp:52
void calculer_centre_de_gravite(Domaine_VDF &domaine)
Definition Aretes.cpp:101
void dimensionner(int)
Dimensionne les tableaux.
Definition Aretes.cpp:261
void trier(int &, int &, int &, int &)
reoordonne le tableaux des aretes avec d'abord les aretes coins (elles n'ont que deux faces)
Definition Aretes.cpp:300
class Domaine_VDF
Definition Domaine_VDF.h:64
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
static int dimension
Definition Objet_U.h:99
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static int me()
renvoie mon rang dans le groupe de communication courant.
Definition Process.cpp:125
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ size() const
Definition TRUSTVect.tpp:45