Group one, parabolic, explicit

From Interactive System for Ice sheet Simulation
Jump to: navigation, search
      program explicit_diffusion
      implicit none
 
      integer n, nx, nt,ii,tt
      real(8) dt,tend, dx
      real(8),dimension(:), allocatable :: x
      real(8),dimension(:), allocatable :: t
      real(8),dimension(:,:), allocatable :: u
      real(8) :: pi
 
      pi=2.*acos(0.)
 
      !allocate x array
      nx=11
      dx=0.1
      allocate(x(nx))
      do n=1,nx
        x(n)=(real(n)-1.)*dx
      enddo
 
      !allocate t array
      dt=0.005125
      tend=1.025
      nt=nint(tend/dt)+1
      allocate(t(nt))
 
      !allocate u array
      allocate(u(nx,nt))
 
      !set initial, boundary conditions
      !u(x,0)=sin(pi*x)
      !u(0,t)=u(1,t)=0.
      u(1:nx,1)=sin(pi*x)
      u(1,1:nt)=0.
      u(nx,1:nt)=0.
 
      !do loop for time
      do tt=2,nt
       do ii=2,nx-1
         u(ii,tt)=u(ii,tt-1)+dt*(u(ii-1,tt-1)
     $     -2.*u(ii,tt-1)+u(ii+1,tt-1))/dx**2.
       enddo
       write(*,*),u(:,tt)
      enddo
 
      end