/*********************************************************************/ /* Numerical hydrodynamics in one-dimensional space */ /* sample program using Lax-Wendroff method */ /* */ /* 11/18/93 by R.Matsumoto */ /* modified 09/25/97 by R.M. */ /*********************************************************************/ #include #include #define NX 1002 #define SAFETY 0.4 /* global variables */ float dt,tm; float qav,gm; int ns,nstop; int ix; float x[NX],dx[NX],dxm[NX],w0[NX],w1[NX],dx0; float ro[NX],rvx[NX],ee[NX],pr[NX],g; FILE *fp1,*fp2,*fp3; main() { int i,nstep; tm = 0.0; ns = 0; read_parameters(); initialize_fp(); generate_grid(); shock_tube_model(); minimum_dt(); printf("dt = %f\n",dt); for(nstep=1; nstep<=nstop; nstep++) { ns = ns+1; tm = tm+dt; Lax_Wendroff_1d(); apply_boundary_condition(); minimum_dt(); } printf("ns = %d time = %f\n",ns,tm); graph_output(); fclose(fp1); fclose(fp2); fclose(fp3); } read_parameters() { scanf("%f %f %d %d",&qav,&gm,&ix,&nstop); dx0 = 100.0/(ix-1); } initialize_fp() { if ((fp1=fopen("output.density","w+"))==NULL) { fprintf(stderr,"cannot open output.density\n"); exit(-2); }; if ((fp2=fopen("output.velocity","w+"))==NULL) { fprintf(stderr,"cannot open output.velocity\n"); exit(-2); }; if ((fp3=fopen("output.pressure","w+"))==NULL) { fprintf(stderr,"cannot open output.pressure\n"); exit(-2); }; } generate_grid() { int i; dx[0] = dx0; x[0] = 0.0; for(i=0; i