// Compile using g++ -O or cpp -O or CC -O depending on architecture. // random numbers might give trouble on some architectures, though... // // Main parameters are: gxmax, gymax - grid size // nparticles - no of particles to deposit // p_solid - sticking probabilities // seed - random number seed // // Output files are: field.dat (dump of the whole grid, x y color format) // ordered.dat (chronological list of particle deposits. // x y no. format). // fractal dimension as function of box size. // // Probably ordered.dat is most useful for fractal dimensions... // // #include #include #include #include //------------------------------------------------------------------- void fileoutput(int world[], int xmax, int ymax); void iterate(int world[], int neighbourx[][8], int neighboury[][8], int xmax, int ymax, int nparticles, double p_move, double p_solid, int colstep, int colrange ); void fractal(int world[], int xmax, int ymax, int nparticles); void init(int world[], int neighbourx[][8], int neighboury[][8], int xmax, int ymax); const int gxmax=300; // size of the grid const int gymax=300; int gworld[gxmax*gymax]; int gneighbourx[gxmax*gymax][8]; int gneighboury[gxmax*gymax][8]; //------------------------------------------------------------------- int main() { double p_move=0.99; // less than one to guarantee ergodicity double p_solid=0.9; // sticking probability int seed=2; // random seed int nparticles=8000; // number of particles int colstep=50; int colrange=10; srand(seed); init(gworld, gneighbourx, gneighboury, gxmax, gymax); iterate(gworld,gneighbourx, gneighboury,gxmax,gymax,nparticles, p_move,p_solid,colstep,colrange); fractal(gworld,gxmax,gymax,nparticles); fileoutput(gworld,gxmax,gymax); return 0; } //------------------------------------------------------------------- void init(int world[], int neighbourx[][8], int neighboury[][8], int xmax, int ymax) { int x,y,yy; int x1,x2,y1,y2; // neighbour coordinates for(y=0;y0 ? x-1 : xmax-1); // find the neighbour x and y coordinates x2= (x0 ? y-1 : ymax-1); y1*=xmax; y2= (yymax) blmax=xmax; else blmax=ymax; for(bl=2;bl