BLCMDprintfield Class Reference

Inheritance diagram for BLCMDprintfield:

BLCommand BLCallback

List of all members.


Detailed Description

class BLCMDprintfield is a command to print E or B fields

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


Constructor & Destructor Documentation

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                 "BLFieldMap file, but can in the printout.");
00124 
00125         type = "print";
00126         exit = 0;
00127         field = "By";
00128         layout = "zx";
00129         x = y = z = t = 0.0;
00130         drow = dcol = 1.0*cm;
00131         nrow = ncol = 1;
00132         X0 = Y0 = Z0 = 0.0;
00133         nX = nY = nZ = 0;
00134         dX = dY = dZ = 0.0;
00135         nR = 0;
00136         dR = 0.0;
00137 }

BLCMDprintfield::~BLCMDprintfield (  )  [inline]

00077 { }


Member Function Documentation

G4String BLCMDprintfield::commandName (  )  [inline, virtual]

Implements BLCommand.

00079 { return "printfield"; }

int BLCMDprintfield::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

Implements BLCommand.

References BLCMDprintfield(), BLManager::getObject(), BLCommand::handleNamedArgs(), BLCommand::printError(), and BLManager::registerCallback().

00140 {
00141         if(argv.size() > 0) {
00142                 printError("printfield: Invalid argument\n");
00143                 return -1;
00144         }
00145 
00146         BLCMDprintfield *p = new BLCMDprintfield(defaultPrintField);
00147         int retval = p->handleNamedArgs(namedArgs);
00148 
00149         // register the object to be called back to do its print.
00150         // 1 => after reference particle is tracked.
00151         BLManager::getObject()->registerCallback(p,1);
00152 
00153         return retval;
00154 }

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.

00157 {
00158         argString(type,"type","print, grid, or cylinder.");
00159         argInt(exit,"exit","Set nonzero to exit after printing field");
00160 
00161         if(argMode == HELP) printf("             Arguments for type=print:\n");
00162         argString(field,"field","The field to print (Bx,By,Bz,Ex,Ey,Ez,Btot,Etot).");
00163         argString(layout,"layout","Layout (RowCol) - 2 chars 'AB' each of {xyzt}.");
00164         argDouble(x,"x","The starting value of x (mm).");
00165         argDouble(y,"y","The starting value of y (mm).");
00166         argDouble(z,"z","The starting value of z (mm).");
00167         argDouble(t,"t","The starting value of time (ns).");
00168         argDouble(drow,"drow","The incr between points in each row (mm|ns).");
00169         argDouble(dcol,"dcol","The incr between points in each column (mm|ns).");
00170         argInt(nrow,"nrow","The number of rows.");
00171         argInt(ncol,"ncol","The number of columns.");
00172 
00173         if(argMode == HELP) printf("             Arguments for type=grid:\n");
00174         argString(file,"file","Filename to write fieldmap to.");
00175         argString(comment,"comment","Comment for fieldmap.");
00176         argDouble(X0,"X0","Initial value of X (mm, default=0).");
00177         argDouble(Y0,"Y0","Initial value of Y (mm, default=0).");
00178         argDouble(Z0,"Z0","Initial value of Z (mm, default=0).");
00179         argInt(nX,"nX","Number of points in X.");
00180         argInt(nY,"nY","Number of points in Y.");
00181         argInt(nZ,"nZ","Number of points in Z.");
00182         argDouble(dX,"dX","Interval in X between points (mm).");
00183         argDouble(dY,"dY","Interval in Y between points (mm).");
00184         argDouble(dZ,"dZ","Interval in Z between points (mm).");
00185 
00186         if(argMode == HELP) printf("             Arguments for type=cylinder:\n");
00187         argString(file,"file","Filename to write fieldmap to.");
00188         argString(comment,"comment","Comment for fieldmap.");
00189         argDouble(Z0,"Z0","Initial value of Z (mm, default=0).");
00190         argInt(nR,"nR","Number of points in R.");
00191         argDouble(dR,"dR","Interval in R between points (mm).");
00192         argInt(nZ,"nZ","Number of points in Z.");
00193         argDouble(dZ,"dZ","Interval in Z between points (mm).");
00194 }

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.

