Boundary layer over a flat plate using CFD

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

May 12, 2011, 19:18
Boundary layer over a flat plate using CFD
#1
New Member

hasan
Join Date: Apr 2011
Posts: 3
Rep Power: 7
I want to solve Continuity and x-momentum Equations using Finite Volume method and first upwind scheme. I wrote a code for this problem but it doesnt work. I got NaN error. Can you help me to find my mistake? Here is my code:
clear all
clc
cv=10;
xi=0; xf=0.1; yi=0; yf=0.1; dx=(xf-xi)/cv; dy=(yf-yi)/cv; U=zeros(cv); v=zeros(cv+1); u=zeros(cv+1); uinf=1; maxerr=1; k=0; nu=15.11*10^-6; D=nu/dy; u(1,=0;
while maxerr>0.000001
k=k+1Uold=U;vold=v;for i=2:cv for j=2:cvu(i,1)=uinf;u(i,cv+1)=u(i,cv);u(i,j)=(U(i-1,j)+U(i,j))/2;u(cv+1,1)=uinf;u(cv+1,i)=uinf;u(i,cv+1)=u(i,cv); u(1,cv+1)=u(1,cv);u(i,cv+1)=u(i,cv);u(cv+1,cv+1)=u (cv+1,cv);u(1,j)=0; endend U(1,1)=(u(1,1)*uinf+D*U(2,1))/(u(1,2)+3*D+v(2,1)); U(cv,1)=((u(1,1)+2*D)*uinf+((v(cv,1)+D)*U(cv-1,1)))/(u(cv,2)+3*D); U(cv,cv)=(u(cv,cv)*U(cv-1,cv)+D*U(cv,cv-1)+2*D*uinf)/(u(cv,cv)+3*D); U(1,cv)=((u(1,cv))*U(1,cv-1)+D*U(2,cv))/(u(1,cv+1)+v(2,cv)+3*D); for i=2:cv-1 for j=2:cv-1 U(1,j)=(((v(1,j-1))+D)*U(i-1,j)+u(1,1)*uinf)/(u(i,j)+(v(i,j))+2*D); U(cv,j)=((u(cv,j))*U(cv-1,j)+((v(cv,j))+D)*U(cv,j-1)+D*U(cv-1,j))/(u(cv,j)+(v(cv,j))+2*D); U(i,cv)=(((u(i,cv)))*U(i-1,cv)+((v(i,cv))+D)*U(i,cv-1)+2*D*uinf)/(u(i,cv+1)+3*D); U(i,1)=((u(i,1))*U(i-1,1)+D*U(i+1,1))/((u(i-1,1))+(v(i,2))+3*D); U(i,j)=(u(i-1,j)*U(i-1,j)+(v(i,j-1)+D)*U(i,j-1)+D*U(i,j+1))/(u(i+1,j)+v(i,j+1)+2*D); end end for i=2:cv for j=2:cv-1 v(i,j+1)=u(i+1,j)-u(i-1,j)+u(i,j-1); end end for i=1:cv for j=1:cv er=abs(U(i,j)-Uold(i,j)); if er>maxerr maxerr=er; end end endend
Attached Files
 code.txt (1.9 KB, 12 views)

May 12, 2011, 21:28
#2
Member

Skeptic
Join Date: Mar 2009
Posts: 67
Rep Power: 9
Quote:
 Originally Posted by hsnclk I want to solve Continuity and x-momentum Equations using Finite Volume method and first upwind scheme. I wrote a code for this problem but it doesnt work. I got NaN error. Can you help me to find my mistake? Here is my code: clear all clc cv=10; xi=0; xf=0.1; yi=0; yf=0.1; dx=(xf-xi)/cv; dy=(yf-yi)/cv; U=zeros(cv); v=zeros(cv+1); u=zeros(cv+1); uinf=1; maxerr=1; k=0; nu=15.11*10^-6; D=nu/dy; u(1,=0; while maxerr>0.000001 k=k+1Uold=U;vold=v;for i=2:cv for j=2:cvu(i,1)=uinf;u(i,cv+1)=u(i,cv);u(i,j)=(U(i-1,j)+U(i,j))/2;u(cv+1,1)=uinf;u(cv+1,i)=uinf;u(i,cv+1)=u(i,cv); u(1,cv+1)=u(1,cv);u(i,cv+1)=u(i,cv);u(cv+1,cv+1)=u (cv+1,cv);u(1,j)=0; endend U(1,1)=(u(1,1)*uinf+D*U(2,1))/(u(1,2)+3*D+v(2,1)); U(cv,1)=((u(1,1)+2*D)*uinf+((v(cv,1)+D)*U(cv-1,1)))/(u(cv,2)+3*D); U(cv,cv)=(u(cv,cv)*U(cv-1,cv)+D*U(cv,cv-1)+2*D*uinf)/(u(cv,cv)+3*D); U(1,cv)=((u(1,cv))*U(1,cv-1)+D*U(2,cv))/(u(1,cv+1)+v(2,cv)+3*D); for i=2:cv-1 for j=2:cv-1 U(1,j)=(((v(1,j-1))+D)*U(i-1,j)+u(1,1)*uinf)/(u(i,j)+(v(i,j))+2*D); U(cv,j)=((u(cv,j))*U(cv-1,j)+((v(cv,j))+D)*U(cv,j-1)+D*U(cv-1,j))/(u(cv,j)+(v(cv,j))+2*D); U(i,cv)=(((u(i,cv)))*U(i-1,cv)+((v(i,cv))+D)*U(i,cv-1)+2*D*uinf)/(u(i,cv+1)+3*D); U(i,1)=((u(i,1))*U(i-1,1)+D*U(i+1,1))/((u(i-1,1))+(v(i,2))+3*D); U(i,j)=(u(i-1,j)*U(i-1,j)+(v(i,j-1)+D)*U(i,j-1)+D*U(i,j+1))/(u(i+1,j)+v(i,j+1)+2*D); end end for i=2:cv for j=2:cv-1 v(i,j+1)=u(i+1,j)-u(i-1,j)+u(i,j-1); end end for i=1:cv for j=1:cv er=abs(U(i,j)-Uold(i,j)); if er>maxerr maxerr=er; end end endend
Very easy. There should be a space in "endend", ie. make it "end end".

 May 13, 2011, 01:52 #3 New Member   hasan Join Date: Apr 2011 Posts: 3 Rep Power: 7 no there is not missing line. the code looks like that when it is uploaded here, that's why I also added code.txt file..

 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 waynezw0618 OpenFOAM 6 August 12, 2010 02:19 Luk CFX 3 February 27, 2009 04:22 Eldude Main CFD Forum 2 October 16, 2008 02:44 Xavier Silvani Main CFD Forum 0 September 22, 2005 08:14 Biga Main CFD Forum 0 June 17, 2005 15:30

All times are GMT -4. The time now is 06:43.