Guest User

Untitled

a guest
Feb 9th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program newgaussfield
  2. implicit none
  3.  
  4. double precision :: x, z, PI, sigma, kxstepfrac, n1,n2
  5. double precision :: xi, zi, xf, zf, eta, xstepfrac, zstepfrac, phi, Ls !Ls is distance between source and interface
  6. complex*16 :: i, kx
  7. integer*4 :: m,n,p, xsize, zsize
  8.  
  9. double precision :: eps1, mu1, eps2, mu2
  10. complex*16 :: Er, Et, kznorm1, kznorm2, chi
  11.  
  12. double precision, dimension(:), allocatable :: xarray
  13. double precision, dimension(:), allocatable :: zarray
  14.  
  15. complex*16, dimension(:,:), allocatable :: fieldtransformed
  16.  
  17. complex*16, dimension(0:500) :: kxarray
  18.  
  19. xi=-20
  20. zi=-20
  21. xf=20
  22. zf=20
  23. xstepfrac = 0.1
  24. zstepfrac = 0.1
  25.  
  26. !Ls is distance between source and interface and is what we use to parametise, setting it equal to 1
  27. Ls=1.0d0
  28.  
  29. xsize = anint((dble(xf-xi)/xstepfrac))
  30. zsize = anint((dble(zf-zi)/zstepfrac))
  31.  
  32. allocate(xarray(0:xsize))
  33. allocate(zarray(0:zsize))
  34. allocate(fieldtransformed(0:xsize,0:zsize))
  35.  
  36. PI=4.D0*DATAN(1.D0)
  37. i=dcmplx(0.0d0,1.0d0)
  38.  
  39. phi=PI/4.0d0
  40. eta=PI
  41. !eta=w/c*Ls
  42. sigma=4.0d0
  43.  
  44. !kxstepfrac=eta/100.0d0 !this should be with cos(phi)???
  45. kxstepfrac=eta*cos(phi)/100.0d0
  46.  
  47. eps1 = 1.0d0
  48. eps2 = 10.0d0
  49. mu1 = 1.0d0
  50. mu2= 1.0d0 !get NaN for normal incidence when n1=n2, look into this after
  51.  
  52. n1 = SQRT(eps1*mu1)
  53. n2 = SQRT(eps2*mu2)
  54.  
  55. !if((real(n2)<0.and.(eps2)>0).or.&
  56. ! (eps2<0.and.(mu2<0).and.real(n2)>0))then    PUT THESE BACK IN FOR NEGATIVE REFRACTION
  57. !  n2=-1*n2
  58. !end if
  59. print *, "n2=",n2
  60. print *, "n1=",n1
  61.  
  62. do p=0,zsize
  63.   zarray(p) = zi + dble(p)*zstepfrac
  64. end do
  65.  
  66. do p=0,xsize
  67.   xarray(p) = xi + dble(p)*xstepfrac
  68. end do
  69.  
  70. do n=0,xsize
  71.   do m=0, zsize
  72.     fieldtransformed(n,m)=0
  73.   end do
  74. end do
  75.  
  76. do p=0,200
  77.  
  78.   kxarray(p)=-((eta)*cos(phi)) + ((dble(p)*kxstepfrac))
  79.   kx = kxarray(p)
  80.   kznorm1=SQRT(((n1*eta)**2.0d0) - (kx**2.0d0))
  81.   kznorm2=SQRT(((n2*eta)**2.0d0) - (kx**2.0d0))
  82.  
  83.   !print *, "kznorm1=",kznorm1
  84.   !print *, "kznorm2=",kznorm2
  85.  
  86.  ! if ((real(kznorm2)>0).and.(real(n2)<0)) then !this is right   PUT THIS BACK IN AFTER
  87.  !  kznorm2 = -kznorm2
  88.  ! end if
  89.    
  90.  ! if (real(kznorm1)<0) then   PUT THIS BACK IN
  91.  !  kznorm1 = -kznorm1
  92.  ! end if
  93.  
  94.    chi=(kznorm2*mu1)/(kznorm1*mu2)
  95.  
  96.    Er = (cdEXP(2*i*kznorm1*Ls))*(1-chi)/(1+chi)
  97.    Et = (cdEXP(i*(kznorm1-kznorm2)*Ls))*2.0d0/(1+chi)
  98.  
  99.   open(unit=2,file='gfield020.dat')
  100.  
  101.   do m=0, zsize
  102.     z=zarray(m)
  103.  
  104.     do n=0, xsize
  105.       x=xarray(n)
  106.       kx=kxarray(p)
  107.  
  108.   !zrofra = (zarray(m)*DCOS(phi))+(xarray(n)*DSIN(phi))
  109.   !xrofra = (xarray(n)*DCOS(phi))-(zarray(m)*DSIN(phi))
  110.  
  111.   if(z<=Ls) then !this is where we say the source is at z=0, defined negatively in else
  112.     fieldtransformed(n,m)=fieldtransformed(n,m)+ &
  113.      ((dSQRT(sigma/(2.0d0*PI))*cdEXP(i*kx*x)*cdEXP(i*kznorm1*z)*cdEXP(-(sigma/2.0d0)* &
  114.       (((kx*cos(phi))-(kznorm1*sin(phi)))**2.0d0))*kxstepfrac/cos(phi))+ &
  115.        (Er*dSQRT(sigma/(2.0d0*PI))*cdEXP(i*kx*x)*cdEXP(-i*kznorm1*z)*cdEXP(-(sigma/2.0d0)* &
  116.       (((kx*cos(phi))-(kznorm1*sin(phi)))**2.0d0))*kxstepfrac/cos(phi)))
  117.   else
  118.     fieldtransformed(n,m)=fieldtransformed(n,m)+ &
  119.      (Et*dSQRT(sigma/(2.0d0*PI))*cdEXP(i*kx*x)*cdEXP(i*kznorm2*z)*cdEXP(-(sigma/2.0d0)* &
  120.       (((kx*cos(phi))-(kznorm1*sin(phi)))**2.0d0))*kxstepfrac/cos(phi))!change back to 2
  121.   end if
  122. !could be a problem with the numerical integration method, which is why reflection isn't shown. Put it back to normal expressions(factorise)
  123.  
  124.     end do
  125.   end do
  126. end do
  127.  
  128. do m=0,zsize
  129.   do n=0,xsize
  130.  
  131.   write(2,*) xarray(n),zarray(m), abs(fieldtransformed(n,m)), real(fieldtransformed(n,m))
  132.  
  133.   end do
  134. end do
  135.  
  136. end program newgaussfield
Add Comment
Please, Sign In to add comment