CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   Please help me on my Fortran code (https://www.cfd-online.com/Forums/main/133551-please-help-me-my-fortran-code.html)

alinaghedifar April 16, 2014 14:07

Please help me on my Fortran code
 
Hi
I wrote a Fortran code for lid driven cavity by stream-function vorticity equations, but when I ran the code it not converged and exports "NaN". :confused:
Here is my code:



program SimpleCavity
implicit none
integer, parameter::nn=6000
double precision, dimension (nn,nn):: Psi,Omega
integer imax,jmax,i,j,m,maxiter,load,t1,t2,clock_rate,cloc k_max
double precision hx,hy,Lx,Ly,Nu,Uinf


write(*,*)' *=+=**=+=**=+=**=+=**=+=**=+=**=+=**=+=*'
write(*,*)' Simple Lid Driven Cavity '
write(*,*)' *=+=**=+=**=+=**=+=**=+=**=+=**=+=**=+=*'
write(*,*)''

!Inputs
imax=200
jmax=200
!Lx=1.0
!Ly=1.0
maxiter=10000
!hx=real(Lx/(imax+1))
!hy=real(Ly/(jmax+1))
hx=1.0
hy=1.0
Nu=1.0
Uinf=1.0


!Stream-Function Boundary Conditions
do j=1,jmax+2
Psi(1,j)=0.0
Psi(imax+2,j)=0.0
end do

do i=1,imax+2
Psi(i,1)=0.0
Psi(i,jmax+2)=0.0
end do

!Iteration
do m=1,maxiter


!Stream-Function
do j=2,jmax+1
do i=2,imax+1
Psi(i,j)=(Omega(i,j)+Psi(i-1,j)/hx**2+Psi(i+1,j)/hx**2+Psi(i,j-1)/hy**2+Psi(i,j+1)/hy**2)/(2/hx**2+2/hy**2)
end do
end do

!Vorticity Boundary Conditions
do j=1,jmax+2
Omega(1,j)=-2*Psi(2,j)/hx**2
Omega(imax+2,j)=-2*Psi(imax+1,j)/hx**2
end do

do i=1,imax+2
Omega(i,1)=-2*Psi(i,2)/hy**2
Omega(i,jmax+2)=-(2*Psi(i,jmax+1)/hy**2+(2*Uinf)/hy**2)
end do

!Vorticity
do j=jmax+1,2,-1
do i=2,imax+1
Omega(i,j)=( Omega(i-1,j) * ( (Psi(i,j+1)-Psi(i,j-1)) / (2*hy*2*hx)+Nu/hx**2 ) &
+ Omega(i+1,j) * (-1*(Psi(i,j+1)-Psi(i,j-1))/(2*hy*2*hx)+Nu/hx**2 ) &
+ Omega(i,j-1) * (-1*(Psi(i+1,j)-Psi(i-1,j))/(2*hx*2*hy)+Nu/hy**2 ) &
+ Omega(i,j+1) * ( (Psi(i+1,j)-Psi(i-1,j)) / (2*hx*2*hy)+Nu/hy**2 ))&
/ (2*Nu/hx**2+2*Nu/hy**2)
end do
end do
end do


write(*,*) ''
write(*,*) ''
write(*,*) ''
write(*,*) 'Writing results to a text file ...'
open (1,file="Stream-Function Distribution.dat",action="write",status="replace")
write(1,*) 'X Y Stream-Function'
do i=1,imax+2
do j=1,jmax+2
write(1,*) i,' ',j,' ',Psi(i,j)
end do
end do
close(1)

write(*,*) ''
write(*,*) ''
write(*,*) ' *** Done! ***'
read(*,*)
end program SimpleCavity

tas38 April 19, 2014 09:19

I am not sure if the results are correct, but I was able to compile (gfortran 4.6.3 with no flags) and run your code. The values exported were not NaN but real valued.

Note: in your integer declaration on line 5, there should be a comma following "cloc"

alinaghedifar April 21, 2014 02:17

Thank you very much.

alinaghedifar April 21, 2014 02:18

Thank you very much tas38.


All times are GMT -4. The time now is 14:28.