ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mailleur/src/mailleur3d.cpp
Revision: 1189
Committed: Tue Feb 4 17:26:49 2025 UTC (3 months ago) by francois
File size: 17222 byte(s)
Log Message:
Version 5.0 de MAGIC. Integration de ALGLIB pour faire de l'optimisation. ALGLIB se download automatiquement en executant un script dans le repertoire config update_magic.bash


File Contents

# Content
1 //####//------------------------------------------------------------
2 //####//------------------------------------------------------------
3 //####// MAGiC
4 //####// Jean Christophe Cuilliere et Vincent FRANCOIS
5 //####// Departement de Genie Mecanique - UQTR
6 //####//------------------------------------------------------------
7 //####// MAGIC est un projet de recherche de l equipe ERICCA
8 //####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres
9 //####// http://www.uqtr.ca/ericca
10 //####// http://www.uqtr.ca/
11 //####//------------------------------------------------------------
12 //####//------------------------------------------------------------
13 //####//
14 //####// mailleur3d.cpp
15 //####//
16 //####//------------------------------------------------------------
17 //####//------------------------------------------------------------
18 //####// COPYRIGHT 2000-2024
19 //####// jeu 13 jun 2024 11:58:55 EDT
20 //####//------------------------------------------------------------
21 //####//------------------------------------------------------------
22
23
24 #include "gestionversion.h"
25
26
27 #include "tpl_set.h"
28 #include "mailleur3d.h"
29 #include "m3d_triangle.h"
30 #include "mg_gestionnaire.h"
31 #include "mailleur3d_optimisation.h"
32
33
34
35
36 MAILLEUR3D::MAILLEUR3D(MG_MAILLAGE* mgmai,MG_GEOMETRIE *mggeo,FCT_TAILLE* fct_taille,bool save,MG_VOLUME* mgvol,int destruction):MAILLEUR(save),mg_maillage(mgmai),mg_geometrie(mggeo),mg_volume(mgvol),metrique(fct_taille),activelog(0),niveau_optimisation(2),type_mailleur(MAGIC::MAILLEURFRONTALETAT::FRONTAL),typedestruction(destruction)
37 {
38 strcpy(nomfichierdbg,"mailleurautomatique.magicdbg");
39 }
40
41
42 MAILLEUR3D::MAILLEUR3D(FCT_TAILLE *metri,MG_MAILLAGE* mgmai,OT_CPU* comp,int destruction):MAILLEUR(false,comp),metrique(metri),type_mailleur(MAGIC::MAILLEURFRONTALETAT::OCTAL),mg_maillage(mgmai),coef(2.),typedestruction(destruction)
43 {
44 strcpy(nomfichierdbg,"mailleurautomatique.magicdbg");
45 }
46
47
48 MAILLEUR3D::~MAILLEUR3D()
49 {
50 }
51
52
53
54
55 int MAILLEUR3D::maille(MG_GROUPE_TOPOLOGIQUE* mggt)
56 {
57 if (type_mailleur==MAGIC::MAILLEURFRONTALETAT::FRONTAL)
58 {
59 if (mg_volume!=NULL)
60 {
61 if(maille(mg_volume)==FAIL) return FAIL;
62 }
63 else
64 {
65 TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*> lst;
66 if (mggt!=NULL)
67 {
68 std::map<MG_ELEMENT_TOPOLOGIQUE*,MG_ELEMENT_TOPOLOGIQUE*>::iterator it;
69 for(MG_ELEMENT_TOPOLOGIQUE* ele=mggt->get_premier(it);ele!=NULL;ele=mggt->get_suivant(it))
70 {
71 lst.ajouter(ele);
72 ele->get_topologie_sousjacente(&lst);
73 }
74 }
75 int nb_vol=mg_geometrie->get_nb_mg_volume();
76 for (int i=0;i<nb_vol;i++)
77 {
78 MG_VOLUME* mgvol=mg_geometrie->get_mg_volume(i);
79 if (mggt!=NULL)
80 if (lst.existe(mgvol)==0) continue;
81 if(maille(mgvol)==FAIL) return FAIL;
82 }
83 }
84 }
85 if (type_mailleur==MAGIC::MAILLEURFRONTALETAT::OCTAL)
86 {
87 if(maille(metrique)==FAIL) return FAIL;
88 }
89 return OK;
90 }
91
92
93
94 int MAILLEUR3D::maille(MG_VOLUME* mgvol,TPL_LISTE_ENTITE<MG_TRIANGLE*> *lsttri,TPL_LISTE_ENTITE<MG_TETRA*> *lsttet)
95 {
96 cree_ntree();
97 distance_maximale=metrique->get_valeur_maximale(0);
98 affiche((char*)" Construction du front");
99 initialise_front(mgvol);
100 if (lsttri!=NULL) insere_contrainte_triangle(mgvol,lsttri);
101 if (lsttet!=NULL) insere_contrainte_tetra(mgvol,lsttet);
102 affiche((char*)" Progression du front");
103 if(progresse_front(mgvol)==FAIL)
104 {
105 delete ntree_de_front;
106 return FAIL;
107 }
108 affiche((char*)" Construction du maillage final");
109 detruit_element_inactif();
110 affiche((char*)" Optimisation du maillage final");
111 MAILLEUR3D_OPTIMISATION opt(mg_maillage,niveau_optimisation);
112 if (affichageactif==1) opt.active_affichage(affiche2);
113 opt.optimise(mgvol);
114 delete ntree_de_front;
115 return OK;
116 }
117
118
119 void MAILLEUR3D::cree_ntree(void)
120 {
121 BOITE_3D boite=metrique->get_boite_3D();
122 double xmin=boite.get_xmin();
123 double ymin=boite.get_ymin();
124 double zmin=boite.get_zmin();
125 double xmax=boite.get_xmax();
126 double ymax=boite.get_ymax();
127 double zmax=boite.get_zmax();
128 ntree_de_front=new TPL_NTREE_FCT<MG_FRONT_3D*,FCT_TAILLE >;
129 ntree_de_front->initialiser(*metrique,xmin,ymin,zmin,xmax,ymax,zmax);
130 }
131
132 void MAILLEUR3D::initialise_front(MG_VOLUME* mgvol)
133 {
134 cree_front(mgvol);
135 recherche_voisin_front();
136 }
137
138 void MAILLEUR3D::cree_front(MG_VOLUME* mgvol)
139 {
140 int nbcoq=mgvol->get_nb_mg_coquille();
141 for (int i=0;i<nbcoq;i++)
142 {
143 MG_COQUILLE* mgcoq=mgvol->get_mg_coquille(i);
144 int nbcoface=mgcoq->get_nb_mg_coface();
145 for (int j=0;j<nbcoface;j++)
146 {
147 MG_COFACE* coface=mgcoq->get_mg_coface(j);
148 MG_FACE* mgface=coface->get_face();
149
150 TPL_SET<MG_ELEMENT_MAILLAGE*> * lien_maillage = mgface->get_lien_maillage();
151 TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it;
152 MG_ELEMENT_MAILLAGE* element;
153 for (element = lien_maillage->get_premier(it); element; element = lien_maillage->get_suivant(it) )
154 {
155 MG_TRIANGLE* mgtri=(MG_TRIANGLE*)element;
156 MG_TRIANGLE* tritemp=mg_maillage->get_mg_triangleid(mgtri->get_id());
157 if (tritemp==NULL) continue;
158 if (coface->get_orientation()==1) ajouter_front_courant(MAGIC::MAILLEURFRONTALETAT::NONFORCE,mgtri->get_noeud1(),mgtri->get_noeud2(),mgtri->get_noeud3(),mgtri);
159 else ajouter_front_courant(MAGIC::MAILLEURFRONTALETAT::NONFORCE,mgtri->get_noeud1(),mgtri->get_noeud3(),mgtri->get_noeud2(),mgtri);
160 }
161 }
162 }
163 }
164 void MAILLEUR3D::recherche_voisin_front(void)
165 {
166 for (int l=0;l<11;l++)
167 {
168 int nb_front=get_nb_front(front_courant[l]);
169 FRONT::iterator it;
170 for (MG_FRONT_3D *ft=get_premier_front(front_courant[l],it);ft!=NULL;ft=get_suivant_front(front_courant[l],it))
171 {
172 //MG_FRONT_3D* ft=get_front(front_courant[l],i);
173 MG_NOEUD* mgnoeud1=ft->get_noeud1();
174 MG_NOEUD* mgnoeud2=ft->get_noeud2();
175 MG_NOEUD* mgnoeud3=ft->get_noeud3();
176 ft->changer_front_voisin(NULL,0);
177 ft->changer_front_voisin(NULL,1);
178 ft->changer_front_voisin(NULL,2);
179 for (int j=0;j<mgnoeud1->get_lien_triangle()->get_nb();j++)
180 for (int k=0;k<mgnoeud2->get_lien_triangle()->get_nb();k++)
181 {
182 M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud1->get_lien_triangle()->get(j);
183 M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud2->get_lien_triangle()->get(k);
184 if (tri1==tri2)
185 if (tri1->get_etat_front()==MAGIC::MAILLEURFRONTALETAT::FRONT_ACTIF)
186 if (tri1->get_mgfront()!=ft)
187 {
188 MG_FRONT_3D* ft2=tri1->get_mgfront();
189 if (ft->get_front_voisin(0)==NULL)
190 {
191 ft->changer_front_voisin(ft2,0);
192 ft->changer_angle_voisin(angle_front(ft,ft2),0);
193 }
194 else
195 {
196 double angle=angle_front(ft,ft2);
197 if (angle<ft->get_angle_voisin(0))
198 {
199 ft->changer_front_voisin(ft2,0);
200 ft->changer_angle_voisin(angle,0);
201 }
202 }
203 }
204 }
205 for (int j=0;j<mgnoeud1->get_lien_triangle()->get_nb();j++)
206 for (int k=0;k<mgnoeud3->get_lien_triangle()->get_nb();k++)
207 {
208 M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud1->get_lien_triangle()->get(j);
209 M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud3->get_lien_triangle()->get(k);
210 if (tri1==tri2)
211 if (tri1->get_etat_front()==MAGIC::MAILLEURFRONTALETAT::FRONT_ACTIF)
212 if (tri1->get_mgfront()!=ft)
213 {
214 MG_FRONT_3D* ft2=tri1->get_mgfront();
215 if (ft->get_front_voisin(1)==NULL)
216 {
217 ft->changer_front_voisin(ft2,1);
218 ft->changer_angle_voisin(angle_front(ft,ft2),1);
219 }
220 else
221 {
222 double angle=angle_front(ft,ft2);
223 if (angle<ft->get_angle_voisin(1))
224 {
225 ft->changer_front_voisin(ft2,1);
226 ft->changer_angle_voisin(angle,1);
227 }
228 }
229 }
230 }
231 for (int j=0;j<mgnoeud2->get_lien_triangle()->get_nb();j++)
232 for (int k=0;k<mgnoeud3->get_lien_triangle()->get_nb();k++)
233 {
234 M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud2->get_lien_triangle()->get(j);
235 M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud3->get_lien_triangle()->get(k);
236 if (tri1==tri2)
237 if (tri1->get_etat_front()==MAGIC::MAILLEURFRONTALETAT::FRONT_ACTIF)
238 if (tri1->get_mgfront()!=ft)
239 {
240 MG_FRONT_3D* ft2=tri1->get_mgfront();
241 if (ft->get_front_voisin(2)==NULL)
242 {
243 ft->changer_front_voisin(ft2,2);
244 ft->changer_angle_voisin(angle_front(ft,ft2),2);
245 }
246 else
247 {
248 double angle=angle_front(ft,ft2);
249 if (angle<ft->get_angle_voisin(2))
250 {
251 ft->changer_front_voisin(ft2,2);
252 ft->changer_angle_voisin(angle,2);
253 }
254 }
255 }
256 }
257 if ( (ft->get_front_voisin(0)==NULL) || (ft->get_front_voisin(1)==NULL)|| (ft->get_front_voisin(2)==NULL))
258 refresh();
259 }
260
261 }
262
263 }
264
265
266
267 MG_FRONT_3D* MAILLEUR3D::ajouter_front_courant(int numero_front,MG_NOEUD* noeud1,MG_NOEUD* noeud2,MG_NOEUD* noeud3,MG_TRIANGLE* triangle)
268 {
269 int numfront;
270 if (numero_front==MAGIC::MAILLEURFRONTALETAT::NONFORCE)
271 {
272 numfront=(int)(triangle->get_longueur()/distance_maximale*10.);
273 if (numfront>10) numfront=10;
274 }
275 else numfront=numero_front;
276 MG_FRONT_3D* mgfront;
277 if (numfront>11) mgfront=ajouter_front(front_attente,noeud1,noeud2,noeud3,triangle);
278 else mgfront=ajouter_front(front_courant[numfront],noeud1,noeud2,noeud3,triangle);
279 mgfront->changer_numero_front(numfront);
280 if (triangle->get_type_entite()==MAGIC::TYPE_ENTITE::IDM3D_TRIANGLE)
281 {
282 M3D_TRIANGLE* mtri=(M3D_TRIANGLE*)triangle;
283 mtri->change_etat_front(MAGIC::MAILLEURFRONTALETAT::FRONT_ACTIF);
284 mtri->change_mgfront(mgfront);
285 }
286 return mgfront;
287 }
288
289 MG_FRONT_3D* MAILLEUR3D::ajouter_front(FRONT& front,MG_NOEUD* noeud1,MG_NOEUD* noeud2,MG_NOEUD* noeud3,MG_TRIANGLE* triangle)
290 {
291 MG_FRONT_3D* ft=new MG_FRONT_3D(noeud1,noeud2,noeud3,triangle);
292 ajouter_front(front,ft);
293 ntree_de_front->inserer(ft);
294 return ft;
295 }
296
297 void MAILLEUR3D::ajouter_front(FRONT& front,MG_FRONT_3D *ft)
298 {
299 std::pair<const double,MG_FRONT_3D*> tmp(ft->get_triangle()->get_longueur(),ft);
300 front.insert(tmp);
301 }
302
303 MG_FRONT_3D* MAILLEUR3D::get_premier_front(FRONT& front)
304 {
305 if (front.size()==0) return NULL;
306 FRONT::iterator it=front.begin();
307 return (*it).second;
308 }
309
310 MG_FRONT_3D* MAILLEUR3D::get_premier_front(FRONT& front,FRONT::iterator &it)
311 {
312 if (front.size()==0) return NULL;
313 it=front.begin();
314 return (*it).second;
315 }
316
317 MG_FRONT_3D* MAILLEUR3D::get_suivant_front(FRONT& front,FRONT::iterator &it)
318 {
319 it++;
320 if (it==front.end()) return NULL;
321 return (*it).second;
322 }
323
324
325 unsigned int MAILLEUR3D::get_nb_front(FRONT& front)
326 {
327 return front.size();
328 }
329
330 unsigned int MAILLEUR3D::get_nb_front_courant(void)
331 {
332
333 return front_courant[0].size()+front_courant[1].size()+front_courant[2].size()+front_courant[3].size()+front_courant[4].size()+front_courant[5].size()+front_courant[6].size()+front_courant[7].size()+front_courant[8].size()+front_courant[9].size()+front_courant[10].size();
334 }
335
336 void MAILLEUR3D::supprimer_front_en_avancant(MG_FRONT_3D* ft)
337 {
338 supprimer_front_en_avancant_sans_delete(ft);
339 delete ft;
340 }
341
342 void MAILLEUR3D::supprimer_front_en_avancant_sans_delete(MG_FRONT_3D* ft)
343 {
344 ntree_de_front->supprimer(ft);
345 int numfront=ft->get_numero_front();
346 FRONT* front_original;
347 if (numfront==MAGIC::MAILLEURFRONTALETAT::ATTENTE)
348 front_original=&front_attente;
349 else
350 front_original=front_courant+numfront;
351 FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
352 while (ft!=(*j).second) j++;
353 front_original->erase(j);
354 MG_TRIANGLE* mgtri=ft->get_triangle();
355 if (mgtri->get_type_entite()==MAGIC::TYPE_ENTITE::IDM3D_TRIANGLE)
356 {
357 M3D_TRIANGLE* m3dtri=(M3D_TRIANGLE*)mgtri;
358 m3dtri->change_etat_front(MAGIC::MAILLEURFRONTALETAT::FRONT_PASSE);
359 m3dtri->change_mgfront(NULL);
360 }
361 }
362
363 void MAILLEUR3D::supprimer_front_en_reculant(MG_FRONT_3D* ft)
364 {
365 ntree_de_front->supprimer(ft);
366 int numfront=ft->get_numero_front();
367 FRONT* front_original;
368 if (numfront==MAGIC::MAILLEURFRONTALETAT::ATTENTE)
369 front_original=&front_attente;
370 else
371 front_original=front_courant+numfront;
372 FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
373 while (ft!=(*j).second) j++;
374 front_original->erase(j);
375 MG_TRIANGLE* mgtri=ft->get_triangle();
376 if (mgtri->get_type_entite()==MAGIC::TYPE_ENTITE::IDM3D_TRIANGLE)
377 {
378 M3D_TRIANGLE* m3dtri=(M3D_TRIANGLE*)mgtri;
379 m3dtri->change_etat_front(MAGIC::MAILLEURFRONTALETAT::FRONT_NONACTIF);
380 m3dtri->change_mgfront(NULL);
381 }
382 delete ft;
383 }
384
385 void MAILLEUR3D::echange_de_front(FRONT& front_original,FRONT& front_destination,MG_FRONT_3D* ft)
386 {
387 FRONT::iterator j=front_original.lower_bound(ft->get_triangle()->get_longueur());
388 while (ft!=(*j).second) j++;
389 front_original.erase(j);
390 ajouter_front(front_destination,ft);
391 }
392
393 void MAILLEUR3D::echange_de_front(MG_FRONT_3D* ft,int num)
394 {
395 int numfront;
396 if (num==MAGIC::MAILLEURFRONTALETAT::NONFORCE)
397 {
398 numfront=(int)(ft->get_triangle()->get_longueur()/distance_maximale*10.);
399 if (numfront>10) numfront=10;
400 }
401 else if (num==MAGIC::MAILLEURFRONTALETAT::ATTENTE) numfront=MAGIC::MAILLEURFRONTALETAT::ATTENTE;
402 else numfront=num;
403 if (numfront>10) numfront=MAGIC::MAILLEURFRONTALETAT::ATTENTE;
404 FRONT* front_original;
405 int num_front_original=ft->get_numero_front();
406 if (num_front_original==MAGIC::MAILLEURFRONTALETAT::ATTENTE)
407 front_original=&front_attente;
408 else
409 front_original=front_courant+num_front_original;
410 FRONT* front_destination;
411 if (numfront==MAGIC::MAILLEURFRONTALETAT::ATTENTE)
412 front_destination=&front_attente;
413 else
414 front_destination=front_courant+numfront;
415
416
417
418 FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
419 while (ft!=(*j).second) j++;
420 front_original->erase(j);
421 ft->changer_numero_front(numfront);
422 ajouter_front(*front_destination,ft);
423
424 }
425
426
427 void MAILLEUR3D::swap_front(FRONT& front_original,FRONT& front_destination)
428 {
429 front_original.swap(front_destination);
430 }
431
432
433
434 int MAILLEUR3D::premier_front_courant(void)
435 {
436 int num=-1;
437 if (front_courant[0].size()>0) num=0;
438 else if (front_courant[1].size()>0) num=1;
439 else if (front_courant[2].size()>0) num=2;
440 else if (front_courant[3].size()>0) num=3;
441 else if (front_courant[4].size()>0) num=4;
442 else if (front_courant[5].size()>0) num=5;
443 else if (front_courant[6].size()>0) num=6;
444 else if (front_courant[7].size()>0) num=7;
445 else if (front_courant[8].size()>0) num=8;
446 else if (front_courant[9].size()>0) num=9;
447 else if (front_courant[10].size()>0) num=10;
448 return num;
449 }
450
451
452
453 void MAILLEUR3D::active_log(char* nomfile)
454 {
455 activelog=1;
456 nomlog=nomfile;
457 }
458
459 void MAILLEUR3D::desactive_log(void)
460 {
461 activelog=0;
462 }
463
464 void MAILLEUR3D::change_niveau_optimisation(int num)
465 {
466 niveau_optimisation=num;
467 }
468
469 int MAILLEUR3D::get_niveau_optimisation(void)
470 {
471 return niveau_optimisation;
472 }
473
474