Page principale   Liste par ordre alphabétique   Liste des composants   Liste des fichiers   Composants   Déclarations   Pages associées  

G3DC_.c

Aller à la documentation de ce fichier.
00001 
00013 #include "interpolation.h"
00014 #include <unistd.h>
00015 
00016 extern void imerror(int code, char * format, ...);
00017 
00018 void calcul_parametres_differentiels(inricache *W,inricache *A,inricache *B,inricache *C,inricache *D,inricache *E,inricache *F,Fort_int lfmt[9],int time_flag);
00019 void calcul_evolution_surface(inricache *imgPhi,inricache *imgForces,inricache *imgGeod,inricache *imgA,inricache *imgB,inricache *imgC,inricache *imgD,inricache *imgE,inricache *imgF,int nb_iter,float ptTau,Fort_int lfmt[9],int time_flag);
00020 void calcul_force(inricache *imgPhi,inricache *imgForces,inricache *imgA,inricache *imgB,inricache *imgC,inricache *imgD,inricache *imgE,inricache *imgF,Fort_int lfmt[9],int time_flag);
00021 void update_solution(inricache *imgPhi,inricache *imgForces,inricache *imgGeod,int nb_iter,float ptTau,Fort_int lfmt[9],int time_flag);
00022 
00035 void g3Dc(char * distSrc,char * tempoW,char * distGeod,int nb_iter,float ptTau,int taille_cache,int time_flag)
00036 {
00037   inricache *imgSrc,*imgGeod,*imgW;
00038   
00039   /* images temporaires */
00040   inricache *imgPhi,*imgForces;
00041   /* parametres differentiels */
00042   inricache *imgA,*imgB,*imgC,*imgD,*imgE,*imgF;
00043 
00044   struct nf_fmt gfmt;
00045 
00046   clock_t t0=0,t1=0;
00047 
00048   /* chronometrage si on le demande */
00049   if (time_flag)
00050     t0 = clock();
00051   t1=t0;
00052 
00053   fprintf(stderr,"creation des images temporaires ...");
00054   
00055   /* chargement / creation des images necessaires au calcul */
00056 
00057   /* le format est le meme pour toutes les images du processus */
00058   imgW=cree_inricache(tempoW,"e","",&gfmt,taille_cache);
00059   imgSrc=cree_inricache(distSrc,"e","a",&gfmt,taille_cache);
00060 
00061   imgGeod=cree_inricache(distGeod,"c","a",&gfmt,taille_cache);
00062 
00063   /* images temporaires pour le calcul de phi et F */
00064   imgPhi=cree_inricache("phi_cache","c","a",&gfmt,taille_cache);
00065   imgForces=cree_inricache("tempoF_cache","c","a",&gfmt,taille_cache);
00066 
00067   /* images temporaires correspondant aux parametres differentiels de W */
00068 
00069   imgA=cree_inricache("A_cache","c","a",&gfmt,taille_cache);
00070   imgB=cree_inricache("B_cache","c","a",&gfmt,taille_cache);
00071   imgC=cree_inricache("C_cache","c","a",&gfmt,taille_cache);
00072   imgD=cree_inricache("D_cache","c","a",&gfmt,taille_cache);
00073   imgE=cree_inricache("E_cache","c","a",&gfmt,taille_cache);
00074   imgF=cree_inricache("F_cache","c","a",&gfmt,taille_cache);
00075 
00076   if (max(time_flag-1,0))
00077     {
00078       t1=clock()-t1;
00079       fprintf(stderr,"(%f secondes)\n",t1/(float)CLOCKS_PER_SEC);
00080     }
00081 
00082   fprintf(stderr,"initialisation des buffers ...");
00083 
00084   /* on initialise le buffer de phi et de Geod avec l'image distSrc */
00085 
00086   copie_inricache(imgSrc,imgPhi);
00087   copie_inricache(imgSrc,imgGeod);
00088 
00089   /* on n'a plus besoin d'imgSrc */
00090   libere_inricache(imgSrc);
00091 
00092   if (max(time_flag-1,0))
00093     {
00094       t1=clock()-t1;
00095       fprintf(stderr,"(%f secondes)\n",t1/(float)CLOCKS_PER_SEC);
00096     }
00097 
00098   /* calcul de A,B,C,D,E,F,p,q,r */
00099   fprintf(stderr,"calcul des parametres differentiels de W ...");
00100 
00101   calcul_parametres_differentiels(imgW,
00102                                       imgA,imgB,imgC,imgD,imgE,imgF,
00103                                       gfmt.lfmt,(int)max(time_flag-2,0));
00104 
00105   /* on n'a plus besoin de imgW */
00106   libere_inricache(imgW);
00107 
00108   if (max(time_flag-1,0))
00109     {
00110       t1=clock()-t1;
00111       fprintf(stderr,"(%f secondes)\n",t1/(float)CLOCKS_PER_SEC);
00112     }
00113 
00114   /* calcul de l'evolution de la surface */
00115   fprintf(stderr,"calcul de l'evolution de la surface ...");
00116 
00117 
00118   /* on n'a plus besoin d'utiliser W, les coefficients _A,_B,_C,_D,_E et _F suffisent pour le calcul des forces*/
00119   calcul_evolution_surface(imgPhi,imgForces,imgGeod,
00120                               imgA,imgB,imgC,imgD,imgE,imgF,
00121                               nb_iter,ptTau,gfmt.lfmt,(int)max(time_flag-2,0));
00122 
00123   if (max(time_flag-1,0)==1)
00124     {
00125       t1=clock()-t1;
00126       fprintf(stderr,"(%f secondes)\n",t1/(float)CLOCKS_PER_SEC);
00127     }
00128 
00129   /* fermeture et sauvegarde des images */
00130   
00131   libere_inricache(imgGeod);
00132   libere_inricache(imgA);
00133   libere_inricache(imgB);
00134   libere_inricache(imgC);
00135   libere_inricache(imgD);
00136   libere_inricache(imgE);
00137   libere_inricache(imgF);
00138   libere_inricache(imgForces);
00139 
00140   /* suppression Physique des images temporaires * /
00141 
00142   unlink("A_cache");
00143   unlink("B_cache");
00144   unlink("C_cache");
00145   unlink("D_cache");
00146   unlink("E_cache");
00147   unlink("F_cache");
00148   */
00149   if (time_flag)
00150     {
00151       t1 = clock()-t0;
00152       printf("g3Dc: temps mis: %f secondes\n",t1/(float)CLOCKS_PER_SEC);
00153     }
00154 }
00155 
00156 void calcul_parametres_differentiels(inricache *W,inricache *A,inricache *B,inricache *C,inricache *D,inricache *E,inricache *F,Fort_int lfmt[9],int time_flag)
00157 {
00158   register int i,j,k;
00159   clock_t t0=0,t1=0;
00160   float tmp_p,tmp_q,tmp_r,q2,p2,r2,denominateur,wzm,wzp,wym,wyp,wxm,wxp;
00161 
00162   /* chronometrage si on le demande */
00163   if (time_flag)
00164     t0 = clock();
00165 
00166   //  fprintf(stderr,"max=(%d,%d,%d)",lfmt[I_NDIMX],lfmt[I_NDIMY],lfmt[I_NDIMZ]);
00167   for (k=1;k<lfmt[I_NDIMZ]-1;k++)
00168     for (j=1;j<lfmt[I_NDIMY]-1;j++)
00169       for (i=1;i<lfmt[I_NDIMX]-1;i++)
00170          {
00171            wzm = getValue(W,i,j,k-1);
00172            wym = getValue(W,i,j-1,k);
00173            wxm = getValue(W,i-1,j,k);
00174            wxp = getValue(W,i+1,j,k);
00175            wyp = getValue(W,i,j+1,k);
00176            wzp = getValue(W,i,j,k+1);
00177 
00178            /* W en lecture , A B C D E F en ecriture */
00179            /* derivee partielle en x en (i,j,k) */
00180            tmp_p=(wxp - wxm)/2.0;
00181 
00182            /* derivee partielle en y en (i,j,k) */
00183            tmp_q=(wyp - wym)/2.0;
00184            
00185            /* derivee partielle en z en (i,j,k) */
00186            tmp_r=(wzp - wzm)/2.0;
00187            
00188            p2=tmp_p*tmp_p;
00189            q2=tmp_q*tmp_q;
00190            r2=tmp_r*tmp_r;
00191            denominateur=1+p2+q2+r2;
00192            
00193            setValue(A,i,j,k,(1+q2+r2)/denominateur);
00194            setValue(B,i,j,k,(1+p2+r2)/denominateur);
00195            setValue(C,i,j,k,(1+p2+q2)/denominateur);
00196            
00197            setValue(D,i,j,k,(2*tmp_p*tmp_q)/denominateur);
00198            setValue(E,i,j,k,(2*tmp_p*tmp_r)/denominateur);
00199            setValue(F,i,j,k,(2*tmp_q*tmp_r)/denominateur);
00200 
00201          }
00202 
00203   if (time_flag)
00204     {
00205       t1 = clock()-t0;
00206       printf("calcul_parametres_differentiels: temps mis: %f secondes\n",t1/(float)CLOCKS_PER_SEC);
00207     }
00208 }
00209 
00210 void calcul_evolution_surface(inricache *imgPhi,inricache *imgForces,inricache *imgGeod,inricache *imgA,inricache *imgB,inricache *imgC,inricache *imgD,inricache *imgE,inricache *imgF,int nb_iter,float ptTau,Fort_int lfmt[9],int time_flag)
00211 {
00212   int i;
00213   clock_t init=0,prev=0,curr=0;
00214 
00215   /* chronometrage si on le demande. ici on ne chronometrera que le temps d'execution des iterations */
00216   if (time_flag)
00217     init = clock();
00218   curr=init;
00219   prev=init;
00220   
00221   for (i=0;i<nb_iter;i++)
00222     {
00223       calcul_force(imgPhi,imgForces,imgA,imgB,imgC,imgD,imgE,imgF,lfmt,(int)max(time_flag-1,0));
00224       update_solution(imgPhi,imgForces,imgGeod,ptTau,nb_iter,lfmt,(int)max(time_flag-1,0));
00225 
00226       if (time_flag)
00227          {
00228            curr=clock();
00229            fprintf(stderr,"calcul_evolution_surface: iteration %d,temps effectue: %f secondes,moyenne: %f secondes\n",i,(curr-prev)/(float)(CLOCKS_PER_SEC),((curr-init)/(float)(CLOCKS_PER_SEC)/(i+1)));
00230            prev=curr;
00231          }
00232     }
00233 }
00234 
00235 void calcul_force(inricache *imgPhi,inricache *imgForces,inricache *imgA,inricache *imgB,inricache *imgC,inricache *imgD,inricache *imgE,inricache *imgF,Fort_int lfmt[9],int time_flag)
00236 {
00237   /* parametres differentiels */
00238   float a=0,b=0,c=0,d=0,e=0,f=0;
00239   /* derivees partielles en x,y,z de Phi dans les sens positifs et negatifs */
00240   float dxp=0,dxm=0,dyp=0,dym=0,dzp=0,dzm=0;
00241   /* derivees partielles en x,y,z de Phi par la methode du minmod */
00242   float dx=0,dy=0,dz=0;
00243   /* carre des derivees partielles en x,y,z */
00244   float dx2=0,dy2=0,dz2=0;
00245   float currPhi=0;
00246 
00247   register int i,j,k,i2,j2;
00248 
00249   clock_t t0=0,t1=0;
00250 
00251   /* chronometrage si on le demande */
00252   if (time_flag)
00253     t0=clock();
00254 
00255   /* todo: gestion des effets de bords, pixels extremaux */
00256   for (k=1;k<lfmt[I_NDIMZ]-1;k++)
00257     {
00258       for (j=1;j<lfmt[I_NDIMY]-1;j++)
00259          {
00260            for (i=1;i<lfmt[I_NDIMX]-1;i++)
00261              {
00262 
00263                a=getValue(imgA,i,j,k);
00264                b=getValue(imgB,i,j,k);
00265                c=getValue(imgC,i,j,k);
00266                d=getValue(imgD,i,j,k);
00267                e=getValue(imgE,i,j,k);
00268                f=getValue(imgF,i,j,k);
00269 
00270                currPhi = getValue(imgPhi,i,j,k);
00271 
00272                dxp = getValue(imgPhi,i+1,j,k) - currPhi;
00273                dxm = currPhi - getValue(imgPhi,i-1,j,k);
00274 
00275                dyp = getValue(imgPhi,i,j+1,k) - currPhi;
00276                dym = currPhi - getValue(imgPhi,i,j-1,k);
00277 
00278                dzp = getValue(imgPhi,i,j,k+1) - currPhi;
00279                dzm = currPhi - getValue(imgPhi,i,j,k-1);
00280 
00281                dx=minmod(dxp,dxm);
00282                dy=minmod(dyp,dym);
00283                dz=minmod(dzp,dzm);
00284                
00285                dx2=max3(dxp,-dxm,0);
00286                dx2*=dx2;
00287                dy2=max3(dyp,-dym,0);
00288                dy2*=dy2;
00289                dz2=max3(dzp,-dzm,0);           
00290                dz2*=dz2;
00291 
00292                setValue(imgForces,i,j,k,sqrt ((double)max(a*dx2+b*dy2+c*dz2-d*dx*dy-e*dx*dz-f*dy*dz,0)));
00293              }
00294 
00295            /* fin de la boucle en x prolongation des bords */
00296            for (i2=0;i2<lfmt[I_NDIMX];i2++)
00297              {
00298                setValue(imgForces,i2,0,k,getValue(imgForces,i2,1,k));
00299                setValue(imgForces,i2,lfmt[I_NDIMY]-1,k,getValue(imgForces,i2,lfmt[I_NDIMY]-2,k));
00300              }
00301            /* fin de la boucle en y prolongation des bords */
00302            for (j2=0;j2<lfmt[I_NDIMY];j2++)
00303              {
00304                setValue(imgForces,0,j2,k,getValue(imgForces,1,j2,k));
00305                setValue(imgForces,lfmt[I_NDIMX]-1,j2,k,getValue(imgForces,lfmt[I_NDIMX]-2,j2,k));
00306              }
00307          }
00308     }
00309   /*  for (j=0;j<lfmt[I_NDIMY];j++)
00310     for (i=0;i<lfmt[I_NDIMX];i++)
00311       {
00312          ((float *)(bufferF[0]))[indice(i,j,lfmt[I_NDIMX])] = ((float *)(bufferF[1]))[indice(i,j,lfmt[I_NDIMX])];
00313          ((float *)(bufferF[lfmt[I_NDIMZ]-1]))[indice(i,j,lfmt[I_NDIMX])] = ((float *)(bufferF[lfmt[I_NDIMZ]-2]))[indice(i,j,lfmt[I_NDIMX])];
00314       }
00315   */
00316 
00317   if (time_flag)
00318     {
00319       t1 = clock()-t0;
00320       printf("calcul_forces: temps mis: %f secondes\n",t1/(float)CLOCKS_PER_SEC);
00321     }
00322 
00323 }
00324 
00325 void update_solution(inricache *imgPhi,inricache *imgF,inricache *imgGeod,int nb_iter,float ptTau,Fort_int lfmt[9],int time_flag)
00326 {
00327   register int i,j,k;
00328   float nvPhi,oldPhi;
00329 
00330   clock_t t0=0,t1=0;
00331   /* chronometrage si on le demande */
00332   if (time_flag)
00333     t0=clock();
00334 
00335   for (k=0;k<lfmt[I_NDIMZ];k++)
00336     for (j=0;j<lfmt[I_NDIMY];j++)
00337       for (i=0;i<lfmt[I_NDIMX];i++)
00338       {
00339          oldPhi = getValue(imgPhi,i,j,k);
00340          nvPhi = oldPhi + ptTau * getValue(imgF,i,j,k);
00341          setValue(imgPhi,i,j,k,nvPhi);
00342          if (nvPhi * oldPhi < 0)
00343            setValue(imgGeod,i,j,k,ptTau*(nb_iter - (nvPhi / (nvPhi - oldPhi))));
00344       }
00345 
00346   if (time_flag)
00347     {
00348       t1 = clock()-t0;
00349       printf("update_solution: temps mis: %f secondes\n",t1/(float)CLOCKS_PER_SEC);
00350     }
00351 }

Généré le Mon Nov 3 11:50:10 2003 par doxygen1.2.18