CylinderImpl Class Reference

Inheritance diagram for CylinderImpl:

FieldMapImpl

List of all members.


Detailed Description

class CylinderImpl -- class for a Cylinder FieldMap implementation

Public Member Functions

 CylinderImpl (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 ~CylinderImpl ()
void getFieldValue (const G4double local[4], G4double field[6]) const
bool handleCommand (InputFile &in, BLArgumentVector &argv, BLArgumentMap &namedArgs)
virtual void getBoundingPoint (int i, G4double point[4])
virtual bool hasB ()
virtual bool hasE ()
bool setField (G4double R, G4double Z, G4double Br, G4double Bz, G4double Er, G4double Ez, int linenumber)
virtual bool writeFile (FILE *f)

Private Attributes

G4int nR
G4int nZ
G4double dR
G4double dZ
G4double Z0
G4double tolerance
float * mapBr
float * mapBz
float * mapEr
float * mapEz
bool extendZ
float extendBrFactor
float extendBzFactor
float extendErFactor
float extendEzFactor

Constructor & Destructor Documentation

CylinderImpl::CylinderImpl ( BLArgumentVector argv,
BLArgumentMap namedArgs 
)

References argDouble(), argInt(), dR, dZ, extendBrFactor, extendBzFactor, extendErFactor, extendEzFactor, extendZ, mapBr, mapBz, mapEr, mapEz, nR, nZ, tolerance, and Z0.

00979                                                         : FieldMapImpl()
00980 {
00981         nR = 2;
00982         nZ = 2;
00983         dR = 10.0*mm;
00984         dZ = 10.0*mm;
00985         Z0 = 0.0;
00986         tolerance = 0.01*mm;
00987         mapBr = 0;
00988         mapBz = 0;
00989         mapEr = 0;
00990         mapEz = 0;
00991         extendZ = false;
00992         extendBrFactor = extendBzFactor = 1.0;
00993         extendErFactor = extendEzFactor = 1.0;
00994         argInt(nR,"nR",namedArgs);
00995         argInt(nZ,"nZ",namedArgs);
00996         argDouble(dR,"dR",namedArgs);
00997         argDouble(dZ,"dZ",namedArgs);
00998         argDouble(Z0,"Z0",namedArgs);
00999         argDouble(tolerance,"tolerance",namedArgs);
01000 }

CylinderImpl::~CylinderImpl (  ) 

References mapBr, mapBz, mapEr, and mapEz.

01003 {
01004         if(mapBr) delete mapBr;
01005         if(mapBz) delete mapBz;
01006         if(mapEr) delete mapEr;
01007         if(mapEz) delete mapEz;
01008 }


Member Function Documentation

void CylinderImpl::getFieldValue ( const G4double  local[4],
G4double  field[6] 
) const [virtual]

Implements FieldMapImpl.

References dR, dZ, extendBrFactor, extendBzFactor, extendErFactor, extendEzFactor, extendZ, mapBr, mapBz, mapEr, mapEz, nR, nZ, and Z0.

01012 {
01013         G4double z = local[2];
01014         G4double r = sqrt(local[0]*local[0]+local[1]*local[1]);
01015 
01016         bool extending = false;
01017         if(z < 0.0 && extendZ) {
01018                 z = -z;
01019                 extending = true;
01020         }
01021 
01022         z -= Z0;
01023 
01024         // 2D linear average of the 4 surrounding points in the map
01025         int i = (int)floor(r/dR);
01026         int j = (int)floor(z/dZ);
01027         if(z < Z0 || i >= nR-1 || j < 0 || j >= nZ-1) {
01028                 field[0] = field[1] = field[2] = field[3] = field[4] = 
01029                                                                 field[5] = 0.0;
01030                 return;
01031         }
01032 
01033         float fr = 1.0 - (r - i*dR) / dR;
01034         assert(fr >= 0.0 && fr <= 1.0);
01035         float fz = 1.0 - (z - j*dZ) / dZ;
01036         assert(fz >= 0.0 && fz <= 1.0);
01037 
01038         G4double Bz = 0.0;
01039         if(mapBz) Bz =
01040                 mapBz[j*nR+i]*fr*fz +
01041                 mapBz[j*nR+i+1]*(1.0-fr)*fz +
01042                 mapBz[(j+1)*nR+i]*fr*(1.0-fz) +
01043                 mapBz[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz);
01044         G4double Br = 0.0;
01045         if(mapBr) Br =
01046                 mapBr[j*nR+i]*fr*fz +
01047                 mapBr[j*nR+i+1]*(1.0-fr)*fz +
01048                 mapBr[(j+1)*nR+i]*fr*(1.0-fz) +
01049                 mapBr[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz);
01050         G4double Ez = 0.0;
01051         if(mapEz) Ez =
01052                 mapEz[j*nR+i]*fr*fz +
01053                 mapEz[j*nR+i+1]*(1.0-fr)*fz +
01054                 mapEz[(j+1)*nR+i]*fr*(1.0-fz) +
01055                 mapEz[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz);
01056         G4double Er = 0.0;
01057         if(mapEr) Er =
01058                 mapEr[j*nR+i]*fr*fz +
01059                 mapEr[j*nR+i+1]*(1.0-fr)*fz +
01060                 mapEr[(j+1)*nR+i]*fr*(1.0-fz) +
01061                 mapEr[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz);
01062         if(extending) {
01063                 Br *= extendBrFactor;
01064                 Bz *= extendBzFactor;
01065                 Er *= extendErFactor;
01066                 Ez *= extendEzFactor;
01067         }
01068 
01069         G4double phi = atan2(local[1], local[0]);
01070         field[0] = Br * cos(phi);
01071         field[1] = Br * sin(phi);
01072         field[2] = Bz;
01073         field[3] = Er * cos(phi);
01074         field[4] = Er * sin(phi);
01075         field[5] = Ez;
01076 }

bool CylinderImpl::handleCommand ( InputFile in,
BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

Implements FieldMapImpl.

References extendBrFactor, extendBzFactor, extendErFactor, extendEzFactor, extendZ, InputFile::getline(), InputFile::linenumber(), mapBr, mapBz, mapEr, mapEz, nR, nZ, FieldMapImpl::readBlock(), InputFile::repeatLine(), and setField().

01080 {
01081         if(argv[0] == "extendZ") {
01082                 extendZ = true;
01083                 const char *p = namedArgs["flip"].c_str();
01084                 if(strstr(p,"Br")) extendBrFactor = -1.0;
01085                 if(strstr(p,"Bz")) extendBzFactor = -1.0;
01086                 if(strstr(p,"Er")) extendErFactor = -1.0;
01087                 if(strstr(p,"Ez")) extendEzFactor = -1.0;
01088                 return true;
01089         } else if(argv[0] == "Br") {
01090                 if(mapBr) return false;
01091                 mapBr = new float[nR*nZ];
01092                 for(int i=0; i<nR*nZ; ++i) mapBr[i] = 0.0;
01093                 return readBlock(in,mapBr,nZ,nR,tesla);
01094         } else if(argv[0] == "Bz") {
01095                 if(mapBz) return false;
01096                 mapBz = new float[nR*nZ];
01097                 for(int i=0; i<nR*nZ; ++i) mapBz[i] = 0.0;
01098                 return readBlock(in,mapBz,nZ,nR,tesla);
01099         } else if(argv[0] == "Er") {
01100                 if(mapEr) return false;
01101                 mapEr = new float[nR*nZ];
01102                 for(int i=0; i<nR*nZ; ++i) mapEr[i] = 0.0;
01103                 return readBlock(in,mapEr,nZ,nR,megavolt/meter);
01104         } else if(argv[0] == "Ez") {
01105                 if(mapEz) return false;
01106                 mapEz = new float[nR*nZ];
01107                 for(int i=0; i<nR*nZ; ++i) mapEz[i] = 0.0;
01108                 return readBlock(in,mapEz,nZ,nR,megavolt/meter);
01109         } else if(argv[0] == "data") {
01110                 for(char *line=0; (line=in.getline())!=0;) {
01111                         if(isalpha(line[0])) {
01112                                 in.repeatLine();
01113                                 break;
01114                         }
01115                         int n;
01116                         float R=0.0,Z=0.0,Br=0.0,Bz=0.0,Er=0.0,Ez=0.0;
01117                         for(char *p=line; (p=strchr(p,','))!=0;) *p = ' ';
01118                         n = sscanf(line,"%f%f%f%f%f%f",&R,&Z,&Br,&Bz,&Er,&Ez);
01119                         if(n <= 2) continue;
01120                         setField(R,Z,Br*tesla,Bz*tesla,Er*megavolt/meter,
01121                                 Ez*megavolt/meter,in.linenumber());
01122                 }
01123                 return true;
01124         } else {
01125                 return false;
01126         }
01127 }

void CylinderImpl::getBoundingPoint ( int  i,
G4double  point[4] 
) [virtual]

Implements FieldMapImpl.

References dR, dZ, extendZ, nR, nZ, and Z0.

01130 {
01131         point[0] = (i&1 ? 1.0 : -1.0) * (nR-1) * dR;
01132         point[1] = (i&2 ? 1.0 : -1.0) * (nR-1) * dR;
01133         if(extendZ)
01134                 point[2] = (i&4 ? 1.0 : -1.0) * (nZ-1) * dZ;
01135         else
01136                 point[2] = (i&4 ? Z0 : Z0+(nZ-1)*dZ);
01137 }

virtual bool CylinderImpl::hasB (  )  [inline, virtual]

Implements FieldMapImpl.

References mapBr, and mapBz.

00164 { return mapBz != 0 || mapBr != 0; }

virtual bool CylinderImpl::hasE (  )  [inline, virtual]

Implements FieldMapImpl.

References mapEr, and mapEz.

Referenced by writeFile().

00165 { return mapEz != 0 || mapEr != 0; }

bool CylinderImpl::setField ( G4double  R,
G4double  Z,
G4double  Br,
G4double  Bz,
G4double  Er,
G4double  Ez,
int  linenumber 
)

References dR, dZ, mapBr, mapBz, mapEr, mapEz, nR, nZ, BLCommand::printError(), tolerance, and Z0.

Referenced by BLFieldMap::createCylinderMap(), and handleCommand().

01141 {
01142         if((Br != 0.0 || Bz != 0.0) && !mapBr) {
01143                 mapBr = new float[nR*nZ];
01144                 mapBz = new float[nR*nZ];
01145                 assert(mapBr != 0 && mapBz != 0);
01146                 for(int i=0; i<nR*nZ; ++i) 
01147                         mapBr[i] = mapBz[i] = 0.0;
01148         }
01149         if((Er != 0.0 || Ez != 0.0) && !mapEr) {
01150                 mapEr = new float[nR*nZ];
01151                 mapEz = new float[nR*nZ];
01152                 assert(mapEr != 0 && mapEz != 0);
01153                 for(int i=0; i<nR*nZ; ++i) 
01154                         mapEr[i] = mapEz[i] = 0.0;
01155         }
01156         int i = (int)floor((R/dR) + 0.5);
01157         if(i<0 || fabs(i*dR-R)>tolerance || i >= nR) {
01158                 BLCommand::printError("BLFieldMap: ERROR point off"
01159                             " grid R=%.1f line=%d\n",R,linenumber);
01160                 return false;
01161         }
01162         int j = (int)floor(((Z-Z0)/dZ) + 0.5);
01163         if(j<0 || fabs(j*dZ+Z0-Z)>tolerance || j >= nZ) {
01164                 BLCommand::printError("BLFieldMap: ERROR point off"
01165                             " grid Z=%.1f line=%d\n",Z,linenumber);
01166                 return false;
01167         }
01168         if(mapBr) {
01169                 mapBr[j*nR+i] = Br;
01170                 mapBz[j*nR+i] = Bz;
01171         }
01172         if(mapEr) {
01173                 mapEr[j*nR+i] = Er;
01174                 mapEz[j*nR+i] = Ez;
01175         }
01176 
01177         return true;
01178 }

bool CylinderImpl::writeFile ( FILE *  f  )  [virtual]

Implements FieldMapImpl.

References dR, dZ, extendBrFactor, extendBzFactor, extendErFactor, extendEzFactor, extendZ, hasE(), mapBr, mapBz, mapEr, mapEz, nR, nZ, and Z0.

01181 {
01182         fprintf(f,"cylinder Z0=%g nR=%d nZ=%d dR=%g dZ=%g\n",Z0,nR,nZ,dR,dZ);
01183         if(extendZ) {
01184                 fprintf(f,"extendZ flip=");
01185                 if(extendBrFactor < 0.0) fprintf(f,"Br,");
01186                 if(extendBzFactor < 0.0) fprintf(f,"Bz,");
01187                 if(extendErFactor < 0.0) fprintf(f,"Er,");
01188                 if(extendEzFactor < 0.0) fprintf(f,"Ez,");
01189                 fprintf(f,"\n");
01190         }
01191         fprintf(f,"data\n");
01192 
01193         for(int i=0; i<nR; ++i) {
01194                 G4double R = i*dR;
01195                 for(int j=0; j<nZ; ++j) {
01196                         G4double Z = Z0 + j*dZ;
01197                         int m = j*nR + i;
01198                         assert(m >= 0 && m < nR*nZ);
01199                         G4double Br = (mapBr ? mapBr[m] : 0.0);
01200                         G4double Bz = (mapBz ? mapBz[m] : 0.0);
01201                         fprintf(f,"%.1f %.1f %g %g", R,Z,Br/tesla,Bz/tesla);
01202                         if(hasE()) {
01203                                 G4double Er = (mapEr ? mapEr[m] : 0.0);
01204                                 G4double Ez = (mapEz ? mapEz[m] : 0.0);
01205                                 fprintf(f," %g %g", Er/(megavolt/meter),
01206                                                     Ez/(megavolt/meter));
01207                         }
01208                         fprintf(f,"\n");
01209                 }
01210         }
01211         return true;
01212 }


Member Data Documentation

G4int CylinderImpl::nR [private]

G4int CylinderImpl::nZ [private]

G4double CylinderImpl::dR [private]

G4double CylinderImpl::dZ [private]

G4double CylinderImpl::Z0 [private]

G4double CylinderImpl::tolerance [private]

Referenced by CylinderImpl(), and setField().

float* CylinderImpl::mapBr [private]

float* CylinderImpl::mapBz [private]

float* CylinderImpl::mapEr [private]

float* CylinderImpl::mapEz [private]

bool CylinderImpl::extendZ [private]


The documentation for this class was generated from the following file:
g4beamline