📄 ising model.cpp
字号:
#include"iostream.h"
#include"stdlib.h"
#include"math.h"
#include"stdio.h"
#include"string.h"
#include"Box.h"
static long seed1=28;
double rand1()
{
long m;
m=65536;
seed1=(2053*seed1+13849)%m;
return double(seed1)/m;
}
void main()
{
CBox box;
FILE *fp;
char dir[]="F:\\my study\\programme\\Ising Modl\\Mvse.txt";
fp=fopen(dir,"w");
int numheat=100;
int num=100;
int skip=5;
double J=0;
double energy;
int count;
for(double t=0;t<1.4;t=t+0.01)
{
box.SetE(t);
for(int c=0;c<numheat;c++)
{
for(int i=0;i<box.N;i++)
{
for(int j=0;j<box.N;j++)
{
J=box.CalJ(i,j);
if(J<=0)//dE<0
{
box.Reverseij(i,j);
}
else
{ count=(4-J)/2;
energy=box.Energy[count];
if(energy>=rand1())
{
box.Reverseij(i,j);
}
}
}
}
}
double M=0;
double M2=0;
for(c=0;c<num;c++)
{
for(int cc=0;cc<=skip;cc++)
{
for(int i=0;i<box.N;i++)
{
for(int j=0;j<box.N;j++)
{
J=box.CalJ(i,j);
if(J<=0)//dE<0
{
box.Reverseij(i,j);
}
else
{ count=(4-J)/2;
energy=box.Energy[count];
if(energy>=rand1())
{
box.Reverseij(i,j);
}
}
}
}
}
M=M+box.CalM();
M2=M2+box.CalM()*box.CalM();
}
M=M/(num*box.number);
M2=M2/(num*box.number*box.number);
double x=num*box.e*(M2-M*M);
cout<<"the e is "<<box.e<<endl;
cout<<"the M is "<<M<<endl;
cout<<"the x is "<<x<<endl;
fprintf(fp,"%f,%f,%f\n",box.e,M,x);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -