Public Member Functions | |
CylinderImpl (MyBLArgumentVector &argv, MyBLArgumentMap &namedArgs) | |
~CylinderImpl () | |
void | getFieldValue (const G4double local[4], G4double field[6]) const |
bool | handleCommand (InputFile &in, MyBLArgumentVector &argv, MyBLArgumentMap &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) |
bool | readBlock (InputFile &in, float *values, int nRows, int nCols, G4double units) |
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 |
class CylinderImpl -- class for a Cylinder FieldMap implementation
Definition at line 147 of file MyBLFieldMap.cc.
CylinderImpl::CylinderImpl | ( | MyBLArgumentVector & | argv, | |
MyBLArgumentMap & | namedArgs | |||
) |
Definition at line 988 of file MyBLFieldMap.cc.
References argDouble(), argInt(), dR, dZ, extendBrFactor, extendBzFactor, extendErFactor, extendEzFactor, extendZ, mapBr, mapBz, mapEr, mapEz, nR, nZ, tolerance, and Z0.
00989 : FieldMapImpl() { 00990 nR = 2; 00991 nZ = 2; 00992 dR = 10.0*mm; 00993 dZ = 10.0*mm; 00994 Z0 = 0.0; 00995 tolerance = 0.01*mm; 00996 mapBr = 0; 00997 mapBz = 0; 00998 mapEr = 0; 00999 mapEz = 0; 01000 extendZ = false; 01001 extendBrFactor = extendBzFactor = 1.0; 01002 extendErFactor = extendEzFactor = 1.0; 01003 argInt(nR,"nR",namedArgs); 01004 argInt(nZ,"nZ",namedArgs); 01005 argDouble(dR,"dR",namedArgs); 01006 argDouble(dZ,"dZ",namedArgs); 01007 argDouble(Z0,"Z0",namedArgs); 01008 argDouble(tolerance,"tolerance",namedArgs); 01009 }
CylinderImpl::~CylinderImpl | ( | ) |
void CylinderImpl::getBoundingPoint | ( | int | i, | |
G4double | point[4] | |||
) | [virtual] |
Implements FieldMapImpl.
Definition at line 1145 of file MyBLFieldMap.cc.
void CylinderImpl::getFieldValue | ( | const G4double | local[4], | |
G4double | field[6] | |||
) | const [virtual] |
Implements FieldMapImpl.
Definition at line 1020 of file MyBLFieldMap.cc.
References dR, dZ, extendBrFactor, extendBzFactor, extendErFactor, extendEzFactor, extendZ, mapBr, mapBz, mapEr, mapEz, nR, nZ, and Z0.
01021 { 01022 G4double z = local[2]; 01023 G4double r = sqrt(local[0]*local[0]+local[1]*local[1]); 01024 01025 bool extending = false; 01026 if(z < 0.0 && extendZ) { 01027 z = -z; 01028 extending = true; 01029 } 01030 01031 z -= Z0; 01032 01033 // 2D linear average of the 4 surrounding points in the map 01034 int i = (int)floor(r/dR); 01035 int j = (int)floor(z/dZ); 01036 if(z < Z0 || i >= nR-1 || j < 0 || j >= nZ-1) { 01037 field[0] = field[1] = field[2] = field[3] = field[4] = 01038 field[5] = 0.0; 01039 return; 01040 } 01041 01042 float fr = 1.0 - (r - i*dR) / dR; 01043 assert(fr >= 0.0 && fr <= 1.0); 01044 float fz = 1.0 - (z - j*dZ) / dZ; 01045 assert(fz >= 0.0 && fz <= 1.0); 01046 01047 G4double Bz = 0.0; 01048 if(mapBz) Bz = 01049 mapBz[j*nR+i]*fr*fz + 01050 mapBz[j*nR+i+1]*(1.0-fr)*fz + 01051 mapBz[(j+1)*nR+i]*fr*(1.0-fz) + 01052 mapBz[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz); 01053 G4double Br = 0.0; 01054 if(mapBr) Br = 01055 mapBr[j*nR+i]*fr*fz + 01056 mapBr[j*nR+i+1]*(1.0-fr)*fz + 01057 mapBr[(j+1)*nR+i]*fr*(1.0-fz) + 01058 mapBr[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz); 01059 G4double Ez = 0.0; 01060 if(mapEz) Ez = 01061 mapEz[j*nR+i]*fr*fz + 01062 mapEz[j*nR+i+1]*(1.0-fr)*fz + 01063 mapEz[(j+1)*nR+i]*fr*(1.0-fz) + 01064 mapEz[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz); 01065 G4double Er = 0.0; 01066 if(mapEr) Er = 01067 mapEr[j*nR+i]*fr*fz + 01068 mapEr[j*nR+i+1]*(1.0-fr)*fz + 01069 mapEr[(j+1)*nR+i]*fr*(1.0-fz) + 01070 mapEr[(j+1)*nR+i+1]*(1.0-fr)*(1.0-fz); 01071 if(extending) { 01072 Br *= extendBrFactor; 01073 Bz *= extendBzFactor; 01074 Er *= extendErFactor; 01075 Ez *= extendEzFactor; 01076 } 01077 01078 G4double phi = atan2(local[1], local[0]); 01079 field[0] = Br * cos(phi); 01080 field[1] = Br * sin(phi); 01081 field[2] = Bz; 01082 field[3] = Er * cos(phi); 01083 field[4] = Er * sin(phi); 01084 field[5] = Ez; 01085 }
bool CylinderImpl::handleCommand | ( | InputFile & | in, | |
MyBLArgumentVector & | argv, | |||
MyBLArgumentMap & | namedArgs | |||
) | [virtual] |
Implements FieldMapImpl.
Definition at line 1088 of file MyBLFieldMap.cc.
References extendBrFactor, extendBzFactor, extendErFactor, extendEzFactor, extendZ, InputFile::getline(), InputFile::linenumber(), mapBr, mapBz, mapEr, mapEz, nR, nZ, FieldMapImpl::readBlock(), InputFile::repeatLine(), and setField().
01089 { 01090 if(argv[0] == "extendZ") { 01091 extendZ = true; 01092 const char *p = namedArgs["flip"].c_str(); 01093 if(strstr(p,"Br")) extendBrFactor = -1.0; 01094 if(strstr(p,"Bz")) extendBzFactor = -1.0; 01095 if(strstr(p,"Er")) extendErFactor = -1.0; 01096 if(strstr(p,"Ez")) extendEzFactor = -1.0; 01097 return true; 01098 } 01099 else if(argv[0] == "Br") { 01100 if(mapBr) return false; 01101 mapBr = new float[nR*nZ]; 01102 for(int i=0; i<nR*nZ; ++i) mapBr[i] = 0.0; 01103 return readBlock(in,mapBr,nZ,nR,tesla); 01104 } 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 } 01111 else if(argv[0] == "Er") { 01112 if(mapEr) return false; 01113 mapEr = new float[nR*nZ]; 01114 for(int i=0; i<nR*nZ; ++i) mapEr[i] = 0.0; 01115 return readBlock(in,mapEr,nZ,nR,megavolt/meter); 01116 } 01117 else if(argv[0] == "Ez") { 01118 if(mapEz) return false; 01119 mapEz = new float[nR*nZ]; 01120 for(int i=0; i<nR*nZ; ++i) mapEz[i] = 0.0; 01121 return readBlock(in,mapEz,nZ,nR,megavolt/meter); 01122 } 01123 else if(argv[0] == "data") { 01124 for(char *line=0; (line=in.getline())!=0;) { 01125 if(isalpha(line[0])) { 01126 in.repeatLine(); 01127 break; 01128 } 01129 int n; 01130 float R=0.0,Z=0.0,Br=0.0,Bz=0.0,Er=0.0,Ez=0.0; 01131 for(char *p=line; (p=strchr(p,','))!=0;) *p = ' '; 01132 n = sscanf(line,"%f%f%f%f%f%f",&R,&Z,&Br,&Bz,&Er,&Ez); 01133 if(n <= 2) continue; 01134 setField(R,Z,Br*tesla,Bz*tesla,Er*megavolt/meter, 01135 Ez*megavolt/meter,in.linenumber()); 01136 } 01137 return true; 01138 } 01139 else { 01140 return false; 01141 } 01142 }
virtual bool CylinderImpl::hasB | ( | ) | [inline, virtual] |
Implements FieldMapImpl.
Definition at line 168 of file MyBLFieldMap.cc.
virtual bool CylinderImpl::hasE | ( | ) | [inline, virtual] |
bool FieldMapImpl::readBlock | ( | InputFile & | in, | |
float * | values, | |||
int | nRows, | |||
int | nCols, | |||
G4double | units | |||
) | [inherited] |
Definition at line 414 of file MyBLFieldMap.cc.
References InputFile::getline().
Referenced by handleCommand().
00415 { 00416 while(nRows-- > 0) { 00417 char *line = in.getline(); 00418 if(!line) return false; 00419 char *p=line; 00420 for(int i=0; i<nCols; ++i) { 00421 while(isspace(*p)) ++p; 00422 if(*p == '\0') return false; 00423 *values++ = strtod(p,&p) * units; 00424 if(*p == ',') ++p; 00425 } 00426 } 00427 return true; 00428 }
bool CylinderImpl::setField | ( | G4double | R, | |
G4double | Z, | |||
G4double | Br, | |||
G4double | Bz, | |||
G4double | Er, | |||
G4double | Ez, | |||
int | linenumber | |||
) |
Definition at line 1155 of file MyBLFieldMap.cc.
References dR, dZ, mapBr, mapBz, mapEr, mapEz, nR, nZ, tolerance, and Z0.
Referenced by MyBLFieldMap::createCylinderMap(), and handleCommand().
01156 { 01157 if((Br != 0.0 || Bz != 0.0) && !mapBr) { 01158 mapBr = new float[nR*nZ]; 01159 mapBz = new float[nR*nZ]; 01160 assert(mapBr != 0 && mapBz != 0); 01161 for(int i=0; i<nR*nZ; ++i) 01162 mapBr[i] = mapBz[i] = 0.0; 01163 } 01164 if((Er != 0.0 || Ez != 0.0) && !mapEr) { 01165 mapEr = new float[nR*nZ]; 01166 mapEz = new float[nR*nZ]; 01167 assert(mapEr != 0 && mapEz != 0); 01168 for(int i=0; i<nR*nZ; ++i) 01169 mapEr[i] = mapEz[i] = 0.0; 01170 } 01171 int i = (int)floor((R/dR) + 0.5); 01172 if(i<0 || fabs(i*dR-R)>tolerance || i >= nR) { 01173 G4cerr << "MyBLFieldMap: ERROR point off grid R=" 01174 << R << " line=" << linenumber << G4endl; 01175 return false; 01176 } 01177 int j = (int)floor(((Z-Z0)/dZ) + 0.5); 01178 if(j<0 || fabs(j*dZ+Z0-Z)>tolerance || j >= nZ) { 01179 G4cerr << "MyBLFieldMap: ERROR point off grid Z=" 01180 << Z << " line=" << linenumber << G4endl; 01181 return false; 01182 } 01183 if(mapBr) { 01184 mapBr[j*nR+i] = Br; 01185 mapBz[j*nR+i] = Bz; 01186 } 01187 if(mapEr) { 01188 mapEr[j*nR+i] = Er; 01189 mapEz[j*nR+i] = Ez; 01190 } 01191 01192 return true; 01193 }
bool CylinderImpl::writeFile | ( | FILE * | f | ) | [virtual] |
Implements FieldMapImpl.
Definition at line 1196 of file MyBLFieldMap.cc.
References dR, dZ, extendBrFactor, extendBzFactor, extendErFactor, extendEzFactor, extendZ, hasE(), mapBr, mapBz, mapEr, mapEz, nR, nZ, and Z0.
01196 { 01197 fprintf(f,"cylinder Z0=%g nR=%d nZ=%d dR=%g dZ=%g\n",Z0,nR,nZ,dR,dZ); 01198 if(extendZ) { 01199 fprintf(f,"extendZ flip="); 01200 if(extendBrFactor < 0.0) fprintf(f,"Br,"); 01201 if(extendBzFactor < 0.0) fprintf(f,"Bz,"); 01202 if(extendErFactor < 0.0) fprintf(f,"Er,"); 01203 if(extendEzFactor < 0.0) fprintf(f,"Ez,"); 01204 fprintf(f,"\n"); 01205 } 01206 fprintf(f,"data\n"); 01207 01208 for(int i=0; i<nR; ++i) { 01209 G4double R = i*dR; 01210 for(int j=0; j<nZ; ++j) { 01211 G4double Z = Z0 + j*dZ; 01212 int m = j*nR + i; 01213 assert(m >= 0 && m < nR*nZ); 01214 G4double Br = (mapBr ? mapBr[m] : 0.0); 01215 G4double Bz = (mapBz ? mapBz[m] : 0.0); 01216 fprintf(f,"%.1f %.1f %g %g", R,Z,Br/tesla,Bz/tesla); 01217 if(hasE()) { 01218 G4double Er = (mapEr ? mapEr[m] : 0.0); 01219 G4double Ez = (mapEz ? mapEz[m] : 0.0); 01220 fprintf(f," %g %g", Er/(megavolt/meter), 01221 Ez/(megavolt/meter)); 01222 } 01223 fprintf(f,"\n"); 01224 } 01225 } 01226 return true; 01227 }
G4double CylinderImpl::dR [private] |
Definition at line 150 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), setField(), and writeFile().
G4double CylinderImpl::dZ [private] |
Definition at line 151 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), setField(), and writeFile().
float CylinderImpl::extendBrFactor [private] |
Definition at line 159 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), and writeFile().
float CylinderImpl::extendBzFactor [private] |
Definition at line 159 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), and writeFile().
float CylinderImpl::extendErFactor [private] |
Definition at line 160 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), and writeFile().
float CylinderImpl::extendEzFactor [private] |
Definition at line 160 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), and writeFile().
bool CylinderImpl::extendZ [private] |
Definition at line 158 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), handleCommand(), and writeFile().
float* CylinderImpl::mapBr [private] |
Definition at line 154 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), hasB(), setField(), writeFile(), and ~CylinderImpl().
float* CylinderImpl::mapBz [private] |
Definition at line 155 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), hasB(), setField(), writeFile(), and ~CylinderImpl().
float* CylinderImpl::mapEr [private] |
Definition at line 156 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), hasE(), setField(), writeFile(), and ~CylinderImpl().
float* CylinderImpl::mapEz [private] |
Definition at line 157 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getFieldValue(), handleCommand(), hasE(), setField(), writeFile(), and ~CylinderImpl().
G4int CylinderImpl::nR [private] |
Definition at line 148 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), handleCommand(), setField(), and writeFile().
G4int CylinderImpl::nZ [private] |
Definition at line 149 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), handleCommand(), setField(), and writeFile().
G4double CylinderImpl::tolerance [private] |
Definition at line 153 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), and setField().
G4double CylinderImpl::Z0 [private] |
Definition at line 152 of file MyBLFieldMap.cc.
Referenced by CylinderImpl(), getBoundingPoint(), getFieldValue(), setField(), and writeFile().