📄 box.cpp
字号:
// Box.cpp: implementation of the CBox class.
//
//////////////////////////////////////////////////////////////////////
#include "Box.h"
#include "math.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
int CBox ::N=60;
double rand1();
CBox::CBox()///坐标i,j均从0开始,计数
{
number=N*N;
pBox=new int[number];
for(int i=0;i<number;i++)
{
if(rand1()<0.5)
{
pBox[i]=-1;
}
else
{
pBox[i]=1;
}
}
SetE(1);
}
CBox::~CBox()
{
delete []pBox;
}
void CBox::SetE(double ee)
{
e=ee;
double t;
for(int i=0;i<5;i++)
{
t=(i*2-4)*2*e;
Energy[i]=exp(t);
}
}
double CBox::CalJ(int i, int j)//计算能量差时要按原来没反转的Jij来代
//result=Jij*(Ji-1j+Ji+1j+Jij-1+Jij+1);
{
double result=0;
int li,ri,tj,bj;//left i=li,right i=i,top j=tj,bottom j=bj
li=i-1;
ri=i+1;
if(li==-1)
{
li=N-1;
}
if(ri==N)
{
ri=0;
}
tj=j-1;
bj=j+1;
if(tj==-1)
{
tj=N-1;
}
if(bj==N)
{
bj=0;
}
result=Getij(i,j)*(Getij(li,j)+Getij(ri,j)+Getij(i,bj)+Getij(i,tj));
return result;
}
int CBox::CalM()
{
int M=0;
for(int i=0;i<number;i++)
{
M=M+pBox[i];
}
if(M<0)
{
return M*(-1);
}
else
{
return M;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -