forked from etmc/tmLQCD
-
Notifications
You must be signed in to change notification settings - Fork 2
/
detratio_monomial.c
303 lines (271 loc) · 11.3 KB
/
detratio_monomial.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
/***********************************************************************
*
* Copyright (C) 1008 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<config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "global.h"
#include "su3.h"
#include "su3adj.h"
#include "su3spinor.h"
#include "ranlxd.h"
#include "start.h"
#include "linalg_eo.h"
#include "linsolve.h"
#include "deriv_Sb.h"
#include "deriv_Sb_D_psi.h"
#include "gamma.h"
#include "tm_operators.h"
#include "hybrid_update.h"
#include "Hopping_Matrix.h"
#include "solver/chrono_guess.h"
#include "solver/bicgstab_complex.h"
#include "solver/solver.h"
#include "read_input.h"
#include "smearing/stout.h"
#include "clover_leaf.h"
#include "monomial.h"
#include "boundary.h"
#include "detratio_monomial.h"
extern int ITER_MAX_BCG;
extern int ITER_MAX_CG;
/* think about chronological solver ! */
void detratio_derivative(const int no, hamiltonian_field_t * const hf) {
int saveiter = ITER_MAX_BCG;
monomial * mnl = &monomial_list[no];
mnl->forcefactor = 1.;
if(mnl->even_odd_flag) {
/*
* this is being run in case there is even/odd preconditioning
*/
/*********************************************************************
*
* This term is det((Q^2 + \mu_1^2)/(Q^2 + \mu_2^2))
* mu1 and mu2 are set according to the monomial
*
*********************************************************************/
/* First term coming from the second field */
/* Multiply with W_+ */
g_mu = mnl->mu2;
boundary(mnl->kappa2);
if(mnl->solver != CG) {
fprintf(stderr, "Bicgstab currently not implemented, using CG instead! (detratio_monomial.c)\n");
}
Qtm_plus_psi(g_spinor_field[DUM_DERI+2], mnl->pf);
g_mu = mnl->mu;
boundary(mnl->kappa);
/* Invert Q_{+} Q_{-} */
/* X_W -> DUM_DERI+1 */
chrono_guess(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+2], mnl->csg_field,
mnl->csg_index_array, mnl->csg_N, mnl->csg_n, VOLUME/2, &Qtm_pm_psi);
mnl->iter1 += cg_her(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+2], mnl->maxiter,
mnl->forceprec, g_relative_precision_flag, VOLUME/2, &Qtm_pm_psi);
chrono_add_solution(g_spinor_field[DUM_DERI+1], mnl->csg_field, mnl->csg_index_array,
mnl->csg_N, &mnl->csg_n, VOLUME/2);
/* Y_W -> DUM_DERI */
Qtm_minus_psi(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1]);
/* apply Hopping Matrix M_{eo} */
/* to get the even sites of X */
H_eo_tm_inv_psi(g_spinor_field[DUM_DERI+2], g_spinor_field[DUM_DERI+1], EO, -1.);
/* \delta Q sandwitched by Y_o^\dagger and X_e */
deriv_Sb(OE, g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+2], hf, mnl->forcefactor);
/* to get the even sites of Y */
H_eo_tm_inv_psi(g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI], EO, +1);
/* \delta Q sandwitched by Y_e^\dagger and X_o */
deriv_Sb(EO, g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+1], hf, mnl->forcefactor);
g_mu = mnl->mu2;
boundary(mnl->kappa2);
/* Second term coming from the second field */
/* The sign is opposite!! */
mul_r(g_spinor_field[DUM_DERI], -1., mnl->pf, VOLUME/2);
/* apply Hopping Matrix M_{eo} */
/* to get the even sites of X */
H_eo_tm_inv_psi(g_spinor_field[DUM_DERI+2], g_spinor_field[DUM_DERI+1], EO, -1.);
/* \delta Q sandwitched by Y_o^\dagger and X_e */
deriv_Sb(OE, g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+2], hf, mnl->forcefactor);
/* to get the even sites of Y */
H_eo_tm_inv_psi(g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI], EO, +1);
/* \delta Q sandwitched by Y_e^\dagger and X_o */
deriv_Sb(EO, g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+1], hf, mnl->forcefactor);
}
else { /* no even/odd preconditioning */
/*********************************************************************
*
* This term is det((Q^2 + \mu_1^2)/(Q^2 + \mu_2^2))
* mu1 and mu2 are set according to the monomial
*
*********************************************************************/
/* First term coming from the second field */
/* Multiply with W_+ */
g_mu = mnl->mu2;
boundary(mnl->kappa2);
Q_plus_psi(g_spinor_field[DUM_DERI+2], mnl->pf);
g_mu = mnl->mu;
boundary(mnl->kappa);
if(mnl->solver == CG) {
/* If CG is used anyhow */
/* gamma5(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+2], VOLUME/2); */
/* Invert Q_{+} Q_{-} */
/* X_W -> DUM_DERI+1 */
chrono_guess(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+2], mnl->csg_field,
mnl->csg_index_array, mnl->csg_N, mnl->csg_n, VOLUME/2, &Q_pm_psi);
mnl->iter1 += cg_her(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+2],
mnl->maxiter, mnl->forceprec, g_relative_precision_flag,
VOLUME, &Q_pm_psi);
chrono_add_solution(g_spinor_field[DUM_DERI+1], mnl->csg_field, mnl->csg_index_array,
mnl->csg_N, &mnl->csg_n, VOLUME/2);
/* Y_W -> DUM_DERI */
Q_minus_psi(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1]);
}
else {
/* Invert first Q_+ */
/* Y_o -> DUM_DERI */
chrono_guess(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+2], mnl->csg_field, mnl->csg_index_array,
mnl->csg_N, mnl->csg_n, VOLUME/2, &Q_plus_psi);
gamma5(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI], VOLUME);
mnl->iter1 += bicgstab_complex(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+2],
mnl->maxiter, mnl->forceprec, g_relative_precision_flag,
VOLUME, Q_plus_psi);
chrono_add_solution(g_spinor_field[DUM_DERI], mnl->csg_field, mnl->csg_index_array,
mnl->csg_N, &mnl->csg_n, VOLUME/2);
/* Now Q_- */
/* X_o -> DUM_DERI+1 */
g_mu = -g_mu;
chrono_guess(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI], mnl->csg_field2,
mnl->csg_index_array2, mnl->csg_N2, mnl->csg_n2, VOLUME/2, &Q_minus_psi);
gamma5(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+1], VOLUME);
mnl->iter1 += bicgstab_complex(g_spinor_field[DUM_DERI+1],g_spinor_field[DUM_DERI],
mnl->maxiter, mnl->forceprec, g_relative_precision_flag,
VOLUME, Q_minus_psi);
chrono_add_solution(g_spinor_field[DUM_DERI+1], mnl->csg_field2, mnl->csg_index_array2,
mnl->csg_N2, &mnl->csg_n2, VOLUME/2);
g_mu = -g_mu;
}
/* \delta Q sandwitched by Y^\dagger and X */
deriv_Sb_D_psi(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1], hf, mnl->forcefactor);
g_mu = mnl->mu2;
boundary(mnl->kappa2);
/* Second term coming from the second field */
/* The sign is opposite!! */
mul_r(g_spinor_field[DUM_DERI], -1., mnl->pf, VOLUME);
/* \delta Q sandwitched by Y^\dagger and X */
deriv_Sb_D_psi(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1], hf, mnl->forcefactor);
}
g_mu = g_mu1;
boundary(g_kappa);
ITER_MAX_BCG = saveiter;
return;
}
void detratio_heatbath(const int id, hamiltonian_field_t * const hf) {
int saveiter = ITER_MAX_BCG;
monomial * mnl = &monomial_list[id];
g_mu = mnl->mu;
boundary(mnl->kappa);
mnl->csg_n = 0;
mnl->csg_n2 = 0;
mnl->iter0 = 0;
mnl->iter1 = 0;
if(mnl->even_odd_flag) {
random_spinor_field(g_spinor_field[4], VOLUME/2, mnl->rngrepro);
mnl->energy0 = square_norm(g_spinor_field[4], VOLUME/2, 1);
Qtm_plus_psi(g_spinor_field[3], g_spinor_field[4]);
g_mu = mnl->mu2;
boundary(mnl->kappa2);
zero_spinor_field(mnl->pf,VOLUME/2);
if(mnl->solver == CG) ITER_MAX_BCG = 0;
ITER_MAX_CG = mnl->maxiter;
mnl->iter0 += bicg(mnl->pf, g_spinor_field[3], mnl->accprec, g_relative_precision_flag);
chrono_add_solution(mnl->pf, mnl->csg_field, mnl->csg_index_array,
mnl->csg_N, &mnl->csg_n, VOLUME/2);
if(mnl->solver != CG) {
chrono_add_solution(mnl->pf, mnl->csg_field2, mnl->csg_index_array2,
mnl->csg_N2, &mnl->csg_n2, VOLUME/2);
}
}
else {
random_spinor_field(g_spinor_field[4], VOLUME, mnl->rngrepro);
mnl->energy0 = square_norm(g_spinor_field[4], VOLUME, 1);
Q_plus_psi(g_spinor_field[3], g_spinor_field[4]);
g_mu = mnl->mu2;
boundary(mnl->kappa2);
zero_spinor_field(mnl->pf,VOLUME);
mnl->iter0 += bicgstab_complex(mnl->pf, g_spinor_field[3], mnl->maxiter, mnl->accprec,
g_relative_precision_flag, VOLUME, Q_plus_psi);
chrono_add_solution(mnl->pf, mnl->csg_field, mnl->csg_index_array,
mnl->csg_N, &mnl->csg_n, VOLUME/2);
if(mnl->solver != CG) {
chrono_add_solution(mnl->pf, mnl->csg_field2, mnl->csg_index_array2,
mnl->csg_N2, &mnl->csg_n2, VOLUME/2);
}
}
if(g_proc_id == 0 && g_debug_level > 3) {
printf("called detratio_heatbath for id %d %d energy %f\n", id, mnl->even_odd_flag, mnl->energy0);
}
g_mu = g_mu1;
boundary(g_kappa);
ITER_MAX_BCG = saveiter;
return;
}
double detratio_acc(const int id, hamiltonian_field_t * const hf) {
monomial * mnl = &monomial_list[id];
int saveiter = ITER_MAX_BCG;
int save_sloppy = g_sloppy_precision_flag;
g_mu = mnl->mu2;
boundary(mnl->kappa2);
if(even_odd_flag) {
Qtm_plus_psi(g_spinor_field[DUM_DERI+5], mnl->pf);
g_mu = mnl->mu;
boundary(mnl->kappa);
if(mnl->solver == CG) ITER_MAX_BCG = 0;
ITER_MAX_CG = mnl->maxiter;
chrono_guess(g_spinor_field[3], g_spinor_field[DUM_DERI+5], mnl->csg_field, mnl->csg_index_array,
mnl->csg_N, mnl->csg_n, VOLUME/2, &Qtm_plus_psi);
g_sloppy_precision_flag = 0;
mnl->iter0 += bicg(g_spinor_field[3], g_spinor_field[DUM_DERI+5], mnl->accprec, g_relative_precision_flag);
g_sloppy_precision_flag = save_sloppy;
/* ITER_MAX_BCG = *saveiter_max; */
/* Compute the energy contr. from second field */
mnl->energy1 = square_norm(g_spinor_field[3], VOLUME/2, 1);
}
else {
Q_plus_psi(g_spinor_field[DUM_DERI+5], mnl->pf);
g_mu = mnl->mu;
boundary(mnl->kappa);
chrono_guess(g_spinor_field[3], g_spinor_field[DUM_DERI+5], mnl->csg_field, mnl->csg_index_array,
mnl->csg_N, mnl->csg_n, VOLUME/2, &Q_plus_psi);
mnl->iter0 += bicgstab_complex(g_spinor_field[3], g_spinor_field[DUM_DERI+5],
mnl->maxiter, mnl->accprec, g_relative_precision_flag,
VOLUME, Q_plus_psi);
/* ITER_MAX_BCG = *saveiter_max; */
/* Compute the energy contr. from second field */
mnl->energy1 = square_norm(g_spinor_field[3], VOLUME, 1);
}
g_mu = g_mu1;
boundary(g_kappa);
ITER_MAX_BCG = saveiter;
if(g_proc_id == 0 && g_debug_level > 3) {
printf("called detratio_acc for id %d %d dH = %1.4e\n",
id, mnl->even_odd_flag, mnl->energy1 - mnl->energy0);
}
return(mnl->energy1 - mnl->energy0);
}