-
Notifications
You must be signed in to change notification settings - Fork 0
/
1D3N_final.cpp
1047 lines (919 loc) · 35.9 KB
/
1D3N_final.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 <iostream>
#include <fstream>
#include <cstdlib>
#include <cmath>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <vector>
#include <mpi.h>
////////////////////
#define n 1000 ///Ввод размерности решетки
float Polevar = 0;
//float Polevar = 0.01; // Поле
/*long int prohod_MC = 1e8; /// Ввод числа шагов Монте-Карло
unsigned long long between_exchange=1e6; //между репличными обменами
*/
unsigned long long Prohod_MC_equilibration = 1e8; /// Ввод числа шагов разогрева
unsigned long long Prohod_MC_sampling = 1e8; /// Ввод числа шагов Монте-Карло
unsigned long long between_exchange_equilibration=1e3; //между репличными обменами
unsigned long long between_exchange=1e3; //между репличными обменами
bool replica_on=1;
int current_value = 0; // выводить текущие значения или нет
unsigned long long CountOut = 1e8; // количество вывода
///////////////////////
using namespace std;
/////////////////////////////////// Ввод переменных
int num_podhod=10; // количвество попыток найти систему связей с мин. кол-м ошибок.
double mintemp=0.1; // выбор min температуры
double maxtemp=3; // выбор max температуры
float Dt = 0.1; // шаг температуры
//int CountOut = 1e6; // количество вывода
////////////////////////////////////
void Slspin (short *spin);
void SpinFerr(short *spin);
void Vivodspin(int spin);
int Slsvaz( short *svaz, int num_podhod);
void VivodSSS( short *spin,short *svaz);
void Energy(short *spin,short *svaz,float *E);
float EnergyIJ(int i, short *spin, short *svaz);
void VivodEnergy( float *E);
void CopyE(float *E,float *E1);
int Claster( float *E1);
int ClasterFerr( float *E1);
void ColorOut2( float *E, short *spin);
void ColorOut( float *E, short *spin);
float SumEnergy(float *E);
void ColorOutIJ( float *E, short *spin, int i,int j);
void ColorOutSpin( float *E, short *spin);
int MaxClass(int per, float *E1, int tmp, int *Ochered);
int MaxClassFerr(int per, float *E1, int tmp, int *Ochered);
int sosed_sl(int top);
int sosed_sp(int top);
int sosed_sd(int top);
double SROTKL(double OutputMass, double SRKVOTKL);
double MagnMet( short *spin);
void PhazDiagramm(int var04, int var02, int var00, int var20, int var40, float *E);
void MCL(double mintemp, double maxtemp, short *spin, short *svaz, float *E, float *E1, int NUM_step_mcl);
void MCProhod(double temp,short *spin,short *svaz,float *E);
void MCProhod2(double temp,short *spin,short *svaz,float *E, int rank);
void Slspin(short *spin)
{
int v=0;
for(int i=0;i<n;i++)
{
v=rand()%(2);
if(v)
spin[i]=1;
else
spin[i]=-1;
}
}
//////////////////////////////////////////////////// Забивает матрицу спинов 1
void SpinFerr(short *spin)
{
for(int i=0;i<n;i++)
{
spin[i]=1;
}
}
///////////////////////////////////////////////////////Подсчитывает энегрию системы
void Energy(short *spin,short *svaz,float *E)
{
for (int i = 2; i < (n-2); i++)
{
if(i%2==0)
E[i] = -svaz[i] * spin[i] * spin[i+1] - svaz[i-1] * spin[i] * spin[i-1]- svaz[n+(i/2)] * spin[i] * spin[i+3] - Polevar;
else
E[i] = -svaz[i] * spin[i] * spin[i+1] - svaz[i-1] * spin[i] * spin[i-1]- svaz[n+((i-3)/2)] * spin[i] * spin[i-3] - Polevar;
}
if(n%4==0)
{
E[0] = -svaz[0] * spin[0] * spin[1] - svaz[n-1] * spin[0] * spin[n-1] - svaz[n] * spin[0] * spin[3] - Polevar;
E[1] = -svaz[0] * spin[0] * spin[1] - svaz[1] * spin[1] * spin[2] - svaz[n+(n/2-1)] * spin[1] * spin[n-2] - Polevar;
E[n-1] = -svaz[n-1] * spin[n-1] * spin[0] - svaz[n-2] * spin[n-1] * spin[n-2] - svaz[n+((n-4)/2)] * spin[n-1] * spin[n-4] - Polevar;
E[n-2] = -svaz[n-2] * spin[n-2] * spin[n-1] - svaz[n-3] * spin[n-3] * spin[n-2] - svaz[n+((n/2)-1)] * spin[n-2] * spin[1] - Polevar;
}
else
{
E[0] = -svaz[0] * spin[0] * spin[1] - svaz[n+((n/2)-1)] * spin[0] * spin[n-2] - svaz[n] * spin[0] * spin[3] - Polevar;
E[1] = -svaz[0] * spin[0] * spin[1] - svaz[1] * spin[1] * spin[2] - svaz[n-1] * spin[1] * spin[n-1] - Polevar;
E[n-1] = -svaz[n-1] * spin[n-1] * spin[1] - svaz[n-2] * spin[n-1] * spin[n-2] - svaz[n+((n-4)/2)] * spin[n-1] * spin[n-4] - Polevar;
E[n-2] = -svaz[n-2] * spin[n-2] * spin[n-1] - svaz[n-3] * spin[n-3] * spin[n-2] - svaz[n+((n/2)-1)] * spin[n-2] * spin[0] - Polevar;
}
}
///////////////////////////////////////////////////////Копирует массив с энергией Е в Е1
void CopyE(float *E,float *E1)
{
for (int i = 0; i < n; i++)
{
E1[i] = E[i];
}
}
///////////////////////////////////////////////////////Копирует массив с энергией Е в Е1
void CopyE(short *E,float *E1)
{
for (int i = 0; i < n; i++)
{
E1[i] = E[i];
}
}
///////////////////////////////////////////////////////Копирует массив с энергией Е в Е1
void CopyE(float *E,short *E1)
{
for (int i = 0; i < n; i++)
{
E1[i] = E[i];
}
}
///////////////////////////////////////////////////////Копирует массив с энергией Е в Е1
void CopyE(short *E,short *E1)
{
for (int i = 0; i < n; i++)
{
E1[i] = E[i];
}
}
/////////////////////////////////////////////////////////Подсчитывает энергию одного спина
float EnergyIJ(int i,short *spin,short *svaz)
{
float Ener = 0;
if(n%4==0)
{
if(i==0)
Ener = - svaz[0] * spin[0] * spin[1] - svaz[n-1] * spin[0] * spin[n-1] - svaz[n] * spin[0] * spin[3] - Polevar;
if(i==1)
Ener = -svaz[0] * spin[0] * spin[1] - svaz[1] * spin[1] * spin[2] - svaz[n+(n/2-1)] * spin[1] * spin[n-2] - Polevar;
if(i==n-1)
Ener = -svaz[n-1] * spin[n-1] * spin[0] - svaz[n-2] * spin[n-1] * spin[n-2] - svaz[n+((n-4)/2)] * spin[n-1] * spin[n-4] - Polevar;
if(i==n-2)
Ener = -svaz[n-2] * spin[n-2] * spin[n-1] - svaz[n-3] * spin[n-3] * spin[n-2] - svaz[n+((n/2)-1)] * spin[n-2] * spin[1] - Polevar;
if(i!=0 && i!=1 && i!=n-1 && i!=n-2)
{
if(i%2==0)
Ener = -svaz[i] * spin[i] * spin[i+1] - svaz[i-1] * spin[i] * spin[i-1]- svaz[n+(i/2)] * spin[i] * spin[i+3] - Polevar;
else
Ener = -svaz[i] * spin[i] * spin[i+1] - svaz[i-1] * spin[i] * spin[i-1]- svaz[n+((i-3)/2)] * spin[i] * spin[i-3] - Polevar;
}
}
else
{
if(i==0)
Ener = -svaz[0] * spin[0] * spin[1] - svaz[n+((n/2)-1)] * spin[0] * spin[n-2] - svaz[n] * spin[0] * spin[3] - Polevar;
if(i==1)
Ener = -svaz[0] * spin[0] * spin[1] - svaz[1] * spin[1] * spin[2] - svaz[n-1] * spin[1] * spin[n-1] - Polevar;
if(i==n-1)
Ener = -svaz[n-1] * spin[n-1] * spin[1] - svaz[n-2] * spin[n-1] * spin[n-2] - svaz[n+((n-4)/2)] * spin[n-1] * spin[n-4] - Polevar;
if(i==n-2)
Ener = -svaz[n-2] * spin[n-2] * spin[n-1] - svaz[n-3] * spin[n-3] * spin[n-2] - svaz[n+((n/2)-1)] * spin[n-2] * spin[0] - Polevar;
if(i!=0 && i!=1 && i!=n-1 && i!=n-2)
{
if(i%2==0)
Ener = -svaz[i] * spin[i] * spin[i+1] - svaz[i-1] * spin[i] * spin[i-1]- svaz[n+(i/2)] * spin[i] * spin[i+3] - Polevar;
else
Ener = -svaz[i] * spin[i] * spin[i+1] - svaz[i-1] * spin[i] * spin[i-1]- svaz[n+((i-3)/2)] * spin[i] * spin[i-3] - Polevar;
}
}
return Ener;
}
void MCProhod2(double temp,short *spin,short *svaz,float *E, int rank)
{
float En1,En2;
int step=0;
double slch;
double veroyatnost=0;
int slspin=rand()%(n);
int i = slspin;
int var = spin[i];
En1 = EnergyIJ(i, spin, svaz);
spin[i] *= -1;
En2 = EnergyIJ(i, spin, svaz);
slch=((double)rand())/RAND_MAX;
//slch=myrandom(my_random_engine);
if (En2 <= En1)
veroyatnost = 1;
else
veroyatnost = exp(-(En2 - En1) / temp);
if (slch < veroyatnost)
{
E[i] = En2;
if(n%4==0)
{
if (i == 0)
{
E[n-1]= EnergyIJ(n-1,spin,svaz);
E[1]= EnergyIJ(1,spin,svaz);
E[3]= EnergyIJ(3,spin,svaz);
}
if (i == 1)
{
E[0]= EnergyIJ(0,spin,svaz);
E[2]= EnergyIJ(2,spin,svaz);
E[n-2]= EnergyIJ(n-2,spin,svaz);
}
if (i == n - 1)
{
E[0] = EnergyIJ(0,spin,svaz);
E[n-2] = EnergyIJ(n-2,spin,svaz);
E[n-4] = EnergyIJ(n-4,spin,svaz);
}
if (i == n - 2)
{
E[1] = EnergyIJ(1,spin,svaz);
E[n-1] = EnergyIJ(n-1,spin,svaz);
E[n-3] = EnergyIJ(n-3,spin,svaz);
}
if (i != 0 && i != 1 && i != n-2 && i != n - 1)
{
if(i%2==0)
{
E[i-1] = EnergyIJ(i-1,spin,svaz);
E[i+1] = EnergyIJ(i+1,spin,svaz);
E[i+3] = EnergyIJ(i+3,spin,svaz);
}
else
{
E[i-1] = EnergyIJ(i-1,spin,svaz);
E[i+1] = EnergyIJ(i+1,spin,svaz);
E[i-3] = EnergyIJ(i-3,spin,svaz);
}
}
}
else
{
if (i == 0)
{
E[n-2]= EnergyIJ(n-2,spin,svaz);
E[1]= EnergyIJ(1,spin,svaz);
E[3]= EnergyIJ(3,spin,svaz);
}
if (i == 1)
{
E[0]= EnergyIJ(0,spin,svaz);
E[2]= EnergyIJ(2,spin,svaz);
E[n-1]= EnergyIJ(n-1,spin,svaz);
}
if (i == n - 1)
{
E[1] = EnergyIJ(1,spin,svaz);
E[n-2] = EnergyIJ(n-2,spin,svaz);
E[n-4] = EnergyIJ(n-4,spin,svaz);
}
if (i == n - 2)
{
E[0] = EnergyIJ(0,spin,svaz);
E[n-1] = EnergyIJ(n-1,spin,svaz);
E[n-3] = EnergyIJ(n-3,spin,svaz);
}
if (i != 0 && i != 1 && i != n-2 && i != n - 1)
{
if(i%2)
{
E[i-1] = EnergyIJ(i-1,spin,svaz);
E[i+1] = EnergyIJ(i+1,spin,svaz);
E[i+3] = EnergyIJ(i+3,spin,svaz);
}
else
{
E[i-1] = EnergyIJ(i-1,spin,svaz);
E[i+1] = EnergyIJ(i+1,spin,svaz);
E[i-3] = EnergyIJ(i-3,spin,svaz);
}
}
}
}
else
spin[i] *= -1;
step++;
// Energy(spin,svaz,E);
}
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////////Подсчет намагниченности
double MagnMet(short *spin)
{
double Magnvar=0;
for (int i = 0; i < n; ++i)
{
Magnvar += spin[i];
}
return abs(Magnvar/(n));
}
////////////////////////////////////////////////Для подсчета макс.кластера для спинового стекла
int Claster(float *E1)
{
int tmp = 0;
int t;
int Max = 0;
int *Ochered;
Ochered = new int[n];
for (int i = 0; i < n; i++)
{
if (E1[i] == -3 || E1[i] == -1)
{
tmp = 1;
int top = i;
t = MaxClass(top, E1, tmp,Ochered);
if (t >= Max)
Max = t;
t = 0;
}
}
delete [] Ochered;
Ochered = NULL;
return Max;
}
//////////////////////////////////////////////////////Для подсчета макс.кластера для ферромагеника
int ClasterFerr(float *E1)
{
int tmp = 0;
int t;
int Max = 0;
int *Ochered;
Ochered = new int[n];
for (int i = 0; i < n; i++)
{
if (E1[i] == -3 )
{
tmp = 1;
int top = i;
t = MaxClassFerr(top, E1, tmp, Ochered);
if (t >= Max)
Max = t;
t = 0;
}
}
delete [] Ochered;
Ochered = NULL;
return Max;
}
//////////////////////////////////////////////////////Для подсчета макс.кластера для спинового стекла
int MaxClass(int per,float *E1,int tmp,int *Ochered)
{
int sl, sp, sd, top;
int w = 0;
int r = 1;
Ochered[0] = per;
E1[per] = 33;
while (w < r)
{
top = Ochered[w];
////
sl = sosed_sl(top);
if (E1[sl] == -3 || E1[sl] == -1)
{
Ochered[r] = sl;
E1[sl] = 33;
r++;
}
////
sp = sosed_sp(top);
if (E1[sp] == -3 || E1[sp] == -1)
{
Ochered[r] = sp;
E1[sp] = 33;
r++;
}
sd = sosed_sd(top);
if (E1[sd] == -3 || E1[sd] == -1)
{
Ochered[r] = sd;
E1[sd] = 33;
r++;
}
////
w++;
}
return r;
}
/////////////////////////////////////////////////////Для подсчета макс.кластера для ферромагеника
int MaxClassFerr(int per,float *E1,int tmp, int *Ochered)
{
int sl, sp, sd,top;
int w = 0;
int r = 1;
Ochered[0] = per;
E1[per] = 33;
while (w < r)
{
top = Ochered[w];
////
sl = sosed_sl(top);
if (E1[sl] == -3 )
{
Ochered[r] = sl;
E1[sl] = 33;
r++;
}
////
sp = sosed_sp(top);
if (E1[sp] == -3 )
{
Ochered[r] = sp;
E1[sp] = 33;
r++;
}
sd = sosed_sd(top);
if (E1[sd] == -3 )
{
Ochered[r] = sd;
E1[sd] = 33;
r++;
}
////
w++;
}
return r;
}
//////////////////////////////////////////////////// Служебные функции для посчета мах.кластера
int sosed_sl( int top)
{
int i = top;
int sl = 0;
if (i == 0)
if(n%4==0)
sl = n-1;
else
sl=n-2;
else
sl = i - 1;
return sl;
}
int sosed_sp( int top)
{
int i = top;
int sp = 0;
if (i == n - 1)
if(n%4==0)
sp = 0;
else
sp =1;
else
sp = i + 1;
return sp;
}
int sosed_sd( int top)
{
int i = top;
int sd = 0;
if (i == 0)
{
sd=3;
}
if (i == 1)
{
if(n%4==0)
sd=n-2;
else
sd=n-1;
}
if (i == n - 1)
{
sd=n-4;
}
if (i == n - 2)
{
if(i%4==0)
sd=1;
else
sd=0;
}
if (i != 0 && i != 1 && i != n-2 && i != n - 1)
{
if(i%2==0)
{
sd=i+3;
}
else
{
sd=i-3;
}
}
return sd;
}
//////////////////////////////////////////////////////////Суммирует энергию системы
float SumEnergy( float *E)
{
float Sum = 0;
for (int i = 0; i < n; i++)
{
Sum = Sum + E[i];
}
return Sum/2;
}
/////////////////////////////////////////////////////////// Получает поле
void POLE(short *spin,short *svaz,float *E1)
{
int x = n;
E1[0] = -svaz[0] * spin[1] - svaz[n-1] * spin[n-1] - Polevar;
E1[n-1] = -svaz[n-2] * spin[n-2] - svaz[n-1] * spin[0] - Polevar;
for (int i = 1; i < n - 1; i++)
{
E1[i] = -svaz[i] * spin[i+1] - svaz[i-1] * spin[i-1] - Polevar;
}
}
///////////////////////////////////////////////////////////////
void PhazDiagramm(int *var02,int *var00,int *var20, float *E)
{
*var02=0;
*var00=0;
*var20=0;
for (int i = 0; i < n; i++)
{
if(E[i]==-2)
{
*var02+=1;
} else if (E[i]==0)
{
*var00+=1;
} else if (E[i]==2)
{
*var02+=1;
}
}
}
static void SROTKL(int size,double Outputmass[],double *SRZnach,double *SRKVOtkl)
{
*SRZnach = 0;
*SRKVOtkl = 0;
for (int i = 0; i < size; i++)
{
*SRZnach += Outputmass[i];
}
*SRZnach = *SRZnach / size;
for (int i = 0; i < size; i++)
{
Outputmass[i] = pow((Outputmass[i] - *SRZnach), 2);
*SRKVOtkl += Outputmass[i];
}
*SRKVOtkl = sqrt(*SRKVOtkl / size);
}
static void SROTKL(int size,int Outputmass[],double *SRZnach,double *SRKVOtkl)
{
*SRZnach = 0;
*SRKVOtkl = 0;
for (int i = 0; i < size; i++)
{
*SRZnach += Outputmass[i];
}
*SRZnach = *SRZnach / size;
for (int i = 0; i < size; i++)
{
Outputmass[i] = pow((Outputmass[i] - *SRZnach), 2);
*SRKVOtkl += Outputmass[i];
}
*SRKVOtkl = sqrt(*SRKVOtkl / size);
}
int main(int argc, char **argv)
{
int rank;
int size;
cout<<"START:"<<endl;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
srand((unsigned)time(NULL)+rank);
int CO = Prohod_MC_sampling/CountOut;
// int CO = prohod_MC/CountOut;
///////// Создание массива spin[n]////////////
short *spin=new short[n];
/////////////////////////////////////
//Создание массива svaz[n]////////////
short *svaz = new short[n+(n/2-1)];
/////////////////////////////////////////
////// Создание массива E[n]////////////
float *E=new float[n];
/////////////////////////////////////
////// Создание массива E1[n]////////////
float *E1=new float[n];
////////////////////////////////////
////////// Задание связей ферромагнетика///////////
for (int i=0;i<(n+n/2);i++)
{
svaz[i]=1;
}
/////////////массивы для вывода//////////////////////////
double *recvAE = new double[size];
double *recvAE2 = new double[size];
double *recvAE4 = new double[size];
double *recvAM = new double[size];
double *recvAM2 = new double[size];
double *recvAM4 = new double[size];
double *recvAPP = new double[size];
double *recvAPPF = new double[size];
double *recvHeatCapacity = new double[size];
double *recvVospr = new double[size];
double *recvBCenergy = new double[size];
double *recvBCmagn = new double[size];
double *recvBCPPF = new double[size];
double *recvBCPP = new double[size];
//ofstream outE("energy.dat",ios::out); //энергия
ofstream outAE("energyAVG.dat",ios::out); //средняя энергия
ofstream outAE2("energyAVG2.dat",ios::out); //средняя энергия квадрат
ofstream outAE4("energyAVG4.dat",ios::out); //средняя энергия 4 степень
ofstream outHeatCapacity("C.dat",ios::out); //Теплоемкость
ofstream outVospr("X.dat",ios::out); //Восприимчивость
ofstream outAPP("APP.dat",ios::out); //Средний параметр порядка 1
ofstream outAPPF("APPF.dat",ios::out); //Средний параметр порядка 2
ofstream outAM("AMagn.dat",ios::out); //Средняя намагниченность
ofstream outAM2("AMagn2.dat",ios::out);
ofstream outAM4("AMagn4.dat",ios::out);
// биндеры
ofstream outBCenergy("BC_energy.dat",ios::out); //биндер по энергии
ofstream outBCmagn("BC_magn.dat",ios::out); //биндер по намагниченности
ofstream outBCPP("BC_PP.dat",ios::out); //биндер по параметру порядка
ofstream outBCPPF("BC_PPF.dat",ios::out); //биндер по параметру порядка2
////////////////////////////
SpinFerr(spin);
//srand((unsigned)time(NULL)+rank);
//Slspin(spin);
Energy(spin,svaz,E);
CopyE(E,E1);
/////////////////// время///////////////
//////MC///////////////////////////////
double SumenergyVar,MagnVar,MagnVar2,MagnVar4,Teploemkost,Vospriimchivost;
double predsumenergy=0;
double predMagn=0;
double maxSF,PPF,maxS,PP;
int var02=0;
int var00=0;
int var20=0;
int varPOLE02=0;
int varPOLE00=0;
int varPOLE20=0;
double SumenergyVar2, SumenergyVar4;
double Aenergy2=0;
double Aenegry4=0;
double Amagn2=0;
double Amagn4=0;
double APPF2=0;
double APPF4=0;
double APP2=0;
double APP4=0;
double X_o=0;
// double temp = rank*Dt;int Prohod=0;
// int cicle=1;
vector<double> avgValue; // AE
vector<double> avgValue2; // AE2
vector<double> avgValue4; // AE4
vector<double> avgValuePP; // APP
vector<double> avgValuePPF; // APPF
vector<double> avgValueMagn;// AM
vector<double> CValue; // E
vector<double> CValuePP; // PP
vector<double> CValuePPF; // PPF
vector<double> CValueMagn;// M
double Avalue=0; // для усреднения энергии
double Aenergy=0;
unsigned long long index=0;
double AvaluePP=0; // для усреднения PP
double temPP;
double AvaluePPF=0; // для усреднения PPF
double temPPF;
double AvalueMagn=0; // для усреднения Magn
double temMagn;
//++++++++++++++++++++++++++++++++++++++
double e_AVG=0;
double PP1_AVG=0;
double e1=0;
double pp1=0;
// для вывода БК for PP2
double RBCenergy=0;
double RBCmagn=0;
double RBCPPF=0;
double RBCPP=0;
double E_2=0;
double C_o=0;
//++++++++++++++++++++++++++++++++++++++
//для репличного обмена
double exchange_t=0;
double exchange_e=0;
int yes_no_exchange=0;
double probability_of_exchange=0;
// bool replica_on=1;
MPI_Status status;
short *exchange_state=new short[n];
//++++++++++++++++++++++++++++++++++++++
double temp=(rank+1)*(maxtemp-mintemp)/size;
long int Prohod=0;
while(Prohod<Prohod_MC_equilibration)
{
e1=SumEnergy(E);
if(replica_on)
{
if(Prohod%between_exchange_equilibration==0)
{
for(int i=size-1;i>0;--i)
{
if(rank==i)
{
MPI_Send(&temp,1, MPI_DOUBLE, i-1, 0, MPI_COMM_WORLD);
MPI_Send(&e1,1, MPI_DOUBLE, i-1, 0, MPI_COMM_WORLD);
MPI_Recv(&yes_no_exchange,1, MPI_INT, i-1, 0, MPI_COMM_WORLD,&status);
if(!yes_no_exchange);
else
{
MPI_Send(spin,n, MPI_SHORT, i-1, 0, MPI_COMM_WORLD);
MPI_Recv(exchange_state,n, MPI_SHORT, i-1, 0, MPI_COMM_WORLD,&status);
MPI_Recv(&e1,1, MPI_DOUBLE, i-1, 0, MPI_COMM_WORLD,&status);
CopyE(exchange_state,spin);
}
}
if(rank==i-1)
{
MPI_Recv(&exchange_t,1, MPI_DOUBLE, i, 0, MPI_COMM_WORLD,&status);
MPI_Recv(&exchange_e,1, MPI_DOUBLE, i, 0,MPI_COMM_WORLD,&status);
probability_of_exchange=exp(-((1/temp)-(1/exchange_t))*(exchange_e-e1));
if (probability_of_exchange<(double)(rand())/RAND_MAX)
{
yes_no_exchange=0;
MPI_Send(&yes_no_exchange,1, MPI_INT, i, 0, MPI_COMM_WORLD);
}
else
{
yes_no_exchange=1;
MPI_Send(&yes_no_exchange,1, MPI_INT, i, 0, MPI_COMM_WORLD); //порядок?
MPI_Recv(exchange_state,n, MPI_SHORT, i, 0, MPI_COMM_WORLD,&status);
MPI_Send(spin,n, MPI_SHORT, i, 0, MPI_COMM_WORLD);
MPI_Send(&e1,1, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
CopyE(exchange_state, spin);
}
}
MPI_Barrier(MPI_COMM_WORLD);
}
}
}
Energy(spin,svaz,E);
MCProhod2(temp,spin,svaz,E,rank);
if(rank==0)
{
if(Prohod%(Prohod_MC_equilibration/100)==0) //было if(Prohod%(Prohod_MC_sampling/100)==0)
cout<<"Equilibration status: "<<(Prohod)/(Prohod_MC_equilibration/100)+1<<endl; // было cout<<"Status: "<<Prohod/(Prohod_MC_sampling/100)<<endl;
}
Prohod++;
}
Prohod=0;
///////////////////////////////////
while(Prohod<Prohod_MC_sampling)
{
e1=SumEnergy(E);
if(replica_on)
{
if(Prohod%between_exchange_equilibration==0)
{
for(int i=size-1;i>0;--i)
{
if(rank==i)
{
MPI_Send(&temp,1, MPI_DOUBLE, i-1, 0, MPI_COMM_WORLD);
MPI_Send(&e1,1, MPI_DOUBLE, i-1, 0, MPI_COMM_WORLD);
MPI_Recv(&yes_no_exchange,1, MPI_INT, i-1, 0, MPI_COMM_WORLD,&status);
if(!yes_no_exchange);
else
{
MPI_Send(spin,n, MPI_SHORT, i-1, 0, MPI_COMM_WORLD);
MPI_Recv(exchange_state,n, MPI_SHORT, i-1, 0, MPI_COMM_WORLD,&status);
MPI_Recv(&e1,1, MPI_DOUBLE, i-1, 0, MPI_COMM_WORLD,&status);
CopyE(exchange_state,spin);
}
}
if(rank==i-1)
{
MPI_Recv(&exchange_t,1, MPI_DOUBLE, i, 0, MPI_COMM_WORLD,&status);
MPI_Recv(&exchange_e,1, MPI_DOUBLE, i, 0,MPI_COMM_WORLD,&status);
probability_of_exchange=exp(-((1/temp)-(1/exchange_t))*(exchange_e-e1));
if (probability_of_exchange<(double)(rand())/RAND_MAX)
{
yes_no_exchange=0;
MPI_Send(&yes_no_exchange,1, MPI_INT, i, 0, MPI_COMM_WORLD);
}
else
{
yes_no_exchange=1;
MPI_Send(&yes_no_exchange,1, MPI_INT, i, 0, MPI_COMM_WORLD); //порядок?
MPI_Recv(exchange_state,n, MPI_SHORT, i, 0, MPI_COMM_WORLD,&status);
MPI_Send(spin,n, MPI_SHORT, i, 0, MPI_COMM_WORLD);
MPI_Send(&e1,1, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
e1=exchange_e;
CopyE(exchange_state, spin);
}
}
MPI_Barrier(MPI_COMM_WORLD);
}
}
}
Energy(spin,svaz,E);
MCProhod2(temp,spin,svaz,E,rank);
if(Prohod%CO==0)
{
index++;
if (Polevar==0)
{
CopyE(E,E1); // при расчете кластера, коцаеца массив энергий, поэтому мы его копируем и работаем с копией
maxSF = ClasterFerr(E1);
PPF = maxSF / (n); //
temPPF=(PPF+(index-1)*temPPF)/(index); // не забыть помножить !!!*N куммулятив ферромагнитного кластера
APPF2=(PPF+(index-1)*temPPF)/(index);
APPF4=(PPF+(index-1)*temPPF)/(index);
CopyE(E,E1); // при расчете кластера, коцаеца массив энергий, поэтому мы его копируем и работаем с копией
maxS = Claster(E1);
PP= maxS / (n);
temPP=(PP+(index-1)*temPP)/(index); // !!!*N куммулятив смешанного кластера
APP2=(PP+(index-1)*APP2)/(index);
APP4=(PP+(index-1)*APP4)/(index);
}
SumenergyVar = SumEnergy(E); /////////////
SumenergyVar2=pow(SumenergyVar,2);
SumenergyVar4=pow(SumenergyVar,4);
Aenergy=(SumenergyVar+(index-1)*Aenergy)/(index); //было tem213=Avalue*(CO)/(Prohod);
Aenergy2=(SumenergyVar2+(index-1)*Aenergy2)/(index);
Aenegry4=(SumenergyVar4+(index-1)*Aenegry4)/(index);
MagnVar=MagnMet(spin);
MagnVar2=MagnVar*MagnVar;
MagnVar4=MagnVar*MagnVar*MagnVar*MagnVar; /////////////
temMagn=(MagnVar+(index-1)*temMagn)/(index); // !!!*N куммулятив смешанного кластера
Amagn2=(MagnVar2+(index-1)*Amagn2)/(index);
Amagn4=(MagnVar4+(index-1)*Amagn4)/(index);
////////////////////БК_И_Теплоемкость////////////////////
e_AVG+=SumenergyVar;
E_2+=SumenergyVar*SumenergyVar;
PP1_AVG+=SumenergyVar; //e_AVG+=SumenergyVar;
// }
if(rank==0)
{
if(Prohod%(Prohod_MC_sampling/100)==0) //было if(Prohod%(Prohod_MC_sampling/100)==0)
cout<<"Status: "<<(Prohod)/(Prohod_MC_sampling/100)+1<<endl; // было cout<<"Status: "<<Prohod/(Prohod_MC_sampling/100)<<endl;
}
}
Prohod++;
}
cout<<"index:"<<index<<" Coutout:"<<CountOut<<endl;
C_o=((Aenergy2)-(Aenergy*Aenergy))/(temp*temp*n); // теплоёмкость // теплоёмкость
X_o=((Amagn2)-(temMagn*temMagn))/(temp*n);
RBCenergy = 1-(Aenegry4/(3*pow(Aenergy2,2))); // результирующий БК энергии
RBCmagn = 1-(Amagn4/(3*pow(Amagn2,2))); // результирующий БК магнитный
RBCPPF = 1-(APPF4/(3*pow(APPF2,2))); // результирующий БК параметра порядка 2
RBCPP = 1-(APP4/(3*pow(APP2,2))); // результирующий БК параметра порядка
MPI_Gather(&X_o, 1, MPI_DOUBLE, recvVospr, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Gather(&C_o, 1, MPI_DOUBLE, recvHeatCapacity, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); // Теплоемкость
MPI_Gather(&RBCenergy, 1, MPI_DOUBLE, recvBCenergy, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); // БК энергию
MPI_Gather(&RBCmagn, 1, MPI_DOUBLE, recvBCmagn, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); // БК магн
MPI_Gather(&RBCPPF, 1, MPI_DOUBLE, recvBCPPF, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); // БК PPF
MPI_Gather(&RBCPP, 1, MPI_DOUBLE, recvBCPP, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); // БК PP
MPI_Gather(&Aenergy, 1, MPI_DOUBLE, recvAE, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Gather(&Aenergy2, 1, MPI_DOUBLE, recvAE2, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Gather(&Aenegry4, 1, MPI_DOUBLE, recvAE4, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Gather(&temMagn, 1, MPI_DOUBLE, recvAM, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Gather(&Amagn2, 1, MPI_DOUBLE, recvAM2, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Gather(&Amagn4, 1, MPI_DOUBLE, recvAM4, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Gather(&temPP, 1, MPI_DOUBLE, recvAPP, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Gather(&temPPF, 1, MPI_DOUBLE, recvAPPF, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
if(rank==0) //countOut - количество выводов!!! CO- какое значение из общего количества
{
for(int i=0; i<size; ++i)
{
for(int j=0; j<CountOut; ++j)
{
// outE<<(i+1)*((maxtemp-mintemp)/size)<<'\t'<<recvE[i*CountOut+j]<<endl;
// outPP<<(i+1)*((maxtemp-mintemp)/size)<<'\t'<<recvPP[i*CountOut+j]<<endl;