Exemple #1
0
void poisson_xy(Grid2D& rho, Greenfb& gf)
{
 int j, l,NX=rho.get_NX(),NY=rho.get_NX();
 double dx=rho.get_dx(), dy=rho.get_dy();
 double *temx, *temy;
 temx=new double[NX];
 temy=new double[NY]; 

 gf.add_boundary_potential(rho);

 for(j=0; j<NX; j++)
   {  
    for(l=0;l<NY;l++)
     temy[l]=rho[l+NY*j];
    sinft(temy-1,NY);
    for(l=0;l<NY;l++)
     rho[l+NY*j]=temy[l];
   }
 
 for(l=0; l<NY; l++)
   {
    for(j=0;j<NX;j++)
     temx[j]=rho[l+j*NY];
    sinft(temx-1,NX);
    for(j=0;j<NX;j++)
     rho[l+NY*j]=temx[j];
   }
 
  for(j=1;j<NX;j++)
   for(l=1;l<NY;l++)
     rho[l+j*NY]*=-1.0/eps0             
                  *0.5*dx*dy/(cos(PI*j/NX)+cos(PI*l/NY)-2.0); 
		  
 for(j=0; j<NX; j++)
  {
   for(l=0;l<NY;l++)
    temy[l]=rho[l+NY*j];   
   sinft(temy-1,NY);
   for(l=0;l<NY;l++)
     rho[l+NY*j]=2.0*temy[l]/NY;   
  }
 
 for(l=0; l<NY; l++)
   {
    for(j=0;j<NX;j++)
     temx[j]=rho[l+j*NY];
    sinft(temx-1,NX);
    for(j=0;j<NX;j++)
     rho[l+NY*j]=2.0*temx[j]/NX;
   }

 delete temx;
 delete temy;
 
}
Exemple #2
0
Greenfb::Greenfb(Grid2D& g, double a, double b) : greenf(2*g.get_NX()+2*g.get_NY()-8)
{
  int i, j, v, u=0;
  int Nb=greenf.size(); 	
  int NX=g.get_NX();
  int NY=g.get_NY();
  xb=vektor(Nb);
  yb=vektor(Nb);
  a0=a;
  b0=b;

  for(j=0; j<Nb; j++)
	 {
	   greenf[j]=g;
	   greenf[j].reset();
	 }

  for(i=1; i<NX; i++)
      {
		xb[u]=g.x[i];
		yb[u]=g.y[NY-1];
		u=u+1;
	  }	
  for(j=1; j<NY-1; j++)	
      {
		xb[u]=g.x[NX-1];
		yb[u]=g.y[j];
		u=u+1;
      }   
  for(i=1; i<NX-1; i++)
      {
		xb[u]=g.x[i];
		yb[u]=g.y[1];
	    u=u+1;
	  }
  for(j=2; j<NY-1; j++)	  
	 {
		xb[u]=g.x[1];
		yb[u]=g.y[j];
		u=u+1;
	  }
     	
  for(int j=0; j<Nb; j++)
    for (u=0; u<NX; u++)
		for(v=0; v<NY; v++)
		{
		 if (a0 == 0.0) greenf[j](u,v)=open_2D( g.x[u], xb[j], g.y[v], yb[j]);
		 else if (a0 > 0.0 && b0 == 0.0) greenf[j](u,v)=circle_2D( g.x[u], xb[j], g.y[v], yb[j]);
		 else greenf[j](u,v)=0.0;
		}

}
Exemple #3
0
void Greenfb::add_boundary_potential(Grid2D& rho)
{
	if (a0 > 0.0 && b0 > 0.0) return;
	int i,j, u=0;
	int NX=rho.get_NX();
	int NY=rho.get_NY();
	double dx=rho.get_dx();
	double dy=rho.get_dy();
	Grid2D rho_tmp(NX,NY,dx,dy);
	double* rhotg =rho_tmp.grid;
	double* rhog =rho.grid;
	for(i=0; i<NX; i++)
		for(j=0; j<NY; j++)	 
		  rhotg[j+i*NY]=rhog[j+i*NY];	
	for(i=1; i<NX; i++)
	   {
		rhog[NY-1+i*NY]+=eps0*get_potential_b(u,rho_tmp);  
		u=u+1;
	   }
	for(j=1; j<NY-1; j++)	
	   {  
        rhog[(j)+(NX-1)*NY]+=eps0*get_potential_b(u,rho_tmp); 
		u=u+1;
       }
	for(i=1; i<NX-1; i++)
	   {
		rhog[(1)+(i)*NY]+=eps0*get_potential_b(u,rho_tmp);
		u=u+1;
	   }
	for(j=2; j<NY-1; j++)
	   {	  
        rhog[(j)+(1)*NY]+=eps0*get_potential_b(u,rho_tmp);
		u=u+1;
       }
}
Exemple #4
0
void poisson_xy(Grid2D& Ex, Grid2D& Ey, Grid2D& rho, Greenfb& gf)
{
 int NX=rho.get_NX(),NY=rho.get_NX();
 double dx=rho.get_dx(), dy=rho.get_dy();
 //rho.filtering();
 poisson_xy(rho,gf);
 double* rhog=rho.grid;
 double* Exg=Ex.grid;
 double* Eyg=Ey.grid;
 for(int j=3;j<NX-2;j++)
  for(int l=3;l<NY-2;l++)
   {
/*    Ex(j,l)=-(rho(j+1,l,1)-rho(j-1,l,1))/(2.0*dx);
    Ey(j,l)=-(rho(j,l+1,1)-rho(j,l-1,1))/(2.0*dy);*/
		Exg[l+j*NY]=-(rhog[l+(j+1)*NY]-rhog[l+(j-1)*NY])/(2.0*dx);
		    Eyg[l+j*NY]=-(rhog[l+1+j*NY]-rhog[l-1+j*NY])/(2.0*dy);
   }
}
Exemple #5
0
void poisson_xy(Grid2D& Ex, Grid2D& Ey, Grid2D& rho, Greenfb& gf)
{
// pTimer ffT;
 int NX=rho.get_NX(),NY=rho.get_NX();
 double dx=rho.get_dx(), dy=rho.get_dy();
 poisson_xy(rho,gf);
 double* rhog=rho.grid;
 double* Exg=Ex.grid;
 double* Eyg=Ey.grid;
//ffT.start();
 for(int j=3;j<NX-2;j++)
  for(int l=3;l<NY-2;l++)
   {
/*    Ex(j,l)=-(rho(j+1,l,1)-rho(j-1,l,1))/(2.0*dx);
    Ey(j,l)=-(rho(j,l+1,1)-rho(j,l-1,1))/(2.0*dy);*/
		Exg[l+j*NY]=-(rhog[l+(j+1)*NY]-rhog[l+(j-1)*NY])/(2.0*dx);
		    Eyg[l+j*NY]=-(rhog[l+1+j*NY]-rhog[l-1+j*NY])/(2.0*dy);
   }
//ffT.stop();
//  printf("doubleforloop: %f\n",ffT.t/1000);
}
Exemple #6
0
double Greenfb::get_potential_b(int j, Grid2D& rho)
{
	double tem=0.0;
	int NX=rho.get_NX();
	int NY=rho.get_NY();
	int u,v;
	double* rhog=rho.grid;
	double* greeng=greenf[j].grid;
	for (u=0; u<NX; u++)
		for(v=0; v<NY; v++)
		    tem+=greeng[v+u*NY]*rhog[v+u*NY];
	return tem;
	
}
Exemple #7
0
double Pic::entropy(Grid2D& target){
  double Hfunc = 0.0;
  int NPIC = get_size();
  int Nxs = target.get_NX();
  int Nys = target.get_NY();
  double dxs = target.get_dx();
  double dys = target.get_dy();
  gatherXsYs(1.0/(double)NPIC, target);
  for(int j=0; j<Nxs; ++j)
    for(int l=0; l<Nys; ++l){
      if(target(j, l) > 0.0)	
	Hfunc += target(j, l)*log(target(j, l))*dxs*dys;
    }
  return Hfunc;
}
Exemple #8
0
void init_rho(Grid2D& rho, double rho0, double rbeam)
{
	int l,i;
	int NX=rho.get_NX(), NY=rho.get_NY();
	for(l=0; l<NX; l++)
          for(i=0; i<NY; i++)
          {
           if ( sqrt(pow(rho.x[l],2)+pow(rho.y[i],2)) < rbeam ) 
		       rho(l,i)=rho0;
		   else rho(l,i)=0.0;	   
	  }
	  for(l=0; l<NX; l++)
            for(i=0; i<NY; i++)
            {
             if ( sqrt(pow(rho.x[l],2)+pow(rho.y[i],2)) < 0.8*rbeam ) 
		       rho(l,i)=0.0;	   
	     }
	  	  
}
Exemple #9
0
void poisson_rz(Grid2D& rho)
{
 int j,m;
 int NR=rho.get_NX();
 int NZ=rho.get_NY();
 double dr=rho.get_dx();
 double dz=rho.get_dy();

 double *q1=new double[NR];
 double *q2=new double[NR];
 double *tem=new double[NZ];

 for(j=0; j<NR; j++)
   {
    for(m=0;m<NZ;m++)
     tem[m]=rho[m+NZ*j];
    realft(tem-1,NZ,1);
    //cosft1(tem-1,NZ);
    //sinft(tem-1,NZ);
    for(m=0;m<NZ;m++)
     rho[m+NZ*j]=tem[m];
   }

 for(m=2;m<NZ;m+=2)
    {
     for(j=0;j<NR;j++)
      {
       q1[j]=rho[m+NZ*j];
       q2[j]=rho[m+1+NZ*j];
      }       
     poisson_r(q1,(int)(0.5*m),NR,NZ,dr,dz);
     poisson_r(q2,(int)(0.5*m),NR,NZ,dr,dz);
     for(j=0;j<NR;j++)
      {
       rho[m+NZ*j]=q1[j];
       rho[m+1+NZ*j]=q2[j];
      }    
    }

  for(j=0;j<NR;j++)
       q1[j]=rho[1+NZ*j];
  poisson_r(q1,(int)(0.5*NZ),NR,NZ,dr,dz);
  for(j=0;j<NR;j++)
     rho[1+NZ*j]=q1[j];


  for(j=0;j<NR;j++)               
    q1[j]=rho[j*NZ];          
  poisson_r(q1,0,NR,NZ,dr,dz);      


  for(j=0;j<NR;j++)
    rho[0+NZ*j]=q1[j]; 


  for(j=0; j<NR; j++)
    { 
     for(m=0;m<NZ;m++)
      tem[m]=rho[m+NZ*j];
     realft(tem-1,NZ,-1);
     //cosft1(tem-1,NZ);
     //sinft(tem-1,NZ);
     for(m=0;m<NZ;m++)
      rho[m+NZ*j]=2.0*tem[m]/NZ;     
    }

  delete q1;
  delete q2;
  delete tem;
}