Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exrdmMaterial.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: exrdmMaterial.cc 68030 2013-03-13 13:51:27Z gcosmo $
27 //
28 /// \file radioactivedecay/rdecay02/src/exrdmMaterial.cc
29 /// \brief Implementation of the exrdmMaterial class
30 //
31 ////////////////////////////////////////////////////////////////////////////////
32 //
33 #include "exrdmMaterial.hh"
34 #include "exrdmMaterialData.hh"
36 
37 #include "globals.hh"
38 #include "G4UnitsTable.hh"
39 #include "G4PhysicalConstants.hh"
40 #include "G4SystemOfUnits.hh"
41 #include "G4ios.hh"
42 #include <vector>
43 #include <iomanip>
44 ////////////////////////////////////////////////////////////////////////////////
45 //
47  : fMaterialMessenger(0)
48 {
49  fMaterial.clear();
50  fElement.clear();
51  fIsotope.clear();
52  // some default materials vacuum (0), air (1) and aluminium (2) defined here
53  // examples of vacuum
54  //
55  // G4double a,z;
56 
57  static G4bool bmat = false ;
58 
59  if (!bmat) {
60 
61  // vacuum
62  G4double density = universe_mean_density; //from PhysicalConstants.h
63  G4double pressure = 3.e-18*pascal;
64  G4double temperature = 2.73*kelvin;
65  AddMaterial("Vacuum", "H", density,"gas",temperature,pressure);
66  // air
67  density = 1.290*mg/cm3;
68  AddMaterial("Air", "N0.78-O0.22", density, "gas");
69 
70  // aluminium
71  density=2.700*g/cm3 ;
72  AddMaterial ("Aluminium", "Al", density,"");
73 
74  //silicon
75  density=2.3290*g/cm3 ;
76  AddMaterial ("Silicon", "Si", density,"");
77 
78  bmat = true;
79  }
80  // create commands for interactive definition of the geometry
81  fMaterialMessenger = new exrdmMaterialMessenger(this);
82 }
83 ////////////////////////////////////////////////////////////////////////////////
84 //
86 {
87  delete fMaterialMessenger;
88 }
89 ////////////////////////////////////////////////////////////////////////////////
90 //
92  G4double density, G4String state, G4double tem, G4double pres)
93 {
94  G4int isotope, Z;
95  size_t i;
96  for (i = 0; i<fMaterial.size(); i++) {
97  if (fMaterial[i]->GetName() == name) {
98  G4cerr <<" AddMaterial : material " <<name
99  <<" already exists." <<G4endl;
100  G4cerr <<"--> Command rejected." <<G4endl;
101  return;
102  }
103  }
104 
105  char *tokenPtr1 = NULL;
106  char *sname = NULL;
107  G4String s0, s1("0123456789");
108  G4String element, isotopename;
109  G4int ncomponents, natoms;
110  G4double fatoms = 0.;
111  size_t ls, id=0, ll, lr;
112  ncomponents = 0;
113 
114  sname = new char[strlen(formula)+1];
115  strcpy(sname,formula);
116  tokenPtr1 = strtok(sname,"-");
117 
118  while (tokenPtr1 != NULL) {
119  ncomponents++;
120  tokenPtr1 = strtok( NULL, "-");
121  }
122  delete[] sname;
123 
124  G4Material* aMaterial = 0;
125  G4cout << name <<" "<< formula << " " << density/(g/cm3) << " " << tem <<" "
126  <<pres << G4endl;
127 
128  if (state == "") {
129  aMaterial = new G4Material(name, density, ncomponents);
130  } else if (state == "solid" && tem > 0.) {
131  aMaterial = new G4Material(name, density, ncomponents,
132  kStateSolid, tem );
133  } else if (state == "gas" && pres > 0.) {
134  aMaterial = new G4Material(name, density, ncomponents,
135  kStateGas, tem, pres );
136  }
137  if (aMaterial == 0) {
138  G4cerr <<" AddMaterial : Name " <<name <<"." <<G4endl;
139  G4cerr <<"--> Command failed." <<G4endl;
140  return;
141  }
142 
143  sname=new char[strlen(formula)+1];
144  strcpy(sname,formula);
145  tokenPtr1 = strtok(sname,"-");
146 
147  while (tokenPtr1 != NULL) {
148  isotope = 0;
149  // G4cout << tokenPtr1 << G4endl;
150  s0 = G4String(tokenPtr1);
151  ls = s0.length();
152  ll = s0.find("(");
153  lr = s0.find(")");
154  if (ll == lr) {
155  id = s0.find_first_of(s1);
156  element = s0.substr(0,id);
157 
158  if (element.length() == 1) element.insert(0," ");
159  for (i = 0; i<110; i++) {
160  if (element == fELU[i]) break;
161  }
162  if (i == 110) {
163  for (i = 0; i<110; i++) {
164  if (element == fELL[i]) break;
165  }
166  if (i == 110) {
167  for (i = 0; i<110; i++) {
168  if (element == fEUU[i]) break;
169  }
170  }
171  }
172 
173  if (i == 110) {
174  G4cerr <<"AddMaterial : Invalid element in material formula."
175  <<element <<G4endl;
176  G4cerr <<"--> Command rejected." <<G4endl;
177 // delete aMaterial;
178 // fMaterial[NbMat] = NULL;
179  return;
180  }
181 
182  Z = i+1;
183  element = fELU[i];
184  if (id == std::string::npos) {
185  natoms = 1;
186  } else {
187  natoms = atoi((s0.substr(id,ls-id)).c_str());
188  }
189  if (natoms < 1) fatoms = atof((s0.substr(id,ls-id)).c_str());
190  // G4cout << " Elements = " << element << G4endl;
191  //G4cout << " Nb of atoms = " << natoms << G4endl;
192  } else {
193  element = s0.substr(0,ll);
194  isotope = atoi((s0.substr(ll+1,lr-ll)).c_str());
195  if (element.length() == 1) element.insert(0," ");
196  for (i = 0; i<110; i++) {
197  if (element == fELU[i]) break;
198  }
199  if (i == 110) {
200  for (i = 0; i<110; i++) {
201  if (element == fELL[i]) break;
202  }
203  if (i == 110) {
204  for (i = 0; i<110; i++) {
205  if (element == fEUU[i]) break;
206  }
207  }
208  }
209  if (i == 110) {
210  G4cerr <<"AddMaterial : Invalid element in material formula."
211  <<element <<G4endl;
212  G4cerr <<"--> Command rejected." <<G4endl;
213 // delete aMaterial;
214 // fMaterial[NbMat] = NULL;
215  return;
216  }
217 
218  Z = i+1;
219  element = fELU[i];
220  isotopename = element+s0.substr(ll+1,lr-ll-1);
221  if (lr == std::string::npos ) {
222  natoms = 1;
223  } else {
224  natoms = atoi((s0.substr(lr+1,ls-lr)).c_str());
225  }
226  if (natoms < 1) fatoms = atof((s0.substr(id,ls-id)).c_str());
227  if (fatoms == 0.) natoms = 1;
228  //
229  // G4cout << " Elements = " << element << G4endl;
230  // G4cout << " fIsotope Nb = " << isotope << G4endl;
231  // G4cout << " Nb of atoms = " << natoms << G4endl;
232  }
233  if (isotope != 0) {
234  if (G4Isotope::GetIsotope(isotopename) == NULL) {
235  G4Isotope* aIsotope = new G4Isotope(isotopename, Z, isotope, isotope*g/mole);
236  G4Element* aElement = new G4Element(isotopename, element, 1);
237  aElement->AddIsotope(aIsotope, 100.*perCent);
238  fIsotope.push_back(aIsotope);
239  if (natoms>0) {
240  aMaterial->AddElement(aElement, natoms);
241  } else {
242  aMaterial->AddElement(aElement, fatoms);
243  }
244  fElement.push_back(aElement);
245  } else {
246  if (natoms>0) {
247  aMaterial->AddElement( G4Element::GetElement(isotopename,false) , natoms);
248  } else {
249  aMaterial->AddElement( G4Element::GetElement(isotopename,false) , fatoms);
250  }
251  }
252  } else {
253  if ( G4Element::GetElement(element,false) == NULL) {
254  G4Element* aElement = new G4Element(element, element, Z, fA[Z-1]*g/mole);
255  if (natoms>0) {
256  aMaterial->AddElement(aElement, natoms);
257  } else {
258  aMaterial->AddElement(aElement, fatoms);
259  }
260  fElement.push_back(aElement);
261  } else {
262  if (natoms>0) {
263  aMaterial->AddElement( G4Element::GetElement(element,false) , natoms);
264  } else {
265  aMaterial->AddElement( G4Element::GetElement(element,false) , fatoms);
266  }
267  }
268  }
269  tokenPtr1 = strtok( NULL, "-");
270  // s0.empty();
271  //element.erase();
272  //
273  }
274 
275  delete[] sname;
276  fMaterial.push_back(aMaterial);
277  G4cout <<" fMaterial:" <<name <<" with formula: " <<formula <<" added! "
278  <<G4endl;
279  G4cout <<" Nb of fMaterial = " <<fMaterial.size() <<G4endl;
280  G4cout <<" Nb of fIsotope = " <<fIsotope.size() <<G4endl;
281  G4cout <<" Nb of fElement = " <<fElement.size() <<G4endl;
282 }
283 ////////////////////////////////////////////////////////////////////////////////
284 //
286 {
287  size_t i(j-1);
288  if (i > fMaterial.size()) {
289  G4cerr <<"DeleteMaterial : Invalid material index " <<j <<"." <<G4endl;
290  G4cerr <<"--> Command rejected." <<G4endl;
291  } else {
292  G4cerr <<"It seems there is no mechanism in G4 for deleting a material yet!"
293  <<G4endl;
294  G4cerr <<"--> Command rejected." <<G4endl;
295  }
296 }
297 ////////////////////////////////////////////////////////////////////////////////
298 //
300 {
301  G4cerr <<"It seems there is no mechanism in G4 for deleting a material yet!"
302  <<G4endl;
303  G4cerr <<"--> Command rejected." <<G4endl;
304 }
305 ////////////////////////////////////////////////////////////////////////////////
306 //
308 {
309  size_t i ;
310  for (i = 0; i < fMaterial.size(); i++) {
311  if (fMaterial[i]->GetName() == name) break;
312  }
313  G4int k = G4int(i);
314  if (i == fMaterial.size()) k = -1;
315  return k;
316 }
317 ////////////////////////////////////////////////////////////////////////////////
318 //
320 {
321  G4cout <<" There are" <<std::setw(3) <<fMaterial.size()
322  <<" materials defined." <<G4endl;
323  for (size_t i = 0; i< fMaterial.size(); i++)
324  G4cout <<" fMaterial Index " <<std::setw(3) <<i+1 <<" "
325  <<std::setw(14) <<fMaterial[i]->GetName()
326  <<" density: " <<std::setw(6) <<std::setprecision(3)
327  <<G4BestUnit(fMaterial[i]->GetDensity(),"Volumic Mass") <<G4endl;
328  G4cout <<G4endl;
329 
330 }
331 ////////////////////////////////////////////////////////////////////////////////
static G4Element * GetElement(G4String name, G4bool warning=true)
Definition: G4Element.cc:409
int universe_mean_density
Definition: hepunit.py:307
Definition of the exrdmMaterialMessenger class.
const XML_Char * name
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
G4int GetMaterialIndex(G4String)
static G4Isotope * GetIsotope(const G4String &name, G4bool warning=false)
Definition: G4Isotope.cc:196
void AddMaterial(G4String, G4String, G4double, G4String, G4double tem=CLHEP::STP_Temperature, G4double pres=CLHEP::STP_Pressure)
Definition of the exrdmMaterial class.
G4double density
Definition: TRTMaterials.hh:39
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
void DeleteMaterial(G4int)
bool G4bool
Definition: G4Types.hh:79
void AddIsotope(G4Isotope *isotope, G4double RelativeAbundance)
Definition: G4Element.cc:151
#define pascal
float perCent
Definition: hepunit.py:239
#define G4endl
Definition: G4ios.hh:61
Definition of the exrdmMaterialData class.
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:345
double G4double
Definition: G4Types.hh:76
G4GLOB_DLL std::ostream G4cerr