-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphmc.c
312 lines (255 loc) · 9.29 KB
/
phmc.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
/***********************************************************************
* 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<config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include "global.h"
#include "read_input.h"
#include "init_bispinor_field.h"
#include "eigenvalues_bi.h"
#include "solver/solver.h"
#include "init_chi_spinor_field.h"
#include "chebyshev_polynomial_nd.h"
#include "Ptilde_nd.h"
#include "phmc.h"
#include "monomial.h"
#include "gettime.h"
double phmc_Cpol;
double phmc_cheb_evmin, phmc_cheb_evmax;
double phmc_invmaxev;
_Complex double * phmc_root;
int phmc_dop_n_cheby;
double * phmc_dop_cheby_coef;
int phmc_ptilde_n_cheby;
double * phmc_ptilde_cheby_coef;
int errcode;
phmc_vars *phmc_var_stack=NULL;
int phmc_max_ptilde_degree = NTILDE_CHEBYMAX;
void init_phmc() {
int max_iter_ev, j, k;
FILE *roots;
char *filename_phmc_root = "Square_root_BR_roots.dat";
char *filename_phmc_root_oox = "Square_root_BR_roots.dat.oox";
char title[100];
FILE *Const;
char *filename_const = "normierungLocal.dat";
char *filename_const_oox = "normierungLocal.dat.oox";
/* contains info about the mnl poly_monomial*/
monomial *mnl=NULL;
for(j=0;j<no_monomials;j++)
if(monomial_list[j].type == NDPOLY) mnl= monomial_list + j;
if(mnl==NULL)
fprintf(stderr,"Warning: couldnt find the NDPOLY monomial. Thats VERY strange.\n");
/* START IF PHMC */
phmc_invmaxev=1.0;
if(phmc_compute_evs != 0) {
g_mu = g_mu1;
max_iter_ev = 1000;
no_eigenvalues = 10; /* Number of lowest eigenvalues to be computed */
if(g_epsbar!=0.0)
phmc_cheb_evmin = eigenvalues_bi(&no_eigenvalues, max_iter_ev, eigenvalue_precision, 0);
else {
phmc_cheb_evmin = eigenvalues(&no_eigenvalues, max_iter_ev, eigenvalue_precision, 0, 0, nstore, even_odd_flag);
}
no_eigenvalues = 4; /* Number of highest eigenvalues to be computed */
if(g_epsbar!=0.0)
phmc_cheb_evmax = eigenvalues_bi(&no_eigenvalues, max_iter_ev, eigenvalue_precision, 1);
else
phmc_cheb_evmax = eigenvalues(&no_eigenvalues, max_iter_ev, eigenvalue_precision, 1, 0, nstore, even_odd_flag);
if(g_proc_id==0)
{
printf("PHMC: Ev-max = %e \n", phmc_cheb_evmax);
printf("PHMC: Ev-min = %e \n", phmc_cheb_evmin);
}
#ifdef MPI
MPI_Finalize();
#endif
exit(0);
}
/* This is the epsilon parameter */
phmc_cheb_evmin = stilde_min/(stilde_max);
/* In the following there is the "sqrt" since the value refers to
the hermitian Dirac operator (used in EV-computation), namely
S = Q Q^dag
When "S" is applied, we call phmc_invmaxev twice !!! */
if(g_epsbar!=0.0 || phmc_exact_poly==0) phmc_invmaxev=1./(sqrt(stilde_max));
else if(g_epsbar==0.0 && phmc_exact_poly==1) phmc_invmaxev=1./stilde_max;
phmc_cheb_evmax = 1.0;
/* Here we prepare the less precise polynomial first */
degree_of_polynomial_nd(degree_of_p);
if((g_proc_id == 0) && (g_debug_level > 1)) {
printf("PHMC: interval of approximation [stilde_min, stilde_max] = [%e, %e]\n", stilde_min, stilde_max);
printf("PHMC: degree for P = %d, epsilont = %e, normalisation = %e",
phmc_dop_n_cheby-1, phmc_cheb_evmin, phmc_invmaxev);
}
/* Chi`s-spinors memory allocation */
j = init_chi_spinor_field(VOLUMEPLUSRAND/2, (phmc_dop_n_cheby+1));
if ( j!= 0) {
fprintf(stderr, "Not enough memory for PHMC Chi fields! Aborting...\n");
exit(0);
}
/* End memory allocation */
/* Here we prepare the precise polynomial */
degree_of_Ptilde();
/* THIS IS THE OVERALL CONSTANT */
/* write phmc_Cpol as the result of the simple-program files (BigC^(1/2))^1/2
since BigC^(1/2) is the constant appearing in each factor of the
multiplication defining the monomial basis representation of the
polinomial in s, while its square phmc_root (BigC^(1/2))^1/2 is the
constant appearing in the multiplication representing the
polinomial in sqrt(s) .
*/
if(mnl->MDPolyLocNormConst == -1.0){
if(!(g_epsbar!=0.0 || phmc_exact_poly==0))
filename_const=filename_const_oox;
if((Const=fopen(filename_const,"r")) != (FILE*)NULL) {
errcode = fscanf(Const, " %lf \n", &phmc_Cpol);
fclose(Const);
} else {
fprintf(stderr, "File %s is missing! Aborting...\n", filename_const);
#ifdef MPI
MPI_Finalize();
#endif
exit(6);
}
} else {
phmc_Cpol=mnl->MDPolyLocNormConst;
fprintf(stderr,"phmc_Cpol set to %e " , phmc_Cpol);
}
if(g_epsbar!=0.0 || phmc_exact_poly==0) phmc_Cpol = sqrt(phmc_Cpol);
phmc_root = calloc((2*phmc_dop_n_cheby-2),sizeof(_Complex double));
if(g_epsbar==0.0 && phmc_exact_poly == 1)
filename_phmc_root=filename_phmc_root_oox;
if(strlen(mnl->MDPolyRootsFile)!=0)
filename_phmc_root=mnl->MDPolyRootsFile;
if((roots=fopen(filename_phmc_root,"r")) != (FILE*)NULL) {
if (fgets(title, 100, roots) == NULL)
{
fprintf(stderr, "Error in reading %s! Aborting...\n", filename_phmc_root);
#ifdef MPI
MPI_Finalize();
#endif
exit(6);
}
/* Here we read in the 2n roots needed for the polinomial in sqrt(s) */
double *phmc_darray = (double*)phmc_root;
for(j = 0; j< 2 * phmc_dop_n_cheby - 2; ++j)
errcode = fscanf(roots," %d %lf %lf \n", &k, &phmc_darray[2 * j], &phmc_darray[2 * j + 1]);
fclose(roots);
}
else {
fprintf(stderr, "File %s is missing! Aborting...\n", filename_phmc_root);
#ifdef MPI
MPI_Finalize();
#endif
exit(6);
}
/* END IF PHMC */
return;
}
void phmc_compute_ev(const int trajectory_counter,
const double plaquette_energy) {
double atime, etime, temp=0., temp2=0.;
int max_iter_ev, no_eigenvalues;
char * phmcfilename = "phmc.data";
FILE * countfile;
atime = gettime();
max_iter_ev = 1000;
g_mu = g_mu1;
if((g_proc_id == 0) && (g_debug_level > 0)) {
printf("# Computing eigenvalues for heavy doublet\n");
}
no_eigenvalues = 1;
if(g_epsbar!=0.0)
temp = eigenvalues_bi(&no_eigenvalues, max_iter_ev, eigenvalue_precision, 0);
else
temp = eigenvalues(&no_eigenvalues, max_iter_ev, eigenvalue_precision, 0, 0, nstore, even_odd_flag);
no_eigenvalues = 1;
if(g_epsbar!=0.0)
temp2 = eigenvalues_bi(&no_eigenvalues, max_iter_ev, eigenvalue_precision, 1);
else
temp2 = eigenvalues(&no_eigenvalues, max_iter_ev, eigenvalue_precision, 1, 0, nstore, even_odd_flag);
if((g_proc_id == 0) && (g_debug_level > 0)) {
printf("# PHMC: lowest eigenvalue end of trajectory %d = %e\n",
trajectory_counter, temp);
printf("# PHMC: maximal eigenvalue end of trajectory %d = %e\n",
trajectory_counter, temp2);
}
if(g_proc_id == 0) {
countfile = fopen(phmcfilename, "a");
fprintf(countfile, "%d %1.12f %1.5e %1.5e %1.5e %1.5e\n",
trajectory_counter, plaquette_energy/(6.*VOLUME*g_nproc), temp, temp2, stilde_min, stilde_max);
fclose(countfile);
}
etime = gettime();
if((g_proc_id == 0)) {
printf("# PHMC: time/s for eigenvalue computation %e\n", etime-atime);
}
}
/**
* creates a new stack element and stores a set of phmc
* variables needed in the operators
*/
void pushPhmcVars(){
if(phmc_var_stack==NULL){
phmc_var_stack=(phmc_vars*)malloc(sizeof(phmc_vars));
phmc_var_stack->previous=NULL;
phmc_var_stack->stacksize=1;
} else {
phmc_var_stack->next=malloc(sizeof(phmc_vars));
((phmc_vars*)phmc_var_stack->next)->previous=(void*)phmc_var_stack;
phmc_var_stack=(phmc_vars*)phmc_var_stack->next;
phmc_var_stack->stacksize=((phmc_vars*)phmc_var_stack->previous)->stacksize+1;
}
phmc_var_stack->next=NULL;
/* save global phmc variables */
phmc_var_stack->invmaxev=phmc_invmaxev;
phmc_var_stack->Cpol=phmc_Cpol;
phmc_var_stack->root=phmc_root;
phmc_var_stack->dop_n_cheby=phmc_dop_n_cheby;
if(g_proc_id==0)
fprintf(stderr,"phmc variable stack size is now %d \n",phmc_var_stack->stacksize);
}
/**
* restores the variables to the values stored in the
* top stack element and removes it
*/
void popPhmcVars(){
if(phmc_var_stack!=NULL){
phmc_vars *prev;
/* restore global phmc variables */
phmc_invmaxev=phmc_var_stack->invmaxev;
phmc_Cpol=phmc_var_stack->Cpol;
phmc_root=phmc_var_stack->root;
phmc_dop_n_cheby=phmc_var_stack->dop_n_cheby;
prev=(phmc_vars*)phmc_var_stack->previous;
free(phmc_var_stack);
phmc_var_stack=prev;
if(phmc_var_stack!=NULL)
phmc_var_stack->next=NULL;
} else {
if(g_proc_id==0)
fprintf(stderr,"Error: there is no element on the stack\n");
}
}