BLCMDmaterial Class Reference

Inheritance diagram for BLCMDmaterial:

BLCommand

List of all members.


Detailed Description

class BLCMDmaterial implementa the material command, which defines materials.

The default table of materials is contained in g4beamline.cc, initMaterials().

Public Member Functions

 BLCMDmaterial ()
 Constructor.
 ~BLCMDmaterial ()
 Destructor.
G4String commandName ()
 commandName() returns "material"
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() executes the command associated with this element.
void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for the command.
void help (bool detailed)
 help() prints the help.

Private Attributes

G4double a
G4double z
G4double density
G4double pressure
G4double temperature
G4String state
bool complete_description


Constructor & Destructor Documentation

BLCMDmaterial::BLCMDmaterial (  ) 

Constructor.

References a, BLCMDTYPE_AUX, complete_description, density, pressure, BLCommand::registerCommand(), BLCommand::setDescription(), BLCommand::setSynopsis(), state, temperature, UNDEFINED, and z.

00072                              : BLCommand()
00073 {
00074         registerCommand(BLCMDTYPE_AUX);
00075         setSynopsis("construct a new material.");
00076         setDescription("This is an interface to G4Material.\n"
00077                 "This command is rarely required, because elements and most "
00078                 "common materials are available via the NIST database. "
00079                 "Any material available from the NIST database can simply "
00080                 "be used; if it is unknown then it "
00081                 "will be automatically defined from the database. "
00082                 "Uncommon materials or nonstandard densities must be defined "
00083                 "with this command.\n\n"
00084                 "The first argument to this command is the material name, "
00085                 "which is always required; density is also required. "
00086                 "The command to define an element (e.g. with non-standard "
00087                 "density) is:\n"
00088                 "    material H2 Z=1 A=1.01 density=0.000090\n"
00089                 "A mixture or compound is a combination of known materials "
00090                 "and/or elements; the command is:\n"
00091                 "    material water H,0.1119 O,0.8881 density=1.0\n"
00092                 "The numbers following the element names are their mass "
00093                 "fractions (note that WATER is available from the NIST db). "
00094                 "Either type of command can optionally have: pressure, "
00095                 "temperature, state.\n\n"
00096                 "With no arguments, this command prints the current material "
00097                 "table. Note that 'G4_' is prepended to the names of most "
00098                 "materials that are obtained from the NIST database; 'G4_Al' "
00099                 "and 'Al' refer to the same material (unless one was "
00100                 "previously defined using this command).\n\n"
00101                 "The following materials will be automatically "
00102                 "created on first use:\n\n");
00103         // cannot call GetNistMaterialNames() here, so defer to the help()
00104         // function, based on complete_description.
00105 
00106         // default values (unused)
00107         a = z = density = UNDEFINED;
00108         pressure = STP_Pressure;
00109         temperature = STP_Temperature;
00110         state = "";
00111         complete_description = false;
00112 }

BLCMDmaterial::~BLCMDmaterial (  )  [inline]

Destructor.

00052 { }


Member Function Documentation

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

commandName() returns "material"

Implements BLCommand.

00055 { return "material"; }

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

command() executes the command associated with this element.

Implements BLCommand.

References a, density, BLCommand::getMaterial(), BLCommand::handleNamedArgs(), pressure, BLCommand::printError(), snprintf, state, temperature, UNDEFINED, and z.

