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; } }
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; } }
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; }
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; }
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; } }
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; }