/*** mc.c: simple Ising simulation ***/ #include #include #include /** macros **/ /* for allocating memory in a nice way: **/ #define TFNE_MALLOC_AH(POINTER,ANZAHL,TYPE,STRING) \ { POINTER = (TYPE *) malloc((ANZAHL)*sizeof(TYPE)); \ if(POINTER == NULL) \ { fprintf(stderr, "Achtung: Kein Speicher fuer %s \n", STRING); exit(1);}} /* for using this macros the variables dim,next,j have to be */ /* (locally) defined ! */ /* use the macro 'NEXT' to access the neighbours of a spin */ /* NEXT(t,r) gives the neighbour of spin with id 't' */ /* in direction 'r', with r=0: +x direction, r=1: -x direction */ /* r=2: +y direction, r=3: -y direction */ /* The subroutine mf_init_short takes care of the initalization. */ /* You can use it as a black box, i.e. you don't have to under- */ /* stand that subroutine. */ /* An example how NEXT is used is give in the subroutine 'energy'. */ /* You have to read and to understand that subroutine! */ #define INDEX(t, r, d) ((t)*(2*(d)+2)+r) #define NEXT(t, r) next[INDEX(t, r, dim)] /******************* mf_init_arr() **********************/ /** Allocates and initialises 'n[]', 'N', 'next[][]', **/ /** 't_feld[]' **/ /** PARAMETERS: (*)= return-paramter **/ /** dim: dimension of system **/ /** l: size of system in x,y,.. **/ /** period: with pbc ? **/ /** (*) n_p: p. tosize of 0,1,.. dimensional plane **/ /** (*) N_p: p. to number of spins = inner nodes **/ /**(*) next_p: gives neighbours next[0..N][0..2*dim+1] **/ /** in +x,-x,+y,-y,...,N+1 (sink), 0(source) **/ /** RETURNS: **/ /** 0-> OK **/ /********************************************************/ int mf_init_short(int dim, int *l, int period, int **n_p, int *N_p , int **next_p) { int t, t2, N; int *n, *next; TFNE_MALLOC_AH(n, dim+1, int, "n-Feld"); *n_p = n; n[0] = 1; for(t=1; t0) printf("+"); else printf("-"); if(t%L == 0) printf("\n#"); } printf("\n"); free(n); free(l); free(next); free(spin); /* free memory */ return(0); }