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.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 /global/management/include/G4Pow.hh (Version 11.3.0) and /global/management/include/G4Pow.hh (Version 9.0.p2)


  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 // G4Pow                                          
 27 //                                                
 28 // Class description:                             
 29 //                                                
 30 // Utility singleton class for the fast comput    
 31 // functions. Integer argument should be in th    
 32 // check is performed inside these methods for    
 33 // For factorial integer argument should be in    
 34 // Computations with double arguments are fast    
 35 // 0.002-511.5 for all functions except expone    
 36 // for the interval 0-84.4, standard library i    
 37                                                   
 38 // Author: Vladimir Ivanchenko, 23.05.2009        
 39 // -------------------------------------------    
 40 #ifndef G4Pow_hh                                  
 41 #define G4Pow_hh 1                                
 42                                                   
 43 #include "G4DataVector.hh"                        
 44 #include "G4Exp.hh"                               
 45 #include "G4Log.hh"                               
 46 #include "globals.hh"                             
 47                                                   
 48 class G4Pow                                       
 49 {                                                 
 50  public:                                          
 51   static G4Pow* GetInstance();                    
 52   ~G4Pow() = default;                             
 53                                                   
 54   // Fast computation of Z^1/3                    
 55   //                                              
 56   inline G4double Z13(G4int Z) const;             
 57   G4double A13(G4double A) const;                 
 58                                                   
 59   // Fast computation of Z^2/3                    
 60   //                                              
 61   inline G4double Z23(G4int Z) const;             
 62   inline G4double A23(G4double A) const;          
 63                                                   
 64   // Fast computation of log(Z)                   
 65   //                                              
 66   inline G4double logZ(G4int Z) const;            
 67   inline G4double logA(G4double A) const;         
 68   inline G4double logX(G4double x) const;         
 69                                                   
 70   // Fast computation of log10(Z)                 
 71   //                                              
 72   inline G4double log10Z(G4int Z) const;          
 73   inline G4double log10A(G4double A) const;       
 74                                                   
 75   // Fast computation of exp(X)                   
 76   //                                              
 77   inline G4double expA(G4double A) const;         
 78                                                   
 79   // Fast computation of pow(Z,X)                 
 80   //                                              
 81   inline G4double powZ(G4int Z, G4double y) co    
 82   inline G4double powA(G4double A, G4double y)    
 83   G4double powN(G4double x, G4int n) const;       
 84                                                   
 85   // Fast factorial                               
 86   //                                              
 87   inline G4double factorial(G4int Z) const;       
 88   inline G4double logfactorial(G4int Z) const;    
 89                                                   
 90  private:                                         
 91   G4Pow();                                        
 92                                                   
 93   G4double A13Low(const G4double, const G4bool    
 94   G4double A13High(const G4double, const G4boo    
 95                                                   
 96   inline G4double logBase(G4double x) const;      
 97                                                   
 98   static G4Pow* fpInstance;                       
 99                                                   
100   const G4double onethird = 1.0 / 3.0;            
101   const G4int max2        = 5;                    
102                                                   
103   G4double maxA;                                  
104   G4double maxLowA;                               
105   G4double maxA2;                                 
106   G4double maxAexp;                               
107                                                   
108   G4DataVector ener;                              
109   G4DataVector logen;                             
110   G4DataVector pz13;                              
111   G4DataVector lowa13;                            
112   G4DataVector lz;                                
113   G4DataVector lz2;                               
114   G4DataVector fexp;                              
115   G4DataVector fact;                              
116   G4DataVector logfact;                           
117 };                                                
118                                                   
119 // -----------------------------                  
120 // Inline methods implementation                  
121 // -----------------------------                  
122                                                   
123 inline G4double G4Pow::Z13(G4int Z) const { re    
124                                                   
125 inline G4double G4Pow::Z23(G4int Z) const         
126 {                                                 
127   G4double x = Z13(Z);                            
128   return x * x;                                   
129 }                                                 
130                                                   
131 inline G4double G4Pow::A23(G4double A) const      
132 {                                                 
133   G4double x = A13(A);                            
134   return x * x;                                   
135 }                                                 
136                                                   
137 inline G4double G4Pow::logZ(G4int Z) const { r    
138                                                   
139 inline G4double G4Pow::logBase(G4double a) con    
140 {                                                 
141   G4double res;                                   
142   if(a <= maxA2)                                  
143   {                                               
144     G4int i = G4int(max2 * (a - 1) + 0.5);        
145     if(i > max2)                                  
146     {                                             
147       i = max2;                                   
148     }                                             
149     G4double x = a / (G4double(i) / max2 + 1)     
150     res        = lz2[i] + x * (1.0 - (0.5 - on    
151   }                                               
152   else if(a <= maxA)                              
153   {                                               
154     G4int i    = G4int(a + 0.5);                  
155     G4double x = a / G4double(i) - 1;             
156     res        = lz[i] + x * (1.0 - (0.5 - one    
157   }                                               
158   else                                            
159   {                                               
160     res = G4Log(a);                               
161   }                                               
162   return res;                                     
163 }                                                 
164                                                   
165 inline G4double G4Pow::logA(G4double A) const     
166 {                                                 
167   return (1.0 <= A ? logBase(A) : -logBase(1.     
168 }                                                 
169                                                   
170 inline G4double G4Pow::logX(G4double x) const     
171 {                                                 
172   G4double res = 0.0;                             
173   G4double a   = (1.0 <= x) ? x : 1.0 / x;        
174                                                   
175   if(a <= maxA)                                   
176   {                                               
177     res = logBase(a);                             
178   }                                               
179   else if(a <= ener[2])                           
180   {                                               
181     res = logen[1] + logBase(a / ener[1]);        
182   }                                               
183   else if(a <= ener[3])                           
184   {                                               
185     res = logen[2] + logBase(a / ener[2]);        
186   }                                               
187   else                                            
188   {                                               
189     res = G4Log(a);                               
190   }                                               
191                                                   
192   if(1.0 > x)                                     
193   {                                               
194     res = -res;                                   
195   }                                               
196   return res;                                     
197 }                                                 
198                                                   
199 inline G4double G4Pow::log10Z(G4int Z) const {    
200                                                   
201 inline G4double G4Pow::log10A(G4double A) cons    
202                                                   
203 inline G4double G4Pow::expA(G4double A) const     
204 {                                                 
205   G4double res;                                   
206   G4double a = (0.0 <= A) ? A : -A;               
207                                                   
208   if(a <= maxAexp)                                
209   {                                               
210     G4int i    = G4int(2 * a + 0.5);              
211     G4double x = a - i * 0.5;                     
212     res        = fexp[i] * (1.0 + x * (1.0 + 0    
213   }                                               
214   else                                            
215   {                                               
216     res = G4Exp(a);                               
217   }                                               
218   if(0.0 > A)                                     
219   {                                               
220     res = 1.0 / res;                              
221   }                                               
222   return res;                                     
223 }                                                 
224                                                   
225 inline G4double G4Pow::powZ(G4int Z, G4double     
226 {                                                 
227   return expA(y * lz[Z]);                         
228 }                                                 
229                                                   
230 inline G4double G4Pow::powA(G4double A, G4doub    
231 {                                                 
232   return (0.0 == A ? 0.0 : expA(y * logX(A)));    
233 }                                                 
234                                                   
235 inline G4double G4Pow::factorial(G4int Z) cons    
236                                                   
237 inline G4double G4Pow::logfactorial(G4int Z) c    
238                                                   
239 #endif                                            
240