Group four, parabolic, explicit

From Interactive System for Ice sheet Simulation
Jump to: navigation, search

program heat_equation


 ! Program to solve heat equation using finite differences forward mode


 implicit none
 ! Parameters
 integer             :: ii,jj 
 integer,parameter   :: n=11     ! spatial
 integer,parameter   :: t=501      ! time
 real,parameter      :: dx=0.1,dt=0.005125  ! resolution (km), timestep(yr)
 real,dimension(n,t) :: u               ! velocity
 real,parameter      :: pi=3.141592
 real,dimension(n)   :: soln


 open(19,file="difference_velocity.txt",form='formatted')


 ! spatial initial condition
 do ii=1,n
    u(ii,1)=sin(pi*dx*(ii-1))
 end do
 ! temporal boundary conditions
 do jj=1,t
    u(1,jj)= 0.0
    u(n,jj)= 0.0
 end do



 ! Loop using leap frog scheme, over two grid spacings
 do jj=1,t-1
    do ii=2,n-1
       u(ii,jj+1)= u(ii,jj)+dt*( u(ii+1,jj)-2.0*u(ii,jj)+u(ii-1,jj) )/ dx**2
       soln(ii)= exp( -(pi**2*jj*dt))*sin(pi*(ii-1)*dx)
    enddo
    ! Difference of solutions
    soln(1)=0.0
    soln(n)=0.0
    
    write(19,"(i3,2x,i2,2x,11f12.6)") jj,ii,(soln(ii)-u(ii,jj),ii=1,n)
 enddo


 close(19)


end program heat_equation