2 * ising.c - visualization of ising spins in an N x N lattice
6 * author: hackbard@hackdaworld.dyndns.org
20 int main(int argc, char **argv)
27 int max_x,x_c,max_y,y_c;
39 /* we will parse argv later ... */
43 d2_lattice_init(&argc,argv,&d2_l,max_x,max_y);
45 atom=(unsigned char *)(malloc(max_x*max_y*sizeof(unsigned char)));
49 /* begin at T=0 M=1 situation */
50 memset(atom,0,max_x*max_y*sizeof(unsigned char));
52 S=1; /* i have no idea! */
56 beta=1.0/T; /* k_B = 1 */
57 /* do 100 itterations, we will need more */
61 for(x_c=0;x_c<max_x;x_c++)
63 for(y_c=0;y_c<max_y;y_c++)
67 if((*(atom+x_c+((2*y_c+1)%max_y)*max_x))&1) ++count_p;
68 if((*(atom+x_c+((2*y_c-1)%max_y)*max_x))&1) ++count_p;
69 if((*(atom+((2*x_c+1)%max_x)+y_c*max_x))&1) ++count_p;
70 if((*(atom+((2*x_c-1)%max_x)+y_c*max_x))&1) ++count_p;
71 if(((*(atom+x_c+y_c*max_x))&1)==0) count_p=4-count_p;
72 delta_e=(4-2*count_p)*S;
73 if(delta_e<0) *(atom+x_c+y_c*max_x)=(*(atom+x_c+y_c*max_x)+1)&1;
76 if(1.0*rand()/RAND_MAX<exp(-1.0*delta_e*beta))
77 *(atom+x_c+y_c*max_x)=(*(atom+x_c+y_c*max_x)+1)&1;
82 sprintf(t_text,"T = %d",T);
84 sprintf(b_text,"b = %f",beta);
86 sprintf(m_text,"M = %f",1.0-2*M/(max_x*max_y));
88 d2_lattice_draw(&d2_l,0,0,3,arg_v);