If type=print (the default), prints a 2-d array to stdout.
If type=grid or type=cylinder, BLCMDprintfield will write to a file, in the format of BLFieldMap. This can be used to combine multiple overlapping magnets/solenoids into a single map, which will be more efficient in particle tracking. All nonzero field components are included.
Public Member Functions | |
BLCMDprintfield () | |
~BLCMDprintfield () | |
G4String | commandName () |
int | command (BLArgumentVector &argv, BLArgumentMap &namedArgs) |
void | defineNamedArgs () |
void | callback (int type) |
callback() from BLCallback. | |
Private Member Functions | |
void | do_print () |
void | do_points () |
void | do_grid () |
void | do_cylinder () |
Private Attributes | |
G4String | type |
G4int | exit |
G4String | field |
G4String | layout |
G4double | x |
G4double | y |
G4double | z |
G4double | t |
G4double | drow |
G4double | dcol |
G4int | nrow |
G4int | ncol |
G4String | file |
G4String | comment |
G4double | X0 |
G4double | Y0 |
G4double | Z0 |
G4int | nX |
G4int | nY |
G4int | nZ |
G4double | dX |
G4double | dY |
G4double | dZ |
G4int | nR |
G4double | dR |
BLCMDprintfield::BLCMDprintfield | ( | ) |
References BLCMDTYPE_DATA, dcol, dR, drow, dX, dY, dZ, exit, field, layout, ncol, nR, nrow, nX, nY, nZ, BLCommand::registerCommand(), BLCommand::setDescription(), BLCommand::setSynopsis(), t, type, x, X0, y, Y0, z, and Z0.
Referenced by command().
00111 { 00112 registerCommand(BLCMDTYPE_DATA); 00113 setSynopsis("Prints E or B fields, or writes FieldMap file."); 00114 setDescription("Prints the value of the electromagnetic field components.\n" 00115 "For type=print, prints one component of the field\n" 00116 "in a 2-d table.\n" 00117 "Any coordinate plane can be printed (XY ... ZT).\n" 00118 "For type=grid or type=cylinder, writes a file in fieldmap\n" 00119 "format.\n" 00120 "Global coordinates are used.\n" 00121 "Units are Tesla for B and MV/meter for E.\n" 00122 "\nNOTE: This command cannot handle time dependency in the " 00123 "output BLFieldMap file, but can in the printout.\n\n" 00124 "Note: if you want to plot field vs position or time, the " 00125 "'fieldntuple' command is probably better, as it is not " 00126 "limited to the 2-d paper, is easier to use, and lets " 00127 "you use existing NTuple plotting tools. If you just " 00128 "want to test a few points, the 'probefield' command lets " 00129 "you do that interactively."); 00130 00131 type = "print"; 00132 exit = 0; 00133 field = "By"; 00134 layout = "zx"; 00135 x = y = z = t = 0.0; 00136 drow = dcol = 1.0*cm; 00137 nrow = ncol = 1; 00138 X0 = Y0 = Z0 = 0.0; 00139 nX = nY = nZ = 0; 00140 dX = dY = dZ = 0.0; 00141 nR = 0; 00142 dR = 0.0; 00143 }
G4String BLCMDprintfield::commandName | ( | ) | [inline, virtual] |
int BLCMDprintfield::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [virtual] |
Implements BLCommand.
References BLCMDprintfield(), BLManager::getObject(), BLCommand::handleNamedArgs(), BLCommand::printError(), and BLManager::registerCallback().
00146 { 00147 if(argv.size() > 0) { 00148 printError("printfield: Invalid argument\n"); 00149 return -1; 00150 } 00151 00152 BLCMDprintfield *p = new BLCMDprintfield(defaultPrintField); 00153 int retval = p->handleNamedArgs(namedArgs); 00154 00155 // register the object to be called back to do its print. 00156 // 1 => after reference particle is tracked. 00157 BLManager::getObject()->registerCallback(p,1); 00158 00159 return retval; 00160 }
void BLCMDprintfield::defineNamedArgs | ( | ) | [virtual] |
Reimplemented from BLCommand.
References BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argMode, BLCommand::argString(), comment, dcol, dR, drow, dX, dY, dZ, exit, field, file, BLCommand::HELP, layout, ncol, nR, nrow, nX, nY, nZ, t, type, x, X0, y, Y0, z, and Z0.
00163 { 00164 argString(type,"type","print, grid, or cylinder."); 00165 argInt(exit,"exit","Set nonzero to exit after printing field"); 00166 00167 if(argMode == HELP) printf(" Arguments for type=print:\n"); 00168 argString(field,"field","The field to print (Bx,By,Bz,Ex,Ey,Ez,Btot,Etot)."); 00169 argString(layout,"layout","Layout (RowCol) - 2 chars 'AB' each of {xyzt}."); 00170 argDouble(x,"x","The starting value of x (mm)."); 00171 argDouble(y,"y","The starting value of y (mm)."); 00172 argDouble(z,"z","The starting value of z (mm)."); 00173 argDouble(t,"t","The starting value of time (ns)."); 00174 argDouble(drow,"drow","The incr between points in each row (mm|ns)."); 00175 argDouble(dcol,"dcol","The incr between points in each column (mm|ns)."); 00176 argInt(nrow,"nrow","The number of rows."); 00177 argInt(ncol,"ncol","The number of columns."); 00178 00179 if(argMode == HELP) printf(" Arguments for type=grid:\n"); 00180 argString(file,"file","Filename to write fieldmap to."); 00181 argString(comment,"comment","Comment for fieldmap."); 00182 argDouble(X0,"X0","Initial value of X (mm, default=0)."); 00183 argDouble(Y0,"Y0","Initial value of Y (mm, default=0)."); 00184 argDouble(Z0,"Z0","Initial value of Z (mm, default=0)."); 00185 argInt(nX,"nX","Number of points in X."); 00186 argInt(nY,"nY","Number of points in Y."); 00187 argInt(nZ,"nZ","Number of points in Z."); 00188 argDouble(dX,"dX","Interval in X between points (mm)."); 00189 argDouble(dY,"dY","Interval in Y between points (mm)."); 00190 argDouble(dZ,"dZ","Interval in Z between points (mm)."); 00191 00192 if(argMode == HELP) printf(" Arguments for type=cylinder:\n"); 00193 argString(file,"file","Filename to write fieldmap to."); 00194 argString(comment,"comment","Comment for fieldmap."); 00195 argDouble(Z0,"Z0","Initial value of Z (mm, default=0)."); 00196 argInt(nR,"nR","Number of points in R."); 00197 argDouble(dR,"dR","Interval in R between points (mm)."); 00198 argInt(nZ,"nZ","Number of points in Z."); 00199 argDouble(dZ,"dZ","Interval in Z between points (mm)."); 00200 }
void BLCMDprintfield::callback | ( | int | type | ) | [virtual] |
callback() from BLCallback.
Reimplemented from BLCallback.
References do_cylinder(), do_grid(), do_points(), do_print(), exit, g4bl_exit(), BLCommand::printError(), Printf(), and type.
00203 { 00204 if(type == "print") 00205 do_print(); 00206 else if(type == "points") 00207 do_points(); 00208 else if(type == "grid") 00209 do_grid(); 00210 else if(type == "cylinder") 00211 do_cylinder(); 00212 else 00213 printError("printfield: invalid type '%s'\n",type.c_str()); 00214 00215 if(exit) { 00216 Printf("BLCMDprintfield: exit\n"); 00217 G4cout.flush(); 00218 extern void g4bl_exit(int); 00219 g4bl_exit(0); 00220 } 00221 }
void BLCMDprintfield::do_print | ( | ) | [private] |
References dcol, drow, field, BLGlobalField::GetFieldValue(), BLGlobalField::getObject(), layout, ncol, nrow, BLCommand::printError(), Printf(), t, x, y, and z.
Referenced by callback().
00224 { 00225 int index=-1; 00226 if(field == "Bx") index = 0; 00227 else if(field == "By") index = 1; 00228 else if(field == "Bz") index = 2; 00229 else if(field == "Ex") index = 3; 00230 else if(field == "Ey") index = 4; 00231 else if(field == "Ez") index = 5; 00232 else if(field == "Btot") index = 6; 00233 else if(field == "Etot") index = 7; 00234 else printError("printfield: invalid field '%s'\n",field.c_str()); 00235 00236 int irow=-1,icol=-1; 00237 char rowname, colname; 00238 rowname = layout.c_str()[0]; 00239 colname = layout.c_str()[1]; 00240 switch(rowname) { 00241 case 'x': case 'X': irow = 0; break; 00242 case 'y': case 'Y': irow = 1; break; 00243 case 'z': case 'Z': irow = 2; break; 00244 case 't': case 'T': irow = 3; break; 00245 } 00246 switch(colname) { 00247 case 'x': case 'X': icol = 0; break; 00248 case 'y': case 'Y': icol = 1; break; 00249 case 'z': case 'Z': icol = 2; break; 00250 case 't': case 'T': icol = 3; break; 00251 } 00252 00253 if(index < 0 || irow < 0 || icol < 0) { 00254 printError("printfield: Invalid field name or layout\n"); 00255 return; 00256 } 00257 00258 BLGlobalField *gf = BLGlobalField::getObject(); 00259 00260 G4double pos[4]; 00261 pos[0]=x, pos[1]=y, pos[2]=z, pos[3]=t; 00262 G4double col0 = pos[icol]; 00263 00264 Printf("\n%s (%s): ",field.c_str(),(index<=2||index==6 ? "Tesla" : "MV/meter")); 00265 G4double unit = (index<=2||index==6 ? tesla : megavolt/meter); 00266 for(int i=0; i<4; ++i) { 00267 if(i == irow || i == icol) continue; 00268 Printf("%c=%.3f ","xyzt"[i],pos[i]); 00269 } 00270 Printf("\n "); 00271 for(int col=0; col<ncol; ++col) { 00272 char tmp[16]; 00273 sprintf(tmp,"%c=%.3f",colname,pos[icol]); 00274 Printf("%11.11s",tmp); 00275 pos[icol] += dcol; 00276 } 00277 Printf("\n"); 00278 for(int row=0; row<nrow; ++row) { 00279 Printf("%c=%-8.3f ",rowname,pos[irow]); 00280 pos[icol] = col0; 00281 for(int col=0; col<ncol; ++col) { 00282 G4double field[6]; 00283 gf->GetFieldValue(pos,field); 00284 if(index == 6) 00285 Printf(" %10.4f",sqrt(field[0]*field[0]+field[1]*field[1]+field[2]*field[2])/unit); 00286 else if(index == 7) 00287 Printf(" %10.4f",sqrt(field[3]*field[3]+field[4]*field[4]+field[5]*field[5])/unit); 00288 else 00289 Printf(" %10.4f",field[index]/unit); 00290 pos[icol] += dcol; 00291 } 00292 Printf("\n"); 00293 pos[irow] += drow; 00294 } 00295 00296 Printf("\n"); 00297 00298 G4cout.flush(); 00299 }
void BLCMDprintfield::do_points | ( | ) | [private] |
References dcol, drow, exit, field, g4bl_exit(), BLGlobalField::GetFieldValue(), BLGlobalField::getObject(), layout, ncol, nrow, BLCommand::printError(), Printf(), t, x, y, and z.
Referenced by callback().
00302 { 00303 int irow=-1,icol=-1; 00304 char rowname, colname; 00305 rowname = layout.c_str()[0]; 00306 colname = layout.c_str()[1]; 00307 switch(rowname) { 00308 case 'x': case 'X': irow = 0; break; 00309 case 'y': case 'Y': irow = 1; break; 00310 case 'z': case 'Z': irow = 2; break; 00311 case 't': case 'T': irow = 3; break; 00312 } 00313 switch(colname) { 00314 case 'x': case 'X': icol = 0; break; 00315 case 'y': case 'Y': icol = 1; break; 00316 case 'z': case 'Z': icol = 2; break; 00317 case 't': case 'T': icol = 3; break; 00318 } 00319 00320 if(irow < 0 || icol < 0) { 00321 printError("printfield: Invalid field name or layout\n"); 00322 return; 00323 } 00324 00325 BLGlobalField *gf = BLGlobalField::getObject(); 00326 00327 G4double pos[4]; 00328 pos[0]=x, pos[1]=y, pos[2]=z, pos[3]=t; 00329 G4double col0 = pos[icol]; 00330 00331 Printf("# B field: x y z Bx By Bz\n"); 00332 for(int row=0; row<nrow; ++row) { 00333 pos[icol] = col0; 00334 for(int col=0; col<ncol; ++col) { 00335 G4double field[6]; 00336 gf->GetFieldValue(pos,field); 00337 Printf("%.1f %.1f %.1f %.4f %.4f %.4f\n", 00338 pos[0],pos[1],pos[2], 00339 field[0]/tesla,field[1]/tesla,field[2]/tesla); 00340 pos[icol] += dcol; 00341 } 00342 pos[irow] += drow; 00343 } 00344 00345 if(exit) { 00346 Printf("Dprintfield: exit\n"); 00347 extern void g4bl_exit(int); 00348 g4bl_exit(0); 00349 } 00350 }
void BLCMDprintfield::do_grid | ( | ) | [private] |
References comment, BLFieldMap::createGridMap(), dX, dY, dZ, file, BLGlobalField::getObject(), nX, nY, nZ, BLCommand::printError(), BLFieldMap::writeFile(), X0, Y0, and Z0.
Referenced by callback().
00353 { 00354 if(file == "" || nX <= 0 || nY <= 0 || nZ <= 0 || 00355 dX <= 0.0 || dY <= 0.0 || dZ <= 0.0) { 00356 printError("printfield type=grid: invalid arguments\n"); 00357 return; 00358 } 00359 BLFieldMap fm; 00360 fm.createGridMap(X0,Y0,Z0,dX,dY,dZ,nX,nY,nZ,BLGlobalField::getObject()); 00361 fm.writeFile(file, comment); 00362 }
void BLCMDprintfield::do_cylinder | ( | ) | [private] |
References comment, BLFieldMap::createCylinderMap(), dR, dZ, file, BLGlobalField::getObject(), nR, nZ, BLCommand::printError(), BLFieldMap::writeFile(), and Z0.
Referenced by callback().
00365 { 00366 if(file == "" || nR <= 0 || nZ <= 0 || dR <= 0.0) { 00367 printError("printfield type=cylinder: invalid arguments\n"); 00368 return; 00369 } 00370 BLFieldMap fm; 00371 fm.createCylinderMap(Z0,dR,dZ,nR,nZ, BLGlobalField::getObject()); 00372 fm.writeFile(file, comment); 00373 }
G4String BLCMDprintfield::type [private] |
G4int BLCMDprintfield::exit [private] |
Referenced by BLCMDprintfield(), callback(), defineNamedArgs(), and do_points().
G4String BLCMDprintfield::field [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_points(), and do_print().
G4String BLCMDprintfield::layout [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_points(), and do_print().
G4double BLCMDprintfield::x [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_points(), and do_print().
G4double BLCMDprintfield::y [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_points(), and do_print().
G4double BLCMDprintfield::z [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_points(), and do_print().
G4double BLCMDprintfield::t [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_points(), and do_print().
G4double BLCMDprintfield::drow [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_points(), and do_print().
G4double BLCMDprintfield::dcol [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_points(), and do_print().
G4int BLCMDprintfield::nrow [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_points(), and do_print().
G4int BLCMDprintfield::ncol [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_points(), and do_print().
G4String BLCMDprintfield::file [private] |
Referenced by defineNamedArgs(), do_cylinder(), and do_grid().
G4String BLCMDprintfield::comment [private] |
Referenced by defineNamedArgs(), do_cylinder(), and do_grid().
G4double BLCMDprintfield::X0 [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), and do_grid().
G4double BLCMDprintfield::Y0 [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), and do_grid().
G4double BLCMDprintfield::Z0 [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_cylinder(), and do_grid().
G4int BLCMDprintfield::nX [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), and do_grid().
G4int BLCMDprintfield::nY [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), and do_grid().
G4int BLCMDprintfield::nZ [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_cylinder(), and do_grid().
G4double BLCMDprintfield::dX [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), and do_grid().
G4double BLCMDprintfield::dY [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), and do_grid().
G4double BLCMDprintfield::dZ [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), do_cylinder(), and do_grid().
G4int BLCMDprintfield::nR [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), and do_cylinder().
G4double BLCMDprintfield::dR [private] |
Referenced by BLCMDprintfield(), defineNamedArgs(), and do_cylinder().