/* ============================================================================ Name : furtszam.c Author : Stippinger Marcell Version : 1.0 Copyright : BME-TTK FI SzamSzim gyak segedanyag Description : Simple cluster counting in C, Ansi-style ============================================================================ */ #include #include #include #include /* Spin value type */ typedef unsigned char byte; /* Spins */ #define UP 0 #define DOWN 1 #define SEEN 255 /* Lattice dimension */ #define DIMENSION 2 /* Integer power implementation */ int power(int base, int exponent) { int n, product=1; for (n=exponent; n>0; n--) { product*=base; } return product; } /* Initialize a random sample with given occupation probability */ void init_sample(gsl_rng *r, byte *sample, long volume, double probability) { long i; /* index throught the elements of the sample */ for (i=0; i=volume) { neighbour-=volume; } /* If the neighbour of the same spin, it belongs to the * cluster so we have to remember to treat it */ if (sample[neighbour]==mycolor) { *(++queue_tail) = neighbour; /* put the neighbour cell in the queue */ sample[neighbour] = SEEN; /* and mark it as visited */ } } /* Move the head pointer of the queue to the next element in the queue * please note, that we are only changing the variable "queue_head", not "queue" */ queue_head++; } return (queue_tail-queue)+1; /* number of elements put into the queue */ } /* Count the clusters of UP spins */ long cluster_count(byte* sample, long volume, long *step, long* queue) { long i, /* index throught the elements of the sample */ count=0, /* cluster counter */ min_size=volume+1, /* minimum cluster size found */ max_size=-1; /* maximum cluster size found */ long cluster_size; /* the size of the cluster */ /* Search all the lattice for UP spins */ for (i=0; i max_size) { max_size=cluster_size; } } } /* Do output */ printf("%d\t%d\t%d\n", count, min_size, max_size); return count; } int main(int argc, char* argv[], char* envp[]) { int j; /* step indexing variable */ byte *sample; /* lattice using helical boundary conditions */ long *queue; /* queue maximally the same size as the lattice */ long sidelength = 1000; /* sidelength of the lattice */ long volume = power(sidelength,DIMENSION); /* volume of the lattice */ long step[2*DIMENSION]; /* possible steps (composite numbers) */ double p; /* occupation probability */ const double dp = 0.010;/* delta p */ /* GSL RNG */ const gsl_rng_type * T; gsl_rng * r; gsl_rng_env_setup(); T = gsl_rng_mt19937; r = gsl_rng_alloc (T); /* Create composite indices for all possible step directions */ for (j=0; j