Main Page | Directories | File List | File Members

update_potential.h File Reference

Go to the source code of this file.

Functions

void update_potential (void)


Function Documentation

void update_potential void   ) 
 

Definition at line 33 of file update_potential.h.

References free(), i_front, ND, NE, Ne, Ng, noeud_geo, OHMIC, printf(), Q, SCHOTTKY, V, Vi, and VOLUME.

00034 {
00035 // remember the Coulomb law :
00036 // V(r) = 1/(epsr*epsilon0) * q/r
00037  register int i,j;
00038 // double *vertex;
00039 // double *de; 
00040  double *tc; // total charge per every vertex
00041  
00042 /*
00043  for(i=0;i<Ne;i++){
00044   int k;
00045   for(j=0;j<4;j++)
00046    for(k=0;k<1000;k++)
00047     V[noeud_geo[j][i]-1]+=0.0015e-12*(-Q*(NE[noeud_geo[j][i]-1]-ND[i]));
00048  }
00049  return;*/
00050  
00051 // vertex=malloc((Ng+1)*sizeof(double));
00052 // de=malloc((Ng+1)*sizeof(double));
00053  tc=malloc((Ng+1)*sizeof(double)); 
00054  if(/*vertex==NULL || de==NULL ||*/ tc==NULL){
00055   printf("update_potential : not enough memory for dynamical allocation!\n");
00056   exit(0);
00057  }
00058 
00059 // for(i=0;i<Ng;i++) de[i]=vertex[i]=0;
00060 /* 
00061  for(i=0;i<Ne;i++){
00062 //printf("%g %g\n",NE[noeud_geo[0][i]-1],VOLUME[i]);
00063       de[noeud_geo[0][i]-1]+=NE[noeud_geo[0][i]-1]*VOLUME[i];
00064       de[noeud_geo[1][i]-1]+=NE[noeud_geo[1][i]-1]*VOLUME[i];
00065       de[noeud_geo[2][i]-1]+=NE[noeud_geo[2][i]-1]*VOLUME[i];
00066       de[noeud_geo[3][i]-1]+=NE[noeud_geo[3][i]-1]*VOLUME[i];
00067 
00068       vertex[noeud_geo[0][i]-1]++;
00069       vertex[noeud_geo[1][i]-1]++;
00070       vertex[noeud_geo[2][i]-1]++;
00071       vertex[noeud_geo[3][i]-1]++;
00072  }
00073  for(i=0;i<Ng;i++){
00074 //   printf("de = %g vertex = %d\n",de[i],vertex[i]);
00075    de[i]/=vertex[i]; // de[i] = number of electrons in the i-th vertex
00076 //   printf("de = %g\n",de[i]);
00077  }*/
00078 
00079  
00080 // total charge in the i-th element
00081  for(i=0;i<Ne;i++){
00082    double de;
00083    de=0.25*(NE[noeud_geo[0][i]-1]+NE[noeud_geo[1][i]-1]+
00084             NE[noeud_geo[2][i]-1]+NE[noeud_geo[3][i]-1]);
00085    tc[noeud_geo[0][i]-1]=-Q*(de-ND[i])*VOLUME[i];
00086    tc[noeud_geo[1][i]-1]=-Q*(de-ND[i])*VOLUME[i];
00087    tc[noeud_geo[2][i]-1]=-Q*(de-ND[i])*VOLUME[i];
00088    tc[noeud_geo[3][i]-1]=-Q*(de-ND[i])*VOLUME[i];
00089 //   printf("de = %g da = %g tc=%g\n",de,ND[i],tc[i]);
00090  }
00091 //exit(0); 
00092 
00093 // update the potential according to the Coulomb force
00094 //printf("here...\n");
00095  for(i=0;i<Ng;i++) V[i]=0.; // just in case
00096  for(i=0;i<Ng;i++){
00097    for(j=0;j<Ng;j++){
00098 //     printf("V = %g %g\n",Vi[j],tc[i]*k[i]/resr[i][j]);
00099 // maintain the charge neutrality and avoid NaN
00100      if(j!=i && i_front[j]!=OHMIC && i_front[j]!=SCHOTTKY
00101              && i_front[i]!=OHMIC && i_front[i]!=SCHOTTKY) V[j]+=tc[i]*k[i]/resr[i][j];
00102 
00103 //     printf("V = %g\n",V[j]);
00104    }
00105  }
00106 // for(i=0;i<Ng;i++) printf("%g\n",V[i]);
00107  for(i=0;i<Ng;i++) V[i]+=Vi[i];
00108 
00109 //   V[i]=Vi[i];
00110 //printf("that's it!\n");
00111  
00112 /*
00113  printf("\nSolving the 3D Poisson equation...\n");
00114   linbcg(Ng,b,x,itol,tol,itmax);
00115  printf("Poisson equation solved...\n\n");*/
00116 // free(vertex);
00117 // free(de);
00118  free(tc);
00119 }


© sourcejam.com 2005-2008