ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/template/src/tpl_grille.h
Revision: 674
Committed: Tue Jun 9 18:30:54 2015 UTC (9 years, 11 months ago) by francois
Content type: text/plain
File size: 16601 byte(s)
Log Message:
Transformation d'un support de carte de taille non structure en structure (formule à preciser et a revoir)
Calcul du temps CPU pour toutes les applications en incluant le temps CPU de code aster
Changement dans la projection et la comparaison de solution pour la generaliser à tous les maillages
Divers bug petit sur maillage hex/quadra

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4 francois 106 // Jean Christophe Cuilli�re et Vincent FRANCOIS
5     // D�partement de G�nie M�canique - UQTR
6 5 //------------------------------------------------------------
7 francois 106 // Le projet MAGIC est un projet de recherche du d�partement
8     // de g�nie m�canique de l'Universit� du Qu�bec �
9     // Trois Rivi�res
10     // Les librairies ne peuvent �tre utilis�es sans l'accord
11 5 // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // tpl_grille.h
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20 francois 106 // Version du 02/03/2006 � 11H24
21 5 //------------------------------------------------------------
22     //------------------------------------------------------------
23     #ifndef _TPLGRILLE_
24     #define _TPLGRILLE_
25    
26    
27 francois 481 #include "ot_boite_3d.h"
28 5 #include "tpl_liste_entite.h"
29     #include "tpl_map_entite.h"
30    
31     class CELLULE_GRILLE_BASE
32     {
33     public:
34     CELLULE_GRILLE_BASE()
35     {
36     static unsigned long idmax=0;
37     id=idmax;
38     idmax++;
39 francois 106 tag=0;
40 5 };
41    
42     virtual ~CELLULE_GRILLE_BASE() {};
43     virtual BOITE_3D get_boite(void)=0;
44     virtual unsigned long get_id() {return id;};
45 francois 106 virtual int get_tag(void)
46     {
47     return tag;
48     };
49     virtual void change_tag(int val)
50     {
51     tag=val;
52     };
53    
54     private :
55 5 unsigned long id;
56 francois 106 int tag;
57 5 };
58    
59    
60     class GRILLE_BASE
61     {
62     public:
63     GRILLE_BASE() {};
64     virtual ~GRILLE_BASE() {};
65     virtual int get_nb_cellule(void)=0;
66     virtual CELLULE_GRILLE_BASE* get_cellule(int num)=0;
67     };
68    
69    
70     template <class A>
71     class TPL_CELLULE_GRILLE:public CELLULE_GRILLE_BASE
72     {
73     public:
74     TPL_CELLULE_GRILLE(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax):CELLULE_GRILLE_BASE(),boite(xmin,ymin,zmin,xmax,ymax,zmax)
75     {
76     };
77     virtual ~TPL_CELLULE_GRILLE() {};
78     BOITE_3D get_boite(void) {return boite;};
79     BOITE_3D boite;
80     TPL_LISTE_ENTITE<A> lst_entite_A;
81     int get_nb_entite(void)
82     {
83     return lst_entite_A.get_nb();
84     };
85     A get_entite(int num)
86     {
87     return lst_entite_A.get(num);
88     };
89 francois 106
90    
91 5 };
92    
93     template <class A,class B>
94     class TPL_CELLULE_GRILLE_INFO:public CELLULE_GRILLE_BASE
95     {
96     public:
97     TPL_CELLULE_GRILLE_INFO(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax):CELLULE_GRILLE_BASE(),boite(xmin,ymin,zmin,xmax,ymax,zmax)
98     {
99     };
100     virtual ~TPL_CELLULE_GRILLE_INFO() {};
101     BOITE_3D get_boite(void) {return boite;};
102     BOITE_3D boite;
103     TPL_LISTE_ENTITE<A> lst_entite_A;
104     B tab[8];
105     int get_nb_entite(void)
106     {
107     return lst_entite_A.get_nb();
108     };
109     A get_entite(int num)
110     {
111     return lst_entite_A.get(num);
112     };
113    
114     B get_info(int num) {return tab[num];};
115     void change_info(int num,B val) {tab[num]=val;};
116    
117     };
118    
119    
120    
121     template <class A>
122     class TPL_GRILLE:public GRILLE_BASE
123     {
124     public:
125     TPL_GRILLE() {};
126     ~TPL_GRILLE()
127     {
128     for (int i=0;i<lst_entite_cellule.get_nb();i++)
129     {
130     TPL_CELLULE_GRILLE<A>* cellule=lst_entite_cellule.get(i);
131     delete cellule;
132     }
133 francois 106
134    
135    
136 5 };
137    
138     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
139    
140     virtual TPL_CELLULE_GRILLE<A>* get_cellule(int num) {return lst_entite_cellule.get(num); };
141    
142    
143     virtual void initialiser(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax,int nb_pasx,int nb_pasy,int nb_pasz)
144     {
145     nbpasx=nb_pasx;
146     nbpasy=nb_pasy;
147     nbpasz=nb_pasz;
148     pasx=(xmax-xmin)/nb_pasx;
149     pasy=(ymax-ymin)/nb_pasy;
150     pasz=(zmax-zmin)/nb_pasz;
151     boite.reinit(xmin,ymin,zmin,xmax,ymax,zmax);
152     for (int k=0;k<nb_pasz;k++)
153     for (int j=0;j<nb_pasy;j++)
154     for (int i=0;i<nb_pasx;i++)
155     {
156     double x1=xmin+i*pasx;
157     double x2=xmin+(i+1)*pasx;
158     double y1=ymin+j*pasy;
159     double y2=ymin+(j+1)*pasy;
160     double z1=zmin+k*pasz;
161     double z2=zmin+(k+1)*pasz;
162     TPL_CELLULE_GRILLE<A>* cellule=new TPL_CELLULE_GRILLE<A>(x1,y1,z1,x2,y2,z2);
163     lst_entite_cellule.ajouter(cellule);
164     }
165    
166     }
167    
168     virtual TPL_CELLULE_GRILLE<A> *get_cellule(double x,double y, double z)
169     {
170     int nx=(int)((x-boite.get_xmin())/pasx);
171     int ny=(int)((y-boite.get_ymin())/pasy);
172     int nz=(int)((z-boite.get_zmin())/pasz);
173     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
174     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
175     return lst_entite_cellule.get(num);
176     };
177    
178     virtual void get_coord_cellule(TPL_CELLULE_GRILLE<A>* cell,int& nx,int& ny,int& nz)
179     {
180     BOITE_3D boitecell=cell->get_boite();
181     double xyz[3];
182     boitecell.get_centre(xyz);
183     nx=(int)((xyz[0]-boite.get_xmin())/pasx);
184     ny=(int)((xyz[1]-boite.get_ymin())/pasy);
185     nz=(int)((xyz[2]-boite.get_zmin())/pasz);
186     };
187    
188    
189     virtual TPL_CELLULE_GRILLE<A> *get_cellule(int nx,int ny,int nz)
190     {
191     if (nx>=nbpasx) return NULL;
192     if (ny>=nbpasy) return NULL;
193     if (nz>=nbpasz) return NULL;
194     if (nx<0) return NULL;
195     if (ny<0) return NULL;
196     if (nz<0) return NULL;
197     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
198     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
199     return lst_entite_cellule.get(num);
200     };
201    
202    
203 francois 674 virtual void rechercher(BOITE_3D bt,TPL_MAP_ENTITE<A>& liste_entite_trouve)
204     {
205     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
206     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
207     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
208     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
209     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
210     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
211     for (int i=nxmin;i<nxmax+1;i++)
212     for (int j=nymin;j<nymax+1;j++)
213     for (int k=nzmin;k<nzmax+1;k++)
214     {
215     /*int num=i+j*nbpasx+k*nbpasy*nbpasx;
216     if ((num<0) || (num>=lst_entite_cellule.get_nb())) continue;
217     TPL_CELLULE_GRILLE<A>* cellule=lst_entite_cellule.get(num);*/
218     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
219     if (cellule==NULL) continue;
220     for (int ii=0;ii<cellule->lst_entite_A.get_nb();ii++)
221     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(ii));
222     }
223     };
224 5
225     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
226     {
227     BOITE_3D bt(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
228     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
229     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
230     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
231     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
232     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
233     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
234     for (int i=nxmin;i<nxmax+1;i++)
235     for (int j=nymin;j<nymax+1;j++)
236     for (int k=nzmin;k<nzmax+1;k++)
237     {
238     /*int num=i+j*nbpasx+k*nbpasy*nbpasx;
239     if ((num<0) || (num>=lst_entite_cellule.get_nb())) continue;
240     TPL_CELLULE_GRILLE<A>* cellule=lst_entite_cellule.get(num);*/
241     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
242     if (cellule==NULL) continue;
243     for (int ii=0;ii<cellule->lst_entite_A.get_nb();ii++)
244     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(ii));
245     }
246     };
247    
248    
249     virtual void inserer(A a)
250     {
251     BOITE_3D bt=a->get_boite_3D();
252     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
253     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
254     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
255     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
256     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
257     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
258     for (int i=nxmin;i<nxmax+1;i++)
259     for (int j=nymin;j<nymax+1;j++)
260     for (int k=nzmin;k<nzmax+1;k++)
261     {
262     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
263     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
264     if (cellule==NULL) continue;
265     cellule->lst_entite_A.ajouter(a);
266     }
267     }
268    
269     virtual void supprimer(A a)
270     {
271     BOITE_3D bt=a->get_boite_3D();
272     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
273     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
274     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
275     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
276     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
277     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
278     for (int i=nxmin;i<nxmax+1;i++)
279     for (int j=nymin;j<nymax+1;j++)
280     for (int k=nzmin;k<nzmax+1;k++)
281     {
282     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
283     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
284     if (cellule==NULL) continue;
285     cellule->lst_entite_A.supprimer(a);
286     }
287     }
288    
289     virtual BOITE_3D get_boite(void)
290     {
291     return boite;
292     }
293    
294     virtual int get_pasx(void)
295     {
296     return nbpasx;
297     }
298    
299     virtual int get_pasy(void)
300     {
301     return nbpasy;
302     }
303    
304     virtual int get_pasz(void)
305     {
306     return nbpasz;
307     }
308    
309 francois 106
310 5 private:
311     TPL_LISTE_ENTITE<TPL_CELLULE_GRILLE<A>* > lst_entite_cellule;
312     double pasx;
313     double pasy;
314     double pasz;
315     int nbpasx;
316     int nbpasy;
317     int nbpasz;
318     BOITE_3D boite;
319     };
320    
321    
322    
323     template <class A,class B>
324     class TPL_GRILLE_INFO:public GRILLE_BASE
325     {
326     public:
327     TPL_GRILLE_INFO() {};
328     ~TPL_GRILLE_INFO()
329     {
330     for (int i=0;i<lst_entite_cellule.get_nb();i++)
331     {
332     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=lst_entite_cellule.get(i);
333     delete cellule;
334     }
335     };
336    
337     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
338    
339    
340    
341     virtual TPL_CELLULE_GRILLE_INFO<A,B>* get_cellule(int num) {return lst_entite_cellule.get(num); };
342    
343    
344     virtual void initialiser(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax,int nb_pasx,int nb_pasy,int nb_pasz)
345     {
346     nbpasx=nb_pasx;
347     nbpasy=nb_pasy;
348     nbpasz=nb_pasz;
349     pasx=(xmax-xmin)/nb_pasx;
350     pasy=(ymax-ymin)/nb_pasy;
351     pasz=(zmax-zmin)/nb_pasz;
352     boite.reinit(xmin,ymin,zmin,xmax,ymax,zmax);
353     for (int k=0;k<nb_pasz;k++)
354     for (int j=0;j<nb_pasy;j++)
355     for (int i=0;i<nb_pasx;i++)
356     {
357     double x1=xmin+i*pasx;
358     double x2=xmin+(i+1)*pasx;
359     double y1=ymin+j*pasy;
360     double y2=ymin+(j+1)*pasy;
361     double z1=zmin+k*pasz;
362     double z2=zmin+(k+1)*pasz;
363     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=new TPL_CELLULE_GRILLE_INFO<A,B>(x1,y1,z1,x2,y2,z2);
364     lst_entite_cellule.ajouter(cellule);
365     }
366    
367     }
368    
369     virtual TPL_CELLULE_GRILLE_INFO<A,B> *get_cellule(double x,double y, double z)
370     {
371     int nx=(int)((x-boite.get_xmin())/pasx);
372     int ny=(int)((y-boite.get_ymin())/pasy);
373     int nz=(int)((z-boite.get_zmin())/pasz);
374     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
375     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
376     return lst_entite_cellule.get(num);
377     };
378    
379     virtual void get_coord_cellule(TPL_CELLULE_GRILLE_INFO<A,B>* cell,int& nx,int& ny,int& nz)
380     {
381     BOITE_3D boitecell=cell->get_boite();
382     double xyz[3];
383     boitecell.get_centre(xyz);
384     nx=(int)((xyz[0]-boite.get_xmin())/pasx);
385     ny=(int)((xyz[1]-boite.get_ymin())/pasy);
386     nz=(int)((xyz[2]-boite.get_zmin())/pasz);
387     };
388    
389    
390     virtual TPL_CELLULE_GRILLE_INFO<A,B> *get_cellule(int nx,int ny,int nz)
391     {
392     if (nx>=nbpasx) return NULL;
393     if (ny>=nbpasy) return NULL;
394     if (nz>=nbpasz) return NULL;
395     if (nx<0) return NULL;
396     if (ny<0) return NULL;
397     if (nz<0) return NULL;
398     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
399     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
400     return lst_entite_cellule.get(num);
401     };
402    
403    
404     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
405     {
406     BOITE_3D bt(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
407     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
408     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
409     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
410     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
411     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
412     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
413     for (int i=nxmin;i<nxmax+1;i++)
414     for (int j=nymin;j<nymax+1;j++)
415     for (int k=nzmin;k<nzmax+1;k++)
416     {
417     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
418     //if ((num<0) || (num>=lst_entite_cellule.get_nb())) continue;
419     //TPL_CELLULE_GRILLE_INFO<A,B>* cellule=lst_entite_cellule.get(num);
420     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
421     if (cellule==NULL) continue;
422     for (int ii=0;ii<cellule->lst_entite_A.get_nb();ii++)
423     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(ii));
424     }
425    
426     };
427    
428    
429     virtual void inserer(A a)
430     {
431     BOITE_3D bt=a->get_boite_3D();
432     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
433     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
434     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
435     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
436     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
437     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
438     for (int i=nxmin;i<nxmax+1;i++)
439     for (int j=nymin;j<nymax+1;j++)
440     for (int k=nzmin;k<nzmax+1;k++)
441     {
442     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
443     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
444     if (cellule==NULL) continue;
445     cellule->lst_entite_A.ajouter(a);
446     }
447     }
448    
449     virtual void supprimer(A a)
450     {
451     BOITE_3D bt=a->get_boite_3D();
452     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
453     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
454     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
455     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
456     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
457     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
458     for (int i=nxmin;i<nxmax+1;i++)
459     for (int j=nymin;j<nymax+1;j++)
460     for (int k=nzmin;k<nzmax+1;k++)
461     {
462     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
463     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
464     if (cellule==NULL) continue;
465     cellule->lst_entite_A.supprimer(a);
466     }
467     }
468    
469     virtual BOITE_3D get_boite(void)
470     {
471     return boite;
472     }
473    
474     virtual int get_pasx(void)
475     {
476     return nbpasx;
477     }
478    
479     virtual int get_pasy(void)
480     {
481     return nbpasy;
482     }
483    
484     virtual int get_pasz(void)
485     {
486     return nbpasz;
487     }
488    
489 francois 106
490     virtual unsigned long determine_keycode(int nx,int ny,int nz)
491     {
492 francois 295 std::vector<int> bits;
493 francois 106 int ok=0,i=0;
494     do
495     {
496     int nnz=nz>>i;
497     int nny=ny>>i;
498     int nnx=nx>>i;
499     int bit1= nnz & 1;
500     int bit2= nny & 1;
501     int bit3= nnx & 1;
502     if ((nnz==0) && (nny==0) && (nnx==0)) ok=1;
503     bits.insert(bits.end(),bit1);
504     bits.insert(bits.end(),bit2);
505     bits.insert(bits.end(),bit3);
506     i++;
507     }
508     while (ok==0);
509     unsigned long keycode=0;
510     for (int i=0;i<bits.size();i++)
511     keycode=keycode+bits[i]*(1<<i);
512     return keycode;
513     }
514    
515 5 private:
516     TPL_LISTE_ENTITE<TPL_CELLULE_GRILLE_INFO<A,B>* > lst_entite_cellule;
517     double pasx;
518     double pasy;
519     double pasz;
520     int nbpasx;
521     int nbpasy;
522     int nbpasz;
523     BOITE_3D boite;
524     };
525    
526    
527    
528    
529    
530    
531     #endif