/******************Poiseuille flow using LBM*********************** Based on procedures as explained in 'Lattice Gas Cellular Automata and Lattice Boltzmann Models'by Wolf Gladrow compile using gcc. For plotting you may require gnuplot in your system tested on Linux (Ubuntu/Fedora Envt with gcc and gnuplot) */ #include #include float OMEGA=0.2; /*Relaxation factor*/ float TAU=0.5; /* Sahu: Increase XMAX and YMAX to increase execution time*/ #define XMAX 512 /*Mesh size in x-direction */ #define YMAX 512 /*Mesh size in y-direction */ #define ZMAX 10 /*Not a-direction */ #define STEP 8 #define MAXiter 200 float FORCING=(1.024)/YMAX*YMAX*YMAX;/*Forcing term in Poiseuille equation*/ float KVISC = ((1/0.2)-0.5)/3; float UX; int cx[9]={1, 0, -1, 0, 1, -1, -1, 1,0}; /*components of lattice velocities in x-direction*/ int cy[9]={0, 1, 0, -1, 1, 1, -1, -1, 0}; /*components of lattice velocities in y-direction*/ float jx[XMAX][YMAX]; float jy[XMAX][YMAX]; float rho[XMAX][YMAX]; float f[XMAX][YMAX][XMAX]; float fprop[XMAX][YMAX][XMAX]; float feq[XMAX][YMAX][XMAX]; float u[XMAX][YMAX],v[XMAX][YMAX]; float force; float uprofile[YMAX]; void JxJyRhoFFprop(int s, int e){ int i,j; for(i=s;i0) fprintf(fp,"%d ", iter); for (y=0;y0) fprintf(fp," %5.5f", uprofile[y]); } fprintf(fp,"\n"); } /*for each iteration*/ fclose(fp); } void Plot(){ // Serialized code, no scope of parallelization here int y,x=1; FILE *fp=fopen("gnu.cmd","w"); fprintf(fp,"set term postscript eps enhanced color \n"); fprintf(fp,"set output \"lbmout.eps\" \n"); fprintf(fp,"set xlabel \"Iterations\" \n set ylabel \"uprofile (velocities)\" \n"); fprintf(fp,"plot "); for (y=0;y<(YMAX-STEP); y+=STEP){ fprintf(fp,"\"lbmout.txt\" using 1:%d title \"uprofile%d\",",x+1, x+1); x++; } fprintf(fp,"\"lbmout.txt\" using 1:%d title \"uprofile%d\"",x+1, x+1); fclose(fp); system("gnuplot gnu.cmd"); } int main(){ Init(); /* Initialize LBM Structure*/ LBM(); /* Simulate LBM*/ Plot(); /* Plot resultant velocity uprofile of Iterations*/ return 0; }