Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  ja
Language: FORTRAN
Code:
     
program FDT_Algorithm 
implicit none
integer tsteps,spsteps,j,m,period,i,real_file,imag_file,prob_dens_file
real(8) dt,dx,xc,w,s,k0
real(8), allocatable :: RePsi(:),ImPsi(:),RePsiOld(:),ImPsiOld(:),AbsValPsiSq(:),V(:),x(:)

real_file=1
imag_file=2
prob_dens_file=3
dt=0.05d0
dx=0.5d0
tsteps=100
spsteps=100
xc=1.d0
w=1.d0
k0=1.d0
period=10

s=dt/(2*dx*dx) ! Calculates the value of s
allocate(RePsi(0:spsteps+1),ImPsi(0:spsteps+1),RePsiOld(0:spsteps+1),ImPsiOld(0:spsteps+1))
allocate(AbsValPsiSq(0:spsteps+1),V(spsteps),x(spsteps))
RePsiOld(0)=0.d0
RePsiOld(spsteps+1)=0.d0
ImPsiOld(0)=0.d0
RePsiOld(spsteps+1)=0.d0
AbsValPsiSq=0.d0
x=0.d0
V=0
open(real_file,file="real.dat")
open(imag_file,file="imaginary.dat")
open(prob_dens_file,file="ProbDens.dat")
do j=1,spsteps
  x(j)=real(j)*dx
  RePsi(j)=exp(-((x(j)-xc)**2)/(w**2))*cos(k0*x(j))
  ImPsi(j)=exp(-((x(j)-xc)**2)/(w**2))*sin(k0*x(j))
  AbsValPsiSq(j)=RePsi(j)**2+ImPsi(j)**2
if(abs(RePsi(j))<1d-20) RePsi(j)=0.d0
  if(abs(ImPsi(j))<1d-20) ImPsi(j)=0.d0
  if(abs(AbsValPsiSq(j))<1d-20) AbsValPsiSq(j)=0.d0

  write(real_file,'(2ES16.8)')x(j),RePsi(j)
  write(imag_file,'(2ES16.8)')x(j),ImPsi(j)
     write(prob_dens_file,'(2ES16.8)')x(j),AbsValPsiSq(j)
end do     
do j=1,spsteps  
  RePsiOld(j)=RePsi(j)
  ImPsiOld(j)=ImPsi(j)
end do     
write(real_file,*)
write(imag_file,*)
write(prob_dens_file,*)
do m=1,tsteps
  do j=1,spsteps
    RePsi(j)=RePsiOld(j)-s*(ImPsiOld(j+1)-2*ImPsiOld(j)+ImPsiOld(j-1))+V(j)*dt*ImPsiOld(j)
       ImPsi(j)=ImPsiOld(j)+s*(RePsiOld(j+1)-2*RePsiOld(j)+RePsiOld(j-1))-V(j)*dt*RePsiOld(j)
    if(mod(m,period)==0) then
      if(abs(RePsi(j))<1d-20) RePsi(j)=0.d0
      if(abs(ImPsi(j))<1d-20) ImPsi(j)=0.d0
            write(real_file,'(2ES16.8)')x(j),RePsi(j)
      write(imag_file,'(2ES16.8)')x(j),ImPsi(j)
         AbsValPsiSq(j)=(RePsi(j)**2+ImPsi(j)**2)
      if(abs(AbsValPsiSq(j))<1d-20) AbsValPsiSq(j)=0.d0
               write(prob_dens_file,'(2ES16.8)') x(j),AbsValPsiSq(j)
          endif
  end do
do j=1,spsteps  
      RePsiOld(j)=RePsi(j)
      ImPsiOld(j)=ImPsi(j)
  end do     
  write(real_file,*)
  write(imag_file,*)
  write(prob_dens_file,*)
end do
deallocate(RePsi,ImPsi,RePsiOld,ImPsiOld,AbsValPsiSq,V,x)
close(real_file)
close(imag_file)
close(prob_dens_file)
end program FDT_Algorithm
Comments: