Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 /// \file materials/src/G4LatticeManager.cc 27 /// \brief Implementation of the G4LatticeMana 28 // 29 // 30 // 20131113 Delete lattices in (new) registry 31 // 20141008 Change to global singleton; must 32 33 #include "G4LatticeManager.hh" 34 #include "G4AutoLock.hh" 35 #include "G4LatticeLogical.hh" 36 #include "G4LatticePhysical.hh" 37 #include "G4LatticeReader.hh" 38 #include "G4LogicalVolume.hh" 39 #include "G4Material.hh" 40 #include "G4VPhysicalVolume.hh" 41 #include "G4SystemOfUnits.hh" 42 #include "G4Threading.hh" 43 #include <fstream> 44 45 G4LatticeManager* G4LatticeManager::fLM = 0; 46 47 namespace { 48 G4Mutex latMutex = G4MUTEX_INITIALIZER; // F 49 } 50 51 //....oooOO0OOooo........oooOO0OOooo........oo 52 53 G4LatticeManager::G4LatticeManager() : verbose 54 Clear(); 55 } 56 57 G4LatticeManager::~G4LatticeManager() { 58 Reset(); // Deletes all lattices 59 } 60 61 // Delete all registered lattices and clear en 62 63 void G4LatticeManager::Reset() { 64 for (LatticeLogReg::iterator lm=fLLattices.b 65 lm != fLLattices.end(); ++lm) { 66 delete (*lm); 67 } 68 69 for (LatticePhyReg::iterator pm=fPLattices.b 70 pm != fPLattices.end(); ++pm) { 71 delete (*pm); 72 } 73 74 Clear(); 75 } 76 77 // Remove entries without deletion (for begin- 78 79 void G4LatticeManager::Clear() { 80 fPLatticeList.clear(); 81 fPLattices.clear(); 82 83 fLLatticeList.clear(); 84 fLLattices.clear(); 85 } 86 87 //....oooOO0OOooo........oooOO0OOooo........oo 88 89 G4LatticeManager* G4LatticeManager::GetLattice 90 // if no lattice manager exists, create one. 91 G4AutoLock latLock(&latMutex); // Protect b 92 if (!fLM) fLM = new G4LatticeManager(); 93 latLock.unlock(); 94 95 return fLM; 96 } 97 98 //....oooOO0OOooo........oooOO0OOooo........oo 99 100 // Associate logical lattice with material 101 102 G4bool G4LatticeManager::RegisterLattice(G4Mat 103 G4LatticeLogical* Lat) { 104 if (!Mat || !Lat) return false; // Don't reg 105 106 G4AutoLock latLock(&latMutex); // Protect b 107 fLLattices.insert(Lat); // Take ownership 108 fLLatticeList[Mat] = Lat; 109 latLock.unlock(); 110 111 if (verboseLevel) { 112 G4cout << "G4LatticeManager::RegisterLatti 113 << " Total number of logical lattices: " 114 << " (" << fLLattices.size() << " unique) 115 } 116 117 return true; 118 } 119 120 // Construct logical lattice for material from 121 122 G4LatticeLogical* G4LatticeManager::LoadLattic 123 const G4String& latDir) { 124 if (verboseLevel) { 125 G4cout << "G4LatticeManager::LoadLattice m 126 << " " << latDir << G4endl; 127 } 128 129 G4LatticeReader latReader(verboseLevel); 130 G4LatticeLogical* newLat = latReader.MakeLat 131 if (verboseLevel>1) G4cout << " Created newL 132 133 if (newLat) RegisterLattice(Mat, newLat); 134 else { 135 G4cerr << "ERROR creating " << latDir << " 136 << Mat->GetName() << G4endl; 137 } 138 139 return newLat; 140 } 141 142 // Combine loading and registration (Material 143 144 G4LatticePhysical* G4LatticeManager::LoadLatti 145 const G4String& latDir) { 146 if (verboseLevel) { 147 G4cout << "G4LatticeManager::LoadLattice v 148 << " " << latDir << G4endl; 149 } 150 151 G4Material* theMat = Vol->GetLogicalVolume() 152 153 // Create and register the logical lattice, 154 G4LatticeLogical* lLattice = LoadLattice(the 155 if (!lLattice) return 0; 156 157 G4LatticePhysical* pLattice = 158 new G4LatticePhysical(lLattice, Vol->GetFr 159 if (pLattice) RegisterLattice(Vol, pLattice) 160 161 if (verboseLevel>1) G4cout << " Created pLat 162 163 return pLattice; 164 } 165 166 167 //....oooOO0OOooo........oooOO0OOooo........oo 168 169 // Associate physical (oriented) lattice with 170 171 G4bool G4LatticeManager::RegisterLattice(G4VPh 172 G4LatticePhysical* Lat) { 173 if (!Vol || !Lat) return false; // Don't reg 174 175 G4AutoLock latLock(&latMutex); // Protect b 176 177 // SPECIAL: Register first lattice with a nu 178 if (fPLatticeList.empty()) fPLatticeList[0] 179 180 fPLattices.insert(Lat); 181 fPLatticeList[Vol] = Lat; 182 183 latLock.unlock(); 184 185 if (verboseLevel) { 186 G4cout << "G4LatticeManager::RegisterLatti 187 << " Total number of physical lattices: " 188 << " (" << fPLattices.size() << " unique) 189 } 190 191 return true; 192 } 193 194 G4bool G4LatticeManager::RegisterLattice(G4VPh 195 G4LatticeLogical* LLat) { 196 if (!Vol || !LLat) return false; // Don't r 197 198 // Make sure logical lattice is registered f 199 RegisterLattice(Vol->GetLogicalVolume()->Get 200 201 // Create and register new physical lattice 202 return RegisterLattice(Vol, new G4LatticePhy 203 } 204 205 //....oooOO0OOooo........oooOO0OOooo........oo 206 207 // Returns a pointer to the LatticeLogical ass 208 209 G4LatticeLogical* G4LatticeManager::GetLattice 210 LatticeMatMap::const_iterator latFind = fLLa 211 if (latFind != fLLatticeList.end()) { 212 if (verboseLevel) 213 G4cout << "G4LatticeManager::GetLattice 214 << " for "<< (Mat ? Mat->GetName( 215 << G4endl; 216 return latFind->second; 217 } 218 219 if (verboseLevel) 220 G4cerr << "G4LatticeManager:: Found no mat 221 << (Mat ? Mat->GetName() : G4String 222 223 return nullptr; // No lattice associated 224 } 225 226 // Returns a pointer to the LatticePhysical as 227 // NOTE: Passing Vol==0 will return the defau 228 229 G4LatticePhysical* G4LatticeManager::GetLattic 230 LatticeVolMap::const_iterator latFind = fPLa 231 if (latFind != fPLatticeList.end()) { 232 if (verboseLevel) 233 G4cout << "G4LatticeManager::GetLattice 234 << " for " << (Vol ? Vol->GetName 235 << G4endl; 236 return latFind->second; 237 } 238 239 if (verboseLevel) 240 G4cerr << "G4LatticeManager::GetLattice fo 241 << (Vol ? Vol->GetName() : G4String 242 243 return nullptr; // No lattice associated 244 } 245 246 //....oooOO0OOooo........oooOO0OOooo........oo 247 248 // Return true if volume Vol has a physical la 249 250 G4bool G4LatticeManager::HasLattice(G4VPhysica 251 return (fPLatticeList.find(Vol) != fPLattice 252 } 253 254 // Return true if material Mat has a logical l 255 256 G4bool G4LatticeManager::HasLattice(G4Material 257 return (fLLatticeList.find(Mat) != fLLattice 258 } 259 260 //....oooOO0OOooo........oooOO0OOooo........oo 261 262 //Given the phonon wave vector k, phonon physi 263 //and polarizationState(0=LON, 1=FT, 2=ST), 264 //returns phonon velocity in m/s 265 266 G4double G4LatticeManager::MapKtoV(G4VPhysical 267 G4int polarizationState, 268 const G4ThreeVector & k) const { 269 G4LatticePhysical* theLattice = GetLattice(V 270 if (verboseLevel) 271 G4cout << "G4LatticeManager::MapKtoV using 272 << G4endl; 273 274 // If no lattice available, use generic "spe 275 return theLattice ? theLattice->MapKtoV(pola 276 } 277 278 //....oooOO0OOooo........oooOO0OOooo........oo 279 280 // Given the phonon wave vector k, phonon phys 281 // and polarizationState(0=LON, 1=FT, 2=ST), 282 // returns phonon propagation direction as dim 283 284 G4ThreeVector G4LatticeManager::MapKtoVDir(G4V 285 G4int polarizationState, 286 const G4ThreeVector & k) const { 287 G4LatticePhysical* theLattice = GetLattice(V 288 if (verboseLevel) 289 G4cout << "G4LatticeManager::MapKtoVDir us 290 << G4endl; 291 292 // If no lattice available, propagate along 293 return theLattice ? theLattice->MapKtoVDir(p 294 } 295