版块导航
正在加载中...
客户端APP下载
论文辅导
调剂小程序
登录
注册
帖子
帖子
用户
本版
应《网络安全法》要求,自2017年10月1日起,未进行实名认证将不得使用互联网跟帖服务。为保障您的帐号能够正常使用,请尽快对帐号进行手机号验证,感谢您的理解与支持!
24小时热门版块排行榜
>
论坛更新日志
(3069)
>
导师招生
(293)
>
考研
(263)
>
虫友互识
(126)
>
文献求助
(96)
>
基金申请
(62)
>
休闲灌水
(58)
>
教师之家
(42)
>
考博
(40)
>
招聘信息布告栏
(36)
>
硕博家园
(30)
>
论文道贺祈福
(27)
>
论文投稿
(24)
>
无机/物化
(22)
>
留学生活
(19)
>
博后之家
(18)
小木虫论坛-学术科研互动平台
»
计算模拟区
»
分子模拟
»
Monte Carlo
»
【转帖】wolff算法的C代码
1
1/1
返回列表
查看: 1122 | 回复: 0
只看楼主
@他人
存档
新回复提醒
(忽略)
收藏
在APP中查看
zyj8119
木虫
(著名写手)
模拟EPI: 10
应助: 65
(初中生)
贵宾: 0.003
金币: 915.1
散金: 1440
红花: 35
帖子: 2936
在线: 1329.4小时
虫号: 664177
注册: 2008-11-29
性别: GG
专业: 理论和计算化学
[交流]
【转帖】wolff算法的C代码
CODE:
/* Wolff single-cluster algorithm for the two dimensional nearest neighbor
Ising model By Jian-Sheng Wang, February 1995.
Compile with
cc -O Wolff.c -lm
-O for optimization, and -lm to link the math library.
*/
#include
#include
#include
/* macro definitions */
#define L 16 /* lattice linear size */
#define N (L*L) /* total number of spins */
#define Z 4 /* coordination number = 2*d */
#define MCTOT 500 /* total Monte Carlo steps */
#define MCDIS 200 /* steps discarded in the beginning */
/* global variables */
int s[N]; /* spin +1 or -1 */
double p = 1.0; /* percolation probability */
/* funcition prototypes */
void neighbor(int i, int nn[ ]);
void flip(int i, int s0);
void monte_carlo_steps(int n);
void energy(double *);
/* The main program, running the Monte Carlo loop, collecting data */
void main()
{
int i, mc;
double e = 0;
p = 1 - exp( - 2/2.269);
for (i = 0; i < N; ++i) /* initialize, all spin up */
s = 1;
for(mc = 0; mc < MCTOT; ++ mc) {
monte_carlo_steps(5);
if( mc >= MCDIS)
energy(&e);
}
printf("
= %f\n", e/(MCTOT-MCDIS)/N);
}
/* This function monte_carlo_steps performs n cluster flips, eqivalent to
few Monte Carlo steps in standard single-spin-flip algorithms.
It picks a seed site at random and calls the flip function to generate
one cluster. N is total number of spin. They are macro definitions. */
void monte_carlo_steps(int n)
{
int i, k;
for(k = 0; k < n; ++k) {
i = drand48() * (double) N;
flip(i, s);
}
}
/* Perform a Wolff single cluster flip. s[], p, and Z are passed globally.
The first argument i of flip function is the site to be flipped, the
second argument is the spin of the cluster before flipping. */
void flip(int i, int s0)
{
int j, nn[Z];
s = - s0; /* flip the spin immediately */
neighbor(i, nn); /* find nearest neighbor of i */
for(j = 0; j < Z; ++j) /* flip the neighbor if ... */
if(s0 == s[nn[j]] && drand48() < p)
flip(nn[j], s0);
}
/* Neighbor returns in the array nn[ ] the neighbor sites of i. The sites
are labelled sequentially, starting from 0. It works for any hypercubic
lattice. Z (=2*D) is the coordination number, passed as a macro defintion.
L is linear size, also passed as a macro definition. */
void neighbor(int i, int nn[ ])
{
int j, r, p, q;
r = i;
p = 1 - L;
q = 1;
for(j = 0; j < Z; j += 2) {
nn[j] = (r + 1) % L == 0 ? i + p : i + q;
nn[j+1] = r % L == 0 ? i - p : i - q;
r = r/L;
p *= L;
q *= L;
}
}
/* This function calculate the energy of the configuration s[],
in fact, it is the negative of the energy. */
void energy(double *e)
{
int i, j, ie = 0;
int nn[Z];
for(i = 0; i < N; ++i) {
neighbor(i, nn); /* find the neighbor of center site */
for(j = 0; j < Z; j += 2) /* look at positive direction only */
ie += s*s[nn[j]]; /* add nearest neighbor interaction */
}
*e += ie; /* accumulant energy */
}
其中drand48() 为0-1之间均匀分布的随机数
回复此楼
» 猜你喜欢
焦虑
已经有10人回复
298-一志愿中国农业大学-求调剂
已经有3人回复
265求调剂
已经有3人回复
297求调剂
已经有3人回复
302求调剂
已经有8人回复
环境工程调剂
已经有7人回复
268求调剂
已经有6人回复
311求调剂
已经有11人回复
工科材料085601 279求调剂
已经有4人回复
301求调剂
已经有9人回复
高级回复
好好学习,天天向上。
1楼
2010-10-17 01:21:15
已阅
回复此楼
关注TA
给TA发消息
送TA红花
TA的回帖
智能机器人
Robot
(super robot)
我们都爱小木虫
找到一些相关的精华帖子,希望有用哦~
苯环上的一个C两边的邻位上都没有氢的情况下这个C上的H会现d峰吗???怎么解释??
已经有7人回复
求 图像配准 算法的测试数据库
已经有6人回复
支持向量机训练好的参数如何用C代码写测试程序
已经有5人回复
GPU并行计算C语言书籍或者源代码
已经有7人回复
求回归方程参数估计的最优化算法matlab代码
已经有9人回复
28个不得不看的经典编程算法!!
已经有34人回复
哪里能找到FFT算法的C代码??
已经有4人回复
向热心大虾请教:最优化理论和算法方面的学习心得。谢谢!
已经有32人回复
WSN定位中的三边测量算法的代码和原始论文
已经有11人回复
【分享】C/C++常用算法设计方法,fortran其他语言编程也可以参考下
已经有8人回复
点击这里搜索更多相关资源
科研从小木虫开始,人人为我,我为人人
相关版块跳转
第一性原理
量子化学
计算模拟
分子模拟
仿真模拟
程序语言
我要订阅楼主
zyj8119
的主题更新
1
1/1
返回列表
如果回帖内容含有宣传信息,请如实选中。否则帐号将被全论坛禁言
普通表情
龙
兔
虎
猫
高级回复
(可上传附件)
百度网盘
|
360云盘
|
千易网盘
|
华为网盘
在新窗口页面中打开自己喜欢的网盘网站,将文件上传后,然后将下载链接复制到帖子内容中就可以了。
最具人气热帖推荐
[查看全部]
作者
回/看
最后发表
[
教师之家
]
焦虑
+8
水冰月月野兔
2026-03-13
10/500
2026-03-18 09:21
by
咪呜喵呜
[
考研
]
化学工程321分求调剂
+12
大米饭!
2026-03-15
15/750
2026-03-18 08:39
by
星空星月
[
考研
]
304求调剂
+9
小熊joy
2026-03-14
9/450
2026-03-18 04:33
by
anny19840123
[
考研
]
一志愿天津大学化学工艺专业(081702)315分求调剂
+7
yangfz
2026-03-17
7/350
2026-03-17 23:57
by
星空星月
[
考研
]
328求调剂,英语六级551,有科研经历
+3
生物工程调剂
2026-03-16
8/400
2026-03-17 19:03
by
Wangjingyue
[
考研
]
材料专硕274一志愿陕西师范大学求调剂
+5
薛云鹏
2026-03-13
5/250
2026-03-17 10:15
by
Sammy2
[
考研
]
考研调剂
+3
淇ya_~
2026-03-17
5/250
2026-03-17 09:25
by
Winj1e
[
考研
]
326求调剂
+3
mlpqaz03
2026-03-15
3/150
2026-03-16 07:33
by
Iveryant
[
考研
]
327求调剂
+6
拾光任染
2026-03-15
11/550
2026-03-15 22:47
by
拾光任染
[
考研
]
求老师收留调剂
+4
jiang姜66
2026-03-14
5/250
2026-03-15 20:11
by
Winj1e
[
考研
]
070305求调剂
+3
mlpqaz03
2026-03-14
4/200
2026-03-15 11:04
by
peike
[
考研
]
0703,333分求调剂 一志愿郑州大学-物理化学
+3
李魔女斗篷
2026-03-11
3/150
2026-03-13 22:24
by
JourneyLucky
[
考研
]
材料工程调剂
+9
咪咪空空
2026-03-12
9/450
2026-03-13 22:05
by
星空星月
[
考研
]
求调剂
+5
一定有学上-
2026-03-12
5/250
2026-03-13 18:31
by
ms629
[
考研
]
求调剂
+7
18880831720
2026-03-11
7/350
2026-03-13 16:10
by
JourneyLucky
[
考研
]
307求调剂
+5
超级伊昂大王
2026-03-12
5/250
2026-03-13 15:56
by
棒棒球手
[
考研
]
295求调剂
+3
小匕仔汁
2026-03-12
3/150
2026-03-13 15:17
by
vgtyfty
[
论文投稿
]
投稿问题
5
+4
星光灿烂xt
2026-03-12
6/300
2026-03-13 14:17
by
god_tian
[
考研
]
0817化学工程与技术考研312分调剂
+3
T123 tt
2026-03-12
3/150
2026-03-13 10:49
by
houyaoxu
[
考研
]
290求调剂
+3
ADT
2026-03-13
3/150
2026-03-13 10:19
by
peike
信息提示
关闭
请填处理意见
关闭
确定