00197 {
00198         if(type == "print")
00199                 do_print();
00200         else if(type == "points")
00201                 do_points();
00202         else if(type == "grid")
00203                 do_grid();
00204         else if(type == "cylinder")
00205                 do_cylinder();
00206         else
00207                 printError("printfield: invalid type '%s'\n",type.c_str());
00208 
00209         if(exit) {
00210                 Printf("BLCMDprintfield: exit\n");
00211                 G4cout.flush();
00212                 extern void g4bl_exit(int);
00213                 g4bl_exit(0);
00214         }
00215 }

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

00218 {
00219         int index=-1; 
00220         if(field == "Bx") index = 0;
00221         else if(field == "By") index = 1;
00222         else if(field == "Bz") index = 2;
00223         else if(field == "Ex") index = 3;
00224         else if(field == "Ey") index = 4;
00225         else if(field == "Ez") index = 5;
00226         else if(field == "Btot") index = 6;
00227         else if(field == "Etot") index = 7;
00228         else printError("printfield: invalid field '%s'\n",field.c_str());
00229 
00230         int irow=-1,icol=-1;
00231         char rowname, colname;
00232         rowname = layout.c_str()[0];
00233         colname = layout.c_str()[1];
00234         switch(rowname) {
00235         case 'x': case 'X':     irow = 0;       break;
00236         case 'y': case 'Y':     irow = 1;       break;
00237         case 'z': case 'Z':     irow = 2;       break;
00238         case 't': case 'T':     irow = 3;       break;
00239         }
00240         switch(colname) {
00241         case 'x': case 'X':     icol = 0;       break;
00242         case 'y': case 'Y':     icol = 1;       break;
00243         case 'z': case 'Z':     icol = 2;       break;
00244         case 't': case 'T':     icol = 3;       break;
00245         }
00246 
00247         if(index < 0 || irow < 0 || icol < 0) {
00248                 printError("printfield: Invalid field name or layout\n");
00249                 return;
00250         }
00251 
00252         BLGlobalField *gf = BLGlobalField::getObject();
00253 
00254         G4double pos[4];
00255         pos[0]=x, pos[1]=y, pos[2]=z, pos[3]=t;
00256         G4double col0 = pos[icol];
00257 
00258         Printf("\n%s (%s):  ",field.c_str(),(index<=2||index==6 ? "Tesla" : "MV/meter"));
00259         G4double unit = (index<=2||index==6 ? tesla : megavolt/meter);
00260         for(int i=0; i<4; ++i) {
00261                 if(i == irow || i == icol) continue;
00262                 if(i == 3)
00263                         Printf("%c=%.3f ","xyzt"[i],pos[i]);
00264                 else
00265                         Printf("%c=%.1f ","xyzt"[i],pos[i]);
00266         }
00267         Printf("\n         ");
00268         for(int col=0; col<ncol; ++col) {
00269                 char tmp[16];
00270                 sprintf(tmp,"%c=%.1f",colname,pos[icol]);
00271                 Printf("%9.9s",tmp);
00272                 pos[icol] += dcol;
00273         }
00274         Printf("\n");
00275         for(int row=0; row<nrow; ++row) {
00276                 Printf("%c=%-6.1f ",rowname,pos[irow]);
00277                 pos[icol] = col0;
00278                 for(int col=0; col<ncol; ++col) {
00279                         G4double field[6];
00280                         gf->GetFieldValue(pos,field);
00281                         if(index == 6)
00282                                 Printf(" %8.4f",sqrt(field[0]*field[0]+field[1]*field[1]+field[2]*field[2])/unit);
00283                         else if(index == 7)
00284                                 Printf(" %8.4f",sqrt(field[3]*field[3]+field[4]*field[4]+field[5]*field[5])/unit);
00285                         else
00286                                 Printf(" %8.4f",field[index]/unit);
00287                         pos[icol] += dcol;
00288                 }
00289                 Printf("\n");
00290                 pos[irow] += drow;
00291         }
00292 
00293         Printf("\n");
00294 
00295         G4cout.flush();
00296 }

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

