File indexing completed on 2025-01-18 09:58:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #ifndef G4Pow_hh
0041 #define G4Pow_hh 1
0042
0043 #include "G4DataVector.hh"
0044 #include "G4Exp.hh"
0045 #include "G4Log.hh"
0046 #include "globals.hh"
0047
0048 class G4Pow
0049 {
0050 public:
0051 static G4Pow* GetInstance();
0052 ~G4Pow() = default;
0053
0054
0055
0056 inline G4double Z13(G4int Z) const;
0057 G4double A13(G4double A) const;
0058
0059
0060
0061 inline G4double Z23(G4int Z) const;
0062 inline G4double A23(G4double A) const;
0063
0064
0065
0066 inline G4double logZ(G4int Z) const;
0067 inline G4double logA(G4double A) const;
0068 inline G4double logX(G4double x) const;
0069
0070
0071
0072 inline G4double log10Z(G4int Z) const;
0073 inline G4double log10A(G4double A) const;
0074
0075
0076
0077 inline G4double expA(G4double A) const;
0078
0079
0080
0081 inline G4double powZ(G4int Z, G4double y) const;
0082 inline G4double powA(G4double A, G4double y) const;
0083 G4double powN(G4double x, G4int n) const;
0084
0085
0086
0087 inline G4double factorial(G4int Z) const;
0088 inline G4double logfactorial(G4int Z) const;
0089
0090 private:
0091 G4Pow();
0092
0093 G4double A13Low(const G4double, const G4bool) const;
0094 G4double A13High(const G4double, const G4bool) const;
0095
0096 inline G4double logBase(G4double x) const;
0097
0098 static G4Pow* fpInstance;
0099
0100 const G4double onethird = 1.0 / 3.0;
0101 const G4int max2 = 5;
0102
0103 G4double maxA;
0104 G4double maxLowA;
0105 G4double maxA2;
0106 G4double maxAexp;
0107
0108 G4DataVector ener;
0109 G4DataVector logen;
0110 G4DataVector pz13;
0111 G4DataVector lowa13;
0112 G4DataVector lz;
0113 G4DataVector lz2;
0114 G4DataVector fexp;
0115 G4DataVector fact;
0116 G4DataVector logfact;
0117 };
0118
0119
0120
0121
0122
0123 inline G4double G4Pow::Z13(G4int Z) const { return pz13[Z]; }
0124
0125 inline G4double G4Pow::Z23(G4int Z) const
0126 {
0127 G4double x = Z13(Z);
0128 return x * x;
0129 }
0130
0131 inline G4double G4Pow::A23(G4double A) const
0132 {
0133 G4double x = A13(A);
0134 return x * x;
0135 }
0136
0137 inline G4double G4Pow::logZ(G4int Z) const { return lz[Z]; }
0138
0139 inline G4double G4Pow::logBase(G4double a) const
0140 {
0141 G4double res;
0142 if(a <= maxA2)
0143 {
0144 G4int i = G4int(max2 * (a - 1) + 0.5);
0145 if(i > max2)
0146 {
0147 i = max2;
0148 }
0149 G4double x = a / (G4double(i) / max2 + 1) - 1;
0150 res = lz2[i] + x * (1.0 - (0.5 - onethird * x) * x);
0151 }
0152 else if(a <= maxA)
0153 {
0154 G4int i = G4int(a + 0.5);
0155 G4double x = a / G4double(i) - 1;
0156 res = lz[i] + x * (1.0 - (0.5 - onethird * x) * x);
0157 }
0158 else
0159 {
0160 res = G4Log(a);
0161 }
0162 return res;
0163 }
0164
0165 inline G4double G4Pow::logA(G4double A) const
0166 {
0167 return (1.0 <= A ? logBase(A) : -logBase(1. / A));
0168 }
0169
0170 inline G4double G4Pow::logX(G4double x) const
0171 {
0172 G4double res = 0.0;
0173 G4double a = (1.0 <= x) ? x : 1.0 / x;
0174
0175 if(a <= maxA)
0176 {
0177 res = logBase(a);
0178 }
0179 else if(a <= ener[2])
0180 {
0181 res = logen[1] + logBase(a / ener[1]);
0182 }
0183 else if(a <= ener[3])
0184 {
0185 res = logen[2] + logBase(a / ener[2]);
0186 }
0187 else
0188 {
0189 res = G4Log(a);
0190 }
0191
0192 if(1.0 > x)
0193 {
0194 res = -res;
0195 }
0196 return res;
0197 }
0198
0199 inline G4double G4Pow::log10Z(G4int Z) const { return lz[Z] / lz[10]; }
0200
0201 inline G4double G4Pow::log10A(G4double A) const { return logX(A) / lz[10]; }
0202
0203 inline G4double G4Pow::expA(G4double A) const
0204 {
0205 G4double res;
0206 G4double a = (0.0 <= A) ? A : -A;
0207
0208 if(a <= maxAexp)
0209 {
0210 G4int i = G4int(2 * a + 0.5);
0211 G4double x = a - i * 0.5;
0212 res = fexp[i] * (1.0 + x * (1.0 + 0.5 * (1.0 + onethird * x) * x));
0213 }
0214 else
0215 {
0216 res = G4Exp(a);
0217 }
0218 if(0.0 > A)
0219 {
0220 res = 1.0 / res;
0221 }
0222 return res;
0223 }
0224
0225 inline G4double G4Pow::powZ(G4int Z, G4double y) const
0226 {
0227 return expA(y * lz[Z]);
0228 }
0229
0230 inline G4double G4Pow::powA(G4double A, G4double y) const
0231 {
0232 return (0.0 == A ? 0.0 : expA(y * logX(A)));
0233 }
0234
0235 inline G4double G4Pow::factorial(G4int Z) const { return fact[Z]; }
0236
0237 inline G4double G4Pow::logfactorial(G4int Z) const { return logfact[Z]; }
0238
0239 #endif