/* * It evolves the equation: * u,t + u,x + u,y = 0 * Using a Lax scheme. * The initial data is a cruddy gaussian. * Boundaries are flat: copying the value of the neighbour */ #include #include #include #include #define NX 100 #define NY 100 #define LX 2.0 #define LY 2.0 #define sigma 0.1 #define tmax 100 /* conversions from discrete to real coordinates */ float ix2x(int ix){ return ((ix - 1) - (NX-1) / 2.0)*LX/(NX-1); } /* * THE FOLLOWING CHANGES: every processor has a different offset. */ float iy2y(int iy, int proc_y, int nprocs){ return ((iy-1) - (NY-1) / 2.0 + proc_y*(NY / nprocs) + (proc_y < NY % nprocs? proc_y:NY % nprocs)) * LY/(NY-1); } /* Function for evaluating the results that calculates the sum of the array values */ float summa(int nx, int ny, float* val){ float summma=0.0; int ix,iy; for(iy=1;iy<=ny;++iy) for(ix=1;ix<=nx;++ix){ summma+=val[((nx+2)*iy)+ix]; } return(summma); } /* * initialize the system with a gaussian temperature distribution */ int init_transport(float *temp, int NLY, int proc_me,int nprocs){ int ix,iy; float x,y; for(iy=1;iy<=NLY;++iy) for(ix=1;ix<=NX;++ix){ x=ix2x(ix); y=iy2y(iy, proc_me, nprocs); temp[((NX+2)*iy)+ix] = tmax*exp((-((x*x)+(y*y)))/(2.0*(sigma*sigma))); } return 0; } /* * save the temperature distribution * the ascii format is suitable for splot gnuplot function */ int save_gnuplot(char *filename, float *temp, int NLY, int proc_me, int nprocs){ float *buf; int ix, iy, iproc=0; FILE *fp; MPI_Status status; if(proc_me == 0){ buf = (float *) malloc ((NX+2)*(NLY+2)*sizeof(float)); fp = fopen(filename, "w"); for(iy=1;iy<=NLY;++iy){ for(ix=1;ix<=NX;++ix){ fprintf(fp, "\t%f\t%f\t%g\n", ix2x(ix), iy2y(iy, proc_me, nprocs), temp[((NX+2)*iy)+ix]); } fprintf(fp, "\n"); } for(iproc=1; iproc