G4NistManager.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id: G4NistManager.cc 67044 2013-01-30 08:50:06Z gcosmo $
00027 //
00028 // -------------------------------------------------------------------
00029 //
00030 // GEANT4 Class file
00031 //
00032 //
00033 // File name:     G4NistManager
00034 //
00035 // Author:        Vladimir Ivanchenko
00036 //
00037 // Creation date: 23.12.2004
00038 //
00039 // Modifications:
00040 // 27.02.06 V.Ivanchneko add ConstructNewGasMaterial
00041 // 18.04.06 V.Ivanchneko add combined creation of materials (NIST + user)
00042 // 11.05.06 V.Ivanchneko add warning flag to FindMaterial method
00043 // 26.07.07 V.Ivanchneko modify destructor to provide complete destruction
00044 //                       of all elements and materials
00045 // 27-07-07, improve destructor (V.Ivanchenko) 
00046 // 28.07.07 V.Ivanchneko make simple methods inline
00047 // 28.07.07 V.Ivanchneko simplify Print methods
00048 // 26.10.11, new scheme for G4Exception  (mma) 
00049 //
00050 // -------------------------------------------------------------------
00051 //
00052 // Class Description:
00053 //
00054 // Element data from the NIST DB on Atomic Weights and Isotope Compositions
00055 // http://physics.nist.gov/PhysRefData/Compositions/index.html
00056 //
00057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00059 
00060 #include "G4NistManager.hh"
00061 #include "G4NistMessenger.hh"
00062 #include "G4Isotope.hh"
00063 
00064 G4NistManager* G4NistManager::instance = 0;
00065 
00066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
00067 
00068 G4NistManager* G4NistManager::Instance()
00069 {
00070   if (instance == 0) {
00071     static G4NistManager manager;
00072     instance = &manager;
00073   }
00074   return instance;
00075 }
00076 
00077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00078 
00079 G4NistManager::G4NistManager()
00080 {
00081   nElements  = 0;
00082   nMaterials = 0;
00083   verbose    = 0;
00084 
00085   elmBuilder = new G4NistElementBuilder(verbose);
00086   matBuilder = new G4NistMaterialBuilder(elmBuilder,verbose);
00087   
00088   messenger  = new G4NistMessenger(this);  
00089   g4pow = G4Pow::GetInstance();
00090 
00091   // compute frequently used values for mean atomic numbers
00092   for(G4int j=1; j<101; ++j) {
00093     G4double A = elmBuilder->GetAtomicMassAmu(j);
00094     POWERA27[j] = std::pow(A,0.27);
00095     LOGAZ[j]    = std::log(A);
00096   }
00097   POWERA27[0] = 1.0;
00098   LOGAZ[0]    = 0.0;
00099 }
00100 
00101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00102 
00103 G4NistManager::~G4NistManager()
00104 {
00105   //  G4cout << "NistManager: start material destruction" << G4endl;
00106   const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
00107   size_t nmat = theMaterialTable->size();
00108   size_t i;
00109   for(i=0; i<nmat; i++) {
00110     if((*theMaterialTable)[i]) { delete (*theMaterialTable)[i]; }
00111   }
00112   //  G4cout << "NistManager: start element destruction" << G4endl;
00113   const G4ElementTable* theElementTable = G4Element::GetElementTable();
00114   size_t nelm = theElementTable->size();
00115   for(i=0; i<nelm; i++) {
00116     if((*theElementTable)[i]) { delete (*theElementTable)[i]; }
00117   }
00118   //  G4cout << "NistManager: start isotope destruction" << G4endl;
00119   const G4IsotopeTable* theIsotopeTable = G4Isotope::GetIsotopeTable();
00120   size_t niso = theIsotopeTable->size();
00121   for(i=0; i<niso; i++) {
00122     if((*theIsotopeTable)[i]) { delete (*theIsotopeTable)[i]; }
00123   }
00124   //  G4cout << "NistManager: end isotope destruction" << G4endl;
00125   delete messenger;
00126   delete matBuilder;
00127   delete elmBuilder;  
00128   // G4cout << "NistManager: end destruction" << G4endl;
00129 }
00130 
00131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00132 
00133 G4Material* 
00134 G4NistManager::BuildMaterialWithNewDensity(const G4String& name,
00135                                            const G4String& basename, 
00136                                            G4double density,
00137                                            G4double temperature,
00138                                            G4double pressure)
00139 {
00140   G4Material* bmat = FindOrBuildMaterial(name);
00141   if(bmat) {
00142     G4cout << "G4NistManager::BuildMaterialWithNewDensity ERROR: " << G4endl;
00143     G4cout << " New material <" << name << "> cannot be built because material"
00144            << " with the same name already exist" << G4endl;
00145     G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat101",
00146                  FatalException, "Wrong material name");
00147     return 0;
00148   }
00149   bmat = FindOrBuildMaterial(basename);
00150   if(!bmat) {
00151     G4cout << "G4NistManager::BuildMaterialWithNewDensity ERROR: " << G4endl;
00152     G4cout << " New material <" << name << "> cannot be built because " << G4endl;
00153     G4cout << " base material <" << basename << "> does not exist" << G4endl;
00154     G4Exception("G4NistManager::BuildMaterialWithNewDensity()", "mat102",
00155                  FatalException, "Wrong material name");    
00156     return 0;
00157   }
00158   G4double dens = density;
00159   G4double temp = temperature;
00160   G4double pres = pressure;
00161   if(dens == 0.0) { 
00162     dens = bmat->GetDensity();
00163     temp = bmat->GetTemperature();
00164     pres = bmat->GetPressure(); 
00165   }
00166   G4Material* mat = new G4Material(name, dens, bmat, bmat->GetState(),
00167                                    temp, pres);
00168   return mat;
00169 }
00170   
00171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00172 
00173 void G4NistManager::PrintElement(const G4String& symbol)
00174 {
00175   if (symbol == "all") { elmBuilder->PrintElement(0); }
00176   else                 { elmBuilder->PrintElement(elmBuilder->GetZ(symbol)); }
00177 }
00178 
00179 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00180 
00181 void G4NistManager::PrintG4Element(const G4String& name)
00182 {
00183   const G4ElementTable* theElementTable = G4Element::GetElementTable();
00184   size_t nelm = theElementTable->size();
00185   for(size_t i=0; i<nelm; i++) {
00186     G4Element* elm = (*theElementTable)[i];
00187     if ( name == elm->GetName() || "all" == name) {
00188       G4cout << *elm << G4endl;
00189       return;
00190     }
00191   }
00192 }
00193 
00194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00195 
00196 void G4NistManager::PrintG4Material(const G4String& name)
00197 {
00198   const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
00199   size_t nmat = theMaterialTable->size();
00200   for(size_t i=0; i<nmat; i++) {
00201     G4Material* mat = (*theMaterialTable)[i];
00202     if ( name == mat->GetName() || "all" == name) {
00203       G4cout << *mat << G4endl;
00204       return;
00205     }
00206   }
00207 }
00208 
00209 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00210 
00211 void G4NistManager::SetVerbose(G4int val)
00212 {
00213   verbose = val;
00214   elmBuilder->SetVerbose(val);
00215   matBuilder->SetVerbose(val);
00216 }
00217 
00218 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

Generated on Mon May 27 17:49:05 2013 for Geant4 by  doxygen 1.4.7