1、相变传热与流体流动数值分析作业3相变传热与流体流动数值分析作业3学 院(系): 能源与动力学院 专 业: 能源与动力工程 * * * * * * * 学 号: * 指 导 教 师: 宋永臣 教授 完 成 日 期: 2012.3.6 大连理工大学Dalian University of TechnologyThe Finite Volume Method for Convection-Diffusion ProblemsSubject:A propertyis transported by means of convection and diffusion through the one-dim
2、ensional domain sketched in Figure1.The governing equation is; boundary conditions are 0=1 at x=0 and L=0 at x=L. Using five equally spaced cells for convection and diffusion calculate the distribution of a function of x for case:(i)Case1:u=0.1m/s;(ii)Case2:u=2.5m/s;(iii)Case3:u=2.5m/s with 20 grid
3、nodes;The following data apply: Length L=1.0m, =1.0kg/m3, =0.1kg/m/s. Solution:(I)The central differencing scheme:/ 王佳琪-作业-中心差分.cpp : 定义控制台应用程序的入口点。/#include #include #include #include #include #include #include #include #include #define N 5using namespace std;int i;double awN,bN,aeN,fN,xN;/*-追赶法求解数
4、组-*/void tdma( ) double lN,uN,yN; for(i=1;iN;i+) u0=b0;l0=0; li=awi/ui-1; ui=bi-li*aei-1; y0=f0; for(i=1;i=0;i-) xi=(yi-aei*xi+1)/ui; void main() void Output( );/*-定义变量及边界条件-*/ double F,D,u,x,L,A,B,SpN; u=0.1;=1;=0.1;L=1;A=1;B=0; x=L/N; F=*u;D=/x;/*-网格离散-*/for(i=0;iN;i+) if(i=0) awi=0;aei=-(D-F/2);S
5、pi=-(2*D+F);fi=(2*D+F)*A; else if(i=N-1) aei=0;awi=-(D+F/2);Spi=-(2*D-F);fi=(2*D-F)*B; else awi=-(D+F/2);aei=-(D-F/2);Spi=0;fi=0; bi=-awi-aei-Spi; tdma(); Output( );void Output( )/*-后处理文件生成-*/ ostringstream name; name.str(); name central_.plt; ofstream out(name.str().c_str();out Title = centralendl
6、VARIABLES = X , Y1 , Y2 nZONE I=N,J=1,F=POINTendl; for(i = 0;i N ;i+) out double(0.2*i+0.1) xi (2.7183-exp(0.2*i+0.1)/1.7183 2).(II)The upwind differencing scheme:/ 王佳琪-作业3-迎风.cpp : 定义控制台应用程序的入口点。/#include stdafx.h#include #include #include #include #include #include #include #include #define N 5usi
7、ng namespace std;int i;double awN,bN,aeN,fN,xN;/*-追赶法求解数组-*/void tdma( ) double lN,uN,yN; for(i=1;iN;i+) u0=b0;l0=0; li=awi/ui-1; ui=bi-li*aei-1; y0=f0; for(i=1;i=0;i-) xi=(yi-aei*xi+1)/ui;void main() void Output( ); double Fw1,Fw,Fe1,Fe,Dw,De,u,x,L,A,B,SpN; u=0.1;=1;=0.1;L=1;A=1;B=0; x=L/N;Fw=Fe=*u
8、;Dw=De=/x; Fw1=0Fw?0:Fw; Fe1=0(-Fe)?0:(-Fe);/*-网格离散-*/ for(i=0;iN;i+) if(i=0) awi=0;aei=-(De-Fe1);Spi=-(2*Dw+Fw1);fi=(2*Dw+Fw1)*A; else if(i=N-1) awi=-(Dw+Fw1);aei=0;Spi=-(2*De+Fe1);fi=(2*De-Fe1)*B; else awi=-(Dw+Fw1);aei=-(De+Fe1);Spi=0;fi=0; bi=-awi-aei-Spi; tdma();Output( );void Output( )ostrings
9、tream name; name.str(); name upwind.plt; ofstream out(name.str().c_str(); out Title = upwind endl VARIABLES = X, Y1, Y2endlZONE I=N,J=1,F=POINTendl; for(i = 0;i N ;i+) out double(0.2*i+0.1) xi (2.7183-exp(0.2*i+0.1)/1.7183 endl; Results:(i)case1: u=0.1m/s; N=5;(ii) Case2: u=2.5m/s; N=5;Discussion:Th
10、e upwind differencing scheme produces a much more realistic solution than the central differencing scheme, however, not very close to the exact solution near boundary B. That is because that its accuracy is only first order, while the central differencing is second order. (III) The hybrid differenci
11、ng scheme:/ 王佳琪-作业-混合.cpp : 定义控制台应用程序的入口点。/#include stdafx.h#include #include #include #include #include #include #include #include #define N 5using namespace std;int i;double awN,bN,aeN,fN,xN;/*-追赶法求解数组-*/void tdma( ) double lN,uN,yN; for(i=1;iN;i+) u0=b0;l0=0; li=awi/ui-1; ui=bi-li*aei-1; y0=f0; f
12、or(i=1;i=0;i-) xi=(yi-aei*xi+1)/ui;void main() void Output( ); double Fw1,Fw,Fe1,Fe,Dw,De,u,x,L,A,B,SpN; u=2.5;=1;=0.1;L=1;A=1;B=0; x=L/N;Fw=Fe=*u;Dw=De=/x; if(Fw0&(Dw+Fw/2)0) Fw1=0; else if(Fw0) Fw1=(Dw+Fw/2); else if(Fw0&(Dw+Fw/2)0) Fw1=Fw; else if(0Fw&Fw(Dw+Fw/2) Fw1=(Dw+Fw/2); else if(0(Dw+Fw/2)
13、&(Dw+Fw/2)Fw) Fw1=Fw; if(-Fe)0&(De-Fe/2)0) Fe1=0; else if(-Fe)0) Fe1=(De-Fe/2); else if(-Fe)0&(De-Fe/2)0) Fe1=(-Fe); else if(0(-Fe)&(-Fe)(De-Fe/2) Fe1=(De-Fe/2); else if(0(De-Fe/2)&(De-Fe/2)(-Fe) Fe1=(-Fe); /*-网格离散-*/ for(i=0;iN;i+) if(i=0) awi=0;aei=-Fe1;Spi=-(2*Dw+Fw1);fi=(2*Dw+Fw1)*A; else if(i=N
14、-1) awi=-Fw1;aei=0;Spi=-(2*De+Fe1);fi=(2*De-Fe1)*B; else awi=-Fw1;aei=-Fe1;Spi=0;fi=0; bi=-awi-aei-Spi; tdma();Output( );void Output( )double m=25; ostringstream name; name.str(); name hybrid.plt; ofstream out(name.str().c_str(); out Title =hybrid endl VARIABLES = X, Y1, Y2endlZONE I=N,J=1,F=POINTen
15、dl; for(i = 0;i N ;i+) out double(0.2*i+0.1) xi (1+(1-exp(25*(0.2*i+0.1)/(exp(m)-1) endl; Results:(i)Case1:u=2.5m/s; N=5;(ii)Case 2:u=2.5m/s; N=25;Discussion:On a combination of central and upwind differencing schemes, the hybrid scheme provides a much more realistic solution and agrees the exact so
16、lution very well. The more nodes, the more accurate the result is. (IV)The power-law scheme:/ 王佳琪-作业-指数.cpp : 定义控制台应用程序的入口点。/#include stdafx.h#include #include#include#include #include #include #include #include #define N 5using namespace std;int i;double awN,bN,aeN,fN,xN;/*-追赶法求解数组-*/void tdma( ) d
17、ouble lN,uN,yN; for(i=1;iN;i+) u0=b0;l0=0; li=awi/ui-1; ui=bi-li*aei-1; y0=f0; for(i=1;i=0;i-) xi=(yi-aei*xi+1)/ui;void main()void Output( );ofstream note;double Fw,Fw1,Fe,Fe1,Dw,De,u,x,L,A,B,SpN,p,p1,Pew,Pee,q,q1;u=2.5;=1;=0.1;L=1;A=1;B=0;x=L/N;Fw=Fe=*u;Dw=De=/x;Pew=Fw/Dw;Pee=Fe/De;Fw1=0Fw?0:Fw;Fe1
18、=0(-Fe)?0:(-Fe);p=pow(1-0.1*fabs(Pew),5);p1=0p?0:p;q=pow(1-0.1*fabs(Pee),5);q1=0q?0:q;/*-网格离散-*/for(i=0;iN;i+) if(i=0) awi=0;aei=-(Fe1+De*q1);Spi=-(2*Dw+Fw1);fi=(2*Dw+Fw1)*A; else if(i=N-1) awi=-(Fw1+Dw*p1);aei=0;Spi=-(2*De+Fe1);fi=(2*De-Fe1)*B; else awi=-(Fw1+Dw*p1);aei=-(Fe1+De*q1);Spi=0;fi=0; bi=
19、-awi-aei-Spi; tdma(); Output( );void Output( )double m=25; ostringstream name; name.str(); name power-law.plt; ofstream out(name.str().c_str();out power-lowendl VARIABLES = X , Y1 , Y2 nZONE I= N,J= 1,F=POINTendl; for(i = 0;i N ;i+) out double(0.2*i+0.1) xi (1+(1-exp(25*(0.2*i+0.1)/(exp(m)-1) endl; Result:(i)Case1:u=2.5m/s; N=5;(ii)Case 2:u=2.5m/s; N=25;Discussion:This result is more accurate than the three former schemes .
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1