forked from kostrzewa/tmLQCD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chebyshev_polynomial_nd.c
372 lines (304 loc) · 11.6 KB
/
chebyshev_polynomial_nd.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
362
363
364
365
366
367
368
369
370
371
372
/***********************************************************************
*
* Copyright (C) 2006,2007,2008 Thomas Chiarappa, 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 "global.h"
#include "linsolve.h"
#include "linalg_eo.h"
#include "start.h"
#include "tm_operators.h"
#include "Nondegenerate_Matrix.h"
#include "phmc.h"
#include "chebyshev_polynomial_nd.h"
#define PI 3.141592653589793
double func(double u, double exponent){
return pow(u,exponent);
}
void chebyshev_coefs(double aa, double bb, double c[], int n, double exponent){
int k,j;
double fac,bpa,bma,*f;
double inv_n;
inv_n=1./(double)n;
f=calloc(n,sizeof(double));/*vector(0,n-1);*/
if((g_proc_id == g_stdio_proc) && (g_debug_level > 2)) {
printf("PHMC: chebyshev_polynomial\n");
printf("PHMC: n= %d inv_n=%e \n",n,inv_n);
printf("PHMC: allocation !!!\n");
}
fflush(stdout);
bma=0.5*(bb-aa);
bpa=0.5*(bb+aa);
for (k=0;k<n;k++) {
double y=cos(PI*(k+0.5)*inv_n);
f[k]=func(y*bma+bpa,exponent);
}
fac=2.0*inv_n;
for (j=0;j<n;j++) {
double sum=0.0;
for (k=0;k<n;k++)
sum += f[k]*cos(PI*j*(k+0.5)*inv_n);
c[j]=fac*sum;
}
free(f);
}
#undef PI
/****************************************************************************
*
* computation of, despite of the name, (Q Q^dagger) on a vector
* by using the chebyshev approximation for the function ()^1/4
* subtraction of low-lying eigenvalues is not yet implemented for this
*
**************************************************************************/
void QdaggerQ_poly(spinor *R_s, spinor *R_c, double *c, int n,
spinor *S_s, spinor *S_c){
int j;
double fact1, fact2, temp1, temp2, temp3, temp4;
spinor *svs_=NULL, *svs=NULL, *ds_=NULL, *ds=NULL, *dds_=NULL, *dds=NULL,
*auxs_=NULL, *auxs=NULL, *aux2s_=NULL, *aux2s=NULL, *aux3s_=NULL,
*aux3s=NULL;
spinor *svc_=NULL, *svc=NULL, *dc_=NULL, *dc=NULL, *ddc_=NULL,
*ddc=NULL, *auxc_=NULL, *auxc=NULL, *aux2c_=NULL, *aux2c=NULL,
*aux3c_=NULL, *aux3c=NULL;
#if ( defined SSE || defined SSE2 )
svs_ = calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
svs = (spinor *)(((unsigned long int)(svs_)+ALIGN_BASE)&~ALIGN_BASE);
ds_ = calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
ds = (spinor *)(((unsigned long int)(ds_)+ALIGN_BASE)&~ALIGN_BASE);
dds_ = calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
dds = (spinor *)(((unsigned long int)(dds_)+ALIGN_BASE)&~ALIGN_BASE);
auxs_ = calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
auxs = (spinor *)(((unsigned long int)(auxs_)+ALIGN_BASE)&~ALIGN_BASE);
aux2s_= calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
aux2s = (spinor *)(((unsigned long int)(aux2s_)+ALIGN_BASE)&~ALIGN_BASE);
aux3s_= calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
aux3s = (spinor *)(((unsigned long int)(aux3s_)+ALIGN_BASE)&~ALIGN_BASE);
svc_ = calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
svc = (spinor *)(((unsigned long int)(svc_)+ALIGN_BASE)&~ALIGN_BASE);
dc_ = calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
dc = (spinor *)(((unsigned long int)(dc_)+ALIGN_BASE)&~ALIGN_BASE);
ddc_ = calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
ddc = (spinor *)(((unsigned long int)(ddc_)+ALIGN_BASE)&~ALIGN_BASE);
auxc_ = calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
auxc = (spinor *)(((unsigned long int)(auxc_)+ALIGN_BASE)&~ALIGN_BASE);
aux2c_= calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
aux2c = (spinor *)(((unsigned long int)(aux2c_)+ALIGN_BASE)&~ALIGN_BASE);
aux3c_= calloc(VOLUMEPLUSRAND+1, sizeof(spinor));
aux3c = (spinor *)(((unsigned long int)(aux3c_)+ALIGN_BASE)&~ALIGN_BASE);
#else
svs_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
svs = svs_;
ds_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
ds = ds_;
dds_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
dds = dds_;
auxs_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
auxs = auxs_;
aux2s_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
aux2s = aux2s_;
aux3s_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
aux3s = aux3s_;
svc_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
svc = svc_;
dc_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
dc = dc_;
ddc_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
ddc = ddc_;
auxc_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
auxc = auxc_;
aux2c_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
aux2c = aux2c_;
aux3c_=calloc(VOLUMEPLUSRAND, sizeof(spinor));
aux3c = aux3c_;
#endif
fact1=4/(phmc_cheb_evmax-phmc_cheb_evmin);
fact2=-2*(phmc_cheb_evmax+phmc_cheb_evmin)/(phmc_cheb_evmax-phmc_cheb_evmin);
zero_spinor_field(&ds[0],VOLUME/2);
zero_spinor_field(&dds[0],VOLUME/2);
zero_spinor_field(&dc[0],VOLUME/2);
zero_spinor_field(&ddc[0],VOLUME/2);
/* sub_low_ev(&aux3[0], &S[0]); */
assign(&aux3s[0], &S_s[0],VOLUME/2);
assign(&aux3c[0], &S_c[0],VOLUME/2);
/* Use the Clenshaw's recursion for the Chebysheff polynomial */
for (j=n-1; j>=1; j--) {
assign(&svs[0],&ds[0],VOLUME/2);
assign(&svc[0],&dc[0],VOLUME/2);
/*
if ( (j%10) == 0 ) {
sub_low_ev(&aux[0], &d[0]);
}
else { */
assign(&auxs[0], &ds[0], VOLUME/2);
assign(&auxc[0], &dc[0], VOLUME/2);
/* } */
Q_Qdagger_ND(&R_s[0], &R_c[0], &auxs[0], &auxc[0]);
temp1=-1.0;
temp2=c[j];
assign_mul_add_mul_add_mul_add_mul_r(&ds[0] , &R_s[0], &dds[0], &aux3s[0], fact2, fact1, temp1, temp2,VOLUME/2);
assign_mul_add_mul_add_mul_add_mul_r(&dc[0] , &R_c[0], &ddc[0], &aux3c[0], fact2, fact1, temp1, temp2,VOLUME/2);
assign(&dds[0], &svs[0],VOLUME/2);
assign(&ddc[0], &svc[0],VOLUME/2);
}
/* sub_low_ev(&R[0],&d[0]); */
assign(&R_s[0], &ds[0],VOLUME/2);
assign(&R_c[0], &dc[0],VOLUME/2);
Q_Qdagger_ND(&auxs[0], &auxc[0], &R_s[0], &R_c[0]);
temp1=-1.0;
temp2=c[0]/2;
temp3=fact1/2;
temp4=fact2/2;
assign_mul_add_mul_add_mul_add_mul_r(&auxs[0], &ds[0], &dds[0], &aux3s[0], temp3, temp4, temp1, temp2,VOLUME/2);
assign_mul_add_mul_add_mul_add_mul_r(&auxc[0], &dc[0], &ddc[0], &aux3c[0], temp3, temp4, temp1, temp2,VOLUME/2);
assign(&R_s[0], &auxs[0],VOLUME/2);
assign(&R_c[0], &auxc[0],VOLUME/2);
/* addproj_q_invsqrt(&R[0], &S[0]); */
/*
#ifndef _SOLVER_OUTPUT
if(g_proc_id == g_stdio_proc){
printf("Order of Chebysheff approximation = %d\n",j);
fflush( stdout);};
#endif
*/
free(svs_);
free(ds_);
free(dds_);
free(auxs_);
free(aux2s_);
free(aux3s_);
free(svc_);
free(dc_);
free(ddc_);
free(auxc_);
free(aux2c_);
free(aux3c_);
}
double cheb_eval(int M, double *c, double s){
double d=0,dd=0, sv, z, z2, res;
int j;
z = (2.0*s - phmc_cheb_evmin - phmc_cheb_evmax)/(double)(phmc_cheb_evmax - phmc_cheb_evmin);
z2 = 2.0*z;
for(j=M-1; j>=1; j--){
sv = d;
d = z2*d - dd + c[j];
dd = sv;
}
res = z*d - dd + 0.5*c[0];
return(res);
}
/**************************************************************************
*
* The externally accessible function is
*
* void degree_of_polynomial_nd(void)
* Computation of (QdaggerQ)^1/4
* by using the chebyshev approximation for the function ()^1/4
*
*
*****************************************************************************/
void degree_of_polynomial_nd(const int degree_of_p){
int j;
double temp, temp2;
static int ini=0;
double sum=0.0;
spinor *ss=NULL, *ss_=NULL, *sc=NULL, *sc_=NULL;
spinor *auxs=NULL, *auxs_=NULL, *auxc=NULL, *auxc_=NULL;
spinor *aux2s=NULL, *aux2s_=NULL, *aux2c=NULL, *aux2c_=NULL;
phmc_dop_n_cheby=degree_of_p+1;
if(ini==0){
phmc_dop_cheby_coef = calloc(phmc_dop_n_cheby,sizeof(double));
ini=1;
}
#if ( defined SSE || defined SSE2 || defined SSE3)
ss_ = calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
auxs_ = calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
aux2s_= calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
sc_ = calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
auxc_ = calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
aux2c_= calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
ss = (spinor *)(((unsigned long int)(ss_)+ALIGN_BASE)&~ALIGN_BASE);
auxs = (spinor *)(((unsigned long int)(auxs_)+ALIGN_BASE)&~ALIGN_BASE);
aux2s = (spinor *)(((unsigned long int)(aux2s_)+ALIGN_BASE)&~ALIGN_BASE);
sc = (spinor *)(((unsigned long int)(sc_)+ALIGN_BASE)&~ALIGN_BASE);
auxc = (spinor *)(((unsigned long int)(auxc_)+ALIGN_BASE)&~ALIGN_BASE);
aux2c = (spinor *)(((unsigned long int)(aux2c_)+ALIGN_BASE)&~ALIGN_BASE);
#else
ss =calloc(VOLUMEPLUSRAND/2, sizeof(spinor));
auxs =calloc(VOLUMEPLUSRAND/2, sizeof(spinor));
aux2s=calloc(VOLUMEPLUSRAND/2, sizeof(spinor));
sc =calloc(VOLUMEPLUSRAND/2, sizeof(spinor));
auxc =calloc(VOLUMEPLUSRAND/2, sizeof(spinor));
aux2c=calloc(VOLUMEPLUSRAND/2, sizeof(spinor));
#endif
chebyshev_coefs(phmc_cheb_evmin, phmc_cheb_evmax, phmc_dop_cheby_coef, phmc_dop_n_cheby, -0.5);
random_spinor_field(ss,VOLUME/2, 1);
random_spinor_field(sc,VOLUME/2, 1);
if((g_proc_id == g_stdio_proc) && (g_debug_level > 0)){
printf("NDPOLY MD Polynomial: EVmin = %e EVmax = %e \n", phmc_cheb_evmin, phmc_cheb_evmax);
printf("NDPOLY MD Polynomial: the degree was set to: %d\n", phmc_dop_n_cheby);
fflush(stdout);
}
/* Here we check the accuracy */
QdaggerQ_poly(&auxs[0], &auxc[0], phmc_dop_cheby_coef, phmc_dop_n_cheby, &ss[0], &sc[0]);
Q_Qdagger_ND(&aux2s[0], &aux2c[0], &auxs[0], &auxc[0]);
QdaggerQ_poly(&auxs[0], &auxc[0], phmc_dop_cheby_coef, phmc_dop_n_cheby, &aux2s[0], &aux2c[0]);
diff(&aux2s[0],&auxs[0],&ss[0],VOLUME/2);
temp=square_norm(&aux2s[0],VOLUME/2, 1)/square_norm(&ss[0],VOLUME/2, 1)/4.0;
diff(&aux2c[0],&auxc[0],&sc[0],VOLUME/2);
temp2 = square_norm(&aux2c[0],VOLUME/2, 1)/square_norm(&sc[0],VOLUME/2, 1)/4.0;
if(g_epsbar == 0.){
temp2 = 0.0;
}
if(g_proc_id == g_stdio_proc && g_debug_level > 0){
/* this is || (P S P - 1)X ||^2 /|| 2X ||^2 */
/* where X is a random spinor field */
printf("NDPOLY MD Polynomial: relative squared accuracy in components:\n UP=%e DN=%e \n", temp, temp2);
/* printf("NDPOLY: Sum remaining | c_n | = %e \n", sum); */
fflush(stdout);
}
if(g_debug_level > 1) {
temp = cheb_eval(phmc_dop_n_cheby, phmc_dop_cheby_coef, phmc_cheb_evmin);
temp *= phmc_cheb_evmin;
temp *= cheb_eval(phmc_dop_n_cheby, phmc_dop_cheby_coef, phmc_cheb_evmin);
temp = 0.5*fabs(temp - 1);
if(g_proc_id == g_stdio_proc) {
printf("PHMC: Delta_IR at s=%f: | P s_low P - 1 |/2 = %e \n", phmc_cheb_evmin, temp);
}
}
/* RECALL THAT WE NEED AN EVEN DEGREE !!!! */
#if ( defined SSE || defined SSE2 || defined SSE3)
free(ss_);
free(auxs_);
free(aux2s_);
free(sc_);
free(auxc_);
free(aux2c_);
#else
free(ss);
free(auxs);
free(aux2s);
free(sc);
free(auxc);
free(aux2c);
#endif
}