-
Notifications
You must be signed in to change notification settings - Fork 0
/
measure_sector.c
161 lines (125 loc) · 3.87 KB
/
measure_sector.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
#define MAIN
#define MEASURE_SECTOR
#include "worldline.h"
int target_sector;
double gaussian_weight = 5; // Used in thermalisation even with wall
int current_sector = 0;
double sector_accept(){
double logweight, weight;
int distance, current_distance;
int accept;
int sector = negative_loops();
distance = sector - target_sector;
current_distance = current_sector - target_sector;
logweight = -(distance*distance - current_distance*current_distance)*gaussian_weight;
weight = exp(logweight);
if( mersenne() < weight ){
accept = 1;
current_sector = sector;
} else {
accept = 0;
}
return accept;
}
/* Perform an update and accept/reject */
int update( int nsteps )
{
int changes=0;
for( int i=0; i<nsteps; i++ ){
save_config();
changes += update_config(1);
if( ! sector_accept() ){
restore_config();
}
}
/* Only accept as real configuration if it matches the target sector */
while(current_sector != target_sector){
changes += update_config(1);
current_sector = negative_loops();
}
return changes;
}
/* Main function
*/
int main(int argc, char* argv[])
{
#ifdef DEBUG
feenableexcept(FE_INVALID | FE_OVERFLOW);
#endif
int i,n_loops,n_measure,n_average;
setup_lattice();
/* Read in the input */
get_int("Number of updates", &n_loops);
get_int("Updates / measurement", &n_measure);
get_int("Updates between saves", &n_average);
printf("\n %d updates per measurements\n", n_measure );
read_thirring_parameters();
get_int("Target sector", &target_sector);
printf("\n Measuring expectation values in sector %d\n", target_sector );
/* and the update/measure loop */
int sum_monomers = 0;
int sum_links = 0;
int sum_charge = 0;
int sum_c2 = 0;
int sum_q = 0;
int sum_q2 = 0;
double sum_susc = 0;
double sum_susc_wb = 0;
int sum_sign=0;
int sectors[MAX_SECTOR];
for(i=0; i<MAX_SECTOR; i++)
sectors[i] = 0;
struct timeval start, end;
double updatetime=0, measuretime = 0;
gettimeofday(&start,NULL);
for (i=1; i<n_loops+1; i++) {
/* Update */
update(n_measure);
/* Time and report */
gettimeofday(&end,NULL);
updatetime += 1e6*(end.tv_sec-start.tv_sec) + end.tv_usec-start.tv_usec;
gettimeofday(&start,NULL);
int sector = current_sector;
int sign = 1-(sector%2)*2;
sum_sign += sign;
int n_monomers = 0, n_links = 0;
for (int t=0; t<NT; t++){
for (int x=0; x<NX; x++) {
if(field[t][x] == MONOMER){
n_monomers +=1;
}
if(field[t][x] >= LINK_TUP){
n_links +=1;
}
}
}
sum_monomers += sign*n_monomers;
sum_links += sign*n_links;
int c, q;
measure_charge(&c, &q);
sum_charge += sign*c;
sum_c2 += sign*c*c;
sum_q += sign*q;
sum_q2 += sign*q*q;
gettimeofday(&end,NULL);
measuretime += 1e6*(end.tv_sec-start.tv_sec) + end.tv_usec-start.tv_usec;
if(i%n_average==0){
printf("\n%d, %d updates in %.3g seconds\n", i*n_measure, n_average*n_measure, 1e-6*updatetime);
printf("%d, %d measurements in %.3g seconds\n", i*n_measure, n_average, 1e-6*measuretime);
//measure_propagator( 1 ); //This includes an invertion and therefore takes time
updatetime = 0; measuretime = 0;
printf("MONOMERS %g \n", ((double)sum_monomers)/n_average);
printf("LINKS %g \n", (double)sum_links/n_average);
printf("CHARGE %g %g \n", (double)sum_charge/n_average, (double)sum_c2/n_average);
printf("QCHI %g %g \n", (double)sum_q/n_average, (double)sum_q2/n_average);
printf("SIGN %g\n", (double)sum_sign/n_average);
write_configuration(configuration_filename);
sum_monomers = 0; sum_links = 0; sum_charge = 0;
sum_c2 = 0; sum_q = 0; sum_q2 = 0; sum_susc = 0;
sum_susc_wb = 0; sum_sign = 0;
}
gettimeofday(&start,NULL);
}
printf(" ** simulation done\n");
return(0);
}