Guest User

dissipation

a guest
Sep 26th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module global_vars
  2.     integer :: N = 100, l = 1
  3.     real :: R = 15.0, V_0 = 4.0, a = 5.0, lk = 0.05, rk = 10.0, dk = 0.05, k
  4.     save
  5. end module
  6.    
  7. function V(x)
  8.     use global_vars
  9.     implicit none
  10.     real :: V
  11.     real, intent(in) :: x
  12.     if (x < a) then
  13.         V = -V_0
  14.     else
  15.         V = 0.0
  16.     end if
  17.     return
  18. end function
  19.  
  20. function F(x)
  21.     use global_vars
  22.     implicit none
  23.     real :: F, V
  24.     real, intent(in) :: x
  25.     F = V(x) + l * (l + 1) / x**2 - k**2
  26.     return
  27. end function
  28.  
  29. recursive function jl(x, l) result(ans)
  30.     real, intent(in) :: x
  31.     real :: ans
  32.     integer, intent(in) :: l
  33.     if (l == 0) then
  34.         ans = sin(x) / x
  35.     else if (l == 1) then
  36.         ans = sin(x) / x**2 - cos(x) / x
  37.     else
  38.         ans = (2 * (l - 1) + 1) / x * jl(x, l - 1) - jl(x, l - 2)
  39.     end if
  40. end function
  41.  
  42. function jl_hat(x, l)
  43.     real, intent(in) :: x
  44.     integer, intent(in) :: l
  45.     real :: jl, jl_hat
  46.     jl_hat = jl(x, l) * x
  47.     return
  48. end function
  49.  
  50. subroutine Simpson(h, f, N, ans)
  51.     implicit none
  52.     integer :: i, N
  53.     real :: h
  54.     complex :: f(N), ans
  55.     ans = 0.0
  56.     do i = 2, N - 1, 2
  57.         ans = ans + f(i - 1) + 4.0 * f(i) + f(i + 1)
  58.     end do
  59.     ans = ans * h / 3.0
  60. end subroutine
  61.  
  62. program scattering
  63.     use global_vars
  64.     implicit none
  65.     integer :: i, j, out = 42
  66.     real :: F, V, h, jl_hat,  pi = 3.1415926
  67.     complex :: Al, delta
  68.     integer, allocatable :: ipiv(:)
  69.     complex, allocatable :: X(:),  mA(:, :)
  70.     allocate(X(N))
  71.     allocate(ipiv(N))
  72.     allocate(mA(N, N))
  73.     h = R / N
  74.     k = lk
  75.     open(unit = out, file = "output.txt")
  76.     do while (k <= rk)
  77.         !mA = -d^2/dr^2 + F(r) - k^2
  78.         mA(:, :) = 0.0
  79.         do i = 1, N
  80.             if(i > 1) mA(i, i - 1) = 12.0 / h**2  - F(h * (i - 1))
  81.             mA(i, i) = -24.0 / h**2 - 10.0 * F(h * i)
  82.             if(i < N) mA(i, i + 1) = 12.0 / h**2 - F(h * (i + 1))
  83.         end do
  84.         mA(N, N) = mA(N, N) + exp((0.0, 1.0) * k * h) * (12.0 / h**2 - F(h * (N + 1)))
  85.         !X = -V(r)jl(kr)
  86.         do i = 1, N
  87.             X(i) = 10.0 * V(h * i) * jl_hat(k * i * h, l)
  88.             if(i > 1) X(i) = X(i) + V(h * (i - 1)) * jl_hat(k * (i - 1) * h, l)
  89.             if(i < n) X(i) = X(i) + V(h * (i + 1)) * jl_hat(k * (i + 1) * h, l)
  90.         end do
  91.         !X = chi_l
  92.         call cgesv(N, 1, mA, N, ipiv, X, N, i)
  93.         !X = jl(kr)V(r)f_l(r, k) = jl(kr)V(r)(jl(kr) + chi_l(r, k))
  94.         do i =1,n
  95.             X(i) = jl_hat(k * h * i, l) * V(h * i) * (jl_hat(k * h * i, l) + X(i))
  96.         end do
  97.         call Simpson(h, X, N, Al)
  98.         Al = -1.0 * Al / k**2
  99.         delta = log(1 + (0.0, 2.0) * k * Al) / (0.0, 2.0)
  100.         write(out, *) k, real(delta)
  101.         k = k + dk
  102.     end do
  103.     close(out)
  104. end program
Advertisement
Add Comment
Please, Sign In to add comment