This command has no volumes, logical or physical. it just implements a field (E and/or B) from expressions on its command line.
Public Member Functions | |
BLCMDfieldexpr () | |
Default constructor. Defines the command, args, etc. | |
virtual | ~BLCMDfieldexpr () |
Destructor. | |
BLCMDfieldexpr (const BLCMDfieldexpr &r) | |
Copy constructor. | |
BLElement * | clone () |
clone() | |
G4String | commandName () |
commandName() returns "fieldexpr". | |
int | command (BLArgumentVector &argv, BLArgumentMap &namedArgs) |
command() implements the fieldexpr command. | |
void | defineNamedArgs () |
defineNamedArgs() defines the named arguments for the command. | |
void | construct (G4RotationMatrix *relativeRotation, G4ThreeVector relativePosition, G4LogicalVolume *parent, G4String parentName, G4RotationMatrix *parentRotation, G4ThreeVector parentPosition) |
construct() - construct the fieldexpr | |
G4double | getLength () |
getLength() returns 0 (no physical volume here) | |
G4double | getWidth () |
getWidth() returns 0 (no physical volume nere) | |
G4double | getHeight () |
getHeight() returns 0 (no physical volume nere) | |
G4bool | isOK () |
isOK() returns true. | |
bool | isOutside (G4ThreeVector &local, G4double tolerance) |
isOutside() from BLElement. (no volume => every point is "outside") | |
void | generatePoints (int npoints, std::vector< G4ThreeVector > &v) |
generatePoints() from BLElement. (no volume => no generate) | |
G4double | maxError (class FieldComputation *p) |
maxError() returns the maximum relative error (i.e. error / max field). | |
Private Member Functions | |
void | handleTimeDependence () |
Private Attributes | |
G4double | factorB |
G4double | factorE |
G4double | timeOffset |
G4String | Bx |
G4String | By |
G4String | Bz |
G4String | Br |
G4String | Ex |
G4String | Ey |
G4String | Ez |
G4String | Er |
G4String | time |
G4double | length |
G4double | width |
G4double | height |
G4double | radius |
G4double | tmin |
G4double | tmax |
int | nX |
int | nY |
int | nZ |
int | nR |
int | nT |
G4double | tolerance |
BLFieldMap * | map |
Friends | |
class | FieldComputation |
BLCMDfieldexpr::BLCMDfieldexpr | ( | ) |
Default constructor. Defines the command, args, etc.
References BLCMDTYPE_ELEMENT, Br, Bx, By, Bz, Er, Ex, Ey, Ez, factorB, factorE, height, length, map, nR, nT, nX, nY, nZ, radius, BLCommand::registerCommand(), BLCommand::setDescription(), BLCommand::setSynopsis(), time, timeOffset, tmax, tmin, tolerance, and width.
Referenced by clone(), and command().
00147 : BLElement() 00148 { 00149 // register the commandName(), and its synopsis and description. 00150 registerCommand(BLCMDTYPE_ELEMENT); 00151 setSynopsis("implements a field map, E and/or B, from expressions."); 00152 setDescription("A fieldexpr element can be either a box or a cylinder; " 00153 "set length and radius for cylinder, set length and width and " 00154 "height for a box. Units are Tesla, MegaVolts/meter, mm, and " 00155 "ns. Expressions for the field components can use {x,y,z} for " 00156 "a box or {z,r} for a cylinder; the time expression can use " 00157 "{t}. If present, the time expression multiples all " 00158 "components. The number of points in the map is increased " 00159 "until the largest map error divided by the maximum field " 00160 "is smaller than tolerance, or 1M points is exceeded. " 00161 "Similarly for the time dependence.\n\n" 00162 "For time dependence: if t-timeOffset<tmin, the value at tmin " 00163 "is used; if t-timeOffset>tmax, the value at tmax is used."); 00164 00165 // provide initial values for fields 00166 factorB = 1.0; 00167 factorE = 1.0; 00168 timeOffset = 0.0; 00169 Bx = By = Bz = Br = Ex = Ey = Ez = Er = time = ""; 00170 length = width = height = tmin = tmax = 0.0; 00171 radius = -1.0; 00172 nX = nY = nZ = nR = nT = 11; 00173 tolerance = 0.001; 00174 map = 0; 00175 }
BLCMDfieldexpr::BLCMDfieldexpr | ( | const BLCMDfieldexpr & | r | ) |
Copy constructor.
References Br, Bx, By, Bz, BLTune::copyTunableArg(), Er, Ex, Ey, Ez, factorB, factorE, height, length, map, nR, nT, nX, nY, nZ, radius, time, timeOffset, tmax, tmin, tolerance, and width.
00178 : BLElement(r) 00179 { 00180 // copy fields one at a time (transfers default values from the 00181 // default object to this new object). 00182 BLTune::copyTunableArg(&factorB,&r.factorB); 00183 BLTune::copyTunableArg(&factorE,&r.factorE); 00184 timeOffset = r.timeOffset; 00185 Bx = r.Bx; 00186 By = r.By; 00187 Bz = r.Bz; 00188 Br = r.Br; 00189 Ex = r.Ex; 00190 Ey = r.Ey; 00191 Ez = r.Ez; 00192 Er = r.Er; 00193 time = r.time; 00194 length = r.length; 00195 width = r.width; 00196 height = r.height; 00197 radius = r.radius; 00198 tmin = r.tmin; 00199 tmax = r.tmax; 00200 nX = r.nX; 00201 nY = r.nY; 00202 nZ = r.nZ; 00203 nR = r.nR; 00204 nT = r.nT; 00205 tolerance = r.tolerance; 00206 map = r.map; 00207 }
void BLCMDfieldexpr::handleTimeDependence | ( | ) | [private] |
References BLFieldMap::createTimeDependence(), BLEvaluator::evaluate(), BLElement::getName(), map, nT, time, tmax, and tmin.
Referenced by command().
00328 { 00329 if(time != "" && nT > 1) { 00330 BLEvaluator e; 00331 double *t, *f; 00332 for(;;) { 00333 double dt = (tmax - tmin) / (nT-1); 00334 t = new double[nT]; 00335 f = new double[nT]; 00336 for(int i=0; i<nT; ++i) { 00337 t[i] = tmin + dt*i; 00338 e.setVariable("t",t[i]); 00339 f[i] = e.evaluate(time); 00340 } 00341 // check error, double nT if needed 00342 double err=0.0; 00343 double v=tmin+dt/2.0; 00344 for(int i=0; i<nT-1; ++i) { 00345 e.setVariable("t",v); 00346 double d = (f[i]+f[i+1])/2.0 - e.evaluate(time); 00347 if(fabs(d) > err) err = fabs(d); 00348 v += dt; 00349 } 00350 printf("fieldexpr %s: Time %d points Max Relative Error=%.4f\n", 00351 getName().c_str(),nT,err); 00352 if(err <= tolerance || nT > 1000000) 00353 break; 00354 nT = (nT-1)*2 + 1; 00355 delete[] t; 00356 delete[] f; 00357 } 00358 map->createTimeDependence(nT,t,f,f); 00359 delete[] t; 00360 delete[] f; 00361 } 00362 }
BLElement* BLCMDfieldexpr::clone | ( | ) | [inline, virtual] |
G4String BLCMDfieldexpr::commandName | ( | ) | [inline, virtual] |
int BLCMDfieldexpr::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [virtual] |
command() implements the fieldexpr command.
Implements BLCommand.
References BLCMDfieldexpr(), BLFieldMap::createCylinderMap(), BLFieldMap::createGridMap(), FieldComputation, BLElement::getName(), BLCommand::handleNamedArgs(), handleTimeDependence(), height, length, map, maxError(), nR, nX, nY, nZ, BLCommand::print(), BLCommand::printError(), radius, BLElement::setName(), tolerance, and width.
00210 { 00211 if(argv.size() != 1) { 00212 BLCommand::printError("fieldexpr: Invalid command, must have name"); 00213 return -1; 00214 } 00215 00216 if(argv[0] == "default") { 00217 return defaultBLCMDfieldexpr.handleNamedArgs(namedArgs); 00218 } 00219 00220 BLCMDfieldexpr *t = new BLCMDfieldexpr(defaultBLCMDfieldexpr); 00221 t->setName(argv[0]); 00222 int retval = t->handleNamedArgs(namedArgs); 00223 00224 FieldComputation *p = new FieldComputation(t); 00225 t->map = new BLFieldMap(); 00226 00227 // check error; if necessary, double # map points in each dimension. 00228 double err=0.0; 00229 int ntot=0; 00230 for(;;) { 00231 if(t->radius > 0.0) { 00232 t->map->createCylinderMap(-t->length/2,t->radius/(t->nR-1), 00233 t->length/(t->nZ-1),t->nR,t->nZ,p); 00234 ntot = t->nR*t->nZ; 00235 } else { 00236 t->map->createGridMap(-t->width/2,-t->height/2,-t->length/2, 00237 t->width/(t->nX-1),t->height/(t->nY-1), 00238 t->length/(t->nZ-1),t->nX,t->nY,t->nZ,p); 00239 ntot = t->nX*t->nY*t->nZ; 00240 } 00241 err = t->maxError(p); 00242 printf("fieldexpr %s: Map %d points Max Relative Error = %.4f\n", 00243 t->getName().c_str(),ntot,err); 00244 if(err <= t->tolerance || ntot >= 1000000) 00245 break; 00246 if(t->radius > 0.0) { 00247 t->nR = (t->nR-1)*2 + 1; 00248 t->nZ = (t->nZ-1)*2 + 1; 00249 } else { 00250 t->nX = (t->nX-1)*2 + 1; 00251 t->nY = (t->nY-1)*2 + 1; 00252 t->nZ = (t->nZ-1)*2 + 1; 00253 } 00254 } 00255 00256 delete p; 00257 00258 t->handleTimeDependence(); 00259 00260 t->print(argv[0]); 00261 00262 return retval; 00263 }
void BLCMDfieldexpr::defineNamedArgs | ( | ) | [virtual] |
defineNamedArgs() defines the named arguments for the command.
Reimplemented from BLCommand.
References BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argString(), BLCommand::argTunable(), Br, Bx, By, Bz, Er, Ex, Ey, Ez, factorB, factorE, height, length, nR, nT, nX, nY, nZ, radius, time, timeOffset, tmax, tmin, tolerance, and width.
00266 { 00267 argTunable(factorB,"factorB","Factor for the B-field (1.0)."); 00268 argTunable(factorE,"factorE","Factor for the E-field (1.0)."); 00269 argDouble(timeOffset,"timeOffset","Time offset (ns)."); 00270 // the rest are not permitted to change 00271 argString(Bx,"Bx","Expression for Bx (Tesla), use {x,y,z}.",false); 00272 argString(By,"By","Expression for By (Tesla), use {x,y,z}.",false); 00273 argString(Bz,"Bz","Expression for Bz (Tesla), use {x,y,z} or {r,z}.",false); 00274 argString(Br,"Br","Expression for Br (Tesla), use {r,z}.",false); 00275 argString(Ex,"Ex","Expression for Ex (MV/m), use {x,y,z}.",false); 00276 argString(Ey,"Ey","Expression for Ey (MV/m), use {x,y,z}.",false); 00277 argString(Ez,"Ez","Expression for Ez (MV/m), use {x,y,z} or {r,z}.",false); 00278 argString(Er,"Er","Expression for Er (MV/m), use {r,z}.",false); 00279 argString(time,"time","Expression for time-dependence factor, use {t}.",false); 00280 argInt(nX,"nX","Number of grid point in x.",false); 00281 argInt(nY,"nY","Number of grid point in y.",false); 00282 argInt(nZ,"nZ","Number of grid point in z.",false); 00283 argInt(nR,"nR","Number of grid point in r.",false); 00284 argInt(nT,"nT","Number of grid point in t.",false); 00285 argDouble(tolerance,"tolerance","Required relative accuracy (0.001).",1,"",false); 00286 argDouble(length,"length","Length of field map (mm).",mm,"",false); 00287 argDouble(width,"width","Width of rectangular field map (mm).",mm,"",false); 00288 argDouble(height,"height","Height of rectangular field map (mm).",mm,"",false); 00289 argDouble(radius,"radius","Radius of cylindrical field map (mm).",mm,"",false); 00290 argDouble(tmin,"tmin","Minimum value of t (ns).",mm,"",false); 00291 argDouble(tmax,"tmax","Maximum value of t (ns).",mm,"",false); 00292 }
void BLCMDfieldexpr::construct | ( | G4RotationMatrix * | relativeRotation, | |
G4ThreeVector | relativePosition, | |||
G4LogicalVolume * | parent, | |||
G4String | parentName, | |||
G4RotationMatrix * | parentRotation, | |||
G4ThreeVector | parentPosition | |||
) | [virtual] |
construct() - construct the fieldexpr
Implements BLElement.
References BLGlobalField::addElementField(), factorB, factorE, BLElement::getName(), BLGlobalField::getObject(), map, and timeOffset.
00301 { 00302 G4String thisname = parentName+getName(); 00303 00304 // get globalRotation and globalPosition 00305 G4RotationMatrix *globalRotation = 0; 00306 if(relativeRotation && parentRotation) { 00307 globalRotation = 00308 new G4RotationMatrix(*parentRotation * *relativeRotation); 00309 } else if(relativeRotation) { 00310 globalRotation = relativeRotation; 00311 } else if(parentRotation) { 00312 globalRotation = parentRotation; 00313 } 00314 G4ThreeVector globalPosition(relativePosition + parentPosition); 00315 if(parentRotation) 00316 globalPosition = *parentRotation * relativePosition + 00317 parentPosition; 00318 00319 FieldExprPlacement *p = new FieldExprPlacement(map,globalRotation, 00320 globalPosition,factorB,factorE,timeOffset); 00321 BLGlobalField::getObject()->addElementField(p); 00322 00323 printf("BLMappedMagnet::Construct %s parent=%s relZ=%.1f\n", 00324 thisname.c_str(),parentName.c_str(),relativePosition[2]); 00325 }
G4double BLCMDfieldexpr::getLength | ( | ) | [inline, virtual] |
G4double BLCMDfieldexpr::getWidth | ( | ) | [inline, virtual] |
G4double BLCMDfieldexpr::getHeight | ( | ) | [inline, virtual] |
G4bool BLCMDfieldexpr::isOK | ( | ) | [inline, virtual] |
bool BLCMDfieldexpr::isOutside | ( | G4ThreeVector & | local, | |
G4double | tolerance | |||
) | [inline, virtual] |
void BLCMDfieldexpr::generatePoints | ( | int | npoints, | |
std::vector< G4ThreeVector > & | v | |||
) | [inline, virtual] |
G4double BLCMDfieldexpr::maxError | ( | class FieldComputation * | p | ) |
maxError() returns the maximum relative error (i.e. error / max field).
References FieldComputation::GetFieldValue(), BLFieldMap::getFieldValue(), height, length, map, nR, nX, nY, nZ, radius, and width.
Referenced by command().
00365 { 00366 G4double err[6],maxField[6]; 00367 for(int i=0; i<6; ++i) 00368 err[i] = maxField[i] = 0.0; 00369 00370 // find the max error at the center of every grid box 00371 if(radius > 0.0) { 00372 double dR = radius/(nR-1); 00373 double dZ = length/(nZ-1); 00374 for(double z=(-length+dZ)/2.0; z<length/2.0; z+=dZ) { 00375 for(double r=dR/2.0; r<radius; r+=dR) { 00376 G4double point[4],field1[6],field2[6]; 00377 point[0] = r; 00378 point[1] = 0.0; 00379 point[2] = z; 00380 point[3] = 0.0; // map has no time dependence 00381 map->getFieldValue(point,field1,1.0,1.0); 00382 p->GetFieldValue(point,field2); 00383 for(int i=0; i<6; ++i) { 00384 if(fabs(field2[i]) > maxField[i]) 00385 maxField[i] = fabs(field2[i]); 00386 if(fabs(field2[i]-field1[i]) > err[i]) 00387 err[i] = fabs(field2[i]-field1[i]); 00388 } 00389 } 00390 } 00391 } else { 00392 double dX = width/(nX-1); 00393 double dY = height/(nY-1); 00394 double dZ = length/(nZ-1); 00395 for(double z=(-length+dZ)/2.0; z<length/2.0; z+=dZ) { 00396 for(double y=(-height+dY)/2.0; y<height/2.0; y+= dY) { 00397 for(double x=(-width+dX)/2.0; x<width/2.0; x+=dX) { 00398 G4double point[4],field1[6],field2[6]; 00399 point[0] = x; 00400 point[1] = y; 00401 point[2] = z; 00402 point[3] = 0.0; // map has no time dependence, yet 00403 map->getFieldValue(point,field1,1.0,1.0); 00404 p->GetFieldValue(point,field2); 00405 for(int i=0; i<6; ++i) { 00406 if(fabs(field2[i]) > maxField[i]) 00407 maxField[i] = fabs(field2[i]); 00408 if(fabs(field2[i]-field1[i]) > err[i]) 00409 err[i] = fabs(field2[i]-field1[i]); 00410 } 00411 } 00412 } 00413 } 00414 } 00415 00416 // denominator is largest component, not largest norm -- good enough. 00417 if(maxField[1] > maxField[0]) maxField[0] = maxField[1]; 00418 if(maxField[2] > maxField[0]) maxField[0] = maxField[2]; 00419 if(maxField[4] > maxField[3]) maxField[3] = maxField[4]; 00420 if(maxField[5] > maxField[3]) maxField[3] = maxField[5]; 00421 if(err[1] > err[0]) err[0] = err[1]; 00422 if(err[2] > err[0]) err[0] = err[2]; 00423 if(err[4] > err[3]) err[3] = err[4]; 00424 if(err[5] > err[3]) err[3] = err[5]; 00425 G4double errB=0.0, errE=0.0; 00426 if(maxField[0] > 0.000001) errB = err[0]/maxField[0]; 00427 if(maxField[3] > 0.000001) errE = err[3]/maxField[3]; 00428 return (errB>errE ? errB : errE); 00429 }
friend class FieldComputation [friend] |
Referenced by command().
G4double BLCMDfieldexpr::factorB [private] |
Referenced by BLCMDfieldexpr(), construct(), and defineNamedArgs().
G4double BLCMDfieldexpr::factorE [private] |
Referenced by BLCMDfieldexpr(), construct(), and defineNamedArgs().
G4double BLCMDfieldexpr::timeOffset [private] |
Referenced by BLCMDfieldexpr(), construct(), and defineNamedArgs().
G4String BLCMDfieldexpr::Bx [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and FieldComputation::GetFieldValue().
G4String BLCMDfieldexpr::By [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and FieldComputation::GetFieldValue().
G4String BLCMDfieldexpr::Bz [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and FieldComputation::GetFieldValue().
G4String BLCMDfieldexpr::Br [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and FieldComputation::GetFieldValue().
G4String BLCMDfieldexpr::Ex [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and FieldComputation::GetFieldValue().
G4String BLCMDfieldexpr::Ey [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and FieldComputation::GetFieldValue().
G4String BLCMDfieldexpr::Ez [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and FieldComputation::GetFieldValue().
G4String BLCMDfieldexpr::Er [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and FieldComputation::GetFieldValue().
G4String BLCMDfieldexpr::time [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and handleTimeDependence().
G4double BLCMDfieldexpr::length [private] |
Referenced by BLCMDfieldexpr(), command(), defineNamedArgs(), and maxError().
G4double BLCMDfieldexpr::width [private] |
Referenced by BLCMDfieldexpr(), command(), defineNamedArgs(), and maxError().
G4double BLCMDfieldexpr::height [private] |
Referenced by BLCMDfieldexpr(), command(), defineNamedArgs(), and maxError().
G4double BLCMDfieldexpr::radius [private] |
Referenced by BLCMDfieldexpr(), command(), defineNamedArgs(), FieldComputation::GetFieldValue(), and maxError().
G4double BLCMDfieldexpr::tmin [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and handleTimeDependence().
G4double BLCMDfieldexpr::tmax [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and handleTimeDependence().
int BLCMDfieldexpr::nX [private] |
Referenced by BLCMDfieldexpr(), command(), defineNamedArgs(), and maxError().
int BLCMDfieldexpr::nY [private] |
Referenced by BLCMDfieldexpr(), command(), defineNamedArgs(), and maxError().
int BLCMDfieldexpr::nZ [private] |
Referenced by BLCMDfieldexpr(), command(), defineNamedArgs(), and maxError().
int BLCMDfieldexpr::nR [private] |
Referenced by BLCMDfieldexpr(), command(), defineNamedArgs(), and maxError().
int BLCMDfieldexpr::nT [private] |
Referenced by BLCMDfieldexpr(), defineNamedArgs(), and handleTimeDependence().
G4double BLCMDfieldexpr::tolerance [private] |
Referenced by BLCMDfieldexpr(), command(), and defineNamedArgs().
BLFieldMap* BLCMDfieldexpr::map [private] |
Referenced by BLCMDfieldexpr(), command(), construct(), handleTimeDependence(), and maxError().