/* From: "COMPUTATIONAL PHYSICS, 2nd Ed" by RH Landau, MJ Paez, and CC Bordeianu Copyright Wiley-VCH, 2007. Electronic Materials copyright: R Landau, Oregon State Univ, 2007; MJ Paez, Univ Antioquia, 2007; & CC Bordeianu, Univ Bucharest, 2007 Support by National Science Foundation */ // dla.c: Diffusion-limited aggregation simulation (fractals) #include #include #include // if you don't have drand48 uncomment the following two lines // #define drand48 1.0/RAND_MAX*rand // #define srand48 srand #define max 40000 // number of iterations #define size 401 // size of grid array #define PI 3.1415926535897932385E0 #define seed 68111 // seed for number generator main() { double angle, rad = 180.0; int i,j, x, y, dist,step, trav; int grid[size][size], hit; int gauss_ran(); // gaussian random number FILE *output; // save data in dla.dat output = fopen("dla.dat","w"); // clear for (i=0; i1) && (y<399) && (y>1) && (trav= 1) { // one neighbor is occupied hit = 1; grid[x][y] = 1; // particle sticks, walk is over } else if (drand48() < 0.5) x+=step; // move horizontally else y+=step; // move vertically trav++; } } for (i=0; i=1) || (rr==0)); fac = sqrt(-2*log(rr)/rr); mem = 5000*r1*fac; // save for next call old = 1; // set flag return((int)(5000*r2*fac)); } else { // return second number old = 0; // unset flag return mem; // return number from last call } }