program leapfrog parameter(ni=11,ktime=10) dimension phiold(ni), phi(ni), phinew(ni) !&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ! ! Written by Dr. Pat Fitzpatrick ! Department of Physics, Atmospheric Sciences, & General Sciences ! Jackson State University ! 4/21/97 ! ! This program timesteps the 1D advection equation using the ! leapfrog scheme for a given Courant number ! ! Initialize variables: ! ! ni is the number of grid points ! Co is the Courant number ! ktime is the number of timesteps for a given Courant number ! phiold(i) is the old phi value ! phi(i) is the current phi value ! phinew(i) is the future phi value !&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ! ! !************************************************************ ! Prompt user for Courant number !************************************************************ print*,'Enter Courant number' read(*,*) Co print*,'Co for Leapfrog program is ',Co print*,' ' !************************************************************ ! Initialize phi. Since we are using leapfrog, must know phiold ! and phi to start time stepping !************************************************************ do 10 i=1,ni phiold(i)=0.0 phi(i)=0.0 10 continue phiold(7)=100.0 phi(8)=100.0 !************************************************************ ! Output initial field to screen !************************************************************ write(*,1000) (phiold(i),i=1,ni-1) write(*,1000) (phi(i),i=1,ni-1) 1000 format(10(f5.0,2x)) !************************************************************ ! Begin timestepping !************************************************************ do 100 k=1,ktime do 20 i=2,ni-1 phinew(i)=phiold(i)-Co*(phi(i+1)-phi(i-1)) 20 continue !************************************************************ ! Apply periodic boundary conditions !************************************************************ phinew(ni)=phiold(ni)-Co*(phi(2)-phi(ni-1)) phinew(1)=phinew(ni) !************************************************************ ! Output field to screen !************************************************************ write(*,1000) (phinew(i),i=1,ni-1) !************************************************************ ! Reset phi for next time step !************************************************************ do 30 i=1,ni phiold(i)=phi(i) phi(i)=phinew(i) 30 continue 100 continue end