-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexact_test.c
361 lines (267 loc) · 8.27 KB
/
exact_test.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/****************************************************************
* An exact calculation by enumerating all configurations
*
****************************************************************/
#ifdef DEBUG
#include <fenv.h>
#endif
#include "Staggered.h"
#ifdef FLUCTUATION_DETERMINANT
fluctuation determinant not available for exact test
use full determinant
#endif
/* storage */
int **eta; //Staggered eta matrix
int **ksi; //Staggered ksi matrix for link mass
int *occupied_sites; //List of occupied sites
double U;
double m;
double linkmass;
/* Neighbour index arrays
*/
int **neighbour;
/* Monomers and links
* field stores both, 0 for empty, 1 for monomer and 2+dir for links
*/
int n_occupied[N_FLAVOR];
bool **occupation_field;
int n_fourfermion_monomer;
int n_mass_monomer[N_FLAVOR];
bool *fourfermion_monomer;
bool **mass_monomer;
static inline int opp_dir(int dir){
return ( dir + ND ) % NDIRS;
}
int site_vector_to_index( int vector[] ){
int index = vector[ND-1];
for (int dir=ND-1; dir--;) index = index*Ldim[dir] + vector[dir];
return index;
}
void site_index_to_vector(int index, int vector[] ){
int i = index;
for (int dir=0; dir<ND; dir++){
vector[dir] = i%Ldim[dir];
i = i/Ldim[dir];
}
}
double Z=0;
double ff_density=0;
double m_density=0;
double W = 1;
extern double current_determinant[N_FLAVOR];
void all_configs( int x0 ){
int max=VOLUME+1, min=0;
//Do measurements on the current config
current_determinant[0] = current_determinant[1] = 1;
double det = determinant(0)*determinant(1);
Z += W*det;
ff_density += W*det*n_fourfermion_monomer;
m_density += W*det*n_mass_monomer[0];
//printf("measurements %g %d %d %d\n",det,n_fourfermion_monomer,n_mass_monomer[0],n_mass_monomer[1]);
for(int x=x0; x<VOLUME; x++){
double W_old = W;
//Make it a four fermion monomer
fourfermion_monomer[x] = 1;
occupation_field[0][x] = 1;
occupation_field[1][x] = 1;
n_fourfermion_monomer++;
n_occupied[0]++;
n_occupied[1]++;
W*=U;
all_configs( x+1 );
W=W_old;
fourfermion_monomer[x] = 0;
occupation_field[0][x] = 0;
occupation_field[1][x] = 0;
n_fourfermion_monomer--;
n_occupied[0]--;
n_occupied[1]--;
#ifndef MASS_IN_MATRIX
//Make it a mass monomer
mass_monomer[0][x] = 1;
occupation_field[0][x] = 1;
n_mass_monomer[0]++;
n_occupied[0]++;
W*=m;
all_configs( x+1 );
mass_monomer[1][x] = 1;
occupation_field[1][x] = 1;
n_mass_monomer[1]++;
n_occupied[1]++;
W*=m;
all_configs( x+1 );
mass_monomer[0][x] = 0;
occupation_field[0][x] = 0;
n_mass_monomer[0]--;
n_occupied[0]--;
W/=m;
all_configs( x+1 );
mass_monomer[1][x] = 0;
occupation_field[1][x] = 0;
n_mass_monomer[1]--;
n_occupied[1]--;
W = W_old;
#endif
}
}
void print_config()
{
int s[ND];
for ( s[0]=0; s[0]<Ldim[0]; s[0]++) {
for ( s[1]=0; s[1]<Ldim[1]; s[1]++){
#if ND==4
for ( s[2]=0; s[2]<Ldim[2]; s[2]++) {
for ( s[3]=0; s[3]<Ldim[3]; s[3]++){
#endif
#if ND==3
for ( s[2]=0; s[2]<Ldim[2]; s[2]++) {
#endif
int empty = 1;
int index = site_vector_to_index(s);
if(fourfermion_monomer[index]==1) { empty = 0; printf(" o "); }
if(mass_monomer[0][index]==1) { empty = 0;
if(mass_monomer[1][index]==1) printf(" + ");
else printf(" - "); }
else if(mass_monomer[1][index]==1) { empty = 0; printf(" | "); }
if(empty==1 && occupation_field[0][index] == 1 ) { empty = 0;
if( occupation_field[1][index]==1) printf(" x ");
else printf(" \\ "); }
if(empty==1 && occupation_field[1][index] == 1 ) { empty = 0; printf(" / "); }
if(empty==1) { printf(" . "); }
#if ND==4
}
printf(" ");
}
printf(" \n");
#endif
#if ND==3
}
printf(" ");
#endif
}
printf(" \n");
}
printf(" \n");
//usleep(1000000);
}
/* Main function
*/
int main(int argc, char* argv[])
{
#ifdef DEBUG
feenableexcept(FE_INVALID | FE_OVERFLOW);
#endif
int i,n_updates_per_measure,n_mass_updates_per_measure,n_measure,n_average;
long seed;
/* Read in the input */
printf(" Discarded : ");
scanf("%d",&n_updates_per_measure);
printf(" Discarded : ");
scanf("%d",&n_measure);
printf(" Discarded : ");
scanf("%d",&n_mass_updates_per_measure);
printf(" Discarded : ");
scanf("%d",&n_average);
int max_fluctuations;
printf(" Discarded : ");
scanf("%d",&max_fluctuations);
printf(" U : ");
scanf("%lf",&U);
printf(" m : ");
scanf("%lf",&m);
printf(" linkmass : ");
scanf("%lf",&linkmass);
printf(" \n++++++++++++++++++++++++++++++++++++++++++\n");
printf(" %dD staggered fermion, ( ",ND);
for( int nu=0; nu<ND-1; nu++){
printf("%d , ", Ldim[nu] );
}
printf("%d ) lattice\n", Ldim[ND-1]);
printf(" U %f \n", U);
printf(" m %f %f \n", m, linkmass);
fflush(stdout);
VOLUME = 1;
for( int nu=0; nu<ND; nu++) VOLUME*=Ldim[nu];
occupation_field = malloc( N_FLAVOR*sizeof(bool*) );
for( int i=0; i<N_FLAVOR; i++ ){
occupation_field[i] = malloc( VOLUME*sizeof(bool) );
for (int x=0; x<VOLUME; x++) occupation_field[i][x] = 0;
n_occupied[i] = 0;
}
mass_monomer = malloc( N_FLAVOR*sizeof(bool*) );
for( int i=0; i<N_FLAVOR; i++ ){
mass_monomer[i] = malloc( VOLUME*sizeof(bool) );
for (int x=0; x<VOLUME; x++) mass_monomer[i][x] = 0;
n_mass_monomer[i] = 0;
}
fourfermion_monomer = malloc( VOLUME*sizeof(bool) );
for (int x=0; x<VOLUME; x++) fourfermion_monomer[x] = 0;
n_fourfermion_monomer = 0;
/* The staggered eta matrix */
eta = malloc( ND*sizeof(int *) );
for( int nu=0; nu<ND; nu++) eta[nu] = malloc( VOLUME*sizeof(int) );
for (int x=0; x<VOLUME; x++) {
int vector[ND];
site_index_to_vector(x,vector);
for( int nu=0; nu<ND; nu++) {
int eta_exponent = 0;
for( int mu=0; mu<nu; mu++){
eta_exponent += vector[mu];
}
if( eta_exponent%2 == 0 ){
eta[nu][x] = 1;
} else {
eta[nu][x] = -1;
}
}
}
/* The staggered eps*ksi matrix for link mass */
ksi = malloc( ND*sizeof(int *) );
for (int nu=0; nu<ND; nu++) ksi[nu] = malloc( VOLUME*sizeof(int) );
for (int x=0; x<VOLUME; x++) {
int vector[ND];
site_index_to_vector(x,vector);
int eps_exponent = 0;
for( int nu=0; nu<ND; nu++) eps_exponent += vector[nu];
for( int nu=0; nu<ND; nu++) {
int ksi_exponent = 0;
for( int mu=nu+1; mu<ND; mu++)
ksi_exponent += vector[mu];
if( (eps_exponent+ksi_exponent)%2 == 0 ){
ksi[nu][x] = 1;
} else {
ksi[nu][x] = -1;
}
}
}
/* The nb array */
neighbour = malloc( NDIRS*sizeof(int *) );
for( int nu=0; nu<NDIRS; nu++) neighbour[nu] = malloc( VOLUME*sizeof(int) );
for (int x=0; x<VOLUME; x++) {
int vector[ND];
site_index_to_vector(x,vector);
for( int nu=0; nu<ND; nu++) {
int nb[ND];
for( int mu=0; mu<ND; mu++) nb[mu] = vector[mu];
nb[nu] = (nb[nu]+1)%Ldim[nu];
neighbour[nu][x] = site_vector_to_index(nb);
for( int mu=0; mu<ND; mu++) nb[mu] = vector[mu];
nb[nu] = (nb[nu]+Ldim[nu]-1)%Ldim[nu];
neighbour[opp_dir(nu)][x] = site_vector_to_index(nb);
}
}
/* calculate propagators */
#ifdef PROPAGATOR_MATRIX
calc_Dinv( );
#endif
struct timeval start, end;
gettimeofday(&start,NULL);
/* Background and fluctuation matrix */
#ifdef FLUCTUATION_DETERMINANT
for(int m=0; m<N_FLAVOR; m++) update_background( m );
#endif
all_configs( 0 );
printf("MONOMERDENSITY %g %g\n", ff_density/(Z*VOLUME), m_density/(Z*VOLUME) );
printf(" ** simulation done\n");
return(1);
}