-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigData.hpp
1237 lines (1000 loc) · 42.3 KB
/
ConfigData.hpp
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// v1.1 - 2012-10-11 - 15:00
#ifndef CONFIGFUNCTIONS_H
#define CONFIGFUNCTIONS_H
#include <complex>
#include <vector>
#include <fstream>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <string>
#include "CArray.hpp"
// using namespace std;
#define DIM 4 //Space-Time dimensions
#define MD 3 // SU(MD) Matrix dimension
class ConfigData{
public:
// Constructor
ConfigData(int len1, int len2, int len3, int len4, int md, bool vb);
~ConfigData();
// Interfaces
void extract(std::complex<double> *m, int nindex, int mu); // Returns the matrix @ (nindex,mu)
void replace(std::complex<double> *m, int nindex, int mu); // Replaces the matrix @ (nindex,mu)
void dumpConfig(); // Dumps the config to stdout
void freeConfig(); // Creates a free config (diag(1,1,1) matrices on every link)
int readConfig(std::string fconfigname); // Reads a config from file
int readFConfig(std::string fconfigname); // Fortran config
int readBinaryConfig(std::string fconfigname);
int readBinaryConfig2(std::string fconfigname);
int writeConfig(std::string fconfigname); // Reads a config from file
int writeBinaryConfig(std::string fconfigname);
int writeBinaryConfig2(std::string fconfigname);
int writeNERSCConfig(std::string fconfigname);
int writeBinaryLPoll(std::string fconfigname); // Writes local Polyakov loops in binary
int latmap(int i1, int i2, int i3, int i4);
int neib(int site, int mu);
// MILC
int MILCreadConfig(std::string fconfigname); // Reads a config from file
int MILCreadBinaryConfig(std::string fconfigname);
std::complex<double> U(int nindex, int mu, int c1, int c2);
std::complex<double> calcPoll();
std::complex<double> calcPlaq();
void calcLocalPoll(std::complex<double> *lpoll, int i1, int i2, int i3, std::complex<double> &sum);
// Function tests
void runTests();
// Switch to antiperiodic boundary conditions
void antiperbc();
// Perform random Z3 rotation
void z3rot();
private:
// Variables which store basic dimensions
int leng1, leng2, leng3, leng4, matrixdim, nsite;
int **neibArray;
bool verbose;
// Stores the config
// vector<vector<vector<vector< std::complex<double> > > > > A;
CArray *A;
// Used to create 2D arrays on heap (e.g., neib[][])
int **Create2D(int row, int col);
void Delete2D(int **p, int row);
// Functions for checking the configuration
void staplesum(std::complex<double> *S, int mu, int nindex);
// Matrix functions
void aeb(std::complex<double> *a, std::complex<double> *b);
void apb(std::complex<double> *c, std::complex<double> *a);
void amb(std::complex<double> *c,std::complex<double> *a, std::complex<double> *b);
void capb(std::complex<double> *c, std::complex<double> *a, std::complex<double> *b);
void axb(std::complex<double> *a,std::complex<double> *b, std::complex<double> *c);
void axbdag(std::complex<double> *a,std::complex<double> *b, std::complex<double> *c);
void adagxb(std::complex<double> *a,std::complex<double> *b, std::complex<double> *c);
void adagxbdag(std::complex<double> *a,std::complex<double> *b, std::complex<double> *c);
std::complex<double> multtrace(std::complex<double> *a, std::complex<double> *b);
void za(std::complex<double> *c, double z, std::complex<double> *a);
void adag(std::complex<double> *a);
// Test functions
void printMatrix(std::complex<double> *a, int md);
};
ConfigData::ConfigData(int len1, int len2, int len3, int len4, int md, bool vb=true){
leng1=len1; leng2=len2; leng3=len3; leng4=len4; matrixdim=md;
nsite=leng1*leng2*leng3*leng4;
verbose=vb;
A = new CArray(nsite, DIM, matrixdim, matrixdim);
neibArray = Create2D(nsite, DIM*2);
// Fills the neib array
int i1p,i2p,i3p,i4p,i1m,i2m,i3m,i4m,is,isp1,isp2,isp3,isp4,ism1,ism2,ism3,ism4;
for(int i1 = 0;i1<leng1;i1++){
i1p = i1 + 1;
i1m = i1 - 1;
if (i1p == leng1) i1p = 0;
if (i1m == -1) i1m = leng1-1;
for(int i2 = 0;i2<leng2;i2++){
i2p = i2 + 1;
i2m = i2 - 1;
if (i2p == leng2) i2p = 0;
if (i2m == -1) i2m = leng2-1;
for(int i3 = 0;i3<leng3;i3++){
i3p = i3 + 1;
i3m = i3 - 1;
if (i3p == leng3) i3p = 0;
if (i3m == -1) i3m = leng3-1;
for(int i4 = 0;i4<leng4;i4++){
i4p = i4 + 1;
i4m = i4 - 1;
if (i4p == leng4) i4p = 0;
if (i4m == -1) i4m = leng4-1;
// Compute the site address and the addresses of the sites shifted
// by one unit in each direction
is = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
isp1 = i1p + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
isp2 = i1 + i2p*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
isp3 = i1 + i2*leng1 + i3p*leng1*leng2 + i4*leng1*leng2*leng3;
isp4 = i1 + i2*leng1 + i3*leng1*leng2 + i4p*leng1*leng2*leng3;
ism1 = i1m + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
ism2 = i1 + i2m*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
ism3 = i1 + i2*leng1 + i3m*leng1*leng2 + i4*leng1*leng2*leng3;
ism4 = i1 + i2*leng1 + i3*leng1*leng2 + i4m*leng1*leng2*leng3;
// Fill the neib array
neibArray[is][0] = isp1;
neibArray[is][1] = isp2;
neibArray[is][2] = isp3;
neibArray[is][3] = isp4;
neibArray[is][4] = ism1;
neibArray[is][5] = ism2;
neibArray[is][6] = ism3;
neibArray[is][7] = ism4;
}
}
}
}
}
ConfigData::~ConfigData(){
Delete2D(neibArray, nsite);
delete A; A=0;
}
std::complex<double> ConfigData::U(int nindex, int mu, int c1, int c2){
#ifdef DEBUG
if(nindex<0 || nindex>nsite-1 || c1<0 || c1>3 || c2<0 || c2>3 || mu<0 || mu>3){
std::cout << "Error in ConfigData::U(int nindex, int mu, int c1, int c2)" << std::endl;
return 0;
}
#endif
return (*A)(nindex,mu,c1,c2);
}
void ConfigData::extract(std::complex<double> *m, int nindex, int mu) {
// Extracts the matrix at (x,mu) in A and writes it to m
#ifdef DEBUG
if(nindex<0 || nindex>nsite-1 || mu<0 || mu>DIM*2){
std::cout << "Error in ConfigData::extract(std::complex<double> *m, int mu, int nindex)" << std::endl;
exit(1);
}
#endif
for(int i=0;i<matrixdim;i++)
for(int j=0;j<matrixdim;j++){
m[i*matrixdim + j]=(*A)(nindex,mu,i,j);
}
// memcpy( m, &(*A)(nindex,mu,0,0), entries*sizeof(std::complex<double>) );
}
void ConfigData::replace(std::complex<double> *m, int nindex, int mu) {
// Replaces the matrix at (x,mu) in A with m
#ifdef DEBUG
if(nindex<0 || nindex>nsite-1 || mu<0 || mu>DIM*2){
std::cout << "Error in ConfigData::replace(std::complex<double> *m, int mu, int nindex)" << std::endl;
exit(1);
}
#endif
for(int i=0;i<matrixdim;i++)
for(int j=0;j<matrixdim;j++){
(*A)(nindex,mu,i,j)=m[i*matrixdim + j];
}
// memcpy( &(*A)(nindex,mu,0,0),m, entries*sizeof(std::complex<double>) );
}
int ConfigData::latmap(int i1, int i2, int i3, int i4){
int is = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
return is;
}
int ConfigData::neib(int nindex, int mu){
#ifdef DEBUG
if(nindex>=nsite || nindex<0 || mu>=DIM*2 || mu<0){
std::cout << "Error in ConfigData::neib(int nindex, int mu)" << std::endl;
return -1;
}else{
return neibArray[nindex][mu];
}
#endif
return neibArray[nindex][mu];
}
void ConfigData::antiperbc(){
// Switches to antiperiodic boundary conditions
if(verbose)
std::cout << "Switching to anti-periodic boundary conditions... " << std::flush;
int n=0;
for(int x1=0;x1<leng1;x1++)
for(int x2=0;x2<leng2;x2++)
for(int x3=0;x3<leng3;x3++){
n = x1 + x2*leng1 + x3*leng1*leng2
+ (leng4-1)*leng1*leng2*leng3; // Not sure if this is correct!
for(int i=0;i<matrixdim;i++)
for(int j=0;j<matrixdim;j++){
(*A)(n,3,i,j) = -(*A)(n,3,i,j);
}
}
if(verbose)
std::cout << "done!" << std::endl;
}
void ConfigData::dumpConfig(){
std::complex<double> U[matrixdim][matrixdim];
for(int n=0;n<nsite;n++){
for(int mu=0;mu<DIM;mu++){
extract(*U, n, mu);
for(int i=0; i<matrixdim; i++){
for(int j=0; j<matrixdim; j++){
std::cout << real(U[i][j]) << " " << imag(U[i][j]) << " ";
}
}
std::cout << std::endl;
}
}
}
void ConfigData::freeConfig(){
if(verbose)
std::cout << "Using a free configuration... " << std::flush;
for(int n=0;n<nsite;n++){
for(int mu=0;mu<DIM;mu++){
//for(int i=0;i<matrixdim;i++)
// A[n][mu][i][i]=std::complex<double>(1,0);
(*A)(n,mu,0,0)=std::complex<double>(1, 0);
(*A)(n,mu,1,1)=std::complex<double>(1, 0);
(*A)(n,mu,2,2)=std::complex<double>(1, 0);
}
}
if(verbose)
std::cout << "done!" << std::endl;
}
int ConfigData::readBinaryConfig(std::string fconfigname){
int ERR = A->bread(fconfigname);
std::complex<double> poll=calcPoll();
std::complex<double> plaq=calcPlaq();
if(verbose){
std::cout << "Configfile " << fconfigname << " read (old binary format)." << std::endl << std::endl;
std::cout << "Checks:" << std::endl;
std::cout << "Polyakov loop: calculated=" << poll << std::endl;
std::cout << "Plaquettes: calculated=" << plaq << std::endl << std::endl;
}
return ERR;
}
int ConfigData::writeBinaryConfig(std::string fconfigname){
int ERR = A->bwrite(fconfigname);
return ERR;
}
int ConfigData::writeBinaryConfig2(std::string fconfigname){
int elems=0;
std::complex<double> plaq, poll;
FILE* pFile;
int nindex=nsite*matrixdim*matrixdim*DIM;
pFile = fopen(fconfigname.c_str(), "wb");
if (pFile == NULL) perror ("Error opening file");
else{
elems += fwrite(&leng1, sizeof(int), 1, pFile);
elems += fwrite(&leng2, sizeof(int), 1, pFile);
elems += fwrite(&leng3, sizeof(int), 1, pFile);
elems += fwrite(&leng4, sizeof(int), 1, pFile);
poll=calcPoll();
plaq=calcPlaq();
elems += fwrite(&poll, sizeof(std::complex<double>),1, pFile);
elems += fwrite(&plaq, sizeof(std::complex<double>),1, pFile);
elems += fwrite(&(*A)(0,0,0,0), sizeof(std::complex<double>), nindex, pFile);
fclose(pFile);
}
return nindex + 6 - elems;
}
int ConfigData::writeNERSCConfig(std::string fconfigname){
// This function writes the SU(3) gauge configurations in
// NERSC format. It contains the following headers
// ...
// in ASCII format followed by the binary data
// in the following order:
//
// This uses the original NERSC format where only the
// first two rows of the link matrices are stored.
if(matrixdim != 3){
std::cout << "Not a SU(3) configuration! Can not use" << std::endl
<< "NERSC configuration format!" << std::endl;
return -1;
}
// int elems=0;
// int nindex=nsite*matrixdim*matrixdim*DIM;
// We need the Polyakov loop and plaquette in the file header
// so we calculate it.
std::complex<double> plaq, poll;
poll=calcPoll();
plaq=calcPlaq();
// We also need the average of the trace of all links.
std::complex<double> U[matrixdim][matrixdim];
double linktrace=0;
for(int n=0;n<nsite;n++){
for(int mu=0;mu<DIM;mu++){
extract(*U, n, mu);
for(int i=0; i<matrixdim; i++){
linktrace += real(U[i][i]);
}
}
}
linktrace=linktrace/(double)(nsite*12.0);
FILE* pFile;
pFile = fopen(fconfigname.c_str(), "wb");
// HEADER
fprintf(pFile, "BEGIN_HEADER\n");
fprintf(pFile, "HDR_VERSION=1.0\n");
fprintf(pFile, "DATATYPE=4D_SU3_GAUGE\n");
fprintf(pFile, "STORAGE_FORMAT=1.0\n");
fprintf(pFile, "DIMENSION_1=%i\n", leng1);
fprintf(pFile, "DIMENSION_2=%i\n", leng2);
fprintf(pFile, "DIMENSION_3=%i\n", leng3);
fprintf(pFile, "DIMENSION_4=%i\n", leng4);
fprintf(pFile, "LINK_TRACE=%f\n", linktrace);
fprintf(pFile, "PLAQUETTE=%f\n", real(plaq));
fprintf(pFile, "BOUNDARY_1=PERIODIC\n");
fprintf(pFile, "BOUNDARY_2=PERIODIC\n");
fprintf(pFile, "BOUNDARY_3=PERIODIC\n");
fprintf(pFile, "BOUNDARY_4=PERIODIC\n");
fprintf(pFile, "CHECKSUM=abcdef\n");
fprintf(pFile, "ENSEMBLE_ID=BLA_123\n");
fprintf(pFile, "SEQUENCE_NUMBER=10010000\n");
fprintf(pFile, "CREATOR=UNIGRAZ\n");
fprintf(pFile, "CREATOR_HARDWARE=POWERFULLCOMPUTER\n");
fprintf(pFile, "CREATION_DATE=Sun Jun 10 1990\n");
fprintf(pFile, "ARCHIVE_DATE=Sun Jun 11 1990\n");
// fprintf(pFile, "FLOATING_POINT=IEEE32BIG\n");
fprintf(pFile, "END_HEADER\n");
double areal, aimag;
for (int n=0;n<nsite;n++) {
for (int mu=0;mu<DIM;mu++) {
extract(*U, n, mu);
for (int j=0;j<2;j++)
for (int i=0;i<3;i++) {
areal=real(U[j][i]);
aimag=imag(U[j][i]);
fwrite(&areal, sizeof(double), 1, pFile);
fwrite(&aimag, sizeof(double), 1, pFile);
}
}
}
fclose(pFile);
return 0;
}
int ConfigData::readBinaryConfig2(std::string fconfigname){
int elems=0;
int nindex=nsite*matrixdim*matrixdim*DIM;
int cleng1, cleng2, cleng3, cleng4;
std::complex<double> pollref, plaqref, poll, plaq;
double maxError=1E-10;
FILE* pFile;
pFile = fopen(fconfigname.c_str(), "rb");
if (pFile == NULL) perror ("Error opening file");
else {
elems += fread(&cleng1, sizeof(int), 1, pFile);
elems += fread(&cleng2, sizeof(int), 1, pFile);
elems += fread(&cleng3, sizeof(int), 1, pFile);
elems += fread(&cleng4, sizeof(int), 1, pFile);
// Check lattice dimensions
if (leng1!=cleng1 || leng2!=cleng2 || leng3!=cleng3 || leng4!=cleng4) {
std::cout << "ERROR: lattice dimensions are different in config file and settings !" << std::endl;
return 1;
}
elems += fread(&pollref, sizeof(std::complex<double>),1, pFile);
elems += fread(&plaqref, sizeof(std::complex<double>),1, pFile);
elems += fread(&(*A)(0,0,0,0), sizeof(std::complex<double>), nindex, pFile);
fclose(pFile);
poll=calcPoll();
plaq=calcPlaq();
if(verbose){
std::cout << "Configfile " << fconfigname << " read (new binary format)." << std::endl << std::endl;
std::cout << "Checks:" << std::endl;
std::cout << "Polyakov loop: file=" << pollref << " calculated=" << poll << " diff(abs)=" << abs(pollref-poll) << std::endl;
std::cout << "Plaquettes: file=" << plaqref << " calculated=" << plaq << " diff(abs)=" << abs(plaqref-plaq) << std::endl << std::endl;
}
if(abs(pollref-poll)>maxError || abs(plaqref-plaq)>maxError)
std::cout << "WARNING: Calculated values for Polyakov loop and/or Plaquettes differ!" << std::endl << std::endl;
}
return nindex + 6 - elems;
}
int ConfigData::readConfig(std::string fconfigname){
// Reades the current lattice configuration into file with name
// fconfigname
std::complex<double> U[matrixdim][matrixdim];
int cleng1, cleng2, cleng3, cleng4;
double realnum, imagnum;
std::complex<double> pollref, plaqref, poll, plaq;
std::string strtmp;
double maxError=1E-10;
std::ifstream fconfig;
fconfig.open(fconfigname.c_str());
if(fconfig.is_open()!=true){
std::cout << "ERROR: File " << fconfigname << " to read configuration could not be opened!" << std::endl;
return 1;
}
fconfig >> cleng1 >> cleng2 >> cleng3 >> cleng4;
// Check lattice dimensions
if(leng1!=cleng1 || leng2!=cleng2 || leng3!=cleng3 || leng4!=cleng4){
std::cout << "ERROR: lattice dimensions are different in config file and settings !" << std::endl;
return 1;
}
double pollrefreal, pollrefimag, plaqrefreal, plaqrefimag;
fconfig >> pollrefreal >> pollrefimag;
fconfig >> plaqrefreal >> plaqrefimag;
plaqref=std::complex<double>(plaqrefreal, plaqrefimag);
pollref=std::complex<double>(pollrefreal, pollrefimag);
for(int n=0;n<nsite;n++){
for(int mu=0;mu<DIM;mu++){
for(int i=0; i<matrixdim; i++){
for(int j=0; j<matrixdim; j++){
fconfig >> realnum >> imagnum;
U[i][j]=std::complex<double>(realnum,imagnum);
}
}
replace(*U, n, mu);
}
}
/* for(int j=0;j<lineskip;j++){
getline(fconfig, strtmp);
} */
// Calculation of Plaquette and Pollyakov loop
poll=calcPoll();
plaq=calcPlaq();
if(verbose){
std::cout << "Configfile " << fconfigname << " read (text format)." << std::endl << std::endl;
std::cout << "Checks:" << std::endl;
std::cout << "Polyakov loop: file=" << pollref << " calculated=" << poll << " diff(abs)=" << abs(pollref-poll) << std::endl;
std::cout << "Plaquettes: file=" << plaqref << " calculated=" << plaq << " diff(abs)=" << abs(plaqref-plaq) << std::endl << std::endl;
}
if(abs(pollref-poll)>maxError || abs(plaqref-plaq)>maxError)
std::cout << "WARNING: Calculated values for Polyakov loop and/or Plaquettes differ!" << std::endl << std::endl;
fconfig.close();
return 0;
}
int ConfigData::readFConfig(std::string fconfigname){
// Reades the current lattice configuration into file with name
// fconfigname
// Fortran output
std::complex<double> U[matrixdim][matrixdim];
double realnum, imagnum;
std::complex<double> pollref, plaqref, poll, plaq;
std::string strtmp;
double maxError=1E-10;
std::ifstream fconfig;
fconfig.open(fconfigname.c_str());
if(fconfig.is_open()!=true){
std::cout << "ERROR: File " << fconfigname << " to read configuration could not be opened!" << std::endl;
return 1;
}
for(int i=0;i<28;i++){
getline(fconfig, strtmp);
}
for(int n=0;n<nsite;n++){
for(int mu=0;mu<DIM;mu++){
for(int i=0; i<matrixdim; i++){
for(int j=0; j<matrixdim; j++){
fconfig >> realnum >> imagnum;
U[i][j]=std::complex<double>(realnum,imagnum);
}
}
replace(*U, n, mu);
}
}
// Calculation of Plaquette and Pollyakov loop
poll=calcPoll();
plaq=calcPlaq();
if(verbose){
std::cout << "Configfile " << fconfigname << " read (Fortran format)." << std::endl << std::endl;
std::cout << "Checks:" << std::endl;
std::cout << "Polyakov loop: file=" << pollref << " calculated=" << poll << " diff(abs)=" << abs(pollref-poll) << std::endl;
std::cout << "Plaquettes: file=" << plaqref << " calculated=" << plaq << " diff(abs)=" << abs(plaqref-plaq) << std::endl << std::endl;
}
if(abs(pollref-poll)>maxError || abs(plaqref-plaq)>maxError)
std::cout << "WARNING: Calculated values for Polyakov loop and/or Plaquettes differ!" << std::endl << std::endl;
fconfig.close();
return 0;
}
int ConfigData::writeConfig(std::string fconfigname){
// Writes the current lattice configuration into file with name
// fconfigname
std::complex<double> U[matrixdim][matrixdim], plaq, poll;
std::ofstream fconfig;
fconfig.open(fconfigname.c_str());
if(fconfig.is_open()!=true){
std::cout << "ERROR: File " << fconfigname << " to save configuration could not be opened!" << std::endl;
return 1;
}
fconfig << leng1 << " " << leng2 << " " << leng3 << " " << leng4 << std::endl;
fconfig.flags (std::ios::scientific);
fconfig.precision(std::numeric_limits<double>::digits10 + 1);
poll=calcPoll();
plaq=calcPlaq();
fconfig << real(poll) << " " << imag(poll) << std::endl;
fconfig << real(plaq) << " " << imag(plaq) << std::endl;
for(int n=0;n<nsite;n++){
for(int mu=0;mu<DIM;mu++){
extract(*U, n, mu);
for(int i=0; i<matrixdim; i++){
for(int j=0; j<matrixdim; j++){
fconfig << real(U[i][j]) << " " << imag(U[i][j]) << " ";
}
}
fconfig << std::endl;
}
}
fconfig << std::endl << "# SU(" << matrixdim << ") Settings:" << std::endl;
fconfig << "# Lattice size: " << leng1 << "x" << leng2 << "x" <<leng3 << "x" << leng4 << std::endl;
fconfig << "# Plaquettes=" << plaq << std::endl;
fconfig << "# Polyakov loop=" << poll << std::endl;
fconfig << "# U[0][1] U[0][2] U[0][3] U[1][0] U[1][1] ... @ nsite=0" << std::endl;
fconfig << "# U[0][1] U[0][2] U[0][3] U[1][0] U[1][1] ... @ nsite=1" << std::endl;
fconfig.close();
return 0;
}
// MILC import functions
int ConfigData::MILCreadConfig(std::string fconfigname){
// Reades the current lattice configuration into file with name
// fconfigname
// Confifguration is generated using MILC
std::complex<double> U[matrixdim][matrixdim];
int cleng1, cleng2, cleng3, cleng4;
double realnum, imagnum, pollrefreal, pollrefimag, dtmp, plaqrefreal;
std::complex<double> pollref, plaqref, poll, plaq;
std::string strtmp;
double maxError=1E-7;
std::ifstream fconfig;
fconfig.open(fconfigname.c_str());
if(fconfig.is_open()!=true){
std::cout << "ERROR: File " << fconfigname << " to read configuration could not be opened!" << std::endl;
return 1;
}
// Drop the first two lines
getline(fconfig, strtmp);
getline(fconfig, strtmp);
// Lattice dimension
fconfig >> cleng1 >> cleng2 >> cleng3 >> cleng4;
// Check lattice dimensions
if(leng1!=cleng1 || leng2!=cleng2 || leng3!=cleng3 || leng4!=cleng4){
std::cout << "ERROR: lattice dimensions are different in config file and settings !" << std::endl;
return 1;
}
int n;
for(int t=0;t<leng4;t++)
for(int z=0;z<leng3;z++)
for(int y=0;y<leng2;y++)
for(int x=0;x<leng1;x++){
n = x + y*leng1 + z*leng1*leng2 + t*leng1*leng2*leng3;
for(int mu=0;mu<DIM;mu++){
for(int i=0; i<matrixdim; i++){
for(int j=0; j<matrixdim; j++){
fconfig >> realnum >> imagnum;
U[i][j]=std::complex<double>(realnum,imagnum);
}
}
replace(*U, n, mu);
}
}
getline(fconfig, strtmp);
getline(fconfig, strtmp);
getline(fconfig, strtmp);
fconfig >> pollrefreal >> pollrefimag >> dtmp >> dtmp >> plaqrefreal;
pollref = std::complex<double>(pollrefreal/3.0, pollrefimag/3.0);
plaqref = std::complex<double>(plaqrefreal/6.0, 0);
// Calculation of Plaquette and Pollyakov loop
poll=calcPoll();
plaq=calcPlaq();
double abspollerr=abs(pollref-poll);
double absplaqerr=abs(real(plaqref)-real(plaq));
if(verbose){
std::cout << "Configfile " << fconfigname << " read (MILC format)." << std::endl << std::endl;
std::cout << "Checks (note, MILC output only single precision):" << std::endl;
std::cout << "Polyakov loop: file=" << pollref << " calculated=" << poll << " diff(abs)=" << abspollerr << std::endl;
std::cout << "Plaquettes: file=" << real(plaqref) << " calculated=" << real(plaq) << " diff(abs)=" << absplaqerr << std::endl << std::endl;
}
if(abspollerr>maxError || absplaqerr>maxError)
std::cout << "WARNING: Calculated values for Polyakov loop and/or Plaquettes differ!" << std::endl << std::endl;
return 0;
}
// Local Polyakov loop write
int ConfigData::writeBinaryLPoll(std::string fconfigname){
int elems=0;
std::complex<double> plaq, poll;
FILE* pFile;
int nindex=leng1*leng2*leng3*matrixdim*matrixdim;
std::complex<double> lpoll[matrixdim*matrixdim];
pFile = fopen(fconfigname.c_str(), "wb");
if (pFile == NULL) perror ("Error opening file");
else{
elems += fwrite(&leng1, sizeof(int), 1, pFile);
elems += fwrite(&leng2, sizeof(int), 1, pFile);
elems += fwrite(&leng3, sizeof(int), 1, pFile);
elems += fwrite(&leng4, sizeof(int), 1, pFile);
poll=calcPoll();
plaq=calcPlaq();
elems += fwrite(&poll, sizeof(std::complex<double>),1, pFile);
elems += fwrite(&plaq, sizeof(std::complex<double>),1, pFile);
std::complex<double> sum(0,0);
for(int i1=0;i1<leng1;i1++)
for(int i2=0;i2<leng2;i2++)
for(int i3=0;i3<leng3;i3++){
calcLocalPoll(lpoll, i1, i2, i3, sum);
elems += fwrite(&lpoll[0], sizeof(std::complex<double>), matrixdim*matrixdim, pFile);
}
fclose(pFile);
}
return nindex + 6 - elems;
}
int **ConfigData::Create2D(int row, int col)
{
int **p = new int* [row];
for (int j = 0; j < row; j ++)
p[j] = new int[col];
return p;
}
void ConfigData::Delete2D(int **p, int row)
{
for (int j = 0; j < row; j ++)
delete [] p[j];
delete [] p;
}
/* ----------------------------------------------------------------------- */
/* -------- Observable calculations used for checking the config---------- */
/* ----------------------------------------------------------------------- */
void ConfigData::staplesum(std::complex<double> *S, int mu,int x){
int xpmu,xpnu,xmnupmu,xmnu;
std::complex<double> U1[matrixdim][matrixdim], U2[matrixdim][matrixdim],
U3[matrixdim][matrixdim], U12[matrixdim][matrixdim], U123[matrixdim][matrixdim];
xpmu=neibArray[x][mu];
for(int i=0;i<matrixdim;i++){
for(int j=0;j<matrixdim;j++){
S[i*matrixdim + j]=std::complex<double>(0,0);
}
}
for(int nu=0;nu<DIM;nu++){
if(mu != nu){
xpnu=neibArray[x][nu];
extract(*U1, xpmu, nu);
extract(*U2, xpnu, mu);
extract(*U3, x, nu);
axbdag(*U12,*U1,*U2);
axbdag(*U123,*U12,*U3);
apb(S,*U123);
xmnu = neibArray[x][4+nu];
xmnupmu=neibArray[xmnu][mu];
extract(*U1, xmnupmu, nu);
extract(*U2, xmnu, mu);
extract(*U3, xmnu, nu);
adagxbdag(*U12,*U1,*U2);
axb(*U123,*U12,*U3);
apb(S,*U123);
}
}
}
std::complex<double> ConfigData::calcPoll(){
// Calculates the Polyakov loop spatial average
std::complex<double> poll, trace;
poll=std::complex<double> (0,0);
trace=std::complex<double> (0,0);
std::complex<double> up[matrixdim][matrixdim], uu[matrixdim][matrixdim], upaux[matrixdim][matrixdim];
int is0=0;
int i4=0;
for(int i1=0;i1<leng1;i1++){
for(int i2=0;i2<leng2;i2++){
for(int i3=0;i3<leng3;i3++){
i4 = 0;
is0 = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
extract(*up, is0, 3);
for(i4=1;i4<leng4-1;i4++){
is0 = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
extract(*uu, is0, 3);
axb(*upaux,*up,*uu);
aeb(*up,*upaux);
}
i4 = leng4-1;
is0 = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
extract(*uu, is0, 3);
trace=multtrace(*up,*uu);
poll = poll + trace;
}
}
}
poll = poll/((double)matrixdim*leng1*leng2*leng3);
return poll;
}
std::complex<double> ConfigData::calcPlaq(){
// Calculates the plaquette spatial average over all 6N plaquettes
int ispmu, ispnu;
std::complex<double> sumplaqs = std::complex<double>(0,0), trace;
std::complex<double> u1[matrixdim][matrixdim], u2[matrixdim][matrixdim],u3[matrixdim][matrixdim], u4[matrixdim][matrixdim], u23[matrixdim][matrixdim], u234[matrixdim][matrixdim];
for(int is = 0;is<nsite;is++){
for(int imu = 0;imu<DIM;imu++){
for(int inu = imu+1;inu<DIM;inu++){
ispmu = neibArray[is][imu];
ispnu = neibArray[is][inu];
extract(*u1, is, imu);
extract(*u2, ispmu, inu);
extract(*u3, ispnu, imu);
extract(*u4, is, inu);
axbdag(*u23,*u2,*u3);
axbdag(*u234,*u23,*u4);
trace=multtrace(*u1,*u234);
sumplaqs = sumplaqs + trace;
}
}
}
sumplaqs=sumplaqs/((double)6*matrixdim*(double)nsite); // factor because sum over N lattice points and md from trace
return sumplaqs;
}
void ConfigData::calcLocalPoll(std::complex<double> *lpoll, int i1, int i2, int i3, std::complex<double> &sum){
std::complex<double> up[matrixdim][matrixdim], uu[matrixdim][matrixdim], upaux[matrixdim][matrixdim];
int i4=0, is0=0;
is0 = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
extract(*up, is0, 3);
for(i4=1;i4<leng4-1;i4++){
is0 = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
extract(*uu, is0, 3);
axb(*upaux,*up,*uu);
aeb(*up,*upaux);
}
i4 = leng4-1;
is0 = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
extract(*uu, is0, 3);
axb(lpoll,*up,*uu);
sum += lpoll[0*3 + 0] + lpoll[1*3 + 1] + lpoll[2*3 + 2];
}
void ConfigData::z3rot(){
// Init random number generator
srand ( time(NULL) );
// Performes a Z_3 center rotation (for SU(3) only)
int i1, i2, i3, i4, nphase, is;
double ran1=0, r=0;
std::complex<double> uu[matrixdim][matrixdim], phase;
// ................. 1st Volume ..............................
r=(double)rand()/((double)RAND_MAX+1);
ran1=r*(double)leng1+0.5;
i1 = floor(ran1);
if(i1 == leng1)
i1 = 0;
r=(double)rand()/((double)RAND_MAX+1);
nphase =floor(r*(double)3.0+0.5);
phase = std::complex<double>(cos(2*M_PI*nphase/3.0),sin(2*M_PI*nphase/3.0));
for(i2 = 0;i2<leng2;i2++){
for(i3 = 0;i3<leng3;i3++){
for(i4 = 0;i4<leng4;i4++){
is = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
if(is>nsite){
std::cout << "Error!!!" << std::endl;
std::cout << "Loop 1st volume" << std::endl;
std::cout << "i1=" << i1 << " i2=" << i2 << " i3=" << i3 << " i4=" << i4 << std::endl;
}
extract(*uu, is, 0);
for(int i=0;i<matrixdim;i++)
for(int j=0;j<matrixdim;j++){
uu[i][j]=phase*uu[i][j];
}
replace(*uu, is, 0);
}
}
}
// ................. 2nd Volume ..............................
r=(double)rand()/((double)RAND_MAX+1);
ran1=r*(double)leng2+0.5;
i2 = floor(ran1);
if(i2 == leng2)
i2 = 0;
r=(double)rand()/((double)RAND_MAX+1);
nphase =floor(r*(double)3.0+0.5);
phase = std::complex<double>(cos(2*M_PI*nphase/3.0),sin(2*M_PI*nphase/3.0));
for(i1 = 0;i1<leng1;i1++){
for(i3 = 0;i3<leng3;i3++){
for(i4 = 0;i4<leng4;i4++){
is = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;
if(is>nsite){
std::cout << "Error!!!" << std::endl;
std::cout << "Loop 1st volume" << std::endl;
std::cout << "i1=" << i1 << " i2=" << i2 << " i3=" << i3 << " i4=" << i4 << std::endl;
}
extract(*uu, is, 1);
for(int i=0;i<matrixdim;i++)
for(int j=0;j<matrixdim;j++){
uu[i][j]=phase*uu[i][j];
}
replace(*uu, is, 1);
}
}
}
// ................. 3rd Volume ..............................
r=(double)rand()/((double)RAND_MAX+1);
ran1=r*(double)leng3+0.5;
i3 = floor(ran1);
if(i3 == leng3)
i3 = 0;
r=(double)rand()/((double)RAND_MAX+1);
nphase =floor(r*(double)3.0+0.5);
phase = std::complex<double>(cos(2*M_PI*nphase/3.0),sin(2*M_PI*nphase/3.0));
for(i1 = 0;i1<leng1;i1++){
for(i2 = 0;i2<leng2;i2++){
for(i4 = 0;i4<leng4;i4++){
is = i1 + i2*leng1 + i3*leng1*leng2 + i4*leng1*leng2*leng3;