|
[Sponsors] |
April 16, 2014, 15:07 |
Please help me on my Fortran code
|
#1 |
New Member
S. Ali Naghedifar
Join Date: Feb 2014
Posts: 7
Rep Power: 12 |
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, 10:19 |
|
#2 |
Senior Member
Troy Snyder
Join Date: Jul 2009
Location: Akron, OH
Posts: 220
Rep Power: 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" |
|
April 21, 2014, 03:17 |
|
#3 |
New Member
S. Ali Naghedifar
Join Date: Feb 2014
Posts: 7
Rep Power: 12 |
Thank you very much.
|
|
April 21, 2014, 03:18 |
|
#4 |
New Member
S. Ali Naghedifar
Join Date: Feb 2014
Posts: 7
Rep Power: 12 |
Thank you very much tas38.
|
|
Tags |
cavity, fortran, stream function, vorticity |
|
|
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 |