| 查看: 945 | 回复: 0 | ||
[求助]
二维ising模型蒙特卡洛程序出错,求指点
|
|
#include #include #include #include #define L 150 #define preN 100000 #define lateN 5100000 #define deltaN (lateN-preN) double recordEnergy[deltaN]; int recordMagnet[deltaN]; int lattice[L][L]; int temp[L][L]; double energy; int magnet; double T; struct CX { double C; double X; }; void InitialLattice(); void SaveInitial(); void GetInitial(); void CaculateFirstMagnet(); void CaculateFirstEnergy(); void GenerateNext(); struct CX Caculate_C_and_X(); int main() { int i; struct CX cx[200]; FILE *ft,*fx,*fc; ft=fopen("T.txt","w" ;fx=fopen("X.txt","w" ;fc=fopen("C.txt","w" ;srand(time(NULL)); T = 1.0; for(i=0;T<4.0;i++) { InitialLattice(); cx=Caculate_C_and_X(); fprintf(ft,"%f\n",T); fprintf(fx,"%f\n",cx.X); fprintf(fc,"%f\n",cx.C); printf("T=%f ",T); printf(" X=%f ",cx.X); printf(" C=%f\n",cx.C); T = T+0.05; } fclose(ft); fclose(fx); fclose(fc); return 0; } void InitialLattice() { int i,j; for(i=0;i for(j=0;j if((rand()%10)>5) lattice[j]=1; else lattice[j]=1; } } } void SaveInitial() { int k,m; for(k=0;k for(m=0;m } } void GetInitial() { int k,m; for(k=0;k for(m=0;m } } void CaculateFirstMagnet() { int i,j; int iMagnet=0; for(i=0;i for(j=0;j } magnet = iMagnet; } void CaculateFirstEnergy() { double dEnergy = 0.0; int up,down,right,left,px,py; for(px=0;px for(py=0;py up = (L+px-1)%L; down = (px+1)%L; right = (L+py-1)%L; left = (py+1)%L; dEnergy += 0.5*lattice[px][py]*(lattice[up][py]+lattice[down][py]+lattice[px][right]+lattice[px][left]); } } energy = dEnergy; } void GenerateNext() { int px,py; int dE,sum; int up,down,right,left; px = rand()%L; py = rand()%L; up = (L+px-1)%L; down = (px+1)%L; right = (L+py-1)%L; left = (py+1)%L; sum = (lattice[px][py])*(lattice[up][py]+lattice[down][py]+lattice[px][right]+lattice[px][left]); switch(sum) { case 4: dE= 8; break; case 2: dE= 4; break; case 0: dE= 0; break; case -2: dE= -4; break; case -4: dE= -8; break; default: printf("---Erro!---\n" ; break;} if( dE>0 ) { if((rand()*1.0/RAND_MAX) <= exp((-1.0)*dE/T)) { lattice[px][py] = -lattice[px][py]; magnet += 2*lattice[px][py]; energy += dE; } } else { lattice[px][py] = -lattice[px][py]; magnet += 2*lattice[px][py]; energy += dE; } } struct CX Caculate_C_and_X() { struct CX cx; int i; double AvgEnergy=0.0; double AvgSquareEnergy=0.0; double AvgMagnet=0.0; double AvgSquareMagnet=0.0; CaculateFirstMagnet(); CaculateFirstEnergy(); for(i=0; i GenerateNext(); if(i>=preN) { recordEnergy[i-preN] = energy; recordMagnet[i-preN] = magnet; } } for(i=0;i AvgEnergy += (double)recordEnergy/deltaN; AvgSquareEnergy += (double)recordEnergy*recordEnergy/deltaN; AvgMagnet += (double)recordMagnet/deltaN; AvgSquareMagnet += (double)recordMagnet*recordMagnet/deltaN; } cx.C = (AvgSquareEnergy - AvgEnergy*AvgEnergy)/T/T; cx.X = (AvgSquareMagnet - AvgMagnet*AvgMagnet)/T; return cx; } :\microsoft visual studio\myprojects\ising\ising.cpp(44) : error C2440: '=' : cannot convert from 'struct CX' to 'struct CX [200]' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called d:\microsoft visual studio\myprojects\ising\ising.cpp(46) : error C2228: left of '.X' must have class/struct/union type d:\microsoft visual studio\myprojects\ising\ising.cpp(47) : error C2228: left of '.C' must have class/struct/union type d:\microsoft visual studio\myprojects\ising\ising.cpp(49) : error C2228: left of '.X' must have class/struct/union type d:\microsoft visual studio\myprojects\ising\ising.cpp(50) : error C2228: left of '.C' must have class/struct/union type d:\microsoft visual studio\myprojects\ising\ising.cpp(67) : error C2440: '=' : cannot convert from 'const int' to 'int [150]' There are no conversions to array types, although there are conversions to references or pointers to arrays d:\microsoft visual studio\myprojects\ising\ising.cpp(68) : error C2440: '=' : cannot convert from 'const int' to 'int [150]' There are no conversions to array types, although there are conversions to references or pointers to arrays d:\microsoft visual studio\myprojects\ising\ising.cpp(98) : error C2297: '+=' : illegal, right operand has type 'int [150]' d:\microsoft visual studio\myprojects\ising\ising.cpp(187) : error C2440: 'type cast' : cannot convert from 'double [5000000]' to 'double' There is no context in which this conversion is possible d:\microsoft visual studio\myprojects\ising\ising.cpp(188) : error C2440: 'type cast' : cannot convert from 'double [5000000]' to 'double' There is no context in which this conversion is possible d:\microsoft visual studio\myprojects\ising\ising.cpp(189) : error C2440: 'type cast' : cannot convert from 'int [5000000]' to 'double' There is no context in which this conversion is possible d:\microsoft visual studio\myprojects\ising\ising.cpp(190) : error C2440: 'type cast' : cannot convert from 'int [5000000]' to 'double' There is no context in which this conversion is possible 执行 cl.exe 时出错. ising.obj - 1 error(s), 0 warning(s) 怎么办 |
» 猜你喜欢
三无产品还有机会吗
已经有4人回复
投稿返修后收到这样的回复,还有希望吗
已经有7人回复
压汞仪和BET测气凝胶孔隙率
已经有4人回复
博士申请都是内定的吗?
已经有14人回复
谈谈两天一夜的“延安行”
已经有13人回复
氨基封端PDMS和HDI反应快速固化
已经有11人回复
之前让一硕士生水了7个发明专利,现在这7个获批发明专利的维护费可从哪儿支出哈?
已经有11人回复
论文投稿求助
已经有4人回复
Applied Surface Science 这个期刊。有哪位虫友投过的能把word模板发给我参考一下嘛
已经有3人回复
投稿精细化工
已经有6人回复
找到一些相关的精华帖子,希望有用哦~
人生转折点,真心求帮助!
已经有13人回复
关于ANSYS在体模型的表面施加面载荷的问题。
已经有9人回复
用c语言编程怎来表达时滞!谢谢!
已经有6人回复
请高手指点一下怎么确定一个符号矩阵中的等值元素
已经有6人回复
OPEN CV 帮助文档 参考手册
已经有31人回复
上海药物所悲惨348分,求接收!!!!!!!!!!!!
已经有36人回复
GPC(凝胶渗透色谱)谱图求助
已经有9人回复
求高手指点:对于保守性较低的基因可以用简并引物来扩吗?
已经有9人回复
matlab程序运行出错,求指点修改
已经有4人回复
山东大学有机333,求调剂
已经有8人回复
求助啊!求一程序,用matlab程序做,用蒙特卡洛方法模拟
已经有10人回复
【求助】醇沉
已经有7人回复
【求助】药学基础知识
已经有10人回复
求助C语言有限元一维、二维、矩形网格以及三角形网格程序
已经有4人回复
科研从小木虫开始,人人为我,我为人人













;
回复此楼
点击这里搜索更多相关资源