TrioCFD 1.9.9_beta
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 and 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 Assigns faces f1, f2, f3, f4 to edge numero.
39 *
40 * @brief The edge type2_ is defined as:
41 * type2_ = -1 for a corner edge
42 * type2_ = 0 for a boundary edge
43 * type2_ = 1 for a mixed edge
44 * type2_ = 2 for an internal edge
45 * The edge type1_ dir is defined as:
46 * type1_ = 0 for an XY edge
47 * type1_ = 1 for an XZ edge
48 * type1_ = 2 for a YZ edge
49 * In 2D there are only XY edges.
50 *
51 * @param numero_a Edge index (incremented in place).
52 * @param dir Edge direction type.
53 * @param type Edge category type.
54 * @param nb_face Total number of faces.
55 * @param f1 First face index.
56 * @param f2 Second face index.
57 * @param f3 Third face index.
58 * @param f4 Fourth face index.
59 * @param est_une_plaque Array indicating which faces are plate faces.
60 */
61void Aretes::affecter(int& numero_a, int dir, int type, int nb_face,
62 int f1, int f2, int f3, int f4, const ArrOfInt& est_une_plaque)
63{
64 int nb_plaques = 0;
65 nb_plaques += f1>=0 ? est_une_plaque[f1] : 0;
66 nb_plaques += f2>=0 ? est_une_plaque[f2] : 0;
67 nb_plaques += f3>=0 ? est_une_plaque[f3] : 0;
68 nb_plaques += f4>=0 ? est_une_plaque[f4] : 0;
69 int coin = -1 ;
70 int bord = 0 ;
71 if (type>0)
72 {
73 if (nb_plaques!=0) return;
74 if( (f1<nb_face) || (f2<nb_face) || (f3<nb_face) || (f4<nb_face) )
75 numero_a++;
76 else
77 return;
78 }
79 if (type==bord)
80 {
81 if( (f1<nb_face) || (f2<nb_face) || (f3<nb_face) )
82 numero_a++;
83 else
84 return;
85 }
86 if (type==coin)
87 {
88 if( (f1<nb_face) && (f2<nb_face) && (f3<nb_face) && (f4<nb_face) )
89 numero_a++;
90 else
91 return;
92 }
93
94 faces_(numero_a, 0)=f1;
95 faces_(numero_a, 1)=f2;
96 faces_(numero_a, 2)=f3;
97 faces_(numero_a, 3)=f4;
98 type1_(numero_a)=dir;
99 type2_(numero_a)=type;
100
101 if(type >0)
102 {
103 assert(faces_(numero_a, 0) !=-1);
104 assert(faces_(numero_a, 1) !=-1);
105 assert(faces_(numero_a, 2) !=-1);
106 assert(faces_(numero_a, 3) !=-1);
107 }
108}
109
111{
112 const IntTab& so = domaine.face_sommets();
113 const DoubleTab& co = domaine.domaine().les_sommets();
114 DoubleTab& xa_ = domaine.xa();
115 int i,j,k;
116 int f0=-1,f1=-1,s00,s01,s10,s11;
117 int type;
118 int nb_aretes = faces_.dimension(0);
119 //const IntVect& orient = domaine.orientation();
120 // Compute the edge coordinates
121 if(dimension==2)
122 {
123 xa_.resize(nb_aretes,2);
124 for(i=0; i<nb_aretes; i++)
125 {
126 type = type2_(i);
127 if((type==2)||(type==1)) // internal or mixed edge
128 {
129 f0 = faces_(i,0);
130 s00 = so(f0,0);
131 s01 = so(f0,1);
132 f1 = faces_(i,1);
133 s10 = so(f1,0);
134 s11 = so(f1,1);
135 if((s00==s10)||(s00==s11))
136 {
137 xa_(i,0) = co(s00,0);
138 xa_(i,1) = co(s00,1);
139 }
140 else if((s01==s10)||(s01==s11))
141 {
142 xa_(i,0) = co(s01,0);
143 xa_(i,1) = co(s01,1);
144 }
145 else
146 {
147 Cerr<<"Error: no common vertices found"<<finl;
148 exit();
149 }
150 }
151 else if((type == 0)||(type == -1)) // boundary or corner edge
152 {
153 for(j=0; j<4; j++)
154 {
155 f0=faces_(i,j);
156 if(f0!=-1) break;
157 }
158 assert(j<4);
159 k=j+1;
160 s00 = so(f0,0);
161 s01 = so(f0,1);
162 for(j=k; j<4; j++)
163 {
164 f1=faces_(i,j);
165 if(f1!=-1) break;
166 }
167 assert(j<4);
168 s10 = so(f1,0);
169 s11 = so(f1,1);
170 if((s00==s10)||(s00==s11))
171 {
172 xa_(i,0) = co(s00,0);
173 xa_(i,1) = co(s00,1);
174 }
175 else if((s01==s10)||(s01==s11))
176 {
177 xa_(i,0) = co(s01,0);
178 xa_(i,1) = co(s01,1);
179 }
180 else
181 {
182 Cerr<<"Error: no common vertices found"<<finl;
183 exit();
184 }
185 }
186 }
187 }
188 else if(dimension==3)
189 {
190 xa_.resize(nb_aretes,3);
191 for(i=0; i<nb_aretes; i++)
192 {
193 type = type2_(i);
194 if((type==2)||(type==1)) // internal or mixed edge
195 {
196 f0 = faces_(i,0);
197 f1 = faces_(i,1);
198 int s0,s1,s0j;
199 int deux;
200 for(j=0; j<4; j++)
201 {
202 s0j=so(f0,j);
203 for(k=0; k<4; k++)
204 if(s0j==so(f1,k)) break;
205 if(k<4) break;
206 }
207 assert(j<4);
208 s0 = s0j;
209 deux = j+1;
210 for(j=deux; j<4; j++)
211 {
212 s0j=so(f0,j);
213 for(k=0; k<4; k++)
214 if(s0j==so(f1,k)) break;
215 if(k<4) break;
216 }
217 assert(j<4);
218 s1 = s0j;
219 xa_(i,0) = (co(s0,0)+co(s1,0))/2.0;
220 xa_(i,1) = (co(s0,1)+co(s1,1))/2.0;
221 xa_(i,2) = (co(s0,2)+co(s1,2))/2.0;
222 }
223 else if((type == 0)||(type == -1)) // boundary or corner edge
224 {
225 int f,fdeux;
226 int s0,s1,s0j;
227 int deux;
228 for(f=0; f<4; f++)
229 {
230 f0=faces_(i,f);
231 if(f0!=-1) break;
232 }
233 assert(f<4);
234 fdeux=f+1;
235 for(f=fdeux; f<4; f++)
236 {
237 f1=faces_(i,f);
238 if(f1!=-1) break;
239 }
240 for(j=0; j<4; j++)
241 {
242 s0j=so(f0,j);
243 for(k=0; k<4; k++)
244 if(s0j==so(f1,k)) break;
245 if(k<4) break;
246 }
247 assert(j<4);
248 s0 = s0j;
249 deux = j+1;
250 for(j=deux; j<4; j++)
251 {
252 s0j=so(f0,j);
253 for(k=0; k<4; k++)
254 if(s0j==so(f1,k)) break;
255 if(k<4) break;
256 }
257 assert(j<4);
258 s1 = s0j;
259 xa_(i,0) = (co(s0,0)+co(s1,0))/2.0;
260 xa_(i,1) = (co(s0,1)+co(s1,1))/2.0;
261 xa_(i,2) = (co(s0,2)+co(s1,2))/2.0;
262 }
263 }
264 }
265}
266
267/*! @brief Resizes the arrays.
268 *
269 */
271{
272 faces_.resize(n,4);
273 type1_.resize(n);
274 type2_.resize(n) ;
275}
276
277/*! @brief Called by trier. Swaps edges a1 and a2.
278 *
279 */
280void Aretes::swap(int a1, int a2)
281{
282 int tmp;
283 tmp = faces_(a1, 0);
284 faces_(a1, 0) = faces_(a2, 0);
285 faces_(a2, 0)=tmp;
286 tmp = faces_(a1, 1);
287 faces_(a1, 1) = faces_(a2, 1);
288 faces_(a2, 1)=tmp;
289 tmp = faces_(a1, 2);
290 faces_(a1, 2) = faces_(a2, 2);
291 faces_(a2, 2)=tmp;
292 tmp = faces_(a1, 3);
293 faces_(a1, 3) = faces_(a2, 3);
294 faces_(a2, 3)=tmp;
295 tmp = type1_(a1);
296 type1_(a1)=type1_(a2);
297 type1_(a2)=tmp;
298 tmp = type2_(a1);
299 type2_(a1)=type2_(a2);
300 type2_(a2)=tmp;
301}
302/*! @brief Reorders the edge array: first corner edges (they have only two faces),
303 *
304 * then boundary edges (they have three faces, two of which are boundary),
305 * then mixed edges (they have four faces, two of which are boundary),
306 * then internal edges (they have four internal faces).
307 *
308 */
309void Aretes::trier(int& nb_aretes_coin, int& nb_aretes_bord,
310 int& nb_aretes_mixte, int& nb_aretes_interne)
311{
312 //
313 nb_aretes_coin=nb_aretes_bord=nb_aretes_mixte=nb_aretes_interne=0;
314 int coin = -1 ;
315 int bord = 0 ;
316 int mixte = 1 ;
317 int interne = 2 ;
318 int nb_aretes = type1_.size();
319 int courante=0;
320 int arete;
321 while( (courante<nb_aretes)&&(type2_(courante)==coin) )
322 {
323 courante++;
324 nb_aretes_coin++;
325 }
326 for(arete=courante; arete<nb_aretes; arete++)
327 {
328 if(type2_(arete)==coin)
329 {
330 swap(arete, courante);
331 while( (courante<nb_aretes)&&(type2_(courante)==coin) )
332 {
333 courante++;
334 nb_aretes_coin++;
335 }
336 //arete=courante;
337 }
338 }
339 while( (courante<nb_aretes)&&(type2_(courante)==bord) )
340 {
341 courante++;
342 nb_aretes_bord++;
343 }
344 for(arete=courante; arete<nb_aretes; arete++)
345 {
346 if(type2_(arete)==bord)
347 {
348 swap(arete, courante);
349 assert(type2_(courante) == bord);
350 while( (courante<nb_aretes)&&(type2_(courante)==bord) )
351 {
352 courante++;
353 nb_aretes_bord++;
354 }
355 //arete=courante;
356 }
357 }
358 while( (courante<nb_aretes)&&(type2_(courante)==mixte) )
359 {
360 courante++;
361 nb_aretes_mixte++;
362 }
363 for(arete=courante; arete<nb_aretes; arete++)
364 {
365 if(type2_(arete)==mixte)
366 {
367 swap(arete, courante);
368 assert(faces_(courante, 0) !=-1);
369 assert(faces_(courante, 1) !=-1);
370 assert(faces_(courante, 2) !=-1);
371 assert(faces_(courante, 3) !=-1);
372 while( (courante<nb_aretes)&&(type2_(courante)==mixte) )
373 {
374 courante++;
375 nb_aretes_mixte++;
376 }
377 //arete=courante;
378 }
379 }
380 while( (courante<nb_aretes)&&(type2_(courante)==interne) )
381 {
382 courante++;
383 nb_aretes_interne++;
384 }
385 for(arete=courante; arete<nb_aretes; arete++)
386 {
387 if(type2_(arete)==interne)
388 {
389 swap(arete, courante);
390 assert(faces_(courante, 0) !=-1);
391 assert(faces_(courante, 1) !=-1);
392 assert(faces_(courante, 2) !=-1);
393 assert(faces_(courante, 3) !=-1);
394 while( (courante<nb_aretes)&&(type2_(courante)==interne) )
395 {
396 courante++;
397 nb_aretes_interne++;
398 }
399 //arete=courante;
400 }
401 }
402}
403
404void Aretes::trier_pour_debog(int& nb_aretes_coin, int& nb_aretes_bord,
405 int& nb_aretes_mixte, int& nb_aretes_interne,const DoubleTab&
406 xv)
407{
408
409 ArrOfDouble XVref(dimension),XVref2(dimension);
410 int nb_aretes = type1_.size();
411 int arete;
412 for (int boucle=0; boucle<3; boucle++)
413 {
414 int deb=nb_aretes - nb_aretes_interne;
415 int fin=nb_aretes;
416 if (boucle==1)
417 {
418 fin=deb;
419 deb-=nb_aretes_mixte;
420 }
421 else if (boucle==2)
422 {
423 fin=deb;
424 deb-= nb_aretes_bord;
425 }
426 for ( arete=deb; arete<fin; arete++)
427 {
428 if ((boucle==2)&&(type2_(arete)!=0))
429 {
430 Cerr<<"gros pb "<<arete<<finl;
431 exit();
432 }
433 int ref=faces_(arete,0);
434 for (int i=0; i<dimension; i++) XVref[i]=xv(ref,i);
435 int marq=-1;
436 int ref2;
437 for (int arete2=arete; arete2<fin; arete2++)
438 {
439 ref2=faces_(arete2,0);
440 for (int i=0; i<dimension; i++) XVref2[i]=xv(ref2,i);
441 int test=-1;
442 // int testsa=-1;
443 if (dimension==2)
444 {
445 if (sup_strict(XVref2[1],XVref[1])) test=1;
446 else if ((XVref2[1]==XVref[1])&&(sup_strict(XVref2[0],XVref[0]))) test=0;
447 }
448 else if (dimension==3)
449 {
450 if (XVref2[2]>XVref[2]) test=2;
451 else if (XVref2[2]==XVref[2])
452 {
453 if (XVref2[1]>XVref[1]) test=1;
454 else if ((XVref2[1]==XVref[1])&&(XVref2[0]>XVref[0])) test=0;
455 }
456 }
457 if (test!=-1)
458 {
459 marq=arete2;
460 XVref=XVref2;
461 }
462 }
463 if (marq!=-1) swap(arete,marq);
464 }
465 }
466 for (arete=nb_aretes - nb_aretes_interne; arete<nb_aretes*0; arete++)
467 {
468 Cerr <<me()<<" arete "<<arete<<" "<< faces_(arete,0)<<" "<< faces_(arete,1)<<" "<< faces_(arete,2)<<" "<< faces_(arete,3)<<finl;
469 }
470}
void trier_pour_debog(int &, int &, int &, int &, const DoubleTab &)
Definition Aretes.cpp:404
void affecter(int &, int, int, int, int, int, int, int, const ArrOfInt &)
Assigns faces f1, f2, f3, f4 to edge numero.
Definition Aretes.cpp:61
void calculer_centre_de_gravite(Domaine_VDF &domaine)
Definition Aretes.cpp:110
void dimensionner(int)
Resizes the arrays.
Definition Aretes.cpp:270
void trier(int &, int &, int &, int &)
Reorders the edge array: first corner edges (they have only two faces),.
Definition Aretes.cpp:309
class Domaine_VDF
Definition Domaine_VDF.h:61
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
static int dimension
Definition Objet_U.h:94
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 int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
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