A solenoid consists of a BLCoil and a current value. It is a BLElement and can be placed geometrically (multiple times). The geometrical parameters are in the BLCoil, not the BLCMDsolenoid; this class uses the variables of its BLCoil to determine the geometry of the solenoid.
Public Member Functions | |
BLCMDsolenoid () | |
Default constructor. Defines the command, etc. | |
virtual | ~BLCMDsolenoid () |
Destructor. | |
BLCMDsolenoid (const BLCMDsolenoid &r) | |
Copy constructor. | |
BLElement * | clone () |
clone() | |
G4String | commandName () |
commandName() returns "solenoid". | |
int | command (BLArgumentVector &argv, BLArgumentMap &namedArgs) |
command() implements the solenoid command. | |
void | defineNamedArgs () |
defineNamedArgs() defines the named arguments of the command. | |
void | construct (G4RotationMatrix *relativeRotation, G4ThreeVector relativePosition, G4LogicalVolume *parent, G4String parentName, G4RotationMatrix *parentRotation, G4ThreeVector parentPosition) |
construct() - construct the solenoid. Creates a new SolenoidField and adds it to BLGlobalField. | |
G4double | getLength () |
getLength() returns the length of the solenoid | |
G4double | getWidth () |
getWidth() returns the outer radius of the solenoid | |
G4double | getHeight () |
getHeight() returns the outer radius of the solenoid | |
G4bool | isOK () |
isOK() returns true. | |
void | generatePoints (int npoints, std::vector< G4ThreeVector > &v) |
generatePoints() from BLElement | |
G4bool | isOutside (G4ThreeVector &local, G4double tolerance) |
isOutside() from BLElement | |
Private Attributes | |
G4String | coilName |
G4double | current |
G4String | color |
G4int | alternate |
G4int | kill |
BLCoil * | coil |
std::vector< SolenoidField * > | solenoidField |
Friends | |
class | SolenoidField |
BLCMDsolenoid::BLCMDsolenoid | ( | ) |
Default constructor. Defines the command, etc.
References alternate, BLCMDTYPE_ELEMENT, coil, coilName, color, current, kill, BLCommand::registerCommand(), BLCommand::setDescription(), and BLCommand::setSynopsis().
Referenced by clone(), and command().
00127 : BLElement(), solenoidField() 00128 { 00129 // register the commandName(), and its synopsis and description. 00130 registerCommand(BLCMDTYPE_ELEMENT); 00131 setSynopsis("defines a solenoid (a coil and current)"); 00132 setDescription("A solenoid is a coil and a current. If alternate is\n" 00133 "nonzero, then each placement of the solenoid (or an\n" 00134 "enclosing group) will flip the sign of current."); 00135 00136 // provide initial values for fields 00137 coilName = ""; 00138 current = 0.0; 00139 color = "1,1,1"; 00140 alternate = 0; 00141 kill = 0; 00142 coil = 0; 00143 }
BLCMDsolenoid::BLCMDsolenoid | ( | const BLCMDsolenoid & | r | ) |
Copy constructor.
References alternate, coil, coilName, color, current, and kill.
00146 : BLElement(r), solenoidField() 00147 { 00148 // copy fields one at a time (transfers default values from the 00149 // default object to this new object). 00150 coilName = r.coilName; 00151 current = r.current; 00152 color = r.color; 00153 alternate = r.alternate; 00154 kill = r.kill; 00155 coil = r.coil; 00156 }
BLElement* BLCMDsolenoid::clone | ( | ) | [inline, virtual] |
G4String BLCMDsolenoid::commandName | ( | ) | [inline, virtual] |
int BLCMDsolenoid::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [virtual] |
command() implements the solenoid command.
Implements BLCommand.
References BLCMDsolenoid(), coil, coilName, BLCoil::find(), BLCommand::handleNamedArgs(), BLCommand::print(), BLCommand::printError(), and BLElement::setName().
00159 { 00160 if(argv.size() != 1) { 00161 printError("solenoid: Invalid command, must have name"); 00162 return -1; 00163 } 00164 00165 if(argv[0] == "default") { 00166 return defaultSolenoid.handleNamedArgs(namedArgs); 00167 } 00168 00169 BLCMDsolenoid *t = new BLCMDsolenoid(defaultSolenoid); 00170 t->setName(argv[0]); 00171 int retval = t->handleNamedArgs(namedArgs); 00172 00173 t->coil = BLCoil::find(t->coilName); 00174 if(t->coil == 0) { 00175 printError("solenoid: coil '%s' not found.", 00176 t->coilName.c_str()); 00177 retval = -1; 00178 } 00179 00180 t->print(argv[0]); 00181 00182 return retval; 00183 }
void BLCMDsolenoid::defineNamedArgs | ( | ) | [virtual] |
defineNamedArgs() defines the named arguments of the command.
Reimplemented from BLCommand.
References alternate, BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argString(), coilName, color, current, and kill.
00186 { 00187 argString(coilName,"coilName","The name of the coil (must exist)",false); 00188 // the map was generated for 1 Amp/mm^2, so this factor is actually unitless 00189 argDouble(current,"current","The current density in the conductor (Amp/mm^2)",1.0); 00190 argString(color,"color","The color of the solenoid (''=invisible)."); 00191 argInt(alternate,"alternate","Set nonzero to alternate sign each placement."); 00192 argInt(kill,"kill","Set nonzero to kill all tracks that hit the coil."); 00193 argString(coilName,"coil","Synonym for coilName.",false); 00194 }
void BLCMDsolenoid::construct | ( | G4RotationMatrix * | relativeRotation, | |
G4ThreeVector | relativePosition, | |||
G4LogicalVolume * | parent, | |||
G4String | parentName, | |||
G4RotationMatrix * | parentRotation, | |||
G4ThreeVector | parentPosition | |||
) | [virtual] |
construct() - construct the solenoid. Creates a new SolenoidField and adds it to BLGlobalField.
Implements BLElement.
References BLGlobalField::addElementField(), alternate, coil, color, current, BLCommand::getMaterial(), BLElement::getName(), BLManager::getObject(), BLGlobalField::getObject(), BLCoordinateTransform::getPosition(), BLCommand::getVisAttrib(), SolenoidField::global2local, BLCoil::innerRadius, kill, BLCoil::length, BLCoil::material, BLCoil::outerRadius, solenoidField, and SolenoidField.
00202 { 00203 // geant4 rotation convention is backwards from g4beamline 00204 G4RotationMatrix *g4rot = 0; 00205 if(relativeRotation) 00206 g4rot = new G4RotationMatrix(relativeRotation->inverse()); 00207 00208 // get globalRotation and globalPosition 00209 G4RotationMatrix *globalRotation = 0; 00210 if(relativeRotation && parentRotation) { 00211 globalRotation = 00212 new G4RotationMatrix(*parentRotation * *relativeRotation); 00213 } else if(relativeRotation) { 00214 globalRotation = relativeRotation; 00215 } else if(parentRotation) { 00216 globalRotation = parentRotation; 00217 } 00218 G4ThreeVector globalPosition(relativePosition + parentPosition); 00219 if(parentRotation) 00220 globalPosition = *parentRotation * relativePosition + 00221 parentPosition; 00222 00223 BLCoordinateTransform global2local(globalRotation,globalPosition); 00224 00225 // add this solenoid to the GlobalField 00226 SolenoidField *sf = new SolenoidField(global2local,coil, current); 00227 BLGlobalField::getObject()->addElementField(sf); 00228 solenoidField.push_back(sf); 00229 00230 if(alternate) 00231 current = -current; 00232 00233 if(coil->length == 0.0) 00234 return; 00235 00236 // construct the coil 00237 G4String thisname = parentName+getName(); 00238 G4Tubs *tubs = new G4Tubs(thisname+"Tubs", coil->innerRadius, 00239 coil->outerRadius, coil->length/2.0, 0.0,2.0*pi); 00240 G4Material *mat = getMaterial(coil->material); 00241 G4LogicalVolume *lv = new G4LogicalVolume(tubs,mat, thisname+"LogVol"); 00242 lv->SetVisAttributes(getVisAttrib(color)); 00243 00244 G4PVPlacement *pv = new G4PVPlacement(g4rot,relativePosition,lv, 00245 thisname, parent,false,0); 00246 00247 if(kill) 00248 BLManager::getObject()-> 00249 registerSteppingAction(pv,new BLKillTrack(thisname)); 00250 00251 printf("BLCMDsolenoid::Construct %s parent=%s relZ=%.1f globZ=%.1f\n", 00252 thisname.c_str(),parentName.c_str(),relativePosition[2], 00253 global2local.getPosition()[2]); 00254 printf("\tglobal pos=%.1f,%.1f,%.1f ",globalPosition[0], 00255 globalPosition[1],globalPosition[2]); 00256 }
G4double BLCMDsolenoid::getLength | ( | ) | [inline, virtual] |
getLength() returns the length of the solenoid
Implements BLElement.
References coil, and BLCoil::length.
G4double BLCMDsolenoid::getWidth | ( | ) | [inline, virtual] |
getWidth() returns the outer radius of the solenoid
Implements BLElement.
References coil, and BLCoil::outerRadius.
00108 { return coil->outerRadius*2.0; }
G4double BLCMDsolenoid::getHeight | ( | ) | [inline, virtual] |
getHeight() returns the outer radius of the solenoid
Implements BLElement.
References coil, and BLCoil::outerRadius.
00111 { return coil->outerRadius*2.0; }
G4bool BLCMDsolenoid::isOK | ( | ) | [inline, virtual] |
void BLCMDsolenoid::generatePoints | ( | int | npoints, | |
std::vector< G4ThreeVector > & | v | |||
) | [virtual] |
generatePoints() from BLElement
Implements BLElement.
References coil, BLElement::generateTubs(), BLCoil::innerRadius, BLCoil::length, and BLCoil::outerRadius.
00306 { 00307 v.clear(); 00308 if(coil->length == 0) return; 00309 generateTubs(npoints, coil->innerRadius, coil->outerRadius, 0.0, 00310 360.0*deg, coil->length, v); 00311 }
G4bool BLCMDsolenoid::isOutside | ( | G4ThreeVector & | local, | |
G4double | tolerance | |||
) | [virtual] |
isOutside() from BLElement
Implements BLElement.
References coil, BLCoil::innerRadius, BLCoil::length, and BLCoil::outerRadius.
00314 { 00315 if(coil->length == 0) return true; 00316 G4double r = sqrt(local[0]*local[0]+local[1]*local[1]); 00317 return r < coil->innerRadius+tolerance || 00318 r > coil->outerRadius-tolerance || 00319 fabs(local[2]) > coil->length/2.0-tolerance; 00320 }
friend class SolenoidField [friend] |
Referenced by construct().
G4String BLCMDsolenoid::coilName [private] |
Referenced by BLCMDsolenoid(), command(), and defineNamedArgs().
G4double BLCMDsolenoid::current [private] |
Referenced by BLCMDsolenoid(), construct(), and defineNamedArgs().
G4String BLCMDsolenoid::color [private] |
Referenced by BLCMDsolenoid(), construct(), and defineNamedArgs().
G4int BLCMDsolenoid::alternate [private] |
Referenced by BLCMDsolenoid(), construct(), and defineNamedArgs().
G4int BLCMDsolenoid::kill [private] |
Referenced by BLCMDsolenoid(), construct(), and defineNamedArgs().
BLCoil* BLCMDsolenoid::coil [private] |
Referenced by BLCMDsolenoid(), command(), construct(), generatePoints(), getHeight(), getLength(), getWidth(), and isOutside().
std::vector<SolenoidField *> BLCMDsolenoid::solenoidField [private] |
Referenced by construct().