-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcanonical.c
178 lines (177 loc) · 3.51 KB
/
canonical.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <math.h>
#include <utils.h>
#include <string.h>
#include <time.h>
#include "dSFMT.h"
#include "zargs.h"
#include "params.h"
#include "mm_math.h"
#include "hash.h"
#include "energy.h"
#include "lists.h"
#include "init.h"
#include "patches.h"
#include "graph.h"
#include "optimize.h"
#include "canonical.h"
extern dsfmt_t dsfmt;
int c_en_old(compound_particle *c){
int i;
int en_old=0;
particle *p;
for(i=0;i<c->nparticle;i++){
p=c->p+i;
en_old+=p->en_new;
}
return en_old;
}
int c_en_new(compound_particle *c){
int i;
int en_new=0;
particle *p;
for(i=0;i<c->nparticle;i++){
p=c->p+i;
//en_new+=particle_energy_hash(p,t);
//en_new+=particle_energy_hash2m(p,t);
en_new+=particle_energy_hash2(p);
}
return en_new;
}
void c_list_swap(compound_particle *c){
int i;
particle *p;
for(i=0;i<c->nparticle;i++){
p=c->p+i;
list_swap(p);
}
}
void c_adjust_lists(compound_particle *c){
int i;
particle *p;
for(i=0;i<c->nparticle;i++){
p=c->p+i;
adjust_lists(p);
}
}
int mc_move(compound_particle *c,header *t,int *en){
int eno=0,enn=0;
int de;
double rmd;
__m128d q0=*(c->q);
__m128d rnd=(__m128d){dsfmt_genrand_open_open(&dsfmt)-0.5,dsfmt_genrand_open_open(&dsfmt)-0.5};
__m128d dq=t->max_displacement*rnd;
dq[0]-=dq[1]*t->uy;
*(c->q)+=dq;
reset_particle(c,t); //boundary and hash reinsert
//boundary(p->q,t->box);
//hash_reinsert(p,t->h1,t->table);
//eno=p->en_new;
//list_swap(p);
//if(overlap(p,t)){
eno=c_en_old(c);
c_list_swap(c);
if(compound_overlap(c,t)){
*(c->q)=q0;
reset_particle(c,t);
c_list_swap(c);
//hash_reinsert(p,t->h1,t->table);
//list_swap(p);
return 1;
}
//enn=particle_energy_hash2(p);
enn=c_en_new(c);
de=enn-eno;
rmd=dsfmt_genrand_open_open(&dsfmt);
if(rmd<exp(t->epsilon*de)){
c_adjust_lists(c);
*en+=de;
return 0;
}
else{
*(c->q)=q0;
reset_particle(c,t);
c_list_swap(c);
//hash_reinsert(p,t->h1,t->table);
//list_swap(p);
return 1;
}
}
int mc_rotate(compound_particle *c,header *t,int *en){
int eno=0,enn=0;
int de;
//int k;
double rmd;
double w=t->max_rotation*(dsfmt_genrand_open_open(&dsfmt)-0.5);
//double a;
//double rnd=dsfmt_genrand_open_open(&dsfmt);
__m128d or0=*c->or;
*c->or=rot2w(*c->or,w);
//k=dsfmt_genrand_open_open(&dsfmt)*3.0;
//a=(double)k/3.0*M_PI;
//*(c)->or=sincosa(a);
reset_particle(c,t);
//boundary(p->q,t->box);
//hash_reinsert(p,t->h1,t->table);
//eno=p->en_new;
//list_swap(p);
//if(overlap(p,t)){
eno=c_en_old(c);
c_list_swap(c);
if(compound_overlap(c,t)){
*(c->or)=or0;
reset_particle(c,t);
c_list_swap(c);
//hash_reinsert(p,t->h1,t->table);
//list_swap(p);
return 1;
}
//enn=particle_energy_hash2(p);
enn=c_en_new(c);
de=enn-eno;
rmd=dsfmt_genrand_open_open(&dsfmt);
if(rmd<exp(t->epsilon*de)){
c_adjust_lists(c);
//adjust_lists(p);
*en+=de;
return 0;
}
else{
*(c->or)=or0;
reset_particle(c,t);
c_list_swap(c);
//hash_reinsert(p,t->h1,t->table);
//list_swap(p);
return 1;
}
}
/*
int mc_rotate(particle *p,header *t,int *en){
int eno=0,enn=0;
int de;
double w=t->max_rotation*(dsfmt_genrand_open_open(&dsfmt)-0.5);
double rnd=dsfmt_genrand_open_open(&dsfmt);
__m128d or0=*p->or;
*p->or=rot2w(*p->or,w);
eno=p->en_new;
list_swap(p);
set_patches(p);
enn=particle_energy_hash(p,t);
de=enn-eno;
rnd=dsfmt_genrand_open_open(&dsfmt);
if(rnd<exp(t->epsilon*de)){
adjust_lists(p);
*en+=de;
return 0;
}
else{
*(p->or)=or0;
hash_reinsert(p,t->h1,t->table);
set_patches(p);
list_swap(p);
return 1;
}
}
*/