1、采用 lax 格式用 C 语言模拟一维激波管问题#include#include#include#define N 101#define j 0int main()FILE *fp;double timeOut=0.006,lendom = 10.0,dx = lendom/(N- 1),DiniL,DiniR ,Tini = 300.0,PiniL = 10.0,PiniR = 1.0,dt0,Eini,aini,Hini,uini = 0.0,gamm = 1.4,R = 287.0,CFL = 0.98; /初始条件DiniL = 100000.0*PiniL/(R*Tini);Dini
2、R = 100000.0*PiniR/(R*Tini); /求初始密度Eini = R*Tini/(gamm - 1.0); /求初始 eaini = sqrt(gamm*R*Tini); /求初始声速Hini = gamm*R*Tini/(gamm - 1.0); /求初始 hdt0 = CFL*dx/aini;int i,k;double D2N,E2N,a2N,H2N,U12N,U22N,dt2N,U32N,F12N,F22N,F32N,u2N, C2N,P2N;double time ,dt1;time=0;for(i=0;i0?Cj+1i+uj+1i:Cj+1i-uj+1i) ;/a
3、=/c/+/u/dtj+1i = CFL*dx/aj+1i;dt1=(dtj+1i-1dtj+1i)?dtj+1i:dtj+1i-1;time=time+dt1;U1j+10=U1j+11;U1j+1N-1=U1j+1N-2;U2j+1N-1=U2j+1N-2 ;U2j+10=U2j+11;U3j+1N-1=U3j+1N-2 ;U3j+10=U3j+11;F1j+10=F1j+11;F1j+1N-1=F1j+1N-2;F2j+1N-1=F2j+1N-2 ;F2j+10=F2j+11;F3j+1N-1=F3j+1N-2 ;F3j+10=F3j+11;uj+1N-1=uj+1N-2 ;uj+10=
4、uj+11;Ej+1N-1=Ej+1N-2 ;Ej+10=Ej+11;Dj+1N-1=Dj+1N-2 ;Dj+10=Dj+11;Pj+1N-1=Dj+1N-2 ;Pj+10=Dj+11;Hj+1N-1=Hj+1N-2 ;Hj+10=Hj+11;Cj+1N-1=Cj+1N-2 ;Cj+10=Cj+11;aj+1N-1=aj+1N-2 ;aj+10=aj+11;dtj+1N-1=dtj+1N-2 ;dtj+10=dtj+11;for(i=0;iN;i+)C0i=C1i;C1i=0;D0i=D1i;D1i=0;u0i=u1i;u1i=0;E0i=E1i;E1i=0;P0i=P1i;P1i=0;H0i
5、=H1i;H1i=0;a0i=a1i;a1i=0;U10i=U11i;U11i=0;U20i=U21i;U21i=0;U30i=U31i;U31i=0;F10i=F11i;F11i=0;F20i=F21i;F21i=0;F30i=F31i;F31i=0;while(timetimeOut);double Ma2N;for(i=0;iN;i+)Ma0i=u0i/C0i;printf(“Xtt 密度tt 压力tt 速度tt 马赫数n“);for(i=0;iN-1;i+)printf(“%ft%ft%ft%ft%fn“,dx*i,D0i, P0i,u0i,Ma0i);printf(“n 时间:%fn“,time);fp=fopen(“date.txt“,“wb+“);fprintf(fp,“Xtt 密度tt 压力 tt 速度tt 马赫数rn“);for(i=0;iN-1;i+)fprintf(fp,“%ft%ft%ft%ft%frn“,dx*i,D0i, P0i,u0i,Ma0i);fprintf(fp,“rn 时间:%fn“,time);fclose(fp);