Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 << 25 // >> 26 // $Id: G4NistManager.cc,v 1.19 2008/07/23 14:49:31 vnivanch Exp $ >> 27 // GEANT4 tag $Name: geant4-09-02-patch-03 $ >> 28 // 26 // ------------------------------------------- 29 // ------------------------------------------------------------------- 27 // 30 // 28 // GEANT4 Class file 31 // GEANT4 Class file 29 // 32 // 30 // 33 // 31 // File name: G4NistManager 34 // File name: G4NistManager 32 // 35 // 33 // Author: Vladimir Ivanchenko 36 // Author: Vladimir Ivanchenko 34 // 37 // 35 // Creation date: 23.12.2004 38 // Creation date: 23.12.2004 36 // 39 // >> 40 // Modifications: >> 41 // 27.02.06 V.Ivanchneko add ConstructNewGasMaterial >> 42 // 18.04.06 V.Ivanchneko add combined creation of materials (NIST + user) >> 43 // 11.05.06 V.Ivanchneko add warning flag to FindMaterial method >> 44 // 26.07.07 V.Ivanchneko modify destructor to provide complete destruction >> 45 // of all elements and materials >> 46 // 27-07-07, improve destructor (V.Ivanchenko) >> 47 // 28.07.07 V.Ivanchneko make simple methods inline >> 48 // 28.07.07 V.Ivanchneko simplify Print methods 37 // 49 // 38 // ------------------------------------------- 50 // ------------------------------------------------------------------- 39 // 51 // 40 // Class Description: 52 // Class Description: 41 // 53 // 42 // Element data from the NIST DB on Atomic Wei 54 // Element data from the NIST DB on Atomic Weights and Isotope Compositions 43 // http://physics.nist.gov/PhysRefData/Composi 55 // http://physics.nist.gov/PhysRefData/Compositions/index.html >> 56 // >> 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 44 59 45 #include "G4NistManager.hh" 60 #include "G4NistManager.hh" 46 #include "G4AutoLock.hh" << 47 #include "G4NistMessenger.hh" 61 #include "G4NistMessenger.hh" >> 62 #include "G4Isotope.hh" 48 63 49 << 64 G4NistManager* G4NistManager::instance = 0; 50 namespace << 51 { << 52 G4Mutex nistManagerMutex = G4MUTEX_INITIALIZER << 53 } << 54 65 55 //....oooOO0OOooo........oooOO0OOooo........oo 66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 56 67 57 G4NistManager* G4NistManager::Instance() 68 G4NistManager* G4NistManager::Instance() 58 { 69 { 59 static G4NistManager manager; << 70 if (instance == 0) { 60 return &manager; << 71 static G4NistManager manager; >> 72 instance = &manager; >> 73 } >> 74 return instance; 61 } 75 } 62 76 63 //....oooOO0OOooo........oooOO0OOooo........oo 77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 64 78 65 G4NistManager::~G4NistManager() << 79 G4NistManager::G4NistManager() 66 { 80 { 67 delete messenger; << 81 nElements = 0; 68 delete matBuilder; << 82 nMaterials = 0; 69 delete elmBuilder; << 83 verbose = 0; 70 delete fICRU90; << 84 >> 85 elmBuilder = new G4NistElementBuilder(verbose); >> 86 matBuilder = new G4NistMaterialBuilder(elmBuilder,verbose); >> 87 >> 88 messenger = new G4NistMessenger(this); >> 89 >> 90 // compute frequently used values >> 91 for(G4int i=1; i<256; i++) { >> 92 G4double x = G4double(i); >> 93 POWERZ13[i] = std::pow(x,1.0/3.0); >> 94 LOGA[i] = std::log(x); >> 95 } >> 96 for(G4int j=1; j<101; j++) { >> 97 G4double A = elmBuilder->GetA(j); >> 98 POWERA27[j] = std::pow(A,0.27); >> 99 LOGAZ[j] = std::log(A); >> 100 } >> 101 POWERZ13[0] = 1.0; >> 102 POWERA27[0] = 1.0; >> 103 LOGA[0] = 0.0; >> 104 LOGAZ[0] = 0.0; 71 } 105 } 72 106 73 //....oooOO0OOooo........oooOO0OOooo........oo 107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 74 108 75 G4Material* G4NistManager::BuildMaterialWithNe << 109 G4NistManager::~G4NistManager() 76 const G4String& basename, G4double density, << 77 { 110 { 78 G4Material* bmat = FindOrBuildMaterial(name) << 111 // G4cout << "NistManager: start material destruction" << G4endl; 79 if (bmat != nullptr) { << 112 const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable(); 80 G4cout << "G4NistManager::BuildMaterialWit << 113 size_t nmat = theMaterialTable->size(); 81 G4cout << " New material <" << name << "> << 114 size_t i; 82 << " with the same name already exi << 115 for(i=0; i<nmat; i++) { 83 G4Exception("G4NistManager::BuildMaterialW << 116 if((*theMaterialTable)[i]) delete (*theMaterialTable)[i]; 84 "Wrong material name"); << 117 } 85 return nullptr; << 118 // G4cout << "NistManager: start element destruction" << G4endl; 86 } << 119 const G4ElementTable* theElementTable = G4Element::GetElementTable(); 87 bmat = FindOrBuildMaterial(basename); << 120 size_t nelm = theElementTable->size(); 88 if (bmat == nullptr) { << 121 for(i=0; i<nelm; i++) { 89 G4cout << "G4NistManager::BuildMaterialWit << 122 if((*theElementTable)[i]) delete (*theElementTable)[i]; 90 G4cout << " New material <" << name << "> << 123 } 91 G4cout << " base material <" << basename < << 124 // G4cout << "NistManager: start isotope destruction" << G4endl; 92 G4Exception("G4NistManager::BuildMaterialW << 125 const G4IsotopeTable* theIsotopeTable = G4Isotope::GetIsotopeTable(); 93 "Wrong material name"); << 126 size_t niso = theIsotopeTable->size(); 94 return nullptr; << 127 for(i=0; i<niso; i++) { >> 128 if((*theIsotopeTable)[i]) delete (*theIsotopeTable)[i]; 95 } 129 } 96 G4double dens = density; << 130 // G4cout << "NistManager: end isotope destruction" << G4endl; 97 G4double temp = temperature; << 131 delete messenger; 98 G4double pres = pressure; << 132 delete matBuilder; 99 if (dens == 0.0) { << 133 delete elmBuilder; 100 dens = bmat->GetDensity(); << 134 // G4cout << "NistManager: end destruction" << G4endl; 101 temp = bmat->GetTemperature(); << 102 pres = bmat->GetPressure(); << 103 } << 104 auto mat = new G4Material(name, dens, bmat, << 105 return mat; << 106 } 135 } 107 136 108 //....oooOO0OOooo........oooOO0OOooo........oo 137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 109 138 110 void G4NistManager::PrintElement(const G4Strin << 139 void G4NistManager::PrintElement(const G4String& symbol) 111 { 140 { 112 if (symbol == "all") { << 141 if (symbol == "all") elmBuilder->PrintElement(0); 113 elmBuilder->PrintElement(0); << 142 else elmBuilder->PrintElement(elmBuilder->GetZ(symbol)); 114 } << 115 else { << 116 elmBuilder->PrintElement(elmBuilder->GetZ( << 117 } << 118 } 143 } 119 144 120 //....oooOO0OOooo........oooOO0OOooo........oo 145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 121 146 122 void G4NistManager::PrintG4Element(const G4Str << 147 void G4NistManager::PrintG4Element(const G4String& name) 123 { 148 { 124 for (auto const & elm : *G4Element::GetEleme << 149 const G4ElementTable* theElementTable = G4Element::GetElementTable(); 125 if (name == elm->GetName() || "all" == nam << 150 size_t nelm = theElementTable->size(); >> 151 for(size_t i=0; i<nelm; i++) { >> 152 G4Element* elm = (*theElementTable)[i]; >> 153 if ( name == elm->GetName() || "all" == name) { 126 G4cout << *elm << G4endl; 154 G4cout << *elm << G4endl; >> 155 return; 127 } 156 } 128 } 157 } 129 } 158 } 130 159 131 //....oooOO0OOooo........oooOO0OOooo........oo 160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 132 161 133 void G4NistManager::PrintG4Material(const G4St << 162 void G4NistManager::PrintG4Material(const G4String& name) 134 { 163 { 135 for (auto const & mat : *G4Material::GetMate << 164 const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable(); 136 if (name == mat->GetName() || "all" == nam << 165 size_t nmat = theMaterialTable->size(); >> 166 for(size_t i=0; i<nmat; i++) { >> 167 G4Material* mat = (*theMaterialTable)[i]; >> 168 if ( name == mat->GetName() || "all" == name) { 137 G4cout << *mat << G4endl; 169 G4cout << *mat << G4endl; >> 170 return; 138 } 171 } 139 } 172 } 140 } 173 } 141 174 142 //....oooOO0OOooo........oooOO0OOooo........oo 175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 143 176 144 void G4NistManager::SetVerbose(G4int val) 177 void G4NistManager::SetVerbose(G4int val) 145 { 178 { 146 verbose = val; 179 verbose = val; 147 elmBuilder->SetVerbose(val); 180 elmBuilder->SetVerbose(val); 148 matBuilder->SetVerbose(val); 181 matBuilder->SetVerbose(val); 149 } 182 } 150 183 151 //....oooOO0OOooo........oooOO0OOooo........oo 184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 152 << 153 G4NistManager::G4NistManager() << 154 { << 155 nElements = 0; << 156 nMaterials = 0; << 157 verbose = 0; << 158 << 159 theMaterialTable = G4Material::GetMaterialTa << 160 theElementTable = G4Element::GetElementTable << 161 theIsotopeTable = G4Isotope::GetIsotopeTable << 162 << 163 elmBuilder = new G4NistElementBuilder(verbos << 164 matBuilder = new G4NistMaterialBuilder(elmBu << 165 << 166 messenger = new G4NistMessenger(this); << 167 g4pow = G4Pow::GetInstance(); << 168 << 169 // compute frequently used values for mean a << 170 for (G4int j = 1; j < 101; ++j) { << 171 G4double A = elmBuilder->GetAtomicMassAmu( << 172 POWERA27[j] = std::pow(A, 0.27); << 173 LOGAZ[j] = std::log(A); << 174 } << 175 POWERA27[0] = 1.0; << 176 LOGAZ[0] = 0.0; << 177 fICRU90 = nullptr; << 178 } << 179 << 180 //....oooOO0OOooo........oooOO0OOooo........oo << 181 << 182 G4ICRU90StoppingData* G4NistManager::GetICRU90 << 183 { << 184 if (fICRU90 == nullptr) { << 185 G4AutoLock l(&nistManagerMutex); << 186 if (fICRU90 == nullptr) { << 187 fICRU90 = new G4ICRU90StoppingData(); << 188 } << 189 l.unlock(); << 190 } << 191 return fICRU90; << 192 } << 193 << 194 //....oooOO0OOooo........oooOO0OOooo........oo << 195 << 196 void G4NistManager::SetDensityEffectCalculator << 197 { << 198 if (mname == "all") { << 199 for (auto mat : materials) { << 200 SetDensityEffectCalculatorFlag(mat, val) << 201 } << 202 } << 203 else { << 204 G4Material* mat = FindMaterial(mname); << 205 SetDensityEffectCalculatorFlag(mat, val); << 206 } << 207 } << 208 << 209 //....oooOO0OOooo........oooOO0OOooo........oo << 210 << 211 void G4NistManager::SetDensityEffectCalculator << 212 { << 213 if (mat != nullptr) { << 214 mat->ComputeDensityEffectOnFly(val); << 215 } << 216 } << 217 185