00115 {
00116         if(argv.size() < 1) {
00117                 G4cout << *G4Material::GetMaterialTable() << G4endl;
00118                 return 0;
00119         }
00120 
00121         G4String name = argv[0];
00122 
00123         a = UNDEFINED;
00124         z = UNDEFINED;
00125         density = UNDEFINED;
00126         pressure = STP_Pressure;
00127         temperature = STP_Temperature;
00128         state = "";
00129 
00130         int retval = handleNamedArgs(namedArgs);
00131 
00132         G4State s = kStateUndefined;
00133         switch(state.c_str()[0]) {
00134         case 'g': case 'G':     s = kStateGas;          break;
00135         case 'l': case 'L':     s = kStateLiquid;       break;
00136         case 's': case 'S':     s = kStateSolid;        break;
00137         }
00138 
00139         if(density == UNDEFINED) {
00140                 printError("material: density is required.");
00141                 return -1;
00142         }
00143 
00144         G4Material *mat = 0;
00145         if(argv.size() > 1) {           // mixture of other materials
00146                 int nComponents = argv.size() - 1;
00147                 mat = new G4Material(name,density,nComponents,s,temperature,
00148                                                                 pressure);
00149                 int i;
00150                 G4double sum = 0.0;
00151                 G4String mix;
00152                 for(i=1; i<=nComponents; ++i) {
00153                         unsigned int j = argv[i].find(',');
00154                         if(j == argv[i].npos) break;
00155                         G4String p = argv[i].substr(0,j);
00156                         G4Material *m = getMaterial(p);
00157                         if(!m) break;
00158                         char *q = 0;
00159                         G4double f = strtod(argv[i].substr(j+1).c_str(),&q);
00160                         if(!q || *q != '\0') break;
00161                         mat->AddMaterial(m,f);
00162                         sum += f;
00163                         char tmp[64];
00164                         snprintf(tmp,sizeof(tmp),"%.2f*%s",f,p.c_str());
00165                         if(i > 1) mix += "+";
00166                         mix += tmp;
00167                 }
00168                 if(i != nComponents+1 || sum < 0.99 || sum > 1.01) {
00169                         printError("material %-6s invalid mixture/compound",
00170                                 name.c_str());
00171                         return -1;
00172                 }
00173                 printf("material %-6s Mixture: %s\n",name.c_str(),mix.c_str());
00174                 printf("\t\tdensity=%.3f temperature=%.0f pressure=%.1f\n",
00175                         density/(gram/cm3),temperature,pressure/atmosphere);
00176         } else {                        // standalone material
00177                 if(a == UNDEFINED || z == UNDEFINED) {
00178                         printError("material: need A and/or Z");
00179                         return -1;
00180                 }
00181                 mat = new G4Material(name,z,a,density,s,temperature,pressure);
00182                 printf("material %-6s Z=%.2f A=%.2f\n",name.c_str(),z,
00183                                                         a/(gram/mole));
00184                 printf("\t\tdensity=%.3f temperature=%.0f pressure=%.1f\n",
00185                         density/(gram/cm3),temperature,pressure/atmosphere);
00186         }
00187 
00188         return retval;
00189 }

void BLCMDmaterial::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for the command.

Reimplemented from BLCommand.

References a, BLCommand::argDouble(), BLCommand::argString(), density, pressure, state, temperature, and z.

00192 {
00193         argDouble(a,"a","Effective Atomic Weight of the material (g/mole)",gram/mole);
00194         argDouble(z,"z","Effective Atomic Number of the material");
00195         argDouble(density,"density","Density of the material (gm/cm^3)",gram/cm3);
00196         argDouble(pressure,"pressure","Pressure of the material (Atm)",atmosphere);
00197         argDouble(temperature,"temperature","Temperature of the material (K)");
00198         argString(state,"state","State of the material (g,l, or s)");
00199         argDouble(a,"A","Synonym for a (g/mole)",gram/mole);
00200         argDouble(z,"Z","Synonym for z");
00201 }

void BLCMDmaterial::help ( bool  detailed  )  [virtual]

help() prints the help.

Reimplemented from BLCommand.

References complete_description, BLCommand::description, and BLCommand::help().

00204 {
00205         if(!complete_description) {
00206                 complete_description = true;
00207                 G4NistManager *m = G4NistManager::Instance();
00208                 const std::vector<G4String> &v=m->GetNistMaterialNames();
00209                 for(unsigned i=0; i<v.size(); ++i) {
00210                         const char *p = v[i].c_str();
00211                         if(strncmp(p,"G4_",3) == 0) p += 3; // omit the initial "G4_"
00212                         description += p;
00213                         description += " ";
00214                 }
00215                 description += "Stainless304 Stainless316 lHe ";
00216                 description += "\n\nAliases: LHe=lHe Air=AIR, H2O=WATER, "
00217                                 "Vacuum=Galactic, LH2=lH2, "
00218                                 "Scintillator=POLYSTYRENE\n";
00219         }
00220 
00221         BLCommand::help(detailed);
00222 }


Member Data Documentation

G4double BLCMDmaterial::a [private]

G4double BLCMDmaterial::z [private]

G4double BLCMDmaterial::density [private]

G4double BLCMDmaterial::pressure [private]

G4double BLCMDmaterial::temperature [private]

G4String BLCMDmaterial::state [private]

Referenced by BLCMDmaterial(), and help().


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