Package lib :: Package geometry :: Module pec
[hide private]
[frames] | no frames]

Source Code for Module lib.geometry.pec

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2010,2012 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """Module for the pseudo-elliptical functions.""" 
 24   
 25  # Python module import. 
 26  from math import pi 
 27   
 28   
29 -def factorial(n):
30 """Return n! 31 32 @param n: The number to return the factorial of. 33 @type n: int 34 @return: n! 35 @rtype: int 36 """ 37 38 # A list of factorials. 39 fact = [ 40 1, 41 1, 42 2, 43 6, 44 24, 45 120, 46 720, 47 5040, 48 40320, 49 362880, 50 3628800, 51 39916800, 52 479001600, 53 6227020800, 54 87178291200, 55 1307674368000, 56 20922789888000, 57 355687428096000, 58 6402373705728000, 59 121645100408832000, 60 2432902008176640000, 61 51090942171709440000, 62 1124000727777607680000, 63 25852016738884976640000, 64 620448401733239439360000, 65 15511210043330985984000000, 66 403291461126605635584000000, 67 10888869450418352160768000000, 68 304888344611713860501504000000, 69 8841761993739701954543616000000, 70 265252859812191058636308480000000, 71 8222838654177922817725562880000000, 72 263130836933693530167218012160000000, 73 8683317618811886495518194401280000000, 74 295232799039604140847618609643520000000, 75 10333147966386144929666651337523200000000, 76 371993326789901217467999448150835200000000, 77 13763753091226345046315979581580902400000000, 78 523022617466601111760007224100074291200000000, 79 20397882081197443358640281739902897356800000000 80 ] 81 82 # Return the value. 83 return fact[n]
84 85
86 -def pec(x, y):
87 """The 2D pseudo-elliptic cosine function. 88 89 This is defined as:: 90 91 int_-pi^pi (1 - cos(theta_max)).dphi, 92 93 where:: 94 95 theta_max = 1 / sqrt(cos**2(phi)/x**2 + sin**2(phi)/y**2). 96 97 The function is approximated as:: 98 99 _inf 100 \ (-1)**n 101 2*pi*x*y > ----------------- fn(x, y), 102 /___ 4**n * (2n + 2)! 103 n=0 104 105 and where the individual functions are:: 106 107 n: 0; fn(x,y) = 1 108 n: 1; fn(x,y) = 2*a + 2*b 109 n: 2; fn(x,y) = 6*a^2 + 4*a*b + 6*b^2 110 n: 3; fn(x,y) = 20*a^3 + 12*a^2*b + 12*a*b^2 + 20*b^3 111 n: 4; fn(x,y) = 70*a^4 + 40*a^3*b + 36*a^2*b^2 + 40*a*b^3 + 70*b^4 112 n: 5; fn(x,y) = 252*a^5 + 140*a^4*b + 120*a^3*b^2 + 120*a^2*b^3 + 140*a*b^4 + 252*b^5 113 n: 6; fn(x,y) = 924*a^6 + 504*a^5*b + 420*a^4*b^2 + 400*a^3*b^3 + 420*a^2*b^4 + 504*a*b^5 + 924*b^6 114 n: 7; fn(x,y) = 3432*a^7 + 1848*a^6*b + 1512*a^5*b^2 + 1400*a^4*b^3 + 1400*a^3*b^4 + 1512*a^2*b^5 + 1848*a*b^6 + 3432*b^7 115 n: 8; fn(x,y) = 12870*a^8 + 6864*a^7*b + 5544*a^6*b^2 + 5040*a^5*b^3 + 4900*a^4*b^4 + 5040*a^3*b^5 + 5544*a^2*b^6 + 6864*a*b^7 + 12870*b^8 116 n: 9; fn(x,y) = 48620*a^9 + 25740*a^8*b + 20592*a^7*b^2 + 18480*a^6*b^3 + 17640*a^5*b^4 + 17640*a^4*b^5 + 18480*a^3*b^6 + 20592*a^2*b^7 + 25740*a*b^8 + 48620*b^9 117 n: 10; fn(x,y) = 184756*a^10 + 97240*a^9*b + 77220*a^8*b^2 + 68640*a^7*b^3 + 64680*a^6*b^4 + 63504*a^5*b^5 + 64680*a^4*b^6 + 68640*a^3*b^7 + 77220*a^2*b^8 + 97240*a*b^9 + 184756*b^10 118 n: 11; fn(x,y) = 705432*a^11 + 369512*a^10*b + 291720*a^9*b^2 + 257400*a^8*b^3 + 240240*a^7*b^4 + 232848*a^6*b^5 + 232848*a^5*b^6 + 240240*a^4*b^7 + 257400*a^3*b^8 + 291720*a^2*b^9 + 369512*a*b^10 + 705432*b^11 119 120 121 @param x: The theta_x cone angle (in rad). 122 @type x: float 123 @param y: The theta_y cone angle (in rad). 124 @type y: float 125 @return: The approximate function value. 126 @rtype: float 127 """ 128 129 # Init. 130 fn = 0.0 131 fact = 1.0 132 133 # The x powers. 134 a = x**2 135 a2 = a**2 136 a3 = a**3 137 a4 = a**4 138 a5 = a**5 139 a6 = a**6 140 a7 = a**7 141 a8 = a**8 142 a9 = a**9 143 a10 = a**10 144 145 # The y powers. 146 b = y**2 147 b2 = b**2 148 b3 = b**3 149 b4 = b**4 150 b5 = b**5 151 b6 = b**6 152 b7 = b**7 153 b8 = b**8 154 b9 = b**9 155 b10 = b**10 156 157 # Term 0. 158 f0 = 1.0 159 fn = fn + f0 / factorial(2) 160 161 # Term 1. 162 f1 = 2*a + 2*b 163 fn = fn - f1 / 4.0 / factorial(4) 164 165 # Term 2. 166 f2 = 6*a2 + 4*a*b + 6*b2 167 fn = fn + f2 / 16.0 / factorial(6) 168 169 # Term 3. 170 f3 = 20*a3 + 12*a2*b + 12*a*b2 + 20*b3 171 fn = fn - f3 / 64.0 / factorial(8) 172 173 # Term 4. 174 f4 = 70*a4 + 40*a3*b + 36*a2*b2 + 40*a*b3 + 70*b4 175 fn = fn + f4 / 256.0 / factorial(10) 176 177 # Term 5. 178 f5 = 252*a5 + 140*a4*b + 120*a3*b2 + 120*a2*b3 + 140*a*b4 + 252*b5 179 fn = fn - f5 / 1024.0 / factorial(12) 180 181 # Term 6. 182 f6 = 924*a6 + 504*a5*b + 420*a4*b2 + 400*a3*b3 + 420*a2*b4 + 504*a*b5 + 924*b6 183 fn = fn + f6 / 4096.0 / factorial(14) 184 185 # Term 7. 186 f7 = 3432*a7 + 1848*a6*b + 1512*a5*b2 + 1400*a4*b3 + 1400*a3*b4 + 1512*a2*b5 + 1848*a*b6 + 3432*b7 187 fn = fn - f7 / 16384.0 / factorial(16) 188 189 # Term 8. 190 f8 = 12870*a8 + 6864*a7*b + 5544*a6*b2 + 5040*a5*b3 + 4900*a4*b4 + 5040*a3*b5 + 5544*a2*b6 + 6864*a*b7 + 12870*b8 191 fn = fn + f8 / 65536.0 / factorial(18) 192 193 # Term 9. 194 f9 = 48620*a9 + 25740*a8*b + 20592*a7*b2 + 18480*a6*b3 + 17640*a5*b4 + 17640*a4*b5 + 18480*a3*b6 + 20592*a2*b7 + 25740*a*b8 + 48620*b9 195 fn = fn - f9 / 262144.0 / factorial(20) 196 197 # Term 10. 198 f10 = 184756*a10 + 97240*a9*b + 77220*a8*b2 + 68640*a7*b3 + 64680*a6*b4 + 63504*a5*b5 + 64680*a4*b6 + 68640*a3*b7 + 77220*a2*b8 + 97240*a*b9 + 184756*b10 199 fn = fn + f10 / 1048576.0 / factorial(22) 200 201 # Common factor. 202 fn = 2.0 * pi * x * y * fn 203 204 # Return the approximate function value. 205 return fn
206