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

Please help me on my Fortran code

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   April 16, 2014, 14:07
Unhappy Please help me on my Fortran code
  #1
New Member
 
S. Ali Naghedifar
Join Date: Feb 2014
Posts: 3
Rep Power: 3
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, 09:19
Default
  #2
Member
 
Troy Snyder
Join Date: Jul 2009
Posts: 68
Rep Power: 9
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, 02:17
Default
  #3
New Member
 
S. Ali Naghedifar
Join Date: Feb 2014
Posts: 3
Rep Power: 3
alinaghedifar is on a distinguished road
Thank you very much.
alinaghedifar is offline   Reply With Quote

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

Reply

Tags
cavity, fortran, stream function, vorticity

Thread Tools
Display Modes

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 On
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 11:03
CGNS fortran code compiling with intel visual fortran xe dokeun Main CFD Forum 1 April 5, 2012 21: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 17:02
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 15:56


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