00299 {
00300         int irow=-1,icol=-1;
00301         char rowname, colname;
00302         rowname = layout.c_str()[0];
00303         colname = layout.c_str()[1];
00304         switch(rowname) {
00305         case 'x': case 'X':     irow = 0;       break;
00306         case 'y': case 'Y':     irow = 1;       break;
00307         case 'z': case 'Z':     irow = 2;       break;
00308         case 't': case 'T':     irow = 3;       break;
00309         }
00310         switch(colname) {
00311         case 'x': case 'X':     icol = 0;       break;
00312         case 'y': case 'Y':     icol = 1;       break;
00313         case 'z': case 'Z':     icol = 2;       break;
00314         case 't': case 'T':     icol = 3;       break;
00315         }
00316 
00317         if(irow < 0 || icol < 0) {
00318                 printError("printfield: Invalid field name or layout\n");
00319                 return;
00320         }
00321 
00322         BLGlobalField *gf = BLGlobalField::getObject();
00323 
00324         G4double pos[4];
00325         pos[0]=x, pos[1]=y, pos[2]=z, pos[3]=t;
00326         G4double col0 = pos[icol];
00327 
00328         Printf("# B field: x y z Bx By Bz\n");
00329         for(int row=0; row<nrow; ++row) {
00330                 pos[icol] = col0;
00331                 for(int col=0; col<ncol; ++col) {
00332                         G4double field[6];
00333                         gf->GetFieldValue(pos,field);
00334                         Printf("%.1f %.1f %.1f %.4f %.4f %.4f\n",
00335                                 pos[0],pos[1],pos[2],
00336                                 field[0]/tesla,field[1]/tesla,field[2]/tesla);
00337                         pos[icol] += dcol;
00338                 }
00339                 pos[irow] += drow;
00340         }
00341 
00342         if(exit) {
00343                 Printf("BLCMDprintfield: exit\n");
00344                 extern void g4bl_exit(int);
00345                 g4bl_exit(0);
00346         }
00347 }

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

00350 {
00351         if(file == "" || nX <= 0 || nY <= 0 || nZ <= 0 || 
00352            dX <= 0.0 || dY <= 0.0 || dZ <= 0.0) {
00353                 printError("printfield type=grid: invalid arguments\n");
00354                 return;
00355         }
00356         BLFieldMap fm;
00357         fm.createGridMap(X0,Y0,Z0,dX,dY,dZ,nX,nY,nZ,BLGlobalField::getObject());
00358         fm.writeFile(file, comment);
00359 }

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

00362 {
00363         if(file == "" || nR <= 0 || nZ <= 0 || dR <= 0.0) {
00364                 printError("printfield type=cylinder: invalid arguments\n");
00365                 return;
00366         }
00367         BLFieldMap fm;
00368         fm.createCylinderMap(Z0,dR,dZ,nR,nZ, BLGlobalField::getObject());
00369         fm.writeFile(file, comment);
00370 }


Member Data Documentation

G4String BLCMDprintfield::type [private]

Reimplemented from BLCommand.

Referenced by BLCMDprintfield(), callback(), and defineNamedArgs().

G4int BLCMDprintfield::exit [private]

G4String BLCMDprintfield::field [private]

G4String BLCMDprintfield::layout [private]

G4double BLCMDprintfield::x [private]

G4double BLCMDprintfield::y [private]

G4double BLCMDprintfield::z [private]

G4double BLCMDprintfield::t [private]

G4double BLCMDprintfield::drow [private]

G4double BLCMDprintfield::dcol [private]

G4int BLCMDprintfield::nrow [private]

G4int BLCMDprintfield::ncol [private]

G4String BLCMDprintfield::file [private]

G4String BLCMDprintfield::comment [private]

G4double BLCMDprintfield::X0 [private]

G4double BLCMDprintfield::Y0 [private]

G4double BLCMDprintfield::Z0 [private]

G4int BLCMDprintfield::nX [private]

G4int BLCMDprintfield::nY [private]

G4int BLCMDprintfield::nZ [private]

G4double BLCMDprintfield::dX [private]

G4double BLCMDprintfield::dY [private]

G4double BLCMDprintfield::dZ [private]

G4int BLCMDprintfield::nR [private]

G4double BLCMDprintfield::dR [private]


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