forked from etmc/tmLQCD
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreweighting_factor.c
154 lines (142 loc) · 4.97 KB
/
reweighting_factor.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
/***********************************************************************
*
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Carsten Urbach
*
* This file is part of tmLQCD.
*
* tmLQCD is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* tmLQCD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with tmLQCD. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/
#ifdef HAVE_CONFIG_H
#include "tmlqcd_config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "global.h"
#include "linalg_eo.h"
#include "start.h"
#include "fatal_error.h"
#include "monomial/monomial.h"
#include "hamiltonian_field.h"
#include "operator/clovertm_operators.h"
#include "operator/clover_leaf.h"
#include "reweighting_factor.h"
void reweighting_factor(const int N, const int nstore) {
int n = VOLUME;
monomial * mnl;
FILE * ofs;
hamiltonian_field_t hf;
hf.gaugefield = g_gauge_field;
hf.momenta = NULL;
hf.derivative = NULL;
hf.update_gauge_copy = g_update_gauge_copy;
double * data = (double*)calloc(no_monomials*N, sizeof(double));
double * trlog = (double*)calloc(no_monomials, sizeof(double));
// we compute the trlog part first, because they are independent of
// stochastic noise. This is only needed for even/odd monomials
for(int j = 0; j < no_monomials; j++) {
mnl = &monomial_list[j];
if(mnl->even_odd_flag) {
init_sw_fields();
if(mnl->type != NDCLOVERRATCOR && (mnl->kappa != mnl->kappa2
|| (mnl->type == NDDETRATIO
&& (mnl->mubar != mnl->mubar2 || mnl->epsbar != mnl->epsbar2))
|| (mnl->type != NDDETRATIO
&& (mnl->mu != mnl->mu2)))) {
double c_sw = mnl->c_sw;
if(c_sw < 0.) c_sw = 0.;
sw_term( (const su3**) hf.gaugefield, mnl->kappa, c_sw);
if(mnl->type != NDDETRATIO) {
trlog[j] = -sw_trace(0, mnl->mu);
}
else {
trlog[j] = -sw_trace_nd(0, mnl->mubar, mnl->epsbar);
}
sw_term( (const su3**) hf.gaugefield, mnl->kappa2, c_sw);
if(mnl->type != NDDETRATIO) {
trlog[j] -= -sw_trace(0, mnl->mu2);
}
else {
trlog[j] -= -sw_trace_nd(0, mnl->mubar2, mnl->epsbar2);
}
} else
trlog[j] = 0.;
}
else {
trlog[j] = 0.;
}
if(g_proc_id == 0 && g_debug_level > 0) {
printf("# monomial[%d] %s, trlog = %e\n", j, mnl->name, trlog[j]);
}
}
for(int i = 0; i < N; i++) {
if(g_proc_id == 0 && g_debug_level > 0) {
printf("# computing reweighting factors for sample %d\n", i);
}
for(int j = 0; j < no_monomials; j++) {
mnl = &monomial_list[j];
if(mnl->type != GAUGE) {
if(mnl->even_odd_flag) {
random_spinor_field_eo(mnl->pf, mnl->rngrepro, RN_GAUSS);
mnl->energy0 = square_norm(mnl->pf, n/2, 1);
}
else {
random_spinor_field_lexic(mnl->pf, mnl->rngrepro, RN_GAUSS);
mnl->energy0 = square_norm(mnl->pf, n, 1);
}
if(mnl->type == NDDETRATIO || mnl->type == NDCLOVERRATCOR) {
if(mnl->even_odd_flag) {
random_spinor_field_eo(mnl->pf2, mnl->rngrepro, RN_GAUSS);
mnl->energy0 += square_norm(mnl->pf2, n/2, 1);
}
else {
random_spinor_field_lexic(mnl->pf2, mnl->rngrepro, RN_GAUSS);
mnl->energy0 += square_norm(mnl->pf2, n, 1);
}
}
if(g_proc_id == 0 && g_debug_level > 1) {
printf("# monomial[%d] %s, energy0 = %e\n", j, mnl->name, mnl->energy0);
}
}
}
for(int j = 0; j < no_monomials; j++) {
mnl = &monomial_list[j];
if(mnl->type != GAUGE) {
double y = mnl->accfunction(j, &hf);
data[i*no_monomials + j] = y;
if(g_proc_id == 0 && g_debug_level > 0) {
printf("# monomial[%d] %s, stochastic part: w_%d=%e exp(w_%d)=%e\n", j, mnl->name, j, j, y, exp(y));
}
}
}
}
if(g_proc_id == 0) {
char filename[50];
sprintf(filename, "reweighting_factor.data.%.5d", nstore);
if((ofs = fopen(filename, "w")) == NULL) {
fatal_error("Could not open file for data output", "reweighting_factor");
}
else {
for(int j = 0; j < no_monomials; j++) {
mnl = &monomial_list[j];
for(int i = 0; i < N; i++) {
fprintf(ofs, "%.2d %.5d %.12f %.12f %.12f %.12f %.10e\n", j, i, mnl->kappa, mnl->kappa2, mnl->mu, mnl->mu2, data[i*no_monomials + j] + trlog[j]);
}
}
fclose(ofs);
}
}
free(data);
free(trlog);
}