-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcdis-pt.cpp
1911 lines (1664 loc) · 122 KB
/
mcdis-pt.cpp
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
// #include "mpi.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <cmath>
#include <complex>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>
#include <functional>
#include <omp.h>
static inline int is_odd(int x) { return x & 1; }
#include "Boundaries.h"
#include "params.h"
using namespace std;
int main(int argc, char **argv) {
cout << endl;
clock_t t_total, t; // to measure runtime of simulation
t_total = clock(); // start the clock t_total
/* Read in parameters from terminal */
if (argc == 17) {
dim = atof(argv[1]); // dimensionality of the system
L = atof(argv[2]); // number of sites in x and y direction
Lz = atof(argv[3]); // number of sites in z direction
J33 = atof(argv[4]); // AF between spin-1 satellites
J34 = atof(argv[5]); // FM between core and satellites
J44 = atof(argv[6]); // FM between two different core sites
T_min = atof(argv[7]); // temperature of MC simulation
T_max = atof(argv[8]); // temperature of MC simulation
T_steps = atof(argv[9]); // temperature of MC simulation
disorder_filling = atof(argv[10]); // site filling considered
disorder_steps = atof(argv[11]); // number of different disorder realizations considered
mc_bins = atof(argv[12]); // number of MC steps (per disorder realization)
mc_binsize = atof(argv[13]); // number of MC steps in each bin
thermalization_bins = atof(argv[14]);
seed_disorder = atof(argv[15]); // initial seed of disorder RNG (determining which sites are filled)
seed_mc = atof(argv[16]); // initial seed of MC RNG
output_s_q = false;
output_observables = true;
output_data_fraction = true;
print_all = false;
snapshot_output = false;
parallel_tempering_step = true; // whether or not to include a parallel tempering step
}
else {
cout << "Default parameters" << endl;
dim = 3;
L = 8;
Lz = 8;
J33 = 0.2;
J34 = -1.;
J44 = -1.;
T_min = 0.5;
T_max = 6.;
T_steps = 2;
disorder_filling = 0.2;
disorder_steps = 50;
mc_bins = 1;
mc_binsize = 1;
thermalization_bins = 1;
seed_disorder = 1; // increases by one for each disorder realization (final seed = disorder_steps)
seed_mc = 1; //
output_s_q = false;
output_observables = true;
output_data_fraction = true;
print_all = true;
snapshot_output = true;
parallel_tempering_step = true;
}
N2D = L*L; // total number of sites in 2D system
N3D = L*L*Lz; // total number of sites in 3D system
string outputFilename;
// Define number of neighbors (here for 3D cubic lattice)
if ( (dim == 2) || (Lz == 1) ) {
num_neighbors_direct = 4;
num_neighbors_face = 4;
num_neighbors_body = 4; // use this as being equal to num_neighbors_face
num_neighbors_direct_nn = 4;
N = N2D;
Lz = 1; // set Lz = 1 in case of dim=2 to get correct output values
}
else {
num_neighbors_direct = 6;
num_neighbors_face = 12;
num_neighbors_body = 8;
num_neighbors_direct_nn = 6;
N = N3D;
}
// initialize arrays for neighboring site labels
neighbors_direct = new int[num_neighbors_direct*N]; // initialize array for direct neighbors
neighbors_face = new int[num_neighbors_face*N];
neighbors_body = new int[num_neighbors_body*N];
neighbors_direct_nn = new int[num_neighbors_direct_nn*N];
// Initialize boundary class to initialize all neighbor table
Boundaries boundaries(dim, L, Lz, neighbors_direct, neighbors_face, neighbors_body, neighbors_direct_nn);
// Total number of MCS
mc_steps = (mc_bins + thermalization_bins)*mc_binsize; // total number of MCS
// Setting up table of temperatures (for parallel tempering)
temperatures = new double[T_steps];
for (int idx = 0; idx < T_steps; idx++) {
temperatures[idx] = 0.;
}
temperatures[0] = T_min;
temperatures[T_steps - 1] = T_max;
for (int idx = 1; idx < T_steps - 1; idx++) {
temperatures[idx] = T_min*pow(T_max/T_min, static_cast<double>(idx)/static_cast<double>(T_steps - 1));
}
/*
for (int idx = 0; idx < T_steps; idx++) {
cout << "temperatures[" << idx << "] = " << temperatures[idx] << endl;
}
*/
int *pt_TtoE; // list where entry i gives ensemble at temperature temperatures[i]
int *pt_EtoT; // list where entry i gives temperature of ensemble i
swap_even_pairs = false;
//cout << "swap_even_pairs = " << static_cast<int>(swap_even_pairs) << endl;
pt_TtoE = new int[2*T_steps]; // factor of 2 because of 2 replicas per T
pt_EtoT = new int[2*T_steps];
for (int idx = 0; idx < 2*T_steps; idx++) {
pt_TtoE[idx] = idx % T_steps;
pt_EtoT[idx] = idx % T_steps;
//cout << "pt_TtoE[" << idx << "] = " << pt_TtoE[idx] << endl;
//cout << "pt_EtoT[" << idx << "] = " << pt_EtoT[idx] << endl;
}
/**********************************************************************************
*** Set up table of spin flip probabilities used for Metropolis algorithm *********
**********************************************************************************/
// Construct flip tables: one for each temperature: prob_1 is for core sites S^{4}, prob_2 is for satellite sites S^{3}
prob_1 = new double[T_steps*2*(2*num_neighbors_direct + 1) * (2*num_neighbors_direct + 1)]; // S^(4)
prob_2 = new double[T_steps*2*(2*num_neighbors_direct + 1) * (2*num_neighbors_direct + 1)]; // S^(3)
// Initialize
for (int idx = 0; idx < T_steps*2*(2*num_neighbors_direct + 1) * (2*num_neighbors_direct + 1); idx++) {
prob_1[idx] = 0.; // flip prob. for spin S^(4) with S=1/2: core spin
prob_2[idx] = 0.; // flip prob. for spin S^(3) with S=1: satellite spin
}
for (int T_idx = 0; T_idx < T_steps; T_idx++) {
for (int bdx = -num_neighbors_direct; bdx <= num_neighbors_direct; bdx++) { // bdx = total spin of neighboring S^(4) spins (counting up=+1 and down=-1). Factor of 1/2 is accounted for below in equation
for (int adx = -num_neighbors_direct; adx <= num_neighbors_direct; adx++) { // adx = total spin of neighboring S^(3) spins (counting up=+1 and down=-1).
for (int idx = 0; idx <= 1; idx++) { // idx = direction of central spin: idx=0=spin down, idx=1=spin up
// according to Eq.(36) of Sandvik's short MC notes. Note |S^(4)|=1, |S^(3)|=1 here. For old convention of spin sizes see oldcode.cpp
prob_1[idx + (adx + num_neighbors_direct)*2 + (bdx + num_neighbors_direct)*2*(2*num_neighbors_direct + 1) + T_idx*2*(2*num_neighbors_direct + 1) * (2*num_neighbors_direct + 1)] = exp( (2.*static_cast<double>(2*idx - 1)*(J34*static_cast<double>(adx) + J44*static_cast<double>(bdx)) )/temperatures[T_idx] );
prob_2[idx + (adx + num_neighbors_direct)*2 + (bdx + num_neighbors_direct)*2*(2*num_neighbors_direct + 1) + T_idx*2*(2*num_neighbors_direct + 1) * (2*num_neighbors_direct + 1)] = exp( (2.*static_cast<double>(2*idx - 1)*(J33*static_cast<double>(adx) + J34*static_cast<double>(bdx)) )/temperatures[T_idx] );
}
}
}
}
/*
// Output results
outputFilename = "Data-ProbabilityTable.dat";
outputFile.open(outputFilename);
outputFile.setf(ios::scientific);
// Output probability tables
for (int idx = 0; idx < T_steps*2*(2*num_neighbors_direct + 1) * (2*num_neighbors_direct + 1); idx++) {
outputFile << prob_1[idx] << " " << prob_2[idx] << endl;
}
*/
// Construct spin array (integer)
spins = new int[T_steps*2*N]; // 2 replicas per temperature
order = new int[T_steps*N]; // need only half as many order as the two replicas have the same disorder realization
spins_energy = new double[T_steps*2]; // array that stores energy of spin ensemble
vector<mt19937> mt_rand_mc_vector;
/**************************************************
*** Create arrays used during MC averaging *******
*************************************************/
magnetization1 = new double[2*T_steps*mc_bins]; // stores magnetization1 for each MC bin at each temperature. Is for spin 1 at each site. Factor of two for the replicas.
magnetization2 = new double[2*T_steps*mc_bins]; // stores magnetization2 for each MC bin. Is for spin 3/2 at core Co^{4+} sites. Factor of two for the replicas.
magnetizationAF = new double[2*T_steps*mc_bins]; // stores AF magnetization at Q = (pi,pi,pi). Factor of two for the replicas.
magnetization_replica = new double[T_steps*mc_bins]; // stores m=1/N\sum_{i} m^{1}_i m^{2}_i correlations between two replicas
magnetization1_squared = new double[2*T_steps*mc_bins]; // stores magnetization1 for each MC bin. Is for spin 1 at each site.
magnetization2_squared = new double[2*T_steps*mc_bins]; // stores magnetization2 for each MC bin. Is for spin 3/2 at core Co^{4+} sites.
magnetizationAF_squared = new double[2*T_steps*mc_bins]; // stores AF magnetization^2
magnetization_replica_squared = new double[T_steps*mc_bins];
magnetization1_four = new double[2*T_steps*mc_bins]; // stores magnetization1^4 for each MC bin. Needed for Binder ratio of FM order.
magnetizationAF_four = new double[2*T_steps*mc_bins]; // stores magnetizationAF^4 for each MC bin. Needed for Binder ratio of AF order.
magnetization_replica_four = new double[T_steps*mc_bins];
energy = new double[2*T_steps*mc_bins]; // stores average energy for each MC bin. Factor of two for the replicas.
energy_squared = new double[2*T_steps*mc_bins]; // stores averag energy^2 for each MC bin
s_q = new double[T_steps*mc_bins*L*Lz*(L/2 + 1)];
xi_a = new double[T_steps*mc_bins];
xi_b = new double[T_steps*mc_bins];
/*****************************************************
****** MC averages for each disorder realization ****
*****************************************************/
magnetization1_av_dis = new double[2*T_steps*disorder_steps]; // stores average magnetization1 for each disorder realization. Is for spin 1 at each site
magnetization2_av_dis = new double[2*T_steps*disorder_steps]; // is for spin 3/2 at core Co^{4+} sites.
magnetizationAF_av_dis = new double[2*T_steps*disorder_steps];
magnetization_replica_av_dis = new double[T_steps*disorder_steps];
sigma_magnetization1_av_dis = new double[2*T_steps*disorder_steps]; // stores standard deviation sigma of magnetization1 for each disorder realization. Is for spin 1 at each site
sigma_magnetization2_av_dis = new double[2*T_steps*disorder_steps];
sigma_magnetizationAF_av_dis = new double[2*T_steps*disorder_steps];
sigma_magnetization_replica_av_dis = new double[T_steps*disorder_steps];
magnetization1_squared_av_dis = new double[2*T_steps*disorder_steps]; // stores average magnetization1 for each disorder realization. Is for spin 1 at each site
magnetization2_squared_av_dis = new double[2*T_steps*disorder_steps]; // is for spin 3/2 at core Co^{4+} sites.
magnetizationAF_squared_av_dis = new double[2*T_steps*disorder_steps];
magnetization_replica_squared_av_dis = new double[T_steps*disorder_steps];
magnetization1_four_av_dis = new double[2*T_steps*disorder_steps];
magnetizationAF_four_av_dis = new double[2*T_steps*disorder_steps];
magnetization_replica_four_av_dis = new double[T_steps*disorder_steps];
sigma_magnetization1_squared_av_dis = new double[2*T_steps*disorder_steps]; // stores standard deviation sigma of magnetization1_squared for each disorder realization. Is for spin 1 at each site
sigma_magnetization2_squared_av_dis = new double[2*T_steps*disorder_steps];
sigma_magnetizationAF_squared_av_dis = new double[2*T_steps*disorder_steps];
sigma_magnetization_replica_squared_av_dis = new double[T_steps*disorder_steps];
sigma_magnetization1_four_av_dis = new double[2*T_steps*disorder_steps];
sigma_magnetizationAF_four_av_dis = new double[2*T_steps*disorder_steps];
sigma_magnetization_replica_four_av_dis = new double[T_steps*disorder_steps];
chi_magnetization1_av_dis = new double[2*T_steps*disorder_steps];
sigma_chi_magnetization1_av_dis = new double[2*T_steps*disorder_steps];
chi_magnetizationAF_av_dis = new double[2*T_steps*disorder_steps];
sigma_chi_magnetizationAF_av_dis = new double[2*T_steps*disorder_steps];
chi_magnetization_replica_av_dis = new double[T_steps*disorder_steps];
sigma_chi_magnetization_replica_av_dis = new double[T_steps*disorder_steps];
binder_ratio_av_dis = new double[2*T_steps*disorder_steps];
sigma_binder_ratio_av_dis = new double[2*T_steps*disorder_steps];
binder_ratioAF_av_dis = new double[2*T_steps*disorder_steps];
sigma_binder_ratioAF_av_dis = new double[2*T_steps*disorder_steps];
binder_ratio_replica_av_dis = new double[T_steps*disorder_steps];
sigma_binder_ratio_replica_av_dis = new double[T_steps*disorder_steps];
energy_av_dis = new double[2*T_steps*disorder_steps];
energy_squared_av_dis = new double[2*T_steps*disorder_steps];
specific_heat_av_dis = new double[2*T_steps*disorder_steps];
sigma_specific_heat_av_dis = new double[2*T_steps*disorder_steps];
//spins_q_av_dis = new double[disorder_steps*N];
if (output_s_q == true) {
s_q_av_dis = new double[T_steps*disorder_steps*(L*Lz*(L/2 + 1))];
cout << "T_steps*disorder_steps*(L*Lz*(L/2 + 1)) = " << T_steps*disorder_steps*(L*Lz*(L/2 + 1));
}
xi_a_av_dis = new double[T_steps*disorder_steps];
xi_b_av_dis = new double[T_steps*disorder_steps];
sigma_xi_a_av_dis = new double[T_steps*disorder_steps];
sigma_xi_b_av_dis = new double[T_steps*disorder_steps];
fraction_filled = new double[disorder_steps];
fraction_bonds_J33 = new double[disorder_steps];
fraction_bonds_J34 = new double[disorder_steps];
fraction_bonds_J44 = new double[disorder_steps];
/***************************************************
*** Initialize av_dis variables ********************
***************************************************/
for (int idx = 0; idx < 2*T_steps*disorder_steps; idx++) {
magnetization1_av_dis[idx] = 0.;
magnetization2_av_dis[idx] = 0.;
magnetizationAF_av_dis[idx] = 0.;
sigma_magnetization1_av_dis[idx] = 0.;
sigma_magnetization2_av_dis[idx] = 0.;
sigma_magnetizationAF_av_dis[idx] = 0.;
magnetization1_squared_av_dis[idx] = 0.;
magnetization2_squared_av_dis[idx] = 0.;
magnetization1_four_av_dis[idx] = 0.;
magnetizationAF_four_av_dis[idx] = 0.;
sigma_magnetization1_squared_av_dis[idx] = 0.;
sigma_magnetization2_squared_av_dis[idx] = 0.;
sigma_magnetizationAF_squared_av_dis[idx] = 0.;
sigma_magnetization1_four_av_dis[idx] = 0.;
sigma_magnetizationAF_four_av_dis[idx] = 0.;
chi_magnetization1_av_dis[idx] = 0.;
sigma_chi_magnetization1_av_dis[idx] = 0.;
chi_magnetizationAF_av_dis[idx] = 0.;
sigma_chi_magnetizationAF_av_dis[idx] = 0.;
binder_ratio_av_dis[idx] = 0.;
sigma_binder_ratio_av_dis[idx] = 0.;
binder_ratioAF_av_dis[idx] = 0.;
sigma_binder_ratioAF_av_dis[idx] = 0.;
energy_av_dis[idx] = 0.;
energy_squared_av_dis[idx] = 0.;
specific_heat_av_dis[idx] = 0.;
sigma_specific_heat_av_dis[idx] = 0.;
}
for (int idx = 0; idx < T_steps*disorder_steps; idx++) {
magnetization_replica_av_dis[idx] = 0.;
sigma_magnetization_replica_av_dis[idx] = 0.;
magnetization_replica_squared_av_dis[idx] = 0.;
magnetization_replica_four_av_dis[idx] = 0.;
sigma_magnetization_replica_squared_av_dis[idx] = 0.;
sigma_magnetization_replica_four_av_dis[idx] = 0.;
chi_magnetization_replica_av_dis[idx] = 0.;
sigma_chi_magnetization_replica_av_dis[idx] = 0.;
binder_ratio_replica_av_dis[idx] = 0.;
sigma_binder_ratio_replica_av_dis[idx] = 0.;
if (output_s_q == true) {
for (int jdx = 0; jdx < L*Lz*(L/2+1); jdx++) {
s_q_av_dis[jdx + idx*(L*Lz*(L/2+1))] = 0.;
}
}
xi_a_av_dis[idx] = 0.;
xi_b_av_dis[idx] = 0.;
sigma_xi_a_av_dis[idx] = 0.;
sigma_xi_b_av_dis[idx] = 0.;
}
for (int idx = 0; idx < disorder_steps; idx++) {
fraction_filled[idx] = 0.;
fraction_bonds_J33[idx] = 0.;
fraction_bonds_J34[idx] = 0.;
fraction_bonds_J44[idx] = 0.;
}
/**************************************************************************
***** Final results averaged over MC and disorder ****************
**************************************************************************/
magnetization1_av = new double[T_steps];
magnetization2_av = new double[T_steps];
magnetizationAF_av = new double[T_steps];
magnetization_replica_av = new double[T_steps];
sigma_magnetization1_av = new double[T_steps];
sigma_magnetization2_av = new double[T_steps];
sigma_magnetizationAF_av = new double[T_steps];
sigma_magnetization_replica_av = new double[T_steps];
magnetization1_squared_av = new double[T_steps];
magnetization2_squared_av = new double[T_steps];
magnetizationAF_squared_av = new double[T_steps];
magnetization_replica_squared_av = new double[T_steps];
magnetization1_four_av = new double[T_steps];
magnetizationAF_four_av = new double[T_steps];
magnetization_replica_four_av = new double[T_steps];
sigma_magnetization1_squared_av = new double[T_steps];
sigma_magnetization2_squared_av = new double[T_steps];
sigma_magnetizationAF_squared_av = new double[T_steps];
sigma_magnetization_replica_squared_av = new double[T_steps];
sigma_magnetization1_four_av = new double[T_steps];
sigma_magnetizationAF_four_av = new double[T_steps];
sigma_magnetization_replica_four_av = new double[T_steps];
chi_magnetization1_av = new double[T_steps]; // magnetic susceptibility
sigma_chi_magnetization1_av = new double[T_steps];
chi_magnetizationAF_av = new double[T_steps]; // magnetic susceptibility
sigma_chi_magnetizationAF_av = new double[T_steps];
chi_magnetization_replica_av = new double[T_steps]; // magnetic susceptibility
sigma_chi_magnetization_replica_av = new double[T_steps];
binder_ratio_av = new double[T_steps]; // Binder ratio for FM order
sigma_binder_ratio_av = new double[T_steps];
binder_ratioAF_av = new double[T_steps];// Binder ratio for AF order
sigma_binder_ratioAF_av = new double[T_steps];
binder_ratio_replica_av = new double[T_steps]; // Binder ratio of replica order
sigma_binder_ratio_replica_av = new double[T_steps];
energy_av = new double[T_steps];
energy_squared_av = new double[T_steps];
specific_heat_av = new double[T_steps]; // specific heat
sigma_specific_heat_av = new double[T_steps];
s_q_av = new double[T_steps*L*Lz*(L/2+1)];
for (int idx = 0; idx < T_steps*L*Lz*(L/2+1); idx++) {
s_q_av[idx] = 0.;
}
xi_a_av = new double[T_steps];
xi_b_av = new double[T_steps];
sigma_xi_a_av = new double[T_steps];
sigma_xi_b_av = new double[T_steps];
for (int idx = 0; idx < T_steps; idx++) {
magnetization1_av[idx] = 0.;
magnetization2_av[idx] = 0.;
magnetizationAF_av[idx] = 0.;
magnetization_replica_av[idx] = 0.;
sigma_magnetization1_av[idx] = 0.;
sigma_magnetization2_av[idx] = 0.;
sigma_magnetizationAF_av[idx] = 0.;
sigma_magnetization_replica_av[idx] = 0.;
magnetization1_squared_av[idx] = 0.;
magnetization2_squared_av[idx] = 0.;
magnetizationAF_squared_av[idx] = 0.;
magnetization_replica_squared_av[idx] = 0.;
magnetization1_four_av[idx] = 0.;
magnetizationAF_four_av[idx] = 0.;
magnetization_replica_four_av[idx] = 0.;
sigma_magnetization1_squared_av[idx] = 0.;
sigma_magnetization2_squared_av[idx] = 0.;
sigma_magnetizationAF_squared_av[idx] = 0.;
sigma_magnetization_replica_squared_av[idx] = 0.;
sigma_magnetization1_four_av[idx] = 0.;
sigma_magnetizationAF_four_av[idx] = 0.;
sigma_magnetization_replica_four_av[idx] = 0.;
chi_magnetization1_av[idx] = 0.; // magnetic susceptibility
sigma_chi_magnetization1_av[idx] = 0.;
chi_magnetizationAF_av[idx] = 0.; // magnetic susceptibility
sigma_chi_magnetizationAF_av[idx] = 0.;
chi_magnetization_replica_av[idx] = 0.; // magnetic susceptibility
sigma_chi_magnetization_replica_av[idx] = 0.;
binder_ratio_av[idx] = 0.; // Binder ratio for FM order
sigma_binder_ratio_av[idx] = 0.;
binder_ratioAF_av[idx] = 0.;// Binder ratio for AF order
sigma_binder_ratioAF_av[idx] = 0.;
binder_ratio_replica_av[idx] = 0.; // Binder ratio of replica order
sigma_binder_ratio_replica_av[idx] = 0.;
energy_av[idx] = 0.;
energy_squared_av[idx] = 0.;
specific_heat_av[idx] = 0.; // specific heat
sigma_specific_heat_av[idx] = 0.;
xi_a_av[idx] = 0.;
xi_b_av[idx] = 0.;
sigma_xi_a_av[idx] = 0.;
sigma_xi_b_av[idx] = 0.;
}
/***** End initialize FINAL RESULT VARIABLES *****/
// Initialize RNGs
// Disorder RNG: Set up RNG "mt_rand_disorder" by first using common lc generator that procudes a seed for the mersenne-twister rng
std::minstd_rand0 lc_generator(seed_disorder);
std::uint_least32_t seed_data[std::mt19937::state_size];
std::generate_n(seed_data, std::mt19937::state_size, std::ref(lc_generator));
std::seed_seq q(std::begin(seed_data), std::end(seed_data));
std::mt19937 mt_rand_disorder(q);
// Set up a RNG for each MC simulation (2*T_steps)
for (int idx = 0; idx < 2*T_steps; idx++) {
// Monte Carlo: Set up RNG "mt_rand_mc" by first using common lc generator that procudes a seed for the mersenne-twister rng
std::minstd_rand0 lc_generator_mc(seed_mc + idx ); // seed different for each temperature and replica
std::uint_least32_t seed_data_mc[std::mt19937::state_size];
std::generate_n(seed_data_mc, std::mt19937::state_size, std::ref(lc_generator_mc));
std::seed_seq q_mc(std::begin(seed_data_mc), std::end(seed_data_mc));
mt_rand_mc_vector.push_back(std::mt19937(q_mc));
}
std::uniform_real_distribution<double> dis(0.0,1.0); // random distribution of doubles in interval [0, 1]
cout << endl;
cout << "dim = " << dim << ", L = " << L << ", Lz = " << Lz << ", J33 = " << J33 << ", J34 = " << J34 << ", J44 = " << J44 << ", T_min = " << T_min << ", T_max = " << T_max << ", T_steps = " << T_steps << ", disorder_filling = " << disorder_filling << ", thermalization_bins = " << thermalization_bins << ", mc_bins = " << mc_bins << ", mc_binsize = " << mc_binsize << ", mc_steps = " << mc_steps << ", disorder_steps = " << disorder_steps << ", disorder_seed = " << seed_disorder << ", mc_seed = " << seed_mc << endl;
string Lz_string = to_string(Lz);
string L_string = to_string(L);
string mc_steps_string = to_string(mc_steps);
string J33_string = to_string(J33);
string J34_string = to_string(J34);
string J44_string = to_string(J44);
string T_min_string = to_string(T_min);
string T_max_string = to_string(T_max);
string T_steps_string = to_string(T_steps);
string disorder_filling_string = to_string(disorder_filling);
/*************************************************************************
*** MC SIMULATION FOR FIXED DISORDER REALIZATION (Metropolis + PT) *******
*************************************************************************/
for (int idx_disorder = 0; idx_disorder < disorder_steps; idx_disorder++) {
// Fill lattice randomly
// perform MC simulation of this configuration
// average and compute errors
// output av_dis variables (MC results for this fixed disorder realization)
int s1, s2; // variables needed to set up random order of spin filling (permute array order[i])
// Initialize variables (magnetization per bin, etc)
for (unsigned long int idx = 0; idx < 2*T_steps*mc_bins; idx++) {
magnetization1[idx] = 0.;
magnetization2[idx] = 0.;
magnetizationAF[idx] = 0.;
magnetization1_squared[idx] = 0.;
magnetization2_squared[idx] = 0.;
magnetizationAF_squared[idx] = 0.;
magnetization1_four[idx] = 0.;
magnetizationAF_four[idx] = 0.;
energy[idx] = 0.;
energy_squared[idx] = 0.;
}
// Initialize variables (magnetization per bin, etc)
for (unsigned long int idx = 0; idx < T_steps*mc_bins; idx++) {
magnetization_replica[idx] = 0.;
magnetization_replica_squared[idx] = 0.;
magnetization_replica_four[idx] = 0.;
for (int jdx = 0; jdx < L*Lz*(L/2+1); jdx++) {
s_q[jdx + idx*L*Lz*(L/2+1)] = 0.;
}
xi_a[idx] = 0.;
xi_b[idx] = 0.;
} // for initialize all arrays containing mc bin results
acceptance_number_Metropolis = 0;
acceptance_number_pt = 0;
/********************************************************************************************************************
***** FILL LATTICE RANDOMLY. Different T have same disorder realization. ***
***** Determine the order in which the sites will be filled with Co^{4+}. Set up permuted list of sites: order[i] ***
********************************************************************************************************************/
int N_max = round(disorder_filling*N); // number of core spins that are put in the system
//cout << "N_max = " << N_max << endl;
for (int idx = 0; idx < T_steps*2*N; idx++) {
spins[idx] = 0; // initialize all spins being empty
}
for (int idx = 0; idx < N; idx++) {
order[idx] = idx;
}
// randomly permute the array order[i]
for (int i = 0; i < N; i++) {
int j = i + (N-i)*dis(mt_rand_disorder); // use Merseene Twister RNG to generate uniform distribution in interval [0, 1]
int temp = order[i];
order[i] = order[j];
order[j] = temp;
}
for (int i = 0; i < N_max; i++) { // loop over all sites of the lattice
s1 = order[i]; // s1 are labels of the next site to be filled in the lattice
// site labels are: {0=empty, 1=+1/2=Co^(4+) up, -1=-1/2=Co^(4+) down, 2=+1=Co^(3+) up, -2=-1=Co^(3+) down
// Do not parallelize this loop (using #pragma as it gives wrong results!
// Fill site s1 with spin up or down in ensembles at all T and replicas (2*T_steps)
for (int T_idx = 0; T_idx < T_steps; T_idx++) {
for (int replica_idx = 0; replica_idx <= 1; replica_idx++) {
// create core Co^(4+_ spin up and spin down with equal probabilities
if (dis(mt_rand_disorder) < 0.5 ){
spins[T_idx*2*N + replica_idx*N + s1] = 1; // create spin up at site s1
}
else {
spins[T_idx*2*N + replica_idx*N + s1] = -1; // create spin down at site s1
}
// Update all empty direct nn sites of \pm 2 (since they are part of a polaron). Randomly initialize satellite spin state.
for (int jdx = 0; jdx < num_neighbors_direct; jdx++) {
s2 = neighbors_direct[num_neighbors_direct*s1 + jdx]; // direct neighbor of site s1 (one of num_neighbors_direct = 6)
if (spins[T_idx*2*N + replica_idx*N + s2] == 0) {
if (dis(mt_rand_disorder) < 0.5 ) {
spins[T_idx*2*N + replica_idx*N + s2] = 2; // put direct neighbors into \pm 2 state (Co^{3+} with same direction as polaron core site \pm 1)
}
else {
spins[T_idx*2*N + replica_idx*N + s2] = -2;
}
} // if spins[s2] == 0
} // for jdx over direct neighbors
} // for replica_idx
} // for T_idx
} // for i (runs over filled sites)
// output initial spin state (for debugging)
/*for (int replica_idx = 0; replica_idx <= 1; replica_idx++) {
cout << "Replica " << replica_idx << ": " << endl;
for (int idx = 0; idx < N; idx++) {
cout << "spins[" << idx << "] = " << spins[replica_idx*N + idx] << endl;
}
cout << endl;
}
*/
// Count number of filled sites (= number of spins) for this disorder realization. All 2*T_steps ensembles have the same disorder realization.
int counter_filled = 0;
vector<int> filled_sites(N,0);
for (int idx = 0; idx < N; idx++) {
// generate list of filled sites (these contain a spin and can be flipped)
if (spins[idx] != 0) {
filled_sites[counter_filled] = idx;
counter_filled++;
}
}
if (print_all == true) {
cout << "Total number of filled sites = " << counter_filled << ". Fraction of filled sites = " << static_cast<double>(counter_filled)/static_cast<double>(N) << endl;
}
fraction_filled[idx_disorder] = static_cast<double>(counter_filled)/static_cast<double>(N);
// Measure histogram distribution of bond interactions {J33, J34, J44}
int number_bonds_J33 = 0;
int number_bonds_J34 = 0;
int number_bonds_J44 = 0;
for (int idx = 0; idx < counter_filled; idx++) {
int site = filled_sites[idx];
for (int neighbor_idx = 0; neighbor_idx < num_neighbors_direct; neighbor_idx++) {
int neighbor_site = neighbors_direct[num_neighbors_direct*site + neighbor_idx];
if (abs(spins[site]) == 1) { // central spin is Co^{4+}
if (abs(spins[neighbor_site]) == 1) {
number_bonds_J44++;
}
else if (abs(spins[neighbor_site]) == 2) {
number_bonds_J34++;
}
else {
// do nothing as neighbor site is empty
}
}
else if (abs(spins[site]) == 2) { // central spin is Co^{3+}
if (abs(spins[neighbor_site]) == 1) {
number_bonds_J34++;
}
else if (abs(spins[neighbor_site]) == 2) {
number_bonds_J33++;
}
else {
// do nothing as neighbor site is empty
}
}
else {
// do nothing as core site is empty (should not occur anyway as I am summing over filled sites only)
}
} // for neighbor_idx
} // for idx (over filled sites)
// compute fraction from number of bonds
fraction_bonds_J33[idx_disorder] = static_cast<double>(number_bonds_J33)/static_cast<double>((num_neighbors_direct*N));
fraction_bonds_J34[idx_disorder] = static_cast<double>(number_bonds_J34)/static_cast<double>((num_neighbors_direct*N));
fraction_bonds_J44[idx_disorder] = static_cast<double>(number_bonds_J44)/static_cast<double>((num_neighbors_direct*N));
if (print_all == true) {
cout << "Number of bonds J33 = " << number_bonds_J33 << ", Number of bonds J34 = " << number_bonds_J34 << ", Number of bonds J44 = " << number_bonds_J44 << endl;
cout << "Fraction J33 = " << fraction_bonds_J33[idx_disorder] << ", Fraction J34 = " << fraction_bonds_J34[idx_disorder] << ", Fraction J44 = " << fraction_bonds_J44[idx_disorder] << endl;
// cout << "Fraction Av J33 = " << fraction_bonds_J33_av << ", Fraction Av J34 = " << fraction_bonds_J34_av << ", Fraction Av J44 = " << fraction_bonds_J44_av << ", Fraction Bonds Av All = " << fraction_bonds_J33_av + fraction_bonds_J34_av + fraction_bonds_J44_av << endl;
}
// Output snapshot of spin state
// Output spin state configuration
if (snapshot_output == true) {
outputFilename = "Data-SpinState-L_" + L_string + "-Lz_" + Lz_string + "-disorder_filling_" + disorder_filling_string + "-Before.dat";
outputFile.open(outputFilename);
outputFile.setf(ios::scientific);
for (int idx = 0; idx < N; idx++) {
outputFile << idx << " " << spins[idx] << endl;
}
outputFile.close();
}
if ( idx_disorder == 0 ) {
t = clock();
}
// Perform Metropolis step in parallel for all 2*T_steps ensembles
// Measure energy each ensemble: spins_energy[], 2*T_steps ensembles
#pragma omp parallel for
for (int idx_ensemble = 0; idx_ensemble < 2*T_steps; idx_ensemble++) {
spins_energy[idx_ensemble] = 0.; // initialize to zero
double en = 0.;
for (int i = 0; i < counter_filled; i++) {
int site = filled_sites[i];
int spin1 = spins[idx_ensemble * N + site];
if (abs(spin1) == 1) { // spin[i] is core spin Co^(4+)
for (int j = 0; j < num_neighbors_direct; j++) { // loop over nearest-neighbors of site "site"
int neighbor_site = neighbors_direct[num_neighbors_direct*site + j];
if (abs(spins[idx_ensemble * N + neighbor_site]) == 1) { // neighbor site is Co^(4+) spin 1/2
en += J44*static_cast<double>(spin1*spins[idx_ensemble * N + neighbor_site]);
}
else if (abs(spins[idx_ensemble * N + neighbor_site]) == 2) {
en += J34*static_cast<double>(spin1*spins[idx_ensemble * N + neighbor_site])/2.; // divide by 2 to account for fact that we take all spins to be of size 1 (but store Co^(3+) spins as \pm 2)
}
else {
// do nothing as neighboring site is empty, then spins[n] = 0
}
} // for j over neighboring sites
} // if spin = core spin at given site
else if (abs(spin1) == 2) { // spin[i] is satellite spin Co^(3+)
for (int j = 0; j < num_neighbors_direct; j++) { // loop over nearest-neighbors of site "site"
int neighbor_site = neighbors_direct[num_neighbors_direct*site + j];
if (abs(spins[idx_ensemble * N + neighbor_site]) == 1) { // neighbor site is Co^(4+) spin 1/2
en += J34*static_cast<double>(spin1*spins[idx_ensemble * N + neighbor_site])/2.; // divide by 2 as spin1 is \pm 2
}
else if (abs(spins[idx_ensemble * N + neighbor_site]) == 2) { // this includes if neighboring site is empty, then spins[n] = 0
en += J33*static_cast<double>(spin1*spins[idx_ensemble * N + neighbor_site])/4.; // divide by 4 as both spins are Co^(3+) and thus stored as \pm 2
}
else {
// do nothing as neighboring site is empty
}
} // for j over neighboring sites
}
else {
// do nothing if no spin at site i. This should not occur as we only loop over filled sites.
}
} // for i over all filled sites
en = en/2.; // we have summed over all bonds twice above, so we must divide by 2 here
spins_energy[idx_ensemble] = en; // store energy of ensemble idx_ensemble into array spins_energy
} // for idx_ensemble
// Print energy of each ensemble
/*for (int idx = 0; idx < 2*T_steps; idx++) {
cout << "Energy of ensemble[" << idx << "] = " << spins_energy[idx] << endl;
}*/
// cout << endl << "Thermalization started." << endl << endl;
// Thermalization
for (unsigned long int idx_mc_bin = 0; idx_mc_bin < thermalization_bins; idx_mc_bin++) {
for (unsigned long int idx_mcs = 0; idx_mcs < mc_binsize; idx_mcs++) {
// Metropolis step for each ensemble
#pragma omp parallel for
for (int idx_ensemble = 0; idx_ensemble < 2*T_steps; idx_ensemble++) {
for (int idx = 0; idx < N; idx++) { // loop over all N lattice sites within each MC step
int j = dis(mt_rand_mc_vector[idx_ensemble])*counter_filled; // randomly select site which has non-zero spin (N_max = disorder_filling*N such sites exist): j \in [0, N_max-1]
int site = filled_sites[j]; // site index of this site is determined by the order of which sites are (randomly) filled
int spin1 = spins[idx_ensemble*N + site]; // spin at selected site j
int a = 0; // sum over spin 1 neighbors \in {-6, -5, ..., 6}
int b = 0; // sum over spin 1/2 neighbors \in {-6, -5, ..., 6}
double flip_prob = 0.;
// Determine flip probability by counting number of nearest-neighbor Co^{4+} and Co^{3+} spins
if (abs(spin1) == 1) { // if 4+ site -> apply prob_1 table of flip probabilities
int spin_idx = (spin1 + 1)/2; // = {0, 1}
//cout << "spin_idx = " << spin_idx << endl;
for (int jdx = 0; jdx < num_neighbors_direct; jdx++) { // sum over six nearest neighbors
int neighbor_site = neighbors_direct[num_neighbors_direct*site + jdx];
//cout << "spin_neighbor[" << neighbor_site << "] = " << spin[neighbor_site] << endl;
if (abs(spins[idx_ensemble*N + neighbor_site]) == 1) { // neighbor site is spin 1/2
b += spins[idx_ensemble*N + neighbor_site];
}
else if (abs(spins[idx_ensemble*N + neighbor_site]) == 2) { // else: neighboring site is spin 1 (spin[n] = \pm 2) or empty (spin[n] = 0)
a += spins[idx_ensemble*N + neighbor_site]/2; // a is the sum of S=\tilde{S}/2 \in {-6, -5, ..., 6}
}
else {
// do nothing as neighboring site is empty
}
} // for jdx over neighbors
// Co^{4+} flip probability from table prob_1
// cout << "spin1_initial = " << spin1 << ", b = " << b << ", a = " << a << ", spin_idx = " << spin_idx << endl;
// determine temperature of this ensemble
int T_index = pt_EtoT[idx_ensemble];
flip_prob = prob_1[spin_idx + (a + num_neighbors_direct)*2 + (b + num_neighbors_direct)*2*(2*num_neighbors_direct + 1) + T_index*2*(2*num_neighbors_direct + 1) * (2*num_neighbors_direct + 1)];
} // if core site = 4+ (spin 1/2)
else if (abs(spin1) == 2) { // if 3+ site -> apply prob_2 table of flip probabilities
int spin_idx = (spin1/2 + 1)/2; // = {0, 1}
for (int jdx = 0; jdx < num_neighbors_direct; jdx++) { // sum over six nearest neighbors
int neighbor_site = neighbors_direct[num_neighbors_direct*site + jdx];
if (abs(spins[idx_ensemble*N + neighbor_site]) == 1) { // neighbor site is spin 1/2
b += spins[idx_ensemble*N + neighbor_site];
}
else if (abs(spins[idx_ensemble*N + neighbor_site]) == 2) { // this includes if neighboring site is empty, then spin[n] = 0
a += spins[idx_ensemble*N + neighbor_site]/2; // a is the sum of S=\tilde{S}/2 \in {-6, -5, ..., 6}
}
else {
// do nothing as neighboring site is empty
}
} // for jdx over neighbors
// cout << "b = " << b << ", a = " << a << ", spin_idx = " << spin_idx << endl;
int T_index = pt_EtoT[idx_ensemble];
flip_prob = prob_2[spin_idx + (a + num_neighbors_direct)*2 + (b + num_neighbors_direct)*2*(2*num_neighbors_direct + 1)+ T_index*2*(2*num_neighbors_direct + 1) * (2*num_neighbors_direct + 1)];
} // if core site = 3+ (spin 1)
double prand = dis(mt_rand_mc_vector[idx_ensemble]); // draw random number to compare with flip_prob
if (prand < flip_prob) {
// flip spin
spins[idx_ensemble*N + site] = - spin1;
// update energy due to spin flip. Here, we assume all spins are spin 1
if (abs(spin1) == 1) {
spins_energy[idx_ensemble] += -2.*spin1*(J44*b + J34*a); // Delta E = -2*S_i * (local_field)
}
else if (abs(spin1) == 2) {
spins_energy[idx_ensemble] += -spin1*(J34*b + J33*a); // Delta E = -2*S_i * (local_field). Factor of 2 is already in spin1
}
if (pt_EtoT[idx_ensemble] == 0) {
acceptance_number_Metropolis++; // Metropolis acceptance rate at lowest T
} // increase acceptance prob by one
} // if prand < flip_prob, the flip spin
} // for idx < N: one Metropolis step
} // omp for idx_ensemble
// Print energy of each ensemble
/*for (int idx = 0; idx < 2*T_steps; idx++) {
cout << "Energy of ensemble[" << idx << "] = " << spins_energy[idx] << endl;
}*/
if (parallel_tempering_step == true) {
// Parallel Tempering step
#pragma omp parallel for
for (int idx_replica = 0; idx_replica <= 1; idx_replica++) {
#pragma omp parallel for
for (int idx_T = 0; idx_T < T_steps/2 - static_cast<int>(swap_even_pairs); idx_T++) {
double delta_en = spins_energy[idx_replica*T_steps + pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)]] - spins_energy[idx_replica*T_steps + pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs) + 1]];
//cout << "Pairs of temperatures = (" << 2*idx_T + static_cast<int>(swap_even_pairs) << " = " << temperatures[2*idx_T + static_cast<int>(swap_even_pairs) ] << ", " << 2*idx_T + static_cast<int>(swap_even_pairs) + 1 << " = " << temperatures[2*idx_T + static_cast<int>(swap_even_pairs) + 1] << "). Attempt to exchange temperatures." << endl;
//cout << "pt_TtoE[" << idx_replica*T_steps + 2*idx_T << "] = " << pt_TtoE[idx_replica*T_steps + 2*idx_T] << ", pt_TtoE[" << idx_replica*T_steps + 2*idx_T + 1 << "] = " << pt_TtoE[idx_replica*T_steps +2*idx_T + 1] << endl;
//cout << "spins_energy[" << idx_replica*T_steps + pt_TtoE[idx_replica*T_steps +2*idx_T] << "] = " << spins_energy[idx_replica*T_steps + pt_TtoE[idx_replica*T_steps +2*idx_T]] << ", spins_energy[" << idx_replica*T_steps + pt_TtoE[idx_replica*T_steps +2*idx_T+1] << "] = " << spins_energy[idx_replica*T_steps + pt_TtoE[idx_replica*T_steps +2*idx_T+1]] << endl;
//cout << "delta_en of this pair = " << delta_en << endl;
if (delta_en > 0.) {
// exchange for sure
//cout << "Swap temperatures as positive delta_en = " << delta_en << endl;
int a = pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)];
int b = pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs) + 1];
pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)] = b;
pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs) + 1] = a;
pt_EtoT[idx_replica*T_steps + a] = 2*idx_T + static_cast<int>(swap_even_pairs) + 1;
pt_EtoT[idx_replica*T_steps + b] = 2*idx_T + static_cast<int>(swap_even_pairs);
acceptance_number_pt++;
}
else {
double exchange_prob = exp((1./temperatures[2*idx_T + static_cast<int>(swap_even_pairs)] - 1./temperatures[2*idx_T + static_cast<int>(swap_even_pairs) + 1])*delta_en);
//cout << "exchange_prob = " << exchange_prob << endl;
double prand = dis(mt_rand_mc_vector[idx_replica*T_steps + pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)]]); // draw random number to compare with flip_prob
if (prand < exchange_prob) { // exchange
//cout << "Swap temperatures even though delta_en is negative as prand = " << prand << " < exchange_prob = " << exchange_prob << endl;
int a = pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)];
int b = pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs) + 1];
pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)] = b;
pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs) + 1] = a;
pt_EtoT[idx_replica*T_steps + a] = 2*idx_T + static_cast<int>(swap_even_pairs) + 1;
pt_EtoT[idx_replica*T_steps + b] = 2*idx_T + static_cast<int>(swap_even_pairs);
acceptance_number_pt++;
}
}
} // for idx_T
} // for idx_replica: end of Parallel Tempering step
} // if Parallel Tempering == true
swap_even_pairs = !swap_even_pairs;
//cout << "swap_even_pairs = " << swap_even_pairs << endl;
} // for idx_mcs
} // for idx_mc_bin (end of thermalization)
/*
for (int idx = 0; idx < 2*T_steps; idx++) {
cout << "pt_TtoE[" << idx << "] = " << pt_TtoE[idx] << ", pt_EtoT[" << idx << "] = " << pt_EtoT[idx] << endl;
}
*/
// cout << endl << "Thermalization finished. Measurements begin. " << endl << endl;
/***************************************************************************************
* ***** MC simulation including measurements in each MC bin ***************************
***************************************************************************************/
/*for (int idx = 0; idx < 2*N; idx++) {
cout << "spins[" << idx << "] = " << spins[idx] << endl;
}
*/
for (unsigned long int idx_mc_bin = 0; idx_mc_bin < mc_bins; idx_mc_bin++) {
for (unsigned long int idx_mcs = 0; idx_mcs < mc_binsize; idx_mcs++) {
// Metropolis step for each ensemble
#pragma omp parallel for
for (int idx_ensemble = 0; idx_ensemble < 2*T_steps; idx_ensemble++) {
//cout << endl;
//cout << "idx_ensemble = " << idx_ensemble << endl;
//cout << endl;
//cout << "I am thread number " << omp_get_thread_num() << " working on idx_ensemble = " << idx_ensemble << endl;
int T_index = pt_EtoT[idx_ensemble];
for (int idx = 0; idx < N; idx++) { // loop over all N lattice sites within each MC step
int j = dis(mt_rand_mc_vector[idx_ensemble])*counter_filled; // randomly select site which has non-zero spin (N_max = disorder_filling*N such sites exist): j \in [0, N_max-1]
//omp_get_thread_num()
int site = filled_sites[j]; // site index of this site is determined by the order of which sites are (randomly) filled
int spin1 = spins[idx_ensemble*N + site]; // spin at selected site j
/*if (idx < 10) {
cout << "j = " << j << ", site = " << site << ", spin1 = " << spin1 << endl;
}*/
int a = 0; // sum over spin 1 neighbors \in {-6, -5, ..., 6}
int b = 0; // sum over spin 1/2 neighbors \in {-6, -5, ..., 6}
double flip_prob = 0.;
// Determine flip probability by counting number of nearest-neighbor Co^{4+} and Co^{3+} spins
if (abs(spin1) == 1) { // if 4+ site -> apply prob_1 table of flip probabilities
int spin_idx = (spin1 + 1)/2; // = {0, 1}
/*if (idx < 10) {
cout << "spin_idx at site 4+ = " << spin_idx << endl;
}*/
for (int jdx = 0; jdx < num_neighbors_direct; jdx++) { // sum over six nearest neighbors
int neighbor_site = neighbors_direct[num_neighbors_direct*site + jdx];
/*if (idx < 10) {
cout << "spin_neighbor[" << neighbor_site << "] = " << spins[idx_ensemble*N + neighbor_site] << endl;
}*/
if (abs(spins[idx_ensemble*N + neighbor_site]) == 1) { // neighbor site is spin 1/2
b += spins[idx_ensemble*N + neighbor_site];
}
else if (abs(spins[idx_ensemble*N + neighbor_site]) == 2) { // else: neighboring site is spin 1 (spin[n] = \pm 2) or empty (spin[n] = 0)
a += spins[idx_ensemble*N + neighbor_site]/2; // a is the sum of S=\tilde{S}/2 \in {-6, -5, ..., 6}
}
} // for jdx over neighbors
// Co^{4+} flip probability from table prob_1
/*if (idx < 10) {
cout << "spin1_initial = " << spin1 << ", b = " << b << ", a = " << a << ", spin_idx = " << spin_idx << endl;
}*/
// determine temperature of this ensemble
flip_prob = prob_1[spin_idx + (a + num_neighbors_direct)*2 + (b + num_neighbors_direct)*2*(2*num_neighbors_direct + 1) + T_index*2*(2*num_neighbors_direct + 1) * (2*num_neighbors_direct + 1)];
} // if core site = 4+ (spin 1/2)
else if (abs(spin1) == 2) { // if 3+ site -> apply prob_2 table of flip probabilities
int spin_idx = (spin1/2 + 1)/2; // = {0, 1}
/*if (idx < 10) {
cout << "spin_idx at site 3+ = " << spin_idx << endl;
}*/
for (int jdx = 0; jdx < num_neighbors_direct; jdx++) { // sum over six nearest neighbors
int neighbor_site = neighbors_direct[num_neighbors_direct*site + jdx];
/*if (idx < 10) {
cout << "spin_neighbor[" << neighbor_site << "] = " << spins[idx_ensemble*N + neighbor_site] << endl;
}*/
if (abs(spins[idx_ensemble*N + neighbor_site]) == 1) { // neighbor site is spin 1/2
b += spins[idx_ensemble*N + neighbor_site];
}
else if (abs(spins[idx_ensemble*N + neighbor_site]) == 2) { // this includes if neighboring site is empty, then spin[n] = 0
a += spins[idx_ensemble*N + neighbor_site]/2; // a is the sum of S=\tilde{S}/2 \in {-6, -5, ..., 6}
}
} // for jdx over neighbors
/*if (idx < 10) {
cout << "spin1_initial = " << spin1 << ", b = " << b << ", a = " << a << ", spin_idx = " << spin_idx << endl;
}*/
flip_prob = prob_2[spin_idx + (a + num_neighbors_direct)*2 + (b + num_neighbors_direct)*2*(2*num_neighbors_direct + 1)+ T_index*2*(2*num_neighbors_direct + 1) * (2*num_neighbors_direct + 1)];
/*if (idx < 10) {
cout << "flip_prob = prob_2 = " << flip_prob << endl;
}*/
} // if core site = 3+ (spin 1)
double prand = dis(mt_rand_mc_vector[idx_ensemble]); // draw random number to compare with flip_prob
if (prand < flip_prob) {
// flip spin
spins[idx_ensemble*N + site] = - spin1;
/*if (idx < 10) {
cout << "prand = " << prand << ", flip_prob = " << flip_prob << ". Thus spin is flipped and new spin entry = " << spins[idx_ensemble*N + site] << endl;
}*/
// update energy due to spin flip. Here, we assume all spins are spin 1
if (abs(spin1) == 1) {
spins_energy[idx_ensemble] += -2.*spin1*(J44*b + J34*a); // Delta E = -2*S_i * (local_field)
}
else if (abs(spin1) == 2) {
spins_energy[idx_ensemble] += -spin1*(J34*b + J33*a); // Delta E = -2*S_i * (local_field). Factor of 2 is already in spin1
}
if (pt_EtoT[idx_ensemble] == 0) {
acceptance_number_Metropolis++; // Metropolis acceptance rate at lowest T
} // increase acceptance prob by one
} // if prand < flip_prob, the flip spin
else {
// do not flip spin, so do nothing.
}
} // for idx < N: one Metropolis step
} // omp for idx_ensemble (Metropolis step for each ensemble)
if (parallel_tempering_step == true) {
// Parallel Tempering step
#pragma omp parallel for
for (int idx_replica = 0; idx_replica <= 1; idx_replica++) {
#pragma omp parallel for
for (int idx_T = 0; idx_T < T_steps/2 - static_cast<int>(swap_even_pairs); idx_T++) {
double delta_en = spins_energy[idx_replica*T_steps + pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)]] - spins_energy[idx_replica*T_steps + pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs) + 1]];
//cout << "Pairs of temperatures = (" << 2*idx_T + static_cast<int>(swap_even_pairs) << " = " << temperatures[2*idx_T + static_cast<int>(swap_even_pairs) ] << ", " << 2*idx_T + static_cast<int>(swap_even_pairs) + 1 << " = " << temperatures[2*idx_T + static_cast<int>(swap_even_pairs) + 1] << "). Attempt to exchange temperatures." << endl;
//cout << "pt_TtoE[" << idx_replica*T_steps + 2*idx_T << "] = " << pt_TtoE[idx_replica*T_steps + 2*idx_T] << ", pt_TtoE[" << idx_replica*T_steps + 2*idx_T + 1 << "] = " << pt_TtoE[idx_replica*T_steps +2*idx_T + 1] << endl;
//cout << "spins_energy[" << idx_replica*T_steps + pt_TtoE[idx_replica*T_steps +2*idx_T] << "] = " << spins_energy[idx_replica*T_steps + pt_TtoE[idx_replica*T_steps +2*idx_T]] << ", spins_energy[" << idx_replica*T_steps + pt_TtoE[idx_replica*T_steps +2*idx_T+1] << "] = " << spins_energy[idx_replica*T_steps + pt_TtoE[idx_replica*T_steps +2*idx_T+1]] << endl;
//cout << "delta_en of this pair = " << delta_en << endl;
if (delta_en > 0.) {
// exchange for sure
//cout << "Swap temperatures as positive delta_en = " << delta_en << endl;
int a = pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)];
int b = pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs) + 1];
pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)] = b;
pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs) + 1] = a;
pt_EtoT[idx_replica*T_steps + a] = 2*idx_T + static_cast<int>(swap_even_pairs) + 1;
pt_EtoT[idx_replica*T_steps + b] = 2*idx_T + static_cast<int>(swap_even_pairs);
acceptance_number_pt++;
}
else {
double exchange_prob = exp((1./temperatures[2*idx_T + static_cast<int>(swap_even_pairs)] - 1./temperatures[2*idx_T + static_cast<int>(swap_even_pairs) + 1])*delta_en);
//cout << "exchange_prob = " << exchange_prob << endl;
double prand = dis(mt_rand_mc_vector[idx_replica*T_steps + pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)]]); // draw random number to compare with flip_prob
if (prand < exchange_prob) { // exchange
//cout << "Swap temperatures even though delta_en is negative as prand = " << prand << " < exchange_prob = " << exchange_prob << endl;
int a = pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)];
int b = pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs) + 1];
pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs)] = b;
pt_TtoE[idx_replica*T_steps + 2*idx_T + static_cast<int>(swap_even_pairs) + 1] = a;
pt_EtoT[idx_replica*T_steps + a] = 2*idx_T + static_cast<int>(swap_even_pairs) + 1;
pt_EtoT[idx_replica*T_steps + b] = 2*idx_T + static_cast<int>(swap_even_pairs);
acceptance_number_pt++;
}