math - Finite differences for 2D Parabolic PDE -


this modified problem numerical computing-kincaid's book, chapter 15. (not physics)

how can implement boundary conditions? conditions

u(0,y,t) = u(x,0,t) = u(nx,y,t) = u(x,ny,t) = 0. 

i not doing correctly, seems. code below.

i trying write fortran code solve 2d heat (parabolic) equation using finite differences. when print out results, divergent results , 'nan'. seems not defining boundary conditions correctly. did code in 1 dimension, trying generalize in 2 have troubles @ boundary.

note, i,j x , y position loops respectively, m time loop. nx,ny,w number of grid points in x , y direction , time respectively. lx,ly , tmax size of position , time intervals mesh. position(x,y) steps , time steps given hx,hy,k respectively, , hx , hy equal example below. store solutions in variables u , v shown below.

program parabolic2d  implicit none  integer :: i,j,m  integer, parameter :: nx=10., ny=10., w=21.  real, parameter :: lx=1.0, ly=1.0, tmax=0.1  real :: hx,hy,k,pi,pi2,r,t  real, dimension (0:nx,0:ny) :: u,v    hx=(lx-0.0)/nx  hy=(ly-0.0)/ny  k=(tmax-0.0)/w r=k/hx**2. u(0,0)=0.0; v(0,0)=0.0; u(nx,ny)=0.0; v(nx,ny)=0.0 !boundary conditions u(0,0,t)=0=u(nx,ny,t) pi=4.0*atan(1.0)  pi2=pi*pi    i=1,nx-1 j=1,ny-1 u(i,j)=sin(pi*real(i)*hx)*sin(pi*real(j)*hy)  !initial condition end end  m=1,w  i=1,nx-1 j=1,ny-1 v(i,j) = r*(u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1))+(1-4*r)*u(i,j) !discretization u(x,y,t+k) end end  t = real(m)*k ! t refers time in problem.  i=1,nx-1 j=1,ny-1 u(i,j)=v(i,j) !redefining variables. end end write(*,*) 'for times m, prints out u(x,y,t)',m,((u(i,j),i=0,nx),j=0,ny)  end  end program parabolic2d 

as ross points out, haven't specified boundary conditions edges i=j=0 , i=nx , j=nx. corners of domain have bee specified.

change

u(0,0)=0.0; v(0,0)=0.0; u(nx,ny)=0.0; v(nx,ny)=0.0 !boundary conditions u(0,0,t)=0=u(nx,ny,t)

to

u(0,:)=0.0 u(nx,:)=0.0 u(:,0)=0.0 u(:,ny)=0.0

or even

u=0.0.

the interior points overwritten later.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -