Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 96794 2016-05-09 10:09:30Z 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 
64 G4NistManager* G4NistManager::instance = nullptr;
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
67 
69 {
70  if (instance == nullptr) {
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,
112  G4double density,
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 "
129  << G4endl;
130  G4cout << " base material <" << basename << "> does not exist" << G4endl;
131  G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat102",
132  FatalException, "Wrong material name");
133  return 0;
134  }
135  G4double dens = density;
136  G4double temp = temperature;
137  G4double pres = pressure;
138  if(dens == 0.0) {
139  dens = bmat->GetDensity();
140  temp = bmat->GetTemperature();
141  pres = bmat->GetPressure();
142  }
143  G4Material* mat = new G4Material(name, dens, bmat, bmat->GetState(),
144  temp, pres);
145  return mat;
146 }
147 
148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
149 
150 void G4NistManager::PrintElement(const G4String& symbol) const
151 {
152  if (symbol == "all") { elmBuilder->PrintElement(0); }
153  else { elmBuilder->PrintElement(elmBuilder->GetZ(symbol)); }
154 }
155 
156 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
157 
159 {
160  const G4ElementTable* theElementTable = G4Element::GetElementTable();
161  size_t nelm = theElementTable->size();
162  for(size_t i=0; i<nelm; i++) {
163  G4Element* elm = (*theElementTable)[i];
164  if ( name == elm->GetName() || "all" == name) {
165  G4cout << *elm << G4endl;
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  }
181  }
182 }
183 
184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
185 
187 {
188  verbose = val;
189  elmBuilder->SetVerbose(val);
190  matBuilder->SetVerbose(val);
191 }
192 
193 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
194 
195 #include "G4Threading.hh"
196 
197 G4NistManager::G4NistManager()
198 {
199  if(G4Threading::IsWorkerThread() == true) {
200  G4Exception ("G4NistMaterial::G4NistManager()", "mat090", FatalException,
201  "Attempt to instantiate G4NistManager in worker thread");
202  }
203 
204  nElements = 0;
205  nMaterials = 0;
206  verbose = 0;
207 
208  elmBuilder = new G4NistElementBuilder(verbose);
209  matBuilder = new G4NistMaterialBuilder(elmBuilder,verbose);
210 
211  messenger = new G4NistMessenger(this);
212  g4pow = G4Pow::GetInstance();
213 
214  // compute frequently used values for mean atomic numbers
215  for(G4int j=1; j<101; ++j) {
216  G4double A = elmBuilder->GetAtomicMassAmu(j);
217  POWERA27[j] = std::pow(A,0.27);
218  LOGAZ[j] = std::log(A);
219  }
220  POWERA27[0] = 1.0;
221  LOGAZ[0] = 0.0;
222 }
223 
224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double GetPressure() const
Definition: G4Material.hh:183
static G4Pow * GetInstance()
Definition: G4Pow.cc:55
const XML_Char * name
Definition: expat.h:151
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
const G4String & GetName() const
Definition: G4Material.hh:178
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:587
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()
G4Material * BuildMaterialWithNewDensity(const G4String &name, const G4String &basename, G4double density=0.0, G4double temp=NTP_Temperature, G4double pres=CLHEP::STP_Pressure)
std::vector< G4Isotope * > G4IsotopeTable
Definition: G4Isotope.hh:67
G4GLOB_DLL std::ostream G4cout
double A(double temperature)
G4int GetZ(const G4String &symb) const
void SetVerbose(G4int)
void PrintG4Material(const G4String &) const
void PrintElement(G4int Z) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool IsWorkerThread()
Definition: G4Threading.cc:145
void PrintElement(G4int Z) const
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:398
void PrintG4Element(const G4String &) const