#include #include #include /* * Simple Ising model simulation program * Uses heat bath update * The program simulates Ising model at the given coupling * Prints out measurements of energy and magnetization * * Needs files: ising_sim.c mersenne.h mersenne_inline.c * To compile: * cc -O2 -o ising_sim ising_sim.c mersenne_inline.c -lm * * Asks parameters to be used */ #include "mersenne.h" /* Lattice size, adjust */ #define NX 64 #define NY 64 /* How many iterations for each measurements */ #define N_MEASURE 10 /* spin storage */ static int s[NX][NY]; static double beta; /* Neighbour index arrays, to be filled at the beginning */ static int xup[NX],yup[NY],xdn[NX],ydn[NY]; void update(void); void measure(int iter, FILE *f); int main(int argc, char* argv[]) { int i,x,y,n_loops; long seed; char fname[200]; FILE *f; /* Read in the input */ printf(" Beta (value 0: beta_c = log(1+sqrt(2))) : "); scanf("%lg",&beta); if (beta == 0.0) beta = log(1+sqrt(2.0)); /* critical beta */ printf(" Number of update sweeps : "); scanf("%d",&n_loops); printf(" Name of measurement file : "); scanf("%s",fname); f = fopen(fname,"w"); /* open output file */ printf(" Random number seed : "); scanf("%ld",&seed); seed_mersenne( seed ); /* "Warm up" the rng generator */ for (i=0; i<543210; i++) mersenne(); printf(" ++++++++++++++++++++++++++++++++++++++++++\n"); printf(" Ising model, %d x %d lattice, beta %g\n",NX,NY,beta); printf(" Heat bath update, %d updates/measurement, %d updates\n", N_MEASURE, n_loops); printf(" Output file %s\n",fname); printf(" Random seed %ld\n", seed ); /* fill up the index array */ for (i=0; i