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.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/solidstate/phonon/src/G4LatticeReader.cc (Version 11.3.0) and /processes/solidstate/phonon/src/G4LatticeReader.cc (Version 10.2)


  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 processes/phonon/include/G4LatticeRe    
 27 /// \brief Implementation of the G4LatticeRead    
 28 //                                                
 29 // NOTE:  This reader class for logical lattic    
 30 //    materials/ after the 10.0 release (and t    
 31 //                                                
 32 // 20131106  M.Kelsey -- Add const to getenv()    
 33 // 20131112  Throw exception if input file fai    
 34 // 20131115  Check file input arguments for ma    
 35 //    move ctor, dtor here; check stream point    
 36                                                   
 37 #include "G4LatticeReader.hh"                     
 38 #include "G4ExceptionSeverity.hh"                 
 39 #include "G4LatticeLogical.hh"                    
 40 #include "G4SystemOfUnits.hh"                     
 41 #include <fstream>                                
 42 #include <limits>                                 
 43 #include <stdlib.h>                               
 44                                                   
 45                                                   
 46 // Default path to lattice files, for use with    
 47                                                   
 48 const G4String G4LatticeReader::fDataDir =        
 49   G4FindDataDir("G4LATTICEDATA") ? (const char    
 50                                                   
 51                                                   
 52 // Constructor and destructor                     
 53                                                   
 54 G4LatticeReader::G4LatticeReader(G4int vb)        
 55   : verboseLevel(vb), psLatfile(0), pLattice(0    
 56     fToken(""), fValue(0.), fMap(""), fsPol(""    
 57                                                   
 58 G4LatticeReader::~G4LatticeReader() {             
 59   delete psLatfile; psLatfile = 0;                
 60 }                                                 
 61                                                   
 62                                                   
 63 // Main drivers to read configuration from fil    
 64                                                   
 65 G4LatticeLogical* G4LatticeReader::MakeLattice    
 66   if (verboseLevel) G4cout << "G4LatticeReader    
 67                                                   
 68   if (!OpenFile(filename)) {                      
 69     G4ExceptionDescription msg;                   
 70     msg << "Unable to open " << filename;         
 71     G4Exception("G4LatticeReader::MakeLattice"    
 72     FatalException, msg);                         
 73     return 0;                                     
 74   }                                               
 75                                                   
 76   pLattice = new G4LatticeLogical;  // Create     
 77                                                   
 78   G4bool goodLattice = true;                      
 79   while (!psLatfile->eof()) {                     
 80     goodLattice &= ProcessToken();                
 81   }                                               
 82   CloseFile();                                    
 83                                                   
 84   if (!goodLattice) {                             
 85     G4ExceptionDescription msg;                   
 86     msg << "Error reading lattice from " << fi    
 87     G4Exception("G4LatticeReader::MakeLattice"    
 88     FatalException, msg);                         
 89     delete pLattice;                              
 90     pLattice = 0;                                 
 91   }                                               
 92                                                   
 93   return pLattice;  // Lattice complete; retur    
 94 }                                                 
 95                                                   
 96                                                   
 97 // Open local file or file found under data pa    
 98                                                   
 99 G4bool G4LatticeReader::OpenFile(const G4Strin    
100   if (verboseLevel)                               
101     G4cout << "G4LatticeReader::OpenFile " <<     
102                                                   
103   G4String filepath = filename;                   
104   psLatfile = new std::ifstream(filepath);        
105   if (!psLatfile->good()) {     // Local file     
106     filepath = fDataDir + "/" + filename;         
107     psLatfile->open(filepath);      // Try dat    
108     if (!psLatfile->good()) {                     
109       CloseFile();                                
110       return false;                               
111     }                                             
112     if (verboseLevel>1) G4cout << " Found file    
113   }                                               
114                                                   
115   // Extract path from filename to use in find    
116   size_t lastdir = filepath.rfind('/');           
117   if (lastdir == std::string::npos) fMapPath =    
118   else fMapPath = filepath.substr(0,lastdir);     
119                                                   
120   return true;                                    
121 }                                                 
122                                                   
123 // Close and delete input stream                  
124                                                   
125 void G4LatticeReader::CloseFile() {               
126   if (psLatfile) psLatfile->close();              
127   delete psLatfile;                               
128   psLatfile = 0;                                  
129 }                                                 
130                                                   
131                                                   
132 // Read next token from file, use it to store     
133                                                   
134 G4bool G4LatticeReader::ProcessToken() {          
135   fToken = "";                                    
136   *psLatfile >> fToken;                           
137   if (fToken.empty() || psLatfile->eof()) retu    
138                                                   
139   if (verboseLevel>1) G4cout << " ProcessToken    
140                                                   
141   G4StrUtil::to_lower(fToken);                    
142   if (G4StrUtil::contains(fToken, '#')) return    
143   if (fToken == "vdir")     return ProcessNMap    
144   if (fToken == "vg")       return ProcessMap(    
145   if (fToken == "dyn")      return ProcessCons    
146   return ProcessValue(fToken);        // Singl    
147 }                                                 
148                                                   
149 // Eat remainder of line, assuming a '#' token    
150                                                   
151 G4bool G4LatticeReader::SkipComments() {          
152   psLatfile->ignore(std::numeric_limits<std::s    
153   return true;    // Never fails                  
154 }                                                 
155                                                   
156 // Read double value from file, store based on    
157                                                   
158 G4bool G4LatticeReader::ProcessValue(const G4S    
159   *psLatfile >> fValue;                           
160   if (verboseLevel>1) G4cout << " ProcessValue    
161                                                   
162   G4bool good = true;                             
163   /***** NOTE: Individual Set functions not in    
164        if (name == "beta")   pLattice->SetBeta    
165   else if (name == "gamma")  pLattice->SetGamm    
166   else if (name == "lambda") pLattice->SetLamb    
167   else if (name == "mu")     pLattice->SetMu(f    
168   else *****/                                     
169        if (name == "scat")   pLattice->SetScat    
170   else if (name == "b")      pLattice->SetScat    
171   else if (name == "decay")  pLattice->SetAnhD    
172   else if (name == "a")      pLattice->SetAnhD    
173   else if (name == "ldos")   pLattice->SetLDOS    
174   else if (name == "stdos")  pLattice->SetSTDO    
175   else if (name == "ftdos")  pLattice->SetFTDO    
176   else {                                          
177     G4cerr << "G4LatticeReader: Unrecognized t    
178     good = false;                                 
179   }                                               
180                                                   
181   return good;                                    
182 }                                                 
183                                                   
184 G4bool G4LatticeReader::ProcessConstants() {      
185   G4double beta=0., gamma=0., lambda=0., mu=0.    
186   *psLatfile >> beta >> gamma >> lambda >> mu;    
187   if (verboseLevel>1)                             
188     G4cout << " ProcessConstants " << beta <<     
189      << " " << lambda << " " << mu << G4endl;     
190                                                   
191   pLattice->SetDynamicalConstants(beta, gamma,    
192   return psLatfile->good();                       
193 }                                                 
194                                                   
195 // Read map filename, polarization, and binnin    
196                                                   
197 G4bool G4LatticeReader::ReadMapInfo() {           
198   *psLatfile >> fMap >> fsPol >> fNX >> fNY;      
199   if (verboseLevel>1)                             
200     G4cout << " ReadMapInfo " << fMap << " " <    
201      << " " << fNX << " " << fNY << G4endl;       
202                                                   
203   if (fNX < 0 || fNX >= G4LatticeLogical::MAXR    
204     G4cerr << "G4LatticeReader: Invalid map th    
205     return false;                                 
206   }                                               
207                                                   
208   if (fNY < 0 || fNY >= G4LatticeLogical::MAXR    
209     G4cerr << "G4LatticeReader: Invalid map ph    
210     return false;                                 
211   }                                               
212                                                   
213   // Prepend path to data files to map filenam    
214   fMap = fMapPath + "/" + fMap;                   
215                                                   
216   // Convert string code (L,ST,LT) to polariza    
217   G4StrUtil::to_lower(fsPol);                     
218   fPol = ( (fsPol=="l")  ? 0 :    // Longitudi    
219      (fsPol=="st") ? 1 :    // Slow-transverse    
220      (fsPol=="ft") ? 2 :    // Fast-transverse    
221      -1 );      // Invalid code                   
222                                                   
223   if (fPol<0 || fPol>2) {                         
224     G4cerr << "G4LatticeReader: Invalid polari    
225     return false;                                 
226   }                                               
227                                                   
228   return true;                                    
229 }                                                 
230                                                   
231 G4bool G4LatticeReader::ProcessMap() {            
232   if (!ReadMapInfo()) {   // Get specific para    
233     G4cerr << "G4LatticeReader: Unable to proc    
234     return false;                                 
235   }                                               
236                                                   
237   return pLattice->LoadMap(fNX, fNY, fPol, fMa    
238 }                                                 
239                                                   
240 G4bool G4LatticeReader::ProcessNMap() {           
241   if (!ReadMapInfo()) {   // Get specific para    
242     G4cerr << "G4LatticeReader: Unable to proc    
243     return false;                                 
244   }                                               
245                                                   
246   return pLattice->Load_NMap(fNX, fNY, fPol, f    
247 }                                                 
248