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

 April 16, 2014, 14:07 Please help me on my Fortran code #1 New Member   S. Ali Naghedifar Join Date: Feb 2014 Posts: 3 Rep Power: 3 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

 April 19, 2014, 09:19 #2 Member   Troy Snyder Join Date: Jul 2009 Posts: 68 Rep Power: 9 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"

 April 21, 2014, 02:17 #3 New Member   S. Ali Naghedifar Join Date: Feb 2014 Posts: 3 Rep Power: 3 Thank you very much.

 April 21, 2014, 02:18 #4 New Member   S. Ali Naghedifar Join Date: Feb 2014 Posts: 3 Rep Power: 3 Thank you very much tas38.

 Tags cavity, fortran, stream function, vorticity

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Ehsan-F Fluent UDF and Scheme Programming 6 September 11, 2012 11:03 dokeun Main CFD Forum 1 April 5, 2012 21:01 diedro Main CFD Forum 3 March 12, 2011 11:20 Dong Ye Main CFD Forum 1 October 13, 2005 17:02 John C. Chien Main CFD Forum 19 May 17, 2001 15:56

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