source: trunk/source/materials/src/G4Element.cc@ 1225

Last change on this file since 1225 was 1196, checked in by garnier, 16 years ago

update CVS release candidate geant4.9.3.01

File size: 15.8 KB
Line 
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//
27// $Id: G4Element.cc,v 1.34 2009/09/18 15:35:36 vnivanch Exp $
28// GEANT4 tag $Name: materials-V09-02-18 $
29//
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31
32// 26-06-96: Code uses operators (+=, *=, ++, -> etc.) correctly, P. Urban
33// 09-07-96: new data members added by L.Urban
34// 17-01-97: aesthetic rearrangement, M.Maire
35// 20-01-97: Compute Tsai's formula for the rad length, M.Maire
36// 21-01-97: remove mixture flag, M.Maire
37// 24-01-97: ComputeIonisationParameters().
38// new data member: fTaul, M.Maire
39// 29-01-97: Forbidden to create Element with Z<1 or N<Z, M.Maire
40// 20-03-97: corrected initialization of pointers, M.Maire
41// 28-04-98: atomic subshell binding energies stuff, V. Grichine
42// 09-07-98: Ionisation parameters removed from the class, M.Maire
43// 16-11-98: name Subshell -> Shell; GetBindingEnergy() (mma)
44// 09-03-01: assignement operator revised (mma)
45// 02-05-01: check identical Z in AddIsotope (marc)
46// 03-05-01: flux.precision(prec) at begin/end of operator<<
47// 13-09-01: suppression of the data member fIndexInTable
48// 14-09-01: fCountUse: nb of materials which use this element
49// 26-02-02: fIndexInTable renewed
50// 30-03-05: warning in GetElement(elementName)
51// 15-11-05: GetElement(elementName, G4bool warning=true)
52// 17-10-06: Add fNaturalAbandances (V.Ivanchenko)
53// 27-07-07, improve destructor (V.Ivanchenko)
54// 18-10-07, move definition of material index to ComputeDerivedQuantities (V.Ivanchenko)
55
56//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57
58#include "G4Element.hh"
59#include <iomanip>
60
61G4ElementTable G4Element::theElementTable;
62
63//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64
65// Constructor to Generate an element from scratch
66
67G4Element::G4Element(const G4String& name, const G4String& symbol,
68 G4double zeff, G4double aeff)
69 : fName(name), fSymbol(symbol)
70{
71 G4int iz = (G4int)zeff;
72 if (zeff<1.) {
73 G4cout << "G4Element ERROR: " << name << " Z= " << zeff
74 << " A= " << aeff/(g/mole) << G4endl;
75 G4Exception (" ERROR from G4Element::G4Element !"
76 " It is not allowed to create an Element with Z < 1" );
77 }
78 if (std::abs(zeff - iz) > perMillion) {
79 G4cout << "G4Element Warning: " << name << " Z= " << zeff
80 << " A= " << aeff/(g/mole) << G4endl;
81 G4cerr << name << " : WARNING from G4Element::G4Element !"
82 " Trying to define an element as a mixture directly via effective Z."
83 << G4endl;
84 }
85
86 InitializePointers();
87
88 fZeff = zeff;
89 fNeff = aeff/(g/mole);
90 fAeff = aeff;
91
92 if(fNeff < 1.0) fNeff = 1.0;
93
94 if (fNeff < zeff) {
95 G4cout << "G4Element ERROR: " << name << " Z= " << zeff
96 << " A= " << fNeff << G4endl;
97 G4Exception (" ERROR from G4Element::G4Element !"
98 " Attempt to create an Element with N < Z !!!" );
99 }
100
101 fNbOfAtomicShells = G4AtomicShells::GetNumberOfShells(iz);
102 fAtomicShells = new G4double[fNbOfAtomicShells];
103 fNbOfShellElectrons = new G4int[fNbOfAtomicShells];
104
105 for (G4int i=0;i<fNbOfAtomicShells;i++)
106 {
107 fAtomicShells[i] = G4AtomicShells::GetBindingEnergy(iz, i);
108 fNbOfShellElectrons[i] = G4AtomicShells::GetNumberOfElectrons(iz, i);
109 }
110 ComputeDerivedQuantities();
111}
112
113//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
114
115// Constructor to Generate element from a List of 'nIsotopes' isotopes, added
116// via AddIsotope
117
118G4Element::G4Element(const G4String& name,
119 const G4String& symbol, G4int nIsotopes)
120 : fName(name),fSymbol(symbol)
121{
122 InitializePointers();
123
124 size_t n = size_t(nIsotopes);
125
126 theIsotopeVector = new G4IsotopeVector(n,0);
127 fRelativeAbundanceVector = new G4double[nIsotopes];
128}
129
130//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
131
132// Add an isotope to the element
133
134void G4Element::AddIsotope(G4Isotope* isotope, G4double abundance)
135{
136 if (theIsotopeVector == 0) {
137 G4cout << "G4Element ERROR: " << fName << G4endl;
138 G4Exception ("ERROR from G4Element::AddIsotope!"
139 " Trying to add an Isotope before contructing the element.");
140 }
141 G4int iz = isotope->GetZ();
142
143 // filling ...
144 if ( fNumberOfIsotopes < theIsotopeVector->size() ) {
145 // check same Z
146 if (fNumberOfIsotopes==0) fZeff = G4double(iz);
147 else if (G4double(iz) != fZeff) {
148 G4Exception ("ERROR from G4Element::AddIsotope!"
149 " Try to add isotopes with different Z");
150 }
151 //Z ok
152 fRelativeAbundanceVector[fNumberOfIsotopes] = abundance;
153 (*theIsotopeVector)[fNumberOfIsotopes] = isotope;
154 ++fNumberOfIsotopes;
155 isotope->increaseCountUse();
156 } else {
157 G4cout << "G4Element ERROR: " << fName << G4endl;
158 G4Exception ("ERROR from G4Element::AddIsotope!"
159 " Attempt to add more than the declared number of isotopes.");
160 }
161
162 // filled.
163 if ( fNumberOfIsotopes == theIsotopeVector->size() ) {
164 // Compute Neff, Aeff
165 G4double wtSum=0.0;
166
167 fNeff = fAeff = 0.0;
168 for (size_t i=0;i<fNumberOfIsotopes;i++) {
169 fNeff += fRelativeAbundanceVector[i]*(*theIsotopeVector)[i]->GetN();
170 fAeff += fRelativeAbundanceVector[i]*(*theIsotopeVector)[i]->GetA();
171 wtSum += fRelativeAbundanceVector[i];
172 }
173 fNeff /= wtSum;
174 fAeff /= wtSum;
175
176 fNbOfAtomicShells = G4AtomicShells::GetNumberOfShells(iz);
177 fAtomicShells = new G4double[fNbOfAtomicShells];
178 fNbOfShellElectrons = new G4int[fNbOfAtomicShells];
179
180 for ( G4int j = 0; j < fNbOfAtomicShells; j++ )
181 {
182 fAtomicShells[j] = G4AtomicShells::GetBindingEnergy(iz, j);
183 fNbOfShellElectrons[j] = G4AtomicShells::GetNumberOfElectrons(iz, j);
184 }
185 ComputeDerivedQuantities();
186
187 }
188}
189
190//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
191
192void G4Element::InitializePointers()
193{
194 theIsotopeVector = 0;
195 fRelativeAbundanceVector = 0;
196 fAtomicShells = 0;
197 fNbOfShellElectrons = 0;
198 fIonisation = 0;
199 fNumberOfIsotopes = 0;
200 fNaturalAbandances = false;
201}
202
203//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
204
205// Fake default constructor - sets only member data and allocates memory
206// for usage restricted to object persistency
207
208G4Element::G4Element( __void__& )
209 : fZeff(0), fNeff(0), fAeff(0), fNbOfAtomicShells(0),
210 fAtomicShells(0), fNbOfShellElectrons(0), fNumberOfIsotopes(0), theIsotopeVector(0),
211 fRelativeAbundanceVector(0), fCountUse(0), fIndexInTable(0),
212 fCoulomb(0), fRadTsai(0), fIonisation(0)
213{
214}
215
216//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
217
218G4Element::~G4Element()
219{
220 // G4cout << "### Destruction of element " << fName << " started" <<G4endl;
221
222 if (theIsotopeVector) delete theIsotopeVector;
223 if (fRelativeAbundanceVector) delete [] fRelativeAbundanceVector;
224 if (fAtomicShells) delete [] fAtomicShells;
225 if (fNbOfShellElectrons) delete [] fNbOfShellElectrons;
226 if (fIonisation) delete fIonisation;
227
228 //remove this element from theElementTable
229 theElementTable[fIndexInTable] = 0;
230}
231
232//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
233
234void G4Element::ComputeDerivedQuantities()
235{
236 // some basic functions of the atomic number
237
238 // Store in table
239 theElementTable.push_back(this);
240 fIndexInTable = theElementTable.size() - 1;
241
242 // check if elements with same Z already exist
243 fIndexZ = 0;
244 for (size_t J=0 ; J<fIndexInTable ; J++) {
245 if (theElementTable[J]->GetZ() == fZeff) fIndexZ++;
246 }
247 //nb of materials which use this element
248 fCountUse = 0;
249
250 // Radiation Length
251 ComputeCoulombFactor();
252 ComputeLradTsaiFactor();
253
254 // parameters for energy loss by ionisation
255 if (fIonisation) delete fIonisation;
256 fIonisation = new G4IonisParamElm(fZeff);
257}
258
259//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
260
261void G4Element::ComputeCoulombFactor()
262{
263 //
264 // Compute Coulomb correction factor (Phys Rev. D50 3-1 (1994) page 1254)
265
266 const G4double k1 = 0.0083 , k2 = 0.20206 ,k3 = 0.0020 , k4 = 0.0369 ;
267
268 G4double az2 = (fine_structure_const*fZeff)*(fine_structure_const*fZeff);
269 G4double az4 = az2 * az2;
270
271 fCoulomb = (k1*az4 + k2 + 1./(1.+az2))*az2 - (k3*az4 + k4)*az4;
272}
273
274//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
275
276void G4Element::ComputeLradTsaiFactor()
277{
278 //
279 // Compute Tsai's Expression for the Radiation Length
280 // (Phys Rev. D50 3-1 (1994) page 1254)
281
282 const G4double Lrad_light[] = {5.31 , 4.79 , 4.74 , 4.71} ;
283 const G4double Lprad_light[] = {6.144 , 5.621 , 5.805 , 5.924} ;
284
285 const G4double logZ3 = std::log(fZeff)/3.;
286
287 G4double Lrad, Lprad;
288 G4int iz = (G4int)(fZeff+0.5) - 1 ;
289 if (iz <= 3) { Lrad = Lrad_light[iz] ; Lprad = Lprad_light[iz] ; }
290 else { Lrad = std::log(184.15) - logZ3 ; Lprad = std::log(1194.) - 2*logZ3;}
291
292 fRadTsai = 4*alpha_rcl2*fZeff*(fZeff*(Lrad-fCoulomb) + Lprad);
293}
294
295//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
296
297G4double G4Element::GetAtomicShell(G4int i) const
298{
299 if (i<0 || i>=fNbOfAtomicShells) {
300 G4Exception("Invalid argument in G4Element::GetAtomicShell");
301 }
302 return fAtomicShells[i];
303}
304
305//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
306
307G4int G4Element::GetNbOfShellElectrons(G4int i) const
308{
309 if (i<0 || i>=fNbOfAtomicShells) {
310 G4Exception("Invalid argument in G4Element::GetNbOfShellElectrons");
311 }
312 return fNbOfShellElectrons[i];
313}
314
315//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
316
317const G4ElementTable* G4Element::GetElementTable()
318{
319 return &theElementTable;
320}
321
322//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
323
324size_t G4Element::GetNumberOfElements()
325{
326 return theElementTable.size();
327}
328
329//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
330
331G4Element* G4Element::GetElement(G4String elementName, G4bool warning)
332{
333 // search the element by its name
334 for (size_t J=0 ; J<theElementTable.size() ; J++)
335 {
336 if (theElementTable[J]->GetName() == elementName)
337 return theElementTable[J];
338 }
339
340 // the element does not exist in the table
341 if (warning) {
342 G4cout << "\n---> warning from G4Element::GetElement(). The element: "
343 << elementName << " does not exist in the table. Return NULL pointer."
344 << G4endl;
345 }
346 return 0;
347}
348
349//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
350
351G4Element::G4Element(G4Element& right)
352{
353 InitializePointers();
354 *this = right;
355
356 // Store this new element in table and set the index
357 theElementTable.push_back(this);
358 fIndexInTable = theElementTable.size() - 1;
359}
360
361//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
362
363const G4Element& G4Element::operator=(const G4Element& right)
364{
365 if (this != &right)
366 {
367 fName = right.fName;
368 fSymbol = right.fSymbol;
369 fZeff = right.fZeff;
370 fNeff = right.fNeff;
371 fAeff = right.fAeff;
372
373 if (fAtomicShells) delete [] fAtomicShells;
374 fNbOfAtomicShells = right.fNbOfAtomicShells;
375 fAtomicShells = new G4double[fNbOfAtomicShells];
376
377 if (fNbOfShellElectrons) delete [] fNbOfShellElectrons;
378 fNbOfAtomicShells = right.fNbOfAtomicShells;
379 fNbOfShellElectrons = new G4int[fNbOfAtomicShells];
380
381 for ( G4int i = 0; i < fNbOfAtomicShells; i++ )
382 {
383 fAtomicShells[i] = right.fAtomicShells[i];
384 fNbOfShellElectrons[i] = right.fNbOfShellElectrons[i];
385 }
386 if (theIsotopeVector) delete theIsotopeVector;
387 if (fRelativeAbundanceVector) delete [] fRelativeAbundanceVector;
388
389 fNumberOfIsotopes = right.fNumberOfIsotopes;
390 if (fNumberOfIsotopes > 0)
391 {
392 theIsotopeVector = new G4IsotopeVector(fNumberOfIsotopes,0);
393 fRelativeAbundanceVector = new G4double[fNumberOfIsotopes];
394 for (size_t i=0;i<fNumberOfIsotopes;i++)
395 {
396 (*theIsotopeVector)[i] = (*right.theIsotopeVector)[i];
397 fRelativeAbundanceVector[i] = right.fRelativeAbundanceVector[i];
398 }
399 }
400 ComputeDerivedQuantities();
401 }
402 return *this;
403}
404
405//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
406
407G4int G4Element::operator==(const G4Element& right) const
408{
409 return (this == (G4Element*) &right);
410}
411
412//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
413
414G4int G4Element::operator!=(const G4Element& right) const
415{
416 return (this != (G4Element*) &right);
417}
418
419//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
420
421std::ostream& operator<<(std::ostream& flux, G4Element* element)
422{
423 std::ios::fmtflags mode = flux.flags();
424 flux.setf(std::ios::fixed,std::ios::floatfield);
425 G4long prec = flux.precision(3);
426
427 flux
428 << " Element: " << element->fName << " (" << element->fSymbol << ")"
429 << " Z = " << std::setw(4) << std::setprecision(1) << element->fZeff
430 << " N = " << std::setw(5) << std::setprecision(1) << element->fNeff
431 << " A = " << std::setw(6) << std::setprecision(2)
432 << (element->fAeff)/(g/mole) << " g/mole";
433
434 for (size_t i=0; i<element->fNumberOfIsotopes; i++)
435 flux
436 << "\n ---> " << (*(element->theIsotopeVector))[i]
437 << " abundance: " << std::setw(6) << std::setprecision(2)
438 << (element->fRelativeAbundanceVector[i])/perCent << " %";
439
440 flux.precision(prec);
441 flux.setf(mode,std::ios::floatfield);
442 return flux;
443}
444
445//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
446
447 std::ostream& operator<<(std::ostream& flux, G4Element& element)
448{
449 flux << &element;
450 return flux;
451}
452
453//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
454
455std::ostream& operator<<(std::ostream& flux, G4ElementTable ElementTable)
456{
457 //Dump info for all known elements
458 flux << "\n***** Table : Nb of elements = " << ElementTable.size()
459 << " *****\n" << G4endl;
460
461 for (size_t i=0; i<ElementTable.size(); i++) flux << ElementTable[i]
462 << G4endl << G4endl;
463
464 return flux;
465}
466
467//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.