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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.7)


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