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 |
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.
00980 : FieldMapImpl() 00981 { 00982 nR = 2; 00983 nZ = 2; 00984 dR = 10.0*mm; 00985 dZ = 10.0*mm; 00986 Z0 = 0.0; 00987 tolerance = 0.01*mm; 00988 mapBr = 0; 00989 mapBz = 0; 00990 mapEr = 0; 00991 mapEz = 0; 00992 extendZ = false; 00993 extendBrFactor = extendBzFactor = 1.0; 00994 extendErFactor = extendEzFactor = 1.0; 00995 argInt(nR,"nR",namedArgs); 00996 argInt(nZ,"nZ",namedArgs); 00997 argDouble(dR,"dR",namedArgs); 00998 argDouble(dZ,"dZ",namedArgs); 00999 argDouble(Z0,"Z0",namedArgs); 01000 argDouble(tolerance,"tolerance",namedArgs); 01001 }
CylinderImpl::~CylinderImpl | ( | ) |
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.
01013 { 01014 G4double z = local[2]; 01015 G4double r = sqrt(local[0]*local[0]+local[1]*local[1]); 01016 01017 bool extending = false; 01018 if(z < 0.0 && extendZ) { 01019 z = -z; 01020 extending = true; 01021 } 01022 01023 z -= Z0; 01024 01025 // 2D linear average of the 4 surrounding points in the map 01026 int i = (int)floor(r/dR); 01027 int j = (int)floor(z/dZ); 01028 if(z < Z0 || i >= nR-1 || j < 0 || j >= nZ-1) { 01029 field[0] = field[1] = field[2] = field[3] = field[4] = 01030 field[5] = 0.0; 01031 return; 01032 } 01033 01034 float fr = 1.0 - (r - i*dR) / dR; 01035 BLAssert(fr >= 0.0 && fr <= 1.0); 01036 float fz = 1.0 - (z - j*dZ) / dZ; 01037 BLAssert(fz >= 0.0 && fz <= 1.0); 01038 01039 G4double Bz = 0.0; 01040 if(mapBz) Bz = 01041 mapBz[j*nR+i]*fr*fz + 01042 mapBz[j*nR+i+1]*(1.0-fr)*fz + 01043 mapBz[(j+1)*nR+i]*fr*(1.0-fz) + 01044 mapBz[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz); 01045 G4double Br = 0.0; 01046 if(mapBr) Br = 01047 mapBr[j*nR+i]*fr*fz + 01048 mapBr[j*nR+i+1]*(1.0-fr)*fz + 01049 mapBr[(j+1)*nR+i]*fr*(1.0-fz) + 01050 mapBr[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz); 01051 G4double Ez = 0.0; 01052 if(mapEz) Ez = 01053 mapEz[j*nR+i]*fr*fz + 01054 mapEz[j*nR+i+1]*(1.0-fr)*fz + 01055 mapEz[(j+1)*nR+i]*fr*(1.0-fz) + 01056 mapEz[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz); 01057 G4double Er = 0.0; 01058 if(mapEr) Er = 01059 mapEr[j*nR+i]*fr*fz + 01060 mapEr[j*nR+i+1]*(1.0-fr)*fz + 01061 mapEr[(j+1)*nR+i]*fr*(1.0-fz) + 01062 mapEr[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz); 01063 if(extending) { 01064 Br *= extendBrFactor; 01065 Bz *= extendBzFactor; 01066 Er *= extendErFactor; 01067 Ez *= extendEzFactor; 01068 } 01069 01070 G4double phi = atan2(local[1], local[0]); 01071 field[0] = Br * cos(phi); 01072 field[1] = Br * sin(phi); 01073 field[2] = Bz; 01074 field[3] = Er * cos(phi); 01075 field[4] = Er * sin(phi); 01076 field[5] = Ez; 01077 }
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().
01081 { 01082 if(argv[0] == "extendZ") { 01083 extendZ = true; 01084 const char *p = namedArgs["flip"].c_str(); 01085 if(strstr(p,"Br")) extendBrFactor = -1.0; 01086 if(strstr(p,"Bz")) extendBzFactor = -1.0; 01087 if(strstr(p,"Er")) extendErFactor = -1.0; 01088 if(strstr(p,"Ez")) extendEzFactor = -1.0; 01089 return true; 01090 } else if(argv[0] == "Br") { 01091 if(mapBr) return false; 01092 mapBr = new float[nR*nZ]; 01093 for(int i=0; i<nR*nZ; ++i) mapBr[i] = 0.0; 01094 return readBlock(in,mapBr,nZ,nR,tesla); 01095 } else if(argv[0] == "Bz") { 01096 if(mapBz) return false; 01097 mapBz = new float[nR*nZ]; 01098 for(int i=0; i<nR*nZ; ++i) mapBz[i] = 0.0; 01099 return readBlock(in,mapBz,nZ,nR,tesla); 01100 } else if(argv[0] == "Er") { 01101 if(mapEr) return false; 01102 mapEr = new float[nR*nZ]; 01103 for(int i=0; i<nR*nZ; ++i) mapEr[i] = 0.0; 01104 return readBlock(in,mapEr,nZ,nR,megavolt/meter); 01105 } else if(argv[0] == "Ez") { 01106 if(mapEz) return false; 01107 mapEz = new float[nR*nZ]; 01108 for(int i=0; i<nR*nZ; ++i) mapEz[i] = 0.0; 01109 return readBlock(in,mapEz,nZ,nR,megavolt/meter); 01110 } else if(argv[0] == "data") { 01111 for(char *line=0; (line=in.getline())!=0;) { 01112 if(isalpha(line[0])) { 01113 in.repeatLine(); 01114 break; 01115 } 01116 int n; 01117 float R=0.0,Z=0.0,Br=0.0,Bz=0.0,Er=0.0,Ez=0.0; 01118 for(char *p=line; (p=strchr(p,','))!=0;) *p = ' '; 01119 n = sscanf(line,"%f%f%f%f%f%f",&R,&Z,&Br,&Bz,&Er,&Ez); 01120 if(n <= 2) continue; 01121 setField(R,Z,Br*tesla,Bz*tesla,Er*megavolt/meter, 01122 Ez*megavolt/meter,in.linenumber()); 01123 } 01124 return true; 01125 } else { 01126 return false; 01127 } 01128 }
void CylinderImpl::getBoundingPoint | ( | int | i, | |
G4double | point[4] | |||
) | [virtual] |
Implements FieldMapImpl.
References dR, dZ, extendZ, nR, nZ, and Z0.
01131 { 01132 point[0] = (i&1 ? 1.0 : -1.0) * (nR-1) * dR; 01133 point[1] = (i&2 ? 1.0 : -1.0) * (nR-1) * dR; 01134 if(extendZ) 01135 point[2] = (i&4 ? 1.0 : -1.0) * (nZ-1) * dZ; 01136 else 01137 point[2] = (i&4 ? Z0 : Z0+(nZ-1)*dZ); 01138 }
virtual bool CylinderImpl::hasB | ( | ) | [inline, virtual] |
virtual bool CylinderImpl::hasE | ( | ) | [inline, virtual] |
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().
01142 { 01143 if((Br != 0.0 || Bz != 0.0) && !mapBr) { 01144 mapBr = new float[nR*nZ]; 01145 mapBz = new float[nR*nZ]; 01146 BLAssert(mapBr != 0 && mapBz != 0); 01147 for(int i=0; i<nR*nZ; ++i) 01148 mapBr[i] = mapBz[i] = 0.0; 01149 } 01150 if((Er != 0.0 || Ez != 0.0) && !mapEr) { 01151 mapEr = new float[nR*nZ]; 01152 mapEz = new float[nR*nZ]; 01153 BLAssert(mapEr != 0 && mapEz != 0); 01154 for(int i=0; i<nR*nZ; ++i) 01155 mapEr[i] = mapEz[i] = 0.0; 01156 } 01157 int i = (int)floor((R/dR) + 0.5); 01158 if(i<0 || fabs(i*dR-R)>tolerance || i >= nR) { 01159 BLCommand::printError("BLFieldMap: ERROR point off" 01160 " grid R=%.1f line=%d\n",R,linenumber); 01161 return false; 01162 } 01163 int j = (int)floor(((Z-Z0)/dZ) + 0.5); 01164 if(j<0 || fabs(j*dZ+Z0-Z)>tolerance || j >= nZ) { 01165 BLCommand::printError("BLFieldMap: ERROR point off" 01166 " grid Z=%.1f line=%d\n",Z,linenumber); 01167 return false; 01168 } 01169 if(mapBr) { 01170 mapBr[j*nR+i] = Br; 01171 mapBz[j*nR+i] = Bz; 01172 } 01173 if(mapEr) { 01174 mapEr[j*nR+i] = Er; 01175 mapEz[j*nR+i] = Ez; 01176 } 01177 01178 return true; 01179 }
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.
01182 { 01183 fprintf(f,"cylinder Z0=%g nR=%d nZ=%d dR=%g dZ=%g\n",Z0,nR,nZ,dR,dZ); 01184 if(extendZ) { 01185 fprintf(f,"extendZ flip="); 01186 if(extendBrFactor < 0.0) fprintf(f,"Br,"); 01187 if(extendBzFactor < 0.0) fprintf(f,"Bz,"); 01188 if(extendErFactor < 0.0) fprintf(f,"Er,"); 01189 if(extendEzFactor < 0.0) fprintf(f,"Ez,"); 01190 fprintf(f,"\n"); 01191 } 01192 fprintf(f,"data\n"); 01193 01194 for(int i=0; i<nR; ++i) { 01195 G4double R = i*dR; 01196 for(int j=0; j<nZ; ++j) { 01197 G4double Z = Z0 + j*dZ; 01198 int m = j*nR + i; 01199 BLAssert(m >= 0 && m < nR*nZ); 01200 G4double Br = (mapBr ? mapBr[m] : 0.0); 01201 G4double Bz = (mapBz ? mapBz[m] : 0.0); 01202 fprintf(f,"%.1f %.1f %g %g", R,Z,Br/tesla,Bz/tesla); 01203 if(hasE()) { 01204 G4double Er = (mapEr ? mapEr[m] : 0.0); 01205 G4double Ez = (mapEz ? mapEz[m] : 0.0); 01206 fprintf(f," %g %g", Er/(megavolt/meter), 01207 Ez/(megavolt/meter)); 01208 } 01209 fprintf(f,"\n"); 01210 } 01211 } 01212 return true; 01213 }
G4int CylinderImpl::nR [private] |
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), handleCommand(), setField(), and writeFile().
G4int CylinderImpl::nZ [private] |
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), handleCommand(), setField(), and writeFile().
G4double CylinderImpl::dR [private] |
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), setField(), and writeFile().
G4double CylinderImpl::dZ [private] |
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), setField(), and writeFile().
G4double CylinderImpl::Z0 [private] |
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), setField(), and writeFile().
G4double CylinderImpl::tolerance [private] |
Referenced by CylinderImpl(), and setField().
float* CylinderImpl::mapBr [private] |
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), hasB(), setField(), writeFile(), and ~CylinderImpl().
float* CylinderImpl::mapBz [private] |
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), hasB(), setField(), writeFile(), and ~CylinderImpl().
float* CylinderImpl::mapEr [private] |
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), hasE(), setField(), writeFile(), and ~CylinderImpl().
float* CylinderImpl::mapEz [private] |
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), hasE(), setField(), writeFile(), and ~CylinderImpl().
bool CylinderImpl::extendZ [private] |
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), handleCommand(), and writeFile().
float CylinderImpl::extendBrFactor [private] |
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), and writeFile().
float CylinderImpl::extendBzFactor [private] |
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), and writeFile().
float CylinderImpl::extendErFactor [private] |
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), and writeFile().
float CylinderImpl::extendEzFactor [private] |
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), and writeFile().