Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4LatticeManager.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 /// \file materials/src/G4LatticeManager.cc
27 /// \brief Implementation of the G4LatticeManager class
28 //
29 // $Id: G4LatticeManager.cc 76693 2013-11-14 08:47:37Z gcosmo $
30 //
31 // 20131113 Delete lattices in (new) registry, not in lookup maps
32 
33 #include "G4LatticeManager.hh"
34 #include "G4LatticeLogical.hh"
35 #include "G4LatticePhysical.hh"
36 #include "G4LatticeReader.hh"
37 #include "G4LogicalVolume.hh"
38 #include "G4Material.hh"
39 #include "G4VPhysicalVolume.hh"
40 #include "G4SystemOfUnits.hh"
41 #include <fstream>
42 
43 G4ThreadLocal G4LatticeManager* G4LatticeManager::fLM = 0;
44 
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
47 
48 G4LatticeManager::G4LatticeManager() : verboseLevel(0) {
49  Clear();
50 }
51 
52 G4LatticeManager::~G4LatticeManager() {
53  Reset(); // Deletes all lattices
54 }
55 
56 // Delete all registered lattices and clear entries from lookup tables
57 
59  for (LatticeLogReg::iterator lm=fLLattices.begin();
60  lm != fLLattices.end(); ++lm) {
61  delete (*lm);
62  }
63 
64  for (LatticePhyReg::iterator pm=fPLattices.begin();
65  pm != fPLattices.end(); ++pm) {
66  delete (*pm);
67  }
68 
69  Clear();
70 }
71 
72 // Remove entries without deletion (for begin-job and end-job initializing)
73 
75  fPLatticeList.clear();
76  fPLattices.clear();
77 
78  fLLatticeList.clear();
79  fLLattices.clear();
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
83 
85  //if no lattice manager exists, create one.
86  if (!fLM) fLM = new G4LatticeManager();
87  return fLM;
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
91 
92 // Associate logical lattice with material
93 
95  G4LatticeLogical* Lat) {
96  if (!Mat || !Lat) return false; // Don't register null pointers
97 
98  fLLattices.insert(Lat); // Take ownership in registry
99  fLLatticeList[Mat] = Lat;
100 
101  if (verboseLevel) {
102  G4cout << "G4LatticeManager::RegisterLattice: "
103  << " Total number of logical lattices: " << fLLatticeList.size()
104  << " (" << fLLattices.size() << " unique)" << G4endl;
105  }
106 
107  return true;
108 }
109 
110 // Construct logical lattice for material from config file
111 
113  const G4String& latDir) {
114  if (verboseLevel) {
115  G4cout << "G4LatticeManager::LoadLattice material " << Mat->GetName()
116  << " " << latDir << G4endl;
117  }
118 
119  G4LatticeReader latReader(verboseLevel);
120  G4LatticeLogical* newLat = latReader.MakeLattice(latDir+"/config.txt");
121  if (verboseLevel>1) G4cout << " Created newLat " << newLat << G4endl;
122 
123  if (newLat) RegisterLattice(Mat, newLat);
124  else {
125  G4cerr << "ERROR creating " << latDir << " lattice for material "
126  << Mat->GetName() << G4endl;
127  }
128 
129  return newLat;
130 }
131 
132 // Combine loading and registration (Material extracted from volume)
133 
135  const G4String& latDir) {
136  if (verboseLevel) {
137  G4cout << "G4LatticeManager::LoadLattice volume " << Vol->GetName()
138  << " " << latDir << G4endl;
139  }
140 
141  G4Material* theMat = Vol->GetLogicalVolume()->GetMaterial();
142 
143  // Create and register the logical lattice, then the physical lattice
144  G4LatticeLogical* lLattice = LoadLattice(theMat, latDir);
145  if (!lLattice) return 0;
146 
147  G4LatticePhysical* pLattice =
148  new G4LatticePhysical(lLattice, Vol->GetFrameRotation());
149  if (pLattice) RegisterLattice(Vol, pLattice);
150 
151  if (verboseLevel>1) G4cout << " Created pLattice " << pLattice << G4endl;
152 
153  return pLattice;
154 }
155 
156 
157 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
158 
159 // Associate physical (oriented) lattice with physical volume
160 
162  G4LatticePhysical* Lat) {
163  if (!Vol || !Lat) return false; // Don't register null pointers
164 
165  // SPECIAL: Register first lattice with a null volume to act as default
166  if (fPLatticeList.empty()) fPLatticeList[0] = Lat;
167 
168  fPLattices.insert(Lat);
169  fPLatticeList[Vol] = Lat;
170 
171  if (verboseLevel) {
172  G4cout << "G4LatticeManager::RegisterLattice: "
173  << " Total number of physical lattices: " << fPLatticeList.size()-1
174  << " (" << fPLattices.size() << " unique)" << G4endl;
175  }
176 
177  return true;
178 }
179 
181  G4LatticeLogical* LLat) {
182  if (!Vol || !LLat) return false; // Don't register null pointers
183 
184  // Make sure logical lattice is registered for material
186 
187  // Create and register new physical lattice to go with volume
188  return RegisterLattice(Vol, new G4LatticePhysical(LLat, Vol->GetFrameRotation()));
189 }
190 
191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
192 
193 // Returns a pointer to the LatticeLogical associated with material
194 
196  LatticeMatMap::const_iterator latFind = fLLatticeList.find(Mat);
197  if (latFind != fLLatticeList.end()) {
198  if (verboseLevel)
199  G4cout << "G4LatticeManager::GetLattice found " << latFind->second
200  << " for " << (Mat?Mat->GetName():"NULL") << "." << G4endl;
201  return latFind->second;
202  }
203 
204 
205  if (verboseLevel)
206  G4cerr << "G4LatticeManager:: Found no matching lattices for "
207  << (Mat?Mat->GetName():"NULL") << "." << G4endl;
208 
209  return 0; // No lattice associated with volume
210 }
211 
212 // Returns a pointer to the LatticePhysical associated with volume
213 // NOTE: Passing Vol==0 will return the default lattice
214 
216  LatticeVolMap::const_iterator latFind = fPLatticeList.find(Vol);
217  if (latFind != fPLatticeList.end()) {
218  if (verboseLevel)
219  G4cout << "G4LatticeManager::GetLattice found " << latFind->second
220  << " for " << (Vol?Vol->GetName():"default") << "." << G4endl;
221  return latFind->second;
222  }
223 
224  if (verboseLevel)
225  G4cerr << "G4LatticeManager::GetLattice found no matching lattices for "
226  << (Vol?Vol->GetName():"default") << "." << G4endl;
227 
228  return 0; // No lattice associated with volume
229 }
230 
231 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
232 
233 // Return true if volume Vol has a physical lattice
234 
236  return (fPLatticeList.find(Vol) != fPLatticeList.end());
237 }
238 
239 // Return true if material Mat has a logical lattice
240 
242  return (fLLatticeList.find(Mat) != fLLatticeList.end());
243 }
244 
245 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
246 
247 //Given the phonon wave vector k, phonon physical volume Vol
248 //and polarizationState(0=LON, 1=FT, 2=ST),
249 //returns phonon velocity in m/s
250 
252  G4int polarizationState,
253  const G4ThreeVector & k) const {
254  G4LatticePhysical* theLattice = GetLattice(Vol);
255  if (verboseLevel)
256  G4cout << "G4LatticeManager::MapKtoV using lattice " << theLattice
257  << G4endl;
258 
259  // If no lattice available, use generic "speed of sound"
260  return theLattice ? theLattice->MapKtoV(polarizationState, k) : 300.*m/s;
261 }
262 
263 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
264 
265 // Given the phonon wave vector k, phonon physical volume Vol
266 // and polarizationState(0=LON, 1=FT, 2=ST),
267 // returns phonon propagation direction as dimensionless unit vector
268 
270  G4int polarizationState,
271  const G4ThreeVector & k) const {
272  G4LatticePhysical* theLattice = GetLattice(Vol);
273  if (verboseLevel)
274  G4cout << "G4LatticeManager::MapKtoVDir using lattice " << theLattice
275  << G4endl;
276 
277  // If no lattice available, propagate along input wavevector
278  return theLattice ? theLattice->MapKtoVDir(polarizationState, k) : k.unit();
279 }
static G4LatticeManager * GetLatticeManager()
G4ThreeVector MapKtoVDir(G4VPhysicalVolume *, G4int, const G4ThreeVector &) const
const XML_Char * s
G4Material * GetMaterial() const
const G4String & GetName() const
Definition: G4Material.hh:176
void Clear(Node *)
G4double MapKtoV(G4int, G4ThreeVector) const
G4double MapKtoV(G4VPhysicalVolume *, G4int, const G4ThreeVector &) const
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
const G4RotationMatrix * GetFrameRotation() const
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
bool G4bool
Definition: G4Types.hh:79
G4LatticeLogical * LoadLattice(G4Material *, const G4String &latDir)
G4ThreeVector MapKtoVDir(G4int, G4ThreeVector) const
LatticeVolMap fPLatticeList
G4LogicalVolume * GetLogicalVolume() const
Hep3Vector unit() const
Definition of the G4LatticePhysical class.
Definition of the G4LatticeLogical class.
#define G4endl
Definition: G4ios.hh:61
Definition of the G4LatticeReader class.
G4bool HasLattice(G4Material *) const
G4LatticeLogical * MakeLattice(const G4String &filepath)
double G4double
Definition: G4Types.hh:76
G4bool RegisterLattice(G4VPhysicalVolume *, G4LatticePhysical *)
LatticePhyReg fPLattices
LatticeMatMap fLLatticeList
G4LatticeLogical * GetLattice(G4Material *) const
G4GLOB_DLL std::ostream G4cerr
LatticeLogReg fLLattices