Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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$
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
64G4NistManager* G4NistManager::instance = 0;
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
79G4NistManager::G4NistManager()
80{
81 nElements = 0;
82 nMaterials = 0;
83 verbose = 0;
84
85 elmBuilder = new G4NistElementBuilder(verbose);
86 matBuilder = new G4NistMaterialBuilder(elmBuilder,verbose);
87
88 messenger = new G4NistMessenger(this);
89 g4pow = G4Pow::GetInstance();
90
91 // compute frequently used values for mean atomic numbers
92 for(G4int j=1; j<101; ++j) {
93 G4double A = elmBuilder->GetAtomicMassAmu(j);
94 POWERA27[j] = std::pow(A,0.27);
95 LOGAZ[j] = std::log(A);
96 }
97 POWERA27[0] = 1.0;
98 LOGAZ[0] = 0.0;
99}
100
101//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102
104{
105 // G4cout << "NistManager: start material destruction" << G4endl;
106 const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
107 size_t nmat = theMaterialTable->size();
108 size_t i;
109 for(i=0; i<nmat; i++) {
110 if((*theMaterialTable)[i]) { delete (*theMaterialTable)[i]; }
111 }
112 // G4cout << "NistManager: start element destruction" << G4endl;
113 const G4ElementTable* theElementTable = G4Element::GetElementTable();
114 size_t nelm = theElementTable->size();
115 for(i=0; i<nelm; i++) {
116 if((*theElementTable)[i]) { delete (*theElementTable)[i]; }
117 }
118 // G4cout << "NistManager: start isotope destruction" << G4endl;
119 const G4IsotopeTable* theIsotopeTable = G4Isotope::GetIsotopeTable();
120 size_t niso = theIsotopeTable->size();
121 for(i=0; i<niso; i++) {
122 if((*theIsotopeTable)[i]) { delete (*theIsotopeTable)[i]; }
123 }
124 // G4cout << "NistManager: end isotope destruction" << G4endl;
125 delete messenger;
126 delete matBuilder;
127 delete elmBuilder;
128 // G4cout << "NistManager: end destruction" << G4endl;
129}
130
131//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
132
135 const G4String& basename,
136 G4double density,
137 G4double temperature,
138 G4double pressure)
139{
140 G4Material* bmat = FindOrBuildMaterial(name);
141 if(bmat) {
142 G4cout << "G4NistManager::BuildMaterialWithNewDensity ERROR: " << G4endl;
143 G4cout << " New material <" << name << "> cannot be built because material"
144 << " with the same name already exist" << G4endl;
145 G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat101",
146 FatalException, "Wrong material name");
147 return 0;
148 }
149 bmat = FindOrBuildMaterial(basename);
150 if(!bmat) {
151 G4cout << "G4NistManager::BuildMaterialWithNewDensity ERROR: " << G4endl;
152 G4cout << " New material <" << name << "> cannot be built because " << G4endl;
153 G4cout << " base material <" << basename << "> does not exist" << G4endl;
154 G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat102",
155 FatalException, "Wrong material name");
156 return 0;
157 }
158 G4double dens = density;
159 G4double temp = temperature;
160 G4double pres = pressure;
161 if(dens == 0.0) {
162 dens = bmat->GetDensity();
163 temp = bmat->GetTemperature();
164 pres = bmat->GetPressure();
165 }
166 G4Material* mat = new G4Material(name, dens, bmat, bmat->GetState(),
167 temp, pres);
168 return mat;
169}
170
171//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
172
174{
175 if (symbol == "all") { elmBuilder->PrintElement(0); }
176 else { elmBuilder->PrintElement(elmBuilder->GetZ(symbol)); }
177}
178
179//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
180
182{
183 const G4ElementTable* theElementTable = G4Element::GetElementTable();
184 size_t nelm = theElementTable->size();
185 for(size_t i=0; i<nelm; i++) {
186 G4Element* elm = (*theElementTable)[i];
187 if ( name == elm->GetName() || "all" == name) {
188 G4cout << *elm << G4endl;
189 return;
190 }
191 }
192}
193
194//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
195
197{
198 const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
199 size_t nmat = theMaterialTable->size();
200 for(size_t i=0; i<nmat; i++) {
201 G4Material* mat = (*theMaterialTable)[i];
202 if ( name == mat->GetName() || "all" == name) {
203 G4cout << *mat << G4endl;
204 return;
205 }
206 }
207}
208
209//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
210
212{
213 verbose = val;
214 elmBuilder->SetVerbose(val);
215 matBuilder->SetVerbose(val);
216}
217
218//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::vector< G4Element * > G4ElementTable
@ FatalException
std::vector< G4Isotope * > G4IsotopeTable
Definition: G4Isotope.hh:68
std::vector< G4Material * > G4MaterialTable
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
const G4String & GetName() const
Definition: G4Element.hh:127
static const G4ElementTable * GetElementTable()
Definition: G4Element.cc:399
static const G4IsotopeTable * GetIsotopeTable()
Definition: G4Isotope.cc:182
G4double GetPressure() const
Definition: G4Material.hh:182
G4double GetDensity() const
Definition: G4Material.hh:179
static const G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:562
G4State GetState() const
Definition: G4Material.hh:180
G4double GetTemperature() const
Definition: G4Material.hh:181
const G4String & GetName() const
Definition: G4Material.hh:177
G4int GetZ(const G4String &symb)
G4double GetAtomicMassAmu(const G4String &symb)
void PrintG4Element(const G4String &)
void PrintElement(G4int Z)
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
static G4NistManager * Instance()
void SetVerbose(G4int)
G4Material * BuildMaterialWithNewDensity(const G4String &name, const G4String &basename, G4double density=0.0, G4double temp=CLHEP::STP_Temperature, G4double pres=CLHEP::STP_Pressure)
void PrintG4Material(const G4String &)
static G4Pow * GetInstance()
Definition: G4Pow.cc:50
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41