Public Member Functions | |
Approx (int _nx, int _ny, int _nz) | |
void | reset (Bunch *b) |
void | putCharge (double x, double y, double z, double c) |
void | computeApprox () |
void | reduce () |
std::vector< Charge > | getVector () const |
Private Member Functions | |
int | index (int ix, int iy, int iz) |
Private Attributes | |
int | nx |
int | ny |
int | nz |
double | totalC |
double | dx |
double | dy |
double | dz |
double | xMin |
double | yMin |
double | zMin |
double * | xx |
double * | yy |
double * | zz |
double * | cc |
std::vector< Charge > | v |
Bunch::Approx::Approx | ( | int | _nx, | |
int | _ny, | |||
int | _nz | |||
) | [inline] |
int Bunch::Approx::index | ( | int | ix, | |
int | iy, | |||
int | iz | |||
) | [inline, private] |
void Bunch::Approx::reset | ( | Bunch * | b | ) | [inline] |
References Bunch::bound_x, Bunch::bound_y, Bunch::bound_z, cc, dx, dy, dz, nx, ny, nz, totalC, v, xMin, xx, yMin, yy, zMin, and zz.
Referenced by Bunch::Bunch(), and Bunch::computeField().
00104 { 00105 totalC = 0.0; 00106 dx = b->bound_x*2.0/nx; xMin = -b->bound_x; 00107 dy = b->bound_y*2.0/ny; yMin = -b->bound_y; 00108 dz = b->bound_z*2.0/nz; zMin = -b->bound_z; 00109 int nBins3 = nx*ny*nz; 00110 for(int i=0; i<nBins3; ++i) 00111 xx[i] = yy[i] = zz[i] = cc[i] = 0.0; 00112 v.clear(); 00113 }
void Bunch::Approx::putCharge | ( | double | x, | |
double | y, | |||
double | z, | |||
double | c | |||
) |
References cc, dx, dy, dz, index(), nx, ny, nz, totalC, xMin, xx, yMin, yy, zMin, and zz.
Referenced by Bunch::computeField().
01035 { 01036 // (Must add all charge somewhere, as it was put into the grid.) 01037 int ix=(int)floor((x-xMin)/dx); 01038 if(ix < 0 || ix >= nx) ix = nx/2; 01039 int iy=(int)floor((y-yMin)/dy); 01040 if(iy < 0 || iy >= ny) iy = ny/2; 01041 int iz=(int)floor((z-zMin)/dz); 01042 if(iz < 0 || iz >= nz) iz = nz/2; 01043 int i=index(ix,iy,iz); 01044 xx[i] += c*x; 01045 yy[i] += c*y; 01046 zz[i] += c*z; 01047 cc[i] += c; 01048 totalC += fabs(c); 01049 }
void Bunch::Approx::computeApprox | ( | ) |
References cc, index(), nx, ny, nz, reduce(), v, xx, yy, and zz.
Referenced by Bunch::computeField().
01052 { 01053 reduce(); 01054 v.clear(); 01055 for(int ix=0; ix<nx; ++ix) { 01056 for(int iy=0; iy<ny; ++iy) { 01057 for(int iz=0; iz<nz; ++iz) { 01058 int i=index(ix,iy,iz); 01059 if(cc[i] == 0.0) continue; 01060 v.push_back(Charge(xx[i]/cc[i], yy[i]/cc[i], 01061 zz[i]/cc[i],cc[i])); 01062 } 01063 } 01064 } 01065 }
void Bunch::Approx::reduce | ( | ) |
References cc, index(), nx, ny, nz, totalC, xx, yy, and zz.
Referenced by computeApprox().
01068 { 01069 // This routine finds bins in the 3-d histogram that contain less than 01070 // minFrac of the total charge, and moves their charge 1 bin towards 01071 // the center. This reduces the number of charges in the approximation. 01072 // For tests with gaussian beams and nx=ny=nz=9, the reduction was from 01073 // 124 to 26. 01074 const double minFrac=0.02; 01075 01076 // ix<nx/2 region 01077 for(int ix=0; ix<nx/2; ++ix) { 01078 for(int iy=0; iy<ny; ++iy) { 01079 for(int iz=0; iz<nz; ++iz) { 01080 int i=index(ix,iy,iz); 01081 if(cc[i] == 0.0) continue; 01082 if(fabs(cc[i]) < totalC*minFrac) { 01083 int j=index(ix+1,iy,iz); 01084 xx[j] += xx[i]; 01085 yy[j] += yy[i]; 01086 zz[j] += zz[i]; 01087 cc[j] += cc[i]; 01088 xx[i] = yy[i] = zz[i] = cc[i] = 0.0; 01089 } 01090 } 01091 } 01092 } 01093 01094 // ix>nx/2 region 01095 for(int ix=nx/2+1; ix<nx; ++ix) { 01096 for(int iy=0; iy<ny; ++iy) { 01097 for(int iz=0; iz<nz; ++iz) { 01098 int i=index(ix,iy,iz); 01099 if(cc[i] == 0.0) continue; 01100 if(fabs(cc[i]) < totalC*minFrac) { 01101 int j=index(ix-1,iy,iz); 01102 xx[j] += xx[i]; 01103 yy[j] += yy[i]; 01104 zz[j] += zz[i]; 01105 cc[j] += cc[i]; 01106 xx[i] = yy[i] = zz[i] = cc[i] = 0.0; 01107 } 01108 } 01109 } 01110 } 01111 01112 // iy<ny/2 region 01113 for(int iy=0; iy<ny/2; ++iy) { 01114 for(int ix=0; ix<nx; ++ix) { 01115 for(int iz=0; iz<nz; ++iz) { 01116 int i=index(ix,iy,iz); 01117 if(cc[i] == 0.0) continue; 01118 if(fabs(cc[i]) < totalC*minFrac) { 01119 int j=index(ix,iy+1,iz); 01120 xx[j] += xx[i]; 01121 yy[j] += yy[i]; 01122 zz[j] += zz[i]; 01123 cc[j] += cc[i]; 01124 xx[i] = yy[i] = zz[i] = cc[i] = 0.0; 01125 } 01126 } 01127 } 01128 } 01129 01130 // iy>ny/2 region 01131 for(int iy=ny/2+1; iy<ny; ++iy) { 01132 for(int ix=0; ix<nx; ++ix) { 01133 for(int iz=0; iz<nz; ++iz) { 01134 int i=index(ix,iy,iz); 01135 if(cc[i] == 0.0) continue; 01136 if(fabs(cc[i]) < totalC*minFrac) { 01137 int j=index(ix,iy-1,iz); 01138 xx[j] += xx[i]; 01139 yy[j] += yy[i]; 01140 zz[j] += zz[i]; 01141 cc[j] += cc[i]; 01142 xx[i] = yy[i] = zz[i] = cc[i] = 0.0; 01143 } 01144 } 01145 } 01146 } 01147 01148 // iz<nz/2 region 01149 for(int iz=0; iz<nz/2; ++iz) { 01150 for(int ix=0; ix<nx; ++ix) { 01151 for(int iy=0; iy<ny; ++iy) { 01152 int i=index(ix,iy,iz); 01153 if(cc[i] == 0.0) continue; 01154 if(fabs(cc[i]) < totalC*minFrac) { 01155 int j=index(ix,iy,iz+1); 01156 xx[j] += xx[i]; 01157 yy[j] += yy[i]; 01158 zz[j] += zz[i]; 01159 cc[j] += cc[i]; 01160 xx[i] = yy[i] = zz[i] = cc[i] = 0.0; 01161 } 01162 } 01163 } 01164 } 01165 01166 // iz>nz/2 region 01167 for(int iz=nz/2+1; iz<nz; ++iz) { 01168 for(int ix=0; ix<nx; ++ix) { 01169 for(int iy=0; iy<ny; ++iy) { 01170 int i=index(ix,iy,iz); 01171 if(cc[i] == 0.0) continue; 01172 if(fabs(cc[i]) < totalC*minFrac) { 01173 int j=index(ix,iy,iz-1); 01174 xx[j] += xx[i]; 01175 yy[j] += yy[i]; 01176 zz[j] += zz[i]; 01177 cc[j] += cc[i]; 01178 xx[i] = yy[i] = zz[i] = cc[i] = 0.0; 01179 } 01180 } 01181 } 01182 } 01183 }
std::vector<Charge> Bunch::Approx::getVector | ( | ) | const [inline] |
int Bunch::Approx::nx [private] |
Referenced by Approx(), computeApprox(), index(), putCharge(), reduce(), and reset().
int Bunch::Approx::ny [private] |
Referenced by Approx(), computeApprox(), index(), putCharge(), reduce(), and reset().
int Bunch::Approx::nz [private] |
Referenced by Approx(), computeApprox(), putCharge(), reduce(), and reset().
double Bunch::Approx::totalC [private] |
Referenced by putCharge(), reduce(), and reset().
double Bunch::Approx::dx [private] |
Referenced by putCharge(), and reset().
double Bunch::Approx::dy [private] |
Referenced by putCharge(), and reset().
double Bunch::Approx::dz [private] |
Referenced by putCharge(), and reset().
double Bunch::Approx::xMin [private] |
Referenced by putCharge(), and reset().
double Bunch::Approx::yMin [private] |
Referenced by putCharge(), and reset().
double Bunch::Approx::zMin [private] |
Referenced by putCharge(), and reset().
double* Bunch::Approx::xx [private] |
Referenced by Approx(), computeApprox(), putCharge(), reduce(), and reset().
double * Bunch::Approx::yy [private] |
Referenced by Approx(), computeApprox(), putCharge(), reduce(), and reset().
double * Bunch::Approx::zz [private] |
Referenced by Approx(), computeApprox(), putCharge(), reduce(), and reset().
double * Bunch::Approx::cc [private] |
Referenced by Approx(), computeApprox(), putCharge(), reduce(), and reset().
std::vector<Charge> Bunch::Approx::v [private] |
Referenced by computeApprox(), getVector(), and reset().