CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Please help me on my Fortran code

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 16, 2014, 15:07
Unhappy Please help me on my Fortran code
  #1
New Member
 
S. Ali Naghedifar
Join Date: Feb 2014
Posts: 7
Rep Power: 12
alinaghedifar is on a distinguished road
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".
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
alinaghedifar is offline   Reply With Quote

Old   April 19, 2014, 10:19
Default
  #2
Senior Member
 
Troy Snyder
Join Date: Jul 2009
Location: Akron, OH
Posts: 220
Rep Power: 19
tas38 is on a distinguished road
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"
tas38 is offline   Reply With Quote

Old   April 21, 2014, 03:17
Default
  #3
New Member
 
S. Ali Naghedifar
Join Date: Feb 2014
Posts: 7
Rep Power: 12
alinaghedifar is on a distinguished road
Thank you very much.
alinaghedifar is offline   Reply With Quote

Old   April 21, 2014, 03:18
Default
  #4
New Member
 
S. Ali Naghedifar
Join Date: Feb 2014
Posts: 7
Rep Power: 12
alinaghedifar is on a distinguished road
Thank you very much tas38.
alinaghedifar is offline   Reply With Quote

Reply

Tags
cavity, fortran, stream function, vorticity


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call FORTRAN files as UDF? Ehsan-F Fluent UDF and Scheme Programming 6 September 11, 2012 12:03
CGNS fortran code compiling with intel visual fortran xe dokeun Main CFD Forum 1 April 5, 2012 22:01
Discontinuous Galerkin schemes -- fortran source code diedro Main CFD Forum 3 March 12, 2011 11:20
Who can find me this fortran code 'CHEMR'? Dong Ye Main CFD Forum 1 October 13, 2005 18:02
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 16:56


All times are GMT -4. The time now is 00:33.