#include <stdlib.h>
#include <string.h>
#include <math.h>
+#include <time.h>
+
#include "dfbapi.h"
-#define X 50
-#define Y 50
-#define MAX_T 200
+#define X 200
+#define Y 200
+#define MAX_T 10
int main(int argc, char **argv)
{
unsigned char *atom;
+ char *arg_v[4];
+ char m_text[64];
+ char t_text[64];
+ char b_text[64];
int max_x,x_c,max_y,y_c;
- int i,j;
+ int i;
+ int count_p;
unsigned int T;
- double M;
+ double S;
+ int M;
double beta;
double delta_e;
+ /* random stuff*/
+ srand(time(0));
+
/* display stuff */
d2_lattice d2_l;
/* begin at T=0 M=1 situation */
memset(atom,0,max_x*max_y*sizeof(unsigned char));
+ S=1; /* i have no idea! */
+
for(T=1;T<MAX_T;T++)
{
- beta=1.0/T; /* k_B = 1 */
- /* do N*N itterations, we will need more */
- for(i=0;i<max_x*max_y;i++)
+ beta=5.0/T; /* k_B = 1 */
+ /* do 100 itterations, we will need more */
+ for(i=0;i<100;i++)
{
- for(x_c=0;x_c<max_x-1;x_c++)
+ M=0;
+ for(x_c=0;x_c<max_x;x_c++)
{
- for(y_c=0;y_c<max_y-1;y_c++)
+ for(y_c=0;y_c<max_y;y_c++)
{
- delta_e=0;
- // delta_e+=(-1*(int)(atom
+ count_p=0;
+ if((*(atom+x_c+((y_c+max_y+1)%max_y)*max_x))&1) ++count_p;
+ if((*(atom+x_c+((y_c+max_y-1)%max_y)*max_x))&1) ++count_p;
+ if((*(atom+((max_x+x_c+1)%max_x)+y_c*max_x))&1) ++count_p;
+ if((*(atom+((max_x+x_c-1)%max_x)+y_c*max_x))&1) ++count_p;
+ if(((*(atom+x_c+y_c*max_x))&1)==0) count_p=4-count_p;
+ delta_e=(2*count_p-4)*S;
+ if(delta_e<0) *(atom+x_c+y_c*max_x)=(*(atom+x_c+y_c*max_x)+1)&1;
+ else
+ {
+ if(1.0*rand()/RAND_MAX<exp(-1.0*delta_e*beta))
+ *(atom+x_c+y_c*max_x)=(*(atom+x_c+y_c*max_x)+1)&1;
+ }
+ if((*(atom+x_c+y_c*max_x))&1) ++M;
}
-
}
-
+ sprintf(t_text,"temp = %d",T);
+ arg_v[1]=t_text;
+ sprintf(b_text,"beta = %f",beta);
+ arg_v[2]=b_text;
+ sprintf(m_text,"magn = %f",1.0-2.0*M/(max_x*max_y));
+ arg_v[3]=m_text;
+ d2_lattice_draw(&d2_l,0,0,3,arg_v);
}
- d2_lattice_draw(&d2_l,0,0,0,NULL);
}
getchar();