Geant4-11
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// -------------------------------------------------------------------
27//
28// GEANT4 Class file
29//
30//
31// File name: G4NistManager
32//
33// Author: Vladimir Ivanchenko
34//
35// Creation date: 23.12.2004
36//
37// Modifications:
38// 27.02.06 V.Ivanchneko add ConstructNewGasMaterial
39// 18.04.06 V.Ivanchneko add combined creation of materials (NIST + user)
40// 11.05.06 V.Ivanchneko add warning flag to FindMaterial method
41// 26.07.07 V.Ivanchneko modify destructor to provide complete destruction
42// of all elements and materials
43// 27-07-07, improve destructor (V.Ivanchenko)
44// 28.07.07 V.Ivanchneko make simple methods inline
45// 28.07.07 V.Ivanchneko simplify Print methods
46// 26.10.11, new scheme for G4Exception (mma)
47//
48// -------------------------------------------------------------------
49//
50// Class Description:
51//
52// Element data from the NIST DB on Atomic Weights and Isotope Compositions
53// http://physics.nist.gov/PhysRefData/Compositions/index.html
54//
55//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57
58#include "G4NistManager.hh"
59#include "G4NistMessenger.hh"
60#include "G4Isotope.hh"
61#include "G4Threading.hh"
62
64#ifdef G4MULTITHREADED
65 G4Mutex G4NistManager::nistManagerMutex = G4MUTEX_INITIALIZER;
66#endif
67
68//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
69
71{
72 if (instance == nullptr) {
73#ifdef G4MULTITHREADED
74 G4MUTEXLOCK(&nistManagerMutex);
75 if (instance == nullptr) {
76#endif
77 static G4NistManager manager;
78 instance = &manager;
79#ifdef G4MULTITHREADED
80 }
81 G4MUTEXUNLOCK(&nistManagerMutex);
82#endif
83 }
84 return instance;
85}
86
87//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88
90{
91 // G4cout << "NistManager: start material destruction" << G4endl;
92 const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
93 size_t nmat = theMaterialTable->size();
94 size_t i;
95 for(i=0; i<nmat; i++) {
96 if((*theMaterialTable)[i]) { delete (*theMaterialTable)[i]; }
97 }
98 // G4cout << "NistManager: start element destruction" << G4endl;
99 const G4ElementTable* theElementTable = G4Element::GetElementTable();
100 size_t nelm = theElementTable->size();
101 for(i=0; i<nelm; i++) {
102 if((*theElementTable)[i]) { delete (*theElementTable)[i]; }
103 }
104 // G4cout << "NistManager: start isotope destruction" << G4endl;
105 const G4IsotopeTable* theIsotopeTable = G4Isotope::GetIsotopeTable();
106 size_t niso = theIsotopeTable->size();
107 for(i=0; i<niso; i++) {
108 if((*theIsotopeTable)[i]) { delete (*theIsotopeTable)[i]; }
109 }
110 // G4cout << "NistManager: end isotope destruction" << G4endl;
111 delete messenger;
112 delete matBuilder;
113 delete elmBuilder;
114 delete fICRU90;
115 // G4cout << "NistManager: end destruction" << G4endl;
116}
117
118//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119
122 const G4String& basename,
123 G4double density,
124 G4double temperature,
125 G4double pressure)
126{
128 if(bmat) {
129 G4cout << "G4NistManager::BuildMaterialWithNewDensity ERROR: " << G4endl;
130 G4cout << " New material <" << name << "> cannot be built because material"
131 << " with the same name already exists." << G4endl;
132 G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat101",
133 FatalException, "Wrong material name");
134 return 0;
135 }
136 bmat = FindOrBuildMaterial(basename);
137 if(!bmat) {
138 G4cout << "G4NistManager::BuildMaterialWithNewDensity ERROR: " << G4endl;
139 G4cout << " New material <" << name << "> cannot be built because "
140 << G4endl;
141 G4cout << " base material <" << basename << "> does not exist." << G4endl;
142 G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat102",
143 FatalException, "Wrong material name");
144 return 0;
145 }
146 G4double dens = density;
147 G4double temp = temperature;
148 G4double pres = pressure;
149 if(dens == 0.0) {
150 dens = bmat->GetDensity();
151 temp = bmat->GetTemperature();
152 pres = bmat->GetPressure();
153 }
154 G4Material* mat = new G4Material(name, dens, bmat, bmat->GetState(),
155 temp, pres);
156 return mat;
157}
158
159//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
160
161void G4NistManager::PrintElement(const G4String& symbol) const
162{
163 if (symbol == "all") { elmBuilder->PrintElement(0); }
164 else { elmBuilder->PrintElement(elmBuilder->GetZ(symbol)); }
165}
166
167//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
168
170{
171 const G4ElementTable* theElementTable = G4Element::GetElementTable();
172 size_t nelm = theElementTable->size();
173 for(size_t i=0; i<nelm; i++) {
174 G4Element* elm = (*theElementTable)[i];
175 if ( name == elm->GetName() || "all" == name) {
176 G4cout << *elm << G4endl;
177 }
178 }
179}
180
181//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
182
184{
185 const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
186 size_t nmat = theMaterialTable->size();
187 for(size_t i=0; i<nmat; i++) {
188 G4Material* mat = (*theMaterialTable)[i];
189 if ( name == mat->GetName() || "all" == name) {
190 G4cout << *mat << G4endl;
191 }
192 }
193}
194
195//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
196
198{
199#ifdef G4MULTITHREADED
200 G4MUTEXLOCK(&nistManagerMutex);
201#endif
202 verbose = val;
205#ifdef G4MULTITHREADED
206 G4MUTEXUNLOCK(&nistManagerMutex);
207#endif
208}
209
210//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
211
213{
214 nElements = 0;
215 nMaterials = 0;
216 verbose = 0;
217
220
221 messenger = new G4NistMessenger(this);
223
224 // compute frequently used values for mean atomic numbers
225 for(G4int j=1; j<101; ++j) {
227 POWERA27[j] = std::pow(A,0.27);
228 LOGAZ[j] = std::log(A);
229 }
230 POWERA27[0] = 1.0;
231 LOGAZ[0] = 0.0;
232 fICRU90 = nullptr;
233}
234
235//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
236
238{
239 if (!fICRU90) {
240#ifdef G4MULTITHREADED
241 G4MUTEXLOCK(&nistManagerMutex);
242 if (!fICRU90) {
243#endif
245#ifdef G4MULTITHREADED
246 }
247 G4MUTEXUNLOCK(&nistManagerMutex);
248#endif
249 }
250 return fICRU90;
251}
252
253//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
254
256 G4bool val)
257{
258#ifdef G4MULTITHREADED
259 G4MUTEXLOCK(&nistManagerMutex);
260#endif
261 if(mname == "all") {
262 for(auto mat : materials) {
264 }
265 } else {
266 G4Material* mat = FindMaterial(mname);
268 }
269#ifdef G4MULTITHREADED
270 G4MUTEXUNLOCK(&nistManagerMutex);
271#endif
272}
273
274//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
275
277{
278 if(mat) { mat->ComputeDensityEffectOnFly(val); }
279}
280
281//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::vector< G4Element * > G4ElementTable
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::vector< G4Isotope * > G4IsotopeTable
Definition: G4Isotope.hh:66
std::vector< G4Material * > G4MaterialTable
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:85
#define G4MUTEXLOCK(mutex)
Definition: G4Threading.hh:251
#define G4MUTEXUNLOCK(mutex)
Definition: G4Threading.hh:254
std::mutex G4Mutex
Definition: G4Threading.hh:81
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
const G4double A[17]
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:397
const G4String & GetName() const
Definition: G4Element.hh:127
static const G4IsotopeTable * GetIsotopeTable()
Definition: G4Isotope.cc:181
G4double GetPressure() const
Definition: G4Material.hh:179
G4double GetDensity() const
Definition: G4Material.hh:176
G4State GetState() const
Definition: G4Material.hh:177
G4double GetTemperature() const
Definition: G4Material.hh:178
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:672
const G4String & GetName() const
Definition: G4Material.hh:173
void ComputeDensityEffectOnFly(G4bool)
Definition: G4Material.cc:658
G4double GetAtomicMassAmu(const G4String &symb) const
G4int GetZ(const G4String &symb) const
void PrintElement(G4int Z) const
G4ICRU90StoppingData * GetICRU90StoppingData()
G4NistMessenger * messenger
G4ICRU90StoppingData * fICRU90
void PrintElement(G4int Z) const
G4double POWERA27[101]
void SetDensityEffectCalculatorFlag(const G4String &, G4bool)
static G4NistManager * instance
G4double LOGAZ[101]
G4NistMaterialBuilder * matBuilder
G4NistElementBuilder * elmBuilder
G4Material * BuildMaterialWithNewDensity(const G4String &name, const G4String &basename, G4double density=0.0, G4double temp=NTP_Temperature, G4double pres=CLHEP::STP_Pressure)
void PrintG4Material(const G4String &) const
void PrintG4Element(const G4String &) const
std::vector< G4Material * > materials
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
G4Material * FindMaterial(const G4String &name) const
static G4NistManager * Instance()
void SetVerbose(G4int)
static G4Pow * GetInstance()
Definition: G4Pow.cc:41
const char * name(G4int ptype)