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.

00990                                                         : FieldMapImpl()
00991 {
00992         nR = 2;
00993         nZ = 2;
00994         dR = 10.0*mm;
00995         dZ = 10.0*mm;
00996         Z0 = 0.0;
00997         tolerance = 0.01*mm;
00998         mapBr = 0;
00999         mapBz = 0;
01000         mapEr = 0;
01001         mapEz = 0;
01002         extendZ = false;
01003         extendBrFactor = extendBzFactor = 1.0;
01004         extendErFactor = extendEzFactor = 1.0;
01005         argInt(nR,"nR",namedArgs);
01006         argInt(nZ,"nZ",namedArgs);
01007         argDouble(dR,"dR",namedArgs);
01008         argDouble(dZ,"dZ",namedArgs);
01009         argDouble(Z0,"Z0",namedArgs);
01010         argDouble(tolerance,"tolerance",namedArgs);
01011 }

CylinderImpl::~CylinderImpl (  ) 

References mapBr, mapBz, mapEr, and mapEz.

01014 {
01015         if(mapBr) delete mapBr;
01016         if(mapBz) delete mapBz;
01017         if(mapEr) delete mapEr;
01018         if(mapEz) delete mapEz;
01019 }


Member Function Documentation

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

Implements FieldMapImpl.

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

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

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().

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

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

Implements FieldMapImpl.

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

01141 {
01142         point[0] = (i&1 ? 1.0 : -1.0) * (nR-1) * dR;
01143         point[1] = (i&2 ? 1.0 : -1.0) * (nR-1) * dR;
01144         if(extendZ)
01145                 point[2] = (i&4 ? 1.0 : -1.0) * (nZ-1) * dZ;
01146         else
01147                 point[2] = (i&4 ? Z0 : Z0+(nZ-1)*dZ);
01148 }

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

Implements FieldMapImpl.

References mapBr, and mapBz.

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

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

Implements FieldMapImpl.

References mapEr, and mapEz.

Referenced by writeFile().

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

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

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

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

01152 {
01153         if((Br != 0.0 || Bz != 0.0) && !mapBr) {
01154                 mapBr = new float[nR*nZ];
01155                 mapBz = new float[nR*nZ];
01156                 BLAssert(mapBr != 0 && mapBz != 0);
01157                 for(int i=0; i<nR*nZ; ++i) 
01158                         mapBr[i] = mapBz[i] = 0.0;
01159         }
01160         if((Er != 0.0 || Ez != 0.0) && !mapEr) {
01161                 mapEr = new float[nR*nZ];
01162                 mapEz = new float[nR*nZ];
01163                 BLAssert(mapEr != 0 && mapEz != 0);
01164                 for(int i=0; i<nR*nZ; ++i) 
01165                         mapEr[i] = mapEz[i] = 0.0;
01166         }
01167         int i = (int)floor((R/dR) + 0.5);
01168         if(i<0 || fabs(i*dR-R)>tolerance || i >= nR) {
01169                 BLCommand::printError("BLFieldMap: ERROR point off"
01170                             " grid R=%.1f line=%d\n",R,linenumber);
01171                 return false;
01172         }
01173         int j = (int)floor(((Z-Z0)/dZ) + 0.5);
01174         if(j<0 || fabs(j*dZ+Z0-Z)>tolerance || j >= nZ) {
01175                 BLCommand::printError("BLFieldMap: ERROR point off"
01176                             " grid Z=%.1f line=%d\n",Z,linenumber);
01177                 return false;
01178         }
01179         if(mapBr) {
01180                 mapBr[j*nR+i] = Br;
01181                 mapBz[j*nR+i] = Bz;
01182         }
01183         if(mapEr) {
01184                 mapEr[j*nR+i] = Er;
01185                 mapEz[j*nR+i] = Ez;
01186         }
01187 
01188         return true;
01189 }

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

Implements FieldMapImpl.

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

01192 {
01193         fprintf(f,"cylinder Z0=%g nR=%d nZ=%d dR=%g dZ=%g\n",Z0,nR,nZ,dR,dZ);
01194         if(extendZ) {
01195                 fprintf(f,"extendZ flip=");
01196                 if(extendBrFactor < 0.0) fprintf(f,"Br,");
01197                 if(extendBzFactor < 0.0) fprintf(f,"Bz,");
01198                 if(extendErFactor < 0.0) fprintf(f,"Er,");
01199                 if(extendEzFactor < 0.0) fprintf(f,"Ez,");
01200                 fprintf(f,"\n");
01201         }
01202         fprintf(f,"data\n");
01203 
01204         for(int i=0; i<nR; ++i) {
01205                 G4double R = i*dR;
01206                 for(int j=0; j<nZ; ++j) {
01207                         G4double Z = Z0 + j*dZ;
01208                         int m = j*nR + i;
01209                         BLAssert(m >= 0 && m < nR*nZ);
01210                         G4double Br = (mapBr ? mapBr[m] : 0.0);
01211                         G4double Bz = (mapBz ? mapBz[m] : 0.0);
01212                         fprintf(f,"%.1f %.1f %g %g", R,Z,Br/tesla,Bz/tesla);
01213                         if(hasE()) {
01214                                 G4double Er = (mapEr ? mapEr[m] : 0.0);
01215                                 G4double Ez = (mapEz ? mapEz[m] : 0.0);
01216                                 fprintf(f," %g %g", Er/(megavolt/meter),
01217                                                     Ez/(megavolt/meter));
01218                         }
01219                         fprintf(f,"\n");
01220                 }
01221         }
01222         return true;
01223 }


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