您好,欢迎访问三七文档
//Arthor:吴昱驹//e-mail:328522073@qq.com//date:2013/01/06//四点线性隐格式计算法进行洪水演算//由河海大学计算水力学王船海老师的Fortran程序翻译成C语言//#includeWindows.h#includestdio.h#includestdlib.h#includemath.h#defineNSR30#definePI3.14159intN,NT,IC,ID,IT;intL1,L2,IB;doubleZU,ZD,X;doubleDX,DT,CT,CN0;doubleZ1,Z2,Q1,Q2,A1,A2,B1,B2,R1,R2,U1,U2;doubleP,V,DTT;doubleRDX,SA,SB,BC,C,D,E,F,G,O;doubleY1,Y2,Y3,Y4,W,S,T;//水位流量河段长PVST糙率doubleZZ[NSR],QQ[NSR],DXX[NSR],PP[NSR],VV[NSR],SS[NSR],TT[NSR],CNO[NSR];doubleMT;voidinput();voidoutput();voidEXTERN();voidBAEXT();voidABR(inti,doubleZ,doubleQ,double*B,double*A,double*R,double*U);intmain(intargc,char*argv[]){inti;input();for(i=1;i=N;i++){DXX[i]=DX*1000;CNO[i]=CN0;ZZ[i]=4.0+0.025*(N+1-i);QQ[i]=0.0;}MT=60/DT;DT=DT*60;DTT=2*DT;L1=1;L2=N;if(IC==1){IB=0;ZU=4.5;}elseif(IC==2){IB=1;ZU=500;}else{IB=1;}//以上是初始条件printf(小时数0时段0--断面1断面6断面11断面16断面21(水位Z)\n);for(ID=0;ID=NT;ID++){for(IT=1;IT=MT;IT++){X=ID+IT/MT;ZD=4+1.5*sin(PI*X/12);if(IC==1){P=ZU;V=0.0;}elseif(IC==2){P=ZU;V=0.0;}else{V=20E6/DT;P=V*ZZ[L1];}EXTERN();ZZ[L2]=ZD;QQ[L2]=P-V*ZD;BAEXT();output();}}//for(i=1;i=21;i++)//printf(%lf\n,QQ[i]);system(pause);return0;}voidinput(){N=21;NT=48;IC=1;DX=1.0;DT=10.0;CT=0.75;CN0=0.02;}voidEXTERN(){intj;Z1=ZZ[L1];Q1=QQ[L1];ABR(L1,Z1,Q1,&B1,&A1,&R1,&U1);PP[L1]=P;VV[L1]=V;for(j=L1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);*B=100+6*DH;*A=(*B+100)*DH/2;*R=(*A)/(*B);if(*R=0.1)*R=0.1;*U=Q/(*A);}
本文标题:计算水力学代码
链接地址:https://www.777doc.com/doc-4279636 .html