//###################################################################################### // // Copyright, 2009, Wang Xian, Tokyo Institute of technology // -- HSMAC.c (Feb.2009) // -- Using HSMAC (Highly Simplified Marker and Cell) method to solve the 2D cavity flow // -- CPU code //###################################################################################### #include #include #include #include //what is this? #include #include #include #include #define DOUBLE float #ifndef max #define max(x,y) (((x)<=(y)) ? (y):(x)) #endif #ifndef min #define min(x,y) (((x)>=(y)) ? (y):(x)) #endif #define abs(x) (((x)<0) ? (-x):(x)) /* NOTICE: when using expression a+b, abs((a+b)) should be used instead of abs(a+b) */ //------------------------------------------------------------------------------------------ void init (int,int,DOUBLE,DOUBLE**,DOUBLE**,DOUBLE**); DOUBLE HSMAC_CPU(int,int,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE**,DOUBLE**,DOUBLE**,DOUBLE**,DOUBLE**); void final_output(int,int,int,DOUBLE,DOUBLE,DOUBLE**,DOUBLE**,DOUBLE**) ; void computation_con(int,int,DOUBLE**,DOUBLE**,DOUBLE**); DOUBLE cpu_time(); //********************** START MAIN ******************************************************************** int main(int argc, char *argv[]) { char input[20]; int nx, ny, cycle, cycle_max, output, tt, yy; // real nodes: 1--(nx-2) 1--(ny-2) // imaginary nodes: (0 & nx-1) (0 & ny-1) DOUBLE dt,dx,dy,lx,ly; DOUBLE Re,u_0,omg,epsp; DOUBLE **p0, **u0, **v0, **un, **vn; DOUBLE cpu_t=0.0, cpu_t0=0.0, delt_t=0.0, divmax_cpu=0.0; FILE * time_data, * in_data; //------------------------------------------------------------------------- if((in_data=fopen("INPUT.dat","r"))==NULL) { printf("cannot open this file\n"); exit(0); } if((time_data=fopen("time.dat","w"))==NULL) { printf("cannot open this file\n"); exit(0); } //read paramenter: nx,ny,cycle,cycle_max,output,Re,rho_0,u_0; fscanf(in_data,"%s%d\n",input,&nx); fscanf(in_data,"%s%d\n",input,&ny); fscanf(in_data,"%s%d\n",input,&cycle); /* time step, that is loop counter */ fscanf(in_data,"%s%d\n",input,&cycle_max); /* maximum number of loop */ fscanf(in_data,"%s%d\n",input,&output); /* output interval */ /* NOTICE: double type parameter should use %lf or %le to read !!*/ fscanf(in_data,"%s%f\n",input,&Re); fscanf(in_data,"%s%f\n",input,&dt); fscanf(in_data,"%s%f\n",input,&omg); fscanf(in_data,"%s%f\n",input,&epsp); fclose(in_data); printf("-----Please check the input data!!-----\n"); printf("nx=%d ny=%d cycle=%d cyclemax=%d output=%d\n",nx,ny,cycle,cycle_max,output); printf("Re=%f dt=%f omg=%f epsp=%f\n",Re,dt,omg,epsp); //------------------------------------------------------------------------------- lx = 1.0; ly = 1.0; u_0 = 1.0; //(non-dimensional) dx = lx/(float)(nx-2); dy = ly/(float)(ny-2); //---------------------------------------------------------------------------------- u0 = NULL; v0 = NULL; p0 = NULL; un = NULL; vn = NULL; //------------------------------------------------------------------------------------ /* allocate 2D density rho */ u0=(DOUBLE **)calloc(ny,sizeof(DOUBLE *)); for(yy=0;yy