Geant4  10.01.p03
G4NistManager.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: G4NistManager.cc 90722 2015-06-08 14:30:21Z gcosmo $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 Class file
31 //
32 //
33 // File name: G4NistManager
34 //
35 // Author: Vladimir Ivanchenko
36 //
37 // Creation date: 23.12.2004
38 //
39 // Modifications:
40 // 27.02.06 V.Ivanchneko add ConstructNewGasMaterial
41 // 18.04.06 V.Ivanchneko add combined creation of materials (NIST + user)
42 // 11.05.06 V.Ivanchneko add warning flag to FindMaterial method
43 // 26.07.07 V.Ivanchneko modify destructor to provide complete destruction
44 // of all elements and materials
45 // 27-07-07, improve destructor (V.Ivanchenko)
46 // 28.07.07 V.Ivanchneko make simple methods inline
47 // 28.07.07 V.Ivanchneko simplify Print methods
48 // 26.10.11, new scheme for G4Exception (mma)
49 //
50 // -------------------------------------------------------------------
51 //
52 // Class Description:
53 //
54 // Element data from the NIST DB on Atomic Weights and Isotope Compositions
55 // http://physics.nist.gov/PhysRefData/Compositions/index.html
56 //
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
60 #include "G4NistManager.hh"
61 #include "G4NistMessenger.hh"
62 #include "G4Isotope.hh"
63 
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
67 
69 {
70  if (instance == 0) {
71  static G4NistManager manager;
72  instance = &manager;
73  }
74  return instance;
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78 
80 {
81  // G4cout << "NistManager: start material destruction" << G4endl;
82  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
83  size_t nmat = theMaterialTable->size();
84  size_t i;
85  for(i=0; i<nmat; i++) {
86  if((*theMaterialTable)[i]) { delete (*theMaterialTable)[i]; }
87  }
88  // G4cout << "NistManager: start element destruction" << G4endl;
89  const G4ElementTable* theElementTable = G4Element::GetElementTable();
90  size_t nelm = theElementTable->size();
91  for(i=0; i<nelm; i++) {
92  if((*theElementTable)[i]) { delete (*theElementTable)[i]; }
93  }
94  // G4cout << "NistManager: start isotope destruction" << G4endl;
95  const G4IsotopeTable* theIsotopeTable = G4Isotope::GetIsotopeTable();
96  size_t niso = theIsotopeTable->size();
97  for(i=0; i<niso; i++) {
98  if((*theIsotopeTable)[i]) { delete (*theIsotopeTable)[i]; }
99  }
100  // G4cout << "NistManager: end isotope destruction" << G4endl;
101  delete messenger;
102  delete matBuilder;
103  delete elmBuilder;
104  // G4cout << "NistManager: end destruction" << G4endl;
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
108 
109 G4Material*
111  const G4String& basename,
113  G4double temperature,
114  G4double pressure)
115 {
116  G4Material* bmat = FindOrBuildMaterial(name);
117  if(bmat) {
118  G4cout << "G4NistManager::BuildMaterialWithNewDensity ERROR: " << G4endl;
119  G4cout << " New material <" << name << "> cannot be built because material"
120  << " with the same name already exist" << G4endl;
121  G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat101",
122  FatalException, "Wrong material name");
123  return 0;
124  }
125  bmat = FindOrBuildMaterial(basename);
126  if(!bmat) {
127  G4cout << "G4NistManager::BuildMaterialWithNewDensity ERROR: " << G4endl;
128  G4cout << " New material <" << name << "> cannot be built because " << G4endl;
129  G4cout << " base material <" << basename << "> does not exist" << G4endl;
130  G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat102",
131  FatalException, "Wrong material name");
132  return 0;
133  }
134  G4double dens = density;
135  G4double temp = temperature;
136  G4double pres = pressure;
137  if(dens == 0.0) {
138  dens = bmat->GetDensity();
139  temp = bmat->GetTemperature();
140  pres = bmat->GetPressure();
141  }
142  G4Material* mat = new G4Material(name, dens, bmat, bmat->GetState(),
143  temp, pres);
144  return mat;
145 }
146 
147 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
148 
150 {
151  if (symbol == "all") { elmBuilder->PrintElement(0); }
152  else { elmBuilder->PrintElement(elmBuilder->GetZ(symbol)); }
153 }
154 
155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
156 
158 {
159  const G4ElementTable* theElementTable = G4Element::GetElementTable();
160  size_t nelm = theElementTable->size();
161  for(size_t i=0; i<nelm; i++) {
162  G4Element* elm = (*theElementTable)[i];
163  if ( name == elm->GetName() || "all" == name) {
164  G4cout << *elm << G4endl;
165  }
166  }
167 }
168 
169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
170 
172 {
173  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
174  size_t nmat = theMaterialTable->size();
175  for(size_t i=0; i<nmat; i++) {
176  G4Material* mat = (*theMaterialTable)[i];
177  if ( name == mat->GetName() || "all" == name) {
178  G4cout << *mat << G4endl;
179  }
180  }
181 }
182 
183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
184 
186 {
187  verbose = val;
188  elmBuilder->SetVerbose(val);
189  matBuilder->SetVerbose(val);
190 }
191 
192 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
193 
194 #include "G4Threading.hh"
195 
197 {
198  if(G4Threading::IsWorkerThread() == true) {
199  G4Exception ("G4NistMaterial::G4NistManager()", "mat090", FatalException,
200  "Attempt to instantiate G4NistManager in worker thread");
201  }
202 
203  nElements = 0;
204  nMaterials = 0;
205  verbose = 0;
206 
209 
210  messenger = new G4NistMessenger(this);
212 
213  // compute frequently used values for mean atomic numbers
214  for(G4int j=1; j<101; ++j) {
216  POWERA27[j] = std::pow(A,0.27);
217  LOGAZ[j] = std::log(A);
218  }
219  POWERA27[0] = 1.0;
220  LOGAZ[0] = 0.0;
221 }
222 
223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double GetPressure() const
Definition: G4Material.hh:183
static G4Pow * GetInstance()
Definition: G4Pow.cc:55
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
G4String symbol
Definition: TRTMaterials.hh:40
static G4NistManager * instance
void PrintElement(G4int Z)
G4String name
Definition: TRTMaterials.hh:40
const G4String & GetName() const
Definition: G4Material.hh:178
G4NistMaterialBuilder * matBuilder
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:588
std::vector< G4Material * > G4MaterialTable
G4double GetDensity() const
Definition: G4Material.hh:180
static const G4IsotopeTable * GetIsotopeTable()
Definition: G4Isotope.cc:182
G4double GetAtomicMassAmu(const G4String &symb) const
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
void PrintG4Material(const G4String &)
G4Material * BuildMaterialWithNewDensity(const G4String &name, const G4String &basename, G4double density=0.0, G4double temp=NTP_Temperature, G4double pres=CLHEP::STP_Pressure)
G4double density
Definition: TRTMaterials.hh:39
std::vector< G4Isotope * > G4IsotopeTable
Definition: G4Isotope.hh:67
G4GLOB_DLL std::ostream G4cout
G4int GetZ(const G4String &symb) const
G4double LOGAZ[101]
void SetVerbose(G4int)
void PrintElement(G4int Z) const
void PrintG4Element(const G4String &)
static const G4double A[nN]
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool IsWorkerThread()
Definition: G4Threading.cc:128
G4NistElementBuilder * elmBuilder
G4NistMessenger * messenger
G4double POWERA27[101]
G4double GetTemperature() const
Definition: G4Material.hh:182
#define G4endl
Definition: G4ios.hh:61
G4State GetState() const
Definition: G4Material.hh:181
std::vector< G4Element * > G4ElementTable
double G4double
Definition: G4Types.hh:76
const G4String & GetName() const
Definition: G4Element.hh:127
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:403