Geant4  10.02.p02
G4MaterialPropertiesTable.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 //
27 // $Id: G4MaterialPropertiesTable.cc 80573 2014-04-29 07:40:08Z gcosmo $
28 //
29 //
31 // G4MaterialPropertiesTable Implementation
33 //
34 // File: G4MaterialPropertiesTable.cc
35 // Version: 1.0
36 // Created: 1996-02-08
37 // Author: Juliet Armstrong
38 // Updated: 2005-05-12 add SetGROUPVEL(), courtesy of
39 // Horton-Smith (bug report #741), by P. Gumplinger
40 // 2002-11-05 add named material constants by P. Gumplinger
41 // 1999-11-05 Migration from G4RWTPtrHashDictionary to STL
42 // by John Allison
43 // 1997-03-26 by Peter Gumplinger
44 // > cosmetics (only)
45 // mail: gum@triumf.ca
46 //
48 
49 #include "globals.hh"
51 #include "G4PhysicalConstants.hh"
52 
54 // Constructors
56 
58 {
59 }
60 
62 // Destructor
64 
66 {
67  MPTiterator i;
68  for (i = MPT.begin(); i != MPT.end(); ++i)
69  {
70  delete (*i).second;
71  }
72  MPT.clear();
73  MPTC.clear();
74 }
75 
77 // Methods
79 
81 {
82  MPTiterator i;
83  for (i = MPT.begin(); i != MPT.end(); ++i)
84  {
85  G4cout << (*i).first << G4endl;
86  if ( (*i).second != 0 )
87  {
88  (*i).second->DumpValues();
89  }
90  else
91  {
92  G4Exception("G4MaterialPropertiesTable::DumpTable()", "mat204",
93  JustWarning, "NULL Material Property Vector Pointer.");
94  }
95  }
96  MPTCiterator j;
97  for (j = MPTC.begin(); j != MPTC.end(); ++j)
98  {
99  G4cout << j->first << G4endl;
100  if ( j->second != 0 )
101  {
102  G4cout << j->second << G4endl;
103  }
104  else
105  {
106  G4Exception("G4MaterialPropertiesTable::DumpTable()", "mat202",
107  JustWarning, "No Material Constant Property.");
108  }
109  }
110 }
111 
112 #ifdef G4MULTITHREADED
113 #include "G4AutoLock.hh"
114 namespace {
115  G4Mutex materialPropertyTableMutex = G4MUTEX_INITIALIZER;
116 }
117 #endif
118 
120 {
121 #ifdef G4MULTITHREADED
122  G4AutoLock mptm(&materialPropertyTableMutex);
123 #endif
124 
125  // check if "GROUPVEL" already exists
126  MPTiterator itr;
127  itr = MPT.find("GROUPVEL");
128  if(itr != MPT.end()) return itr->second;
129 
130  // fetch RINDEX data, give up if unavailable
131  //
132  G4MaterialPropertyVector *rindex = this->GetProperty("RINDEX");
133  if (rindex==0) { return 0; }
134 
135  // RINDEX exists but has no entries, give up
136  //
137  if ( rindex->GetVectorLength() == 0 ) { return 0; }
138 
139  // add GROUPVEL vector
140  //
142 
143  // fill GROUPVEL vector using RINDEX values
144  // rindex built-in "iterator" was advanced to first entry above
145  //
146  G4double E0 = rindex->Energy(0);
147  G4double n0 = (*rindex)[0];
148 
149  if (E0 <= 0.)
150  {
151  G4Exception("G4MaterialPropertiesTable::SetGROUPVEL()", "mat205",
152  FatalException, "Optical Photon Energy <= 0");
153  }
154 
155  if ( rindex->GetVectorLength() >= 2 )
156  {
157  // good, we have at least two entries in RINDEX
158  // get next energy/value pair
159 
160  G4double E1 = rindex->Energy(1);
161  G4double n1 = (*rindex)[1];
162 
163  if (E1 <= 0.)
164  {
165  G4Exception("G4MaterialPropertiesTable::SetGROUPVEL()", "mat205",
166  FatalException, "Optical Photon Energy <= 0");
167  }
168 
169  G4double vg;
170 
171  // add entry at first photon energy
172  //
173  vg = c_light/(n0+(n1-n0)/std::log(E1/E0));
174 
175  // allow only for 'normal dispersion' -> dn/d(logE) > 0
176  //
177  if((vg<0) || (vg>c_light/n0)) { vg = c_light/n0; }
178 
179  groupvel->InsertValues( E0, vg );
180 
181  // add entries at midpoints between remaining photon energies
182  //
183 
184  for (size_t i = 2; i < rindex->GetVectorLength(); i++)
185  {
186  vg = c_light/( 0.5*(n0+n1)+(n1-n0)/std::log(E1/E0));
187 
188  // allow only for 'normal dispersion' -> dn/d(logE) > 0
189  //
190  if((vg<0) || (vg>c_light/(0.5*(n0+n1)))) { vg = c_light/(0.5*(n0+n1)); }
191  groupvel->InsertValues( 0.5*(E0+E1), vg );
192 
193  // get next energy/value pair, or exit loop
194  //
195  E0 = E1;
196  n0 = n1;
197  E1 = rindex->Energy(i);
198  n1 = (*rindex)[i];
199 
200  if (E1 <= 0.)
201  {
202  G4Exception("G4MaterialPropertiesTable::SetGROUPVEL()", "mat205",
203  FatalException, "Optical Photon Energy <= 0");
204  }
205  }
206 
207  // add entry at last photon energy
208  //
209  vg = c_light/(n1+(n1-n0)/std::log(E1/E0));
210 
211  // allow only for 'normal dispersion' -> dn/d(logE) > 0
212  //
213  if((vg<0) || (vg>c_light/n1)) { vg = c_light/n1; }
214  groupvel->InsertValues( E1, vg );
215  }
216  else // only one entry in RINDEX -- weird!
217  {
218  groupvel->InsertValues( E0, c_light/n0 );
219  }
220 
221  this->AddProperty( "GROUPVEL", groupvel );
222 
223  return groupvel;
224 }
std::map< G4String, G4double, std::less< G4String > >::iterator MPTCiterator
void InsertValues(G4double energy, G4double value)
G4MaterialPropertyVector * SetGROUPVEL()
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
G4MaterialPropertyVector * AddProperty(const char *key, G4double *PhotonEnergies, G4double *PropertyValues, G4int NumEntries)
G4GLOB_DLL std::ostream G4cout
G4PhysicsOrderedFreeVector G4MaterialPropertyVector
std::map< G4String, G4MaterialPropertyVector *, std::less< G4String > >::iterator MPTiterator
std::map< G4String, G4double, std::less< G4String > > MPTC
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int G4Mutex
Definition: G4Threading.hh:173
#define G4endl
Definition: G4ios.hh:61
std::map< G4String, G4MaterialPropertyVector *, std::less< G4String > > MPT
double G4double
Definition: G4Types.hh:76