Geant4  10.00.p02
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 74262 2013-10-02 14:37:32Z 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  return;
166  }
167  }
168 }
169 
170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
171 
173 {
174  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
175  size_t nmat = theMaterialTable->size();
176  for(size_t i=0; i<nmat; i++) {
177  G4Material* mat = (*theMaterialTable)[i];
178  if ( name == mat->GetName() || "all" == name) {
179  G4cout << *mat << G4endl;
180  return;
181  }
182  }
183 }
184 
185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
186 
188 {
189  verbose = val;
190  elmBuilder->SetVerbose(val);
191  matBuilder->SetVerbose(val);
192 }
193 
194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
195 
196 #include "G4Threading.hh"
197 
199 {
200  if(G4Threading::IsWorkerThread() == true) {
201  G4Exception ("G4NistMaterial::G4NistManager()", "mat090", FatalException,
202  "Attempt to instantiate G4NistManager in worker thread");
203  }
204 
205  nElements = 0;
206  nMaterials = 0;
207  verbose = 0;
208 
211 
212  messenger = new G4NistMessenger(this);
214 
215  // compute frequently used values for mean atomic numbers
216  for(G4int j=1; j<101; ++j) {
218  POWERA27[j] = std::pow(A,0.27);
219  LOGAZ[j] = std::log(A);
220  }
221  POWERA27[0] = 1.0;
222  LOGAZ[0] = 0.0;
223 }
224 
225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double GetPressure() const
Definition: G4Material.hh:181
static G4Pow * GetInstance()
Definition: G4Pow.cc:53
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:176
G4NistMaterialBuilder * matBuilder
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:587
std::vector< G4Material * > G4MaterialTable
G4double GetDensity() const
Definition: G4Material.hh:178
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 &)
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 &)
G4Material * BuildMaterialWithNewDensity(const G4String &name, const G4String &basename, G4double density=0.0, G4double temp=CLHEP::STP_Temperature, G4double pres=CLHEP::STP_Pressure)
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:104
G4NistElementBuilder * elmBuilder
G4NistMessenger * messenger
G4double POWERA27[101]
G4double GetTemperature() const
Definition: G4Material.hh:180
#define G4endl
Definition: G4ios.hh:61
G4State GetState() const
Definition: G4Material.hh:179
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