Group six, parabolic, explicit

From Interactive System for Ice sheet Simulation
Jump to: navigation, search
! finite differencing exercise-I
! coded by Group-6
 
program exercise1
 
	implicit none
 
	! local variables
	real, parameter :: delT = 0.005125 ! time step
	real, parameter :: delX = 0.1      ! spatial step
	real, parameter :: pi = 3.14159265
	integer, parameter :: nT = 201     ! time iterations: initialT = 0.0, endT = 1.025
	integer, parameter :: nX = 11	   ! number of cells: leftX = 0.0, rightX = 1.0
	real, dimension(nX):: u_old, u_new ! static arrays of size 11
	integer         :: ii,jj           ! counters
 
	! initial conditions
	do jj = 1,nX
		u_new(jj) = sin(pi*((jj-1)*delX))
	end do
 
	! main loop 
	do ii = 1,nT
		u_old = u_new ! reset 
		do jj = 1,nX
			! what about the stencil?
			if (jj == 1 .or. jj == nX) then
				! different stencil at the edges, satisfying boundary conditions
				u_new(jj) = 0.0
			else
				! this is the 'normal' situation
				u_new(jj) = u_old(jj) + delT*(u_old(jj-1)-2*u_old(jj)+u_old(jj+1))/delX**2
			end if 
		end do	! end of spatial loop
	end do	! end of main loop
 
	! write the variable u, after the end time t = 1.025
	print *, u_new(:)
 
end program exercise1