文档详情

一维对流扩散问题求解..doc

发布:2017-01-08约字共31页下载文档
文本预览下载声明
Subjects:A property is transported by means of convection and diffusion through the one-dimensional domain. The governing equation is; boundary conditions are at x=0 and at x=L. Using five equally spaced cells and the central differencing scheme for convection and diffusion calculate the distribution of as a function of x for (i)Case 1: case 1 u=0.1 m/s, (ii) Case2: Case 1: u=2.5 m/s, and compare the results with the analytical solution. (iii)Case 3: recalculate the solution for case 3 u=2.5m/s with 20 grid nodes and compare the results with the analytical solution, the following date apply: length L=1.0 m,. Solution: Programming language: File name:二维稳态导热.cpp Compile software: Microsoft Visual C++ 6.0 Code: #include iostream #includemath.h #includestdlib.h using namespace std; #define Gn1 5 //网格节点数. #define Gn2 20 //网格节点数. #define P 1 //流体密度,单位:kg/m/m/m. #define ProA 1 //A端传递特性. #define ProB 0 //B端传递特性. //////FDD///////追赶法过程 void TDMA1(double a[],double b[], double c[] ,double f[],double *p) { //矩阵形式 //b0 c0 0 0 //=f0 //a0 b1 c1 0 //=f1 //... ... ... ... ... //0 0 ... b(N-1) c(N-2) //=f(N-1) double d[Gn1-1],u[Gn1],ll[Gn1-1], y[Gn1],X[Gn1]; int i; for(i=0; i=Gn1-2;i++) { d[i] = c[i]; } u[0] = b[0]; for(i=1; i=Gn1-1;i++) { ll[i-1]=a[i-1]/u[i-1]; u[i]=b[i]-ll[i-1]*c[i-1]; } y[0]=f[0]; for(i=1; i=Gn1-1;i++) { y[i]=f[i]-ll[i-1]*y[i-1]; } X[Gn1-1]=y[Gn1-1]/u[Gn1-1]; for (i=Gn1-2; i=0;i--) { X[i]=(y[i]-c[i]*X[i+1])/u[i]; } for (i=0; i=Gn1-1;i++) *(p+i)=X[i]; } void TDMA2(double a[],double b[], double c[] ,double f[],double *p) { double d[Gn2-1],u[Gn2],ll[Gn2-1], y[Gn2],X[Gn2]; int i; for(i=0;i=Gn2-2;i++) { d[i]=c[i]; } u[0] = b[0]; for(i=1;i=Gn2-1;i++) { ll[i-1]=a[i-1]/u[i-1]; u[i]=b[i]-ll[i-1]*c[i-1]; } y[0] = f[0]; for(i=1;i=Gn2-1;i++) { y[i]=f[i]-ll[i-1]*y[i-1]; } X[Gn2-1]=y[Gn2-1]/u[Gn2-1]; for (i=Gn2-2;i=0;i--) { X[
显示全部
相似文档