/
JQ.f90
2526 lines (2205 loc) · 61.5 KB
/
JQ.f90
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
module configuration
!----------------------------------------------!
! Most important parameters and data structures
!----------------------------------------------!
save
integer :: lx
integer :: ly
integer :: nn ! number of sites
integer :: nb ! number of bonds
integer :: mm ! total string length (mm=ns*ms)
integer :: nq
integer :: nq_all
integer :: ns ! number of substrings (time slices)
!integer :: ms ! maximum sub-string length
integer :: ntau
integer :: tstp
integer :: bincounter
integer :: bnd
integer :: dxl
integer :: mxl
integer :: nms1=0
integer :: nms2=0
integer :: nms3=0
integer :: nms4=0
real(8) :: beta ! inverse temperature
real(8) :: g ! g=J_{perp}/J
real(8) :: habs
real(8) :: qq3
real(8) :: g2
real(8) :: jq1
real(8) :: nu
real(8) :: prob ! part of the acceptance probability for adding (removing) operator
real(8) :: dtau
real(8) :: sun
integer :: loopnumt
integer :: loopnum0
integer :: loopnum1
integer :: loopnumper
integer :: loopnumber
integer :: loopnummax
integer :: looporder
integer :: dloop
integer :: nh
integer :: opstchange
integer, allocatable :: state(:)
integer, allocatable :: linktable(:,:)
integer, allocatable :: bsites(:,:)
integer, allocatable :: opstring(:)
integer, allocatable :: tauscale(:)
integer, allocatable :: oporder(:)
integer, allocatable :: opstfp(:,:)
integer, allocatable :: rebootloop(:)
integer :: rebootnum
integer, allocatable :: frststateop(:)
integer, allocatable :: custstateop(:)
integer, allocatable :: laststateop(:)
integer, allocatable :: vertexlist(:,:)
integer, allocatable :: vertexlist_map(:)
real(8), allocatable :: rantau(:)
real(8), allocatable :: spin(:,:)
real(8), allocatable :: vec(:,:)
integer, allocatable :: phase(:)
integer, allocatable :: recorder(:,:)
integer, allocatable :: recorderhelper(:)
real(8), parameter :: pi=3.14159265358979323d0
end module configuration
module measurementdata
!--------------------------------------------!
!Data we measured
!--------------------------------------------!
save
real(8) :: enrg1=0.d0
real(8) :: enrg2=0.d0
real(8) :: amag1=0.d0
real(8) :: amag2=0.d0
real(8) :: amag3=0.d0
real(8) :: amag4=0.d0
real(8) :: amag5=0.d0
real(8) :: amag6=0.d0
real(8) :: amag7=0.d0
real(8) :: dimr1=0.d0
real(8) :: dimr2=0.d0
real(8) :: dimr3=0.d0
real(8) :: dimerbg=0d0
real(8) :: stiff=0d0
integer :: signal=0d0
real(8), allocatable :: crr(:,:) !correlation function in real space
integer, allocatable :: qpts(:) !list of q-points
integer, allocatable :: tgrd(:) !grid of time points
real(8), allocatable :: tcor(:,:) !correlation function in momentum space
real(8), allocatable :: tcor_real(:,:) !correlation function in momentum space
real(8), allocatable :: tcorpm(:,:) !correlation function in momentum space
real(8), allocatable :: tcordm(:,:,:) !correlation function in momentum space
real(8), allocatable :: tcordz(:,:,:) !correlation function in momentum space
real(8), allocatable :: ref(:,:) ! real part of fourier transform of states
real(8), allocatable :: imf(:,:) ! imaginary part of fourier transform of states
real(8), allocatable :: phi(:,:,:) ! phase factors for fourier transforms
real(8), allocatable :: tc(:)
real(8), allocatable :: PMRS_temp(:,:)
real(8), allocatable :: PMinRealSpace(:,:)
real(8), allocatable :: demo_or(:,:)
real(8), allocatable :: demo_pm(:,:)
real(8), allocatable :: DZinRealSpace(:,:,:)
real(8), allocatable :: DCinRealSpace(:,:,:)
integer :: nc
character(10) :: resname
character(10) :: vecname
character(10) :: odpname
character(10) :: crrname
character(11) :: tcorname
character(11) :: tcpmname
character(11) :: td11name
character(11) :: tz11name
character(11) :: td12name
character(11) :: tz12name
character(11) :: td21name
character(11) :: tz21name
character(11) :: td22name
character(11) :: tz22name
character(11) :: deorname
character(11) :: depmname
character(11) :: dmbgname
end module measurementdata
!==========================!
!main part of the programme!
!==========================!
! nn = number of states
! beta = inverse temperature
! dtau = time-slize widt
! nbin = number of bins
! mstps = steps per bin for measurements
! istps = initial (equlibration) steps
! gtype = time-grid type (1,2,3)
! tmax = maximum delta-time for correlation functions
! nqx(y) = number of q-points for time correlations
! tstp = time-step when computing time averages of correlations
! tmsr = measure time correlations after every tmsr MC sweep
! qpts = q-values to do (among values 0,....,nn/2, actual q is this times 2*pi/nn)
module vertexupdate
save
integer :: v0
integer :: OpTy0
integer :: site0
integer :: site2
integer :: ndotz
integer, allocatable :: ndotc(:)
integer :: v1
integer :: v2
integer :: b
integer :: op
integer :: update_counter
integer :: loop_counter
integer :: counter
integer, allocatable :: dnmsr_counter(:)
integer :: Spm_measure_signal
integer :: OpTy1
integer :: site1
integer :: vo
integer :: mm0
integer :: taumark_o
integer :: cc
integer :: cc0
integer :: cc1
real(8) :: tau0
real(8) :: delta_tau
real(8) :: dmweight
end module vertexupdate
program Jperp_J_heisenberg_sse
use configuration
use measurementdata
implicit none
include 'mpif.h'
integer :: ierr,nprocs
integer :: rank,sz
integer :: i,j,nbins,msteps,isteps,tmsr,gtype
real(8) :: tmax,qq
open(unit=10, file='read.in', status="old")
read(10,*)lx,ly,beta,qq3,g2
read(10,*)sun,bnd
read(10,*)nbins,msteps,isteps
read(10,*)dtau
read(10,*)gtype,tmax
read(10,*)tstp,tmsr
close(unit=10)
jq1=1-qq3
!jq1=1
!qq3=qq/dble(1d0-qq)
!jq1=jq1/sun
!qq3=qq3/sun
!2=g2/sun
!rank=0
nq=lx/2
open(unit=10, file='q_resolution.in', status="replace")
write(10,*)nq
close(unit=10)
if (ly>1) then
nq_all=6*nq+1
else
nq_all=2*nq+1
endif
!habs=0d0
allocate(qpts(nq_all))
call MPI_init(ierr)
call MPI_Comm_size(MPI_COMM_WORLD,nprocs,ierr)
call MPI_Comm_rank(MPI_COMM_WORLD,rank,ierr)
call initran(1,rank)
call makelattice()
call initconfig(rank)
call taugrid(gtype,tmax)
call qarrays()
print*,"step 1",rank
prob=beta*nb
!==================================================================!
!Do isteps equilibration sweeps, find the necessary sweep
do i=1,isteps
call Bilibiliupdate(rank,1,10)
!print*,"a1"
call adjustcutoff(i)
!print*,"b1"
if (mod(i,5000)==1d0) print*,rank,"warm",i,"/",isteps
!print*,"c"
enddo
!==================================================================!
print*,"step 2",rank
call writeconfig(rank)
bincounter=0
print*,"step 3",rank
! Do nbins bins with msteps MC sweeps in each, measure after each
do j=1,nbins
bincounter=bincounter+1
do i=1,msteps
call Bilibiliupdate(rank,1,10)
!print*,"a2"
call measure()
!print*,"b2"
if (mod(i,tmsr)==0) then
endif
if (mod(i,2000)==1d0) print*,rank,"states",i,"/",msteps
!print*,"e",i
enddo
!write bin averages to 'res.dat'!
print*,bincounter
call writeresult(rank)
call writeconfig(rank)
enddo
print*,"step 4",rank
call MPI_Barrier(MPI_COMM_WORLD,ierr)
call MPI_Finalize(ierr)
bincounter=0
call deallocateall()
end program Jperp_J_heisenberg_sse
!==================================================!
!==================================================!
subroutine initconfig(rank)
use configuration
use measurementdata
implicit none
integer :: i
integer :: rank
real(8), external :: ran
allocate(state(nn))
do i=1,nn
state(i)=int(sun*ran())+1
enddo
ns=int(beta/dtau+0.1d0)
!mm=max(4*ns,nn/4)
mm=20
!=============================================================================!
allocate(opstring(0:mm-1)) !according to whether it is a sub-programme
opstring(:)=0 !according to whether it is a sub-programme
allocate(tauscale(0:mm-1)) !according to whether it is a sub-programme
tauscale(:)=0 !according to whether it is a sub-programme
allocate(opstfp(0:mm-1,2*bnd)) !according to whether it is a sub-programme
opstfp(:,:)=0 !according to whether it is a sub-programme
allocate(vertexlist(0:dxl*mm-1,3)) !according to whether it is a sub-programme
allocate(vertexlist_map(0:dxl*mm-1)) !according to whether it is a sub-programme
allocate(rantau(nn)) !according to whether it is a sub-programme
allocate(oporder(nn))
nh=0 !according to whether it is a sub-programme
!=============================================================================!
!=============================================================================!
!call readconfig(rank) !according to whether it is a sub-programme
!=============================================================================!
allocate(frststateop(nn))
allocate(custstateop(nn))
allocate(laststateop(nn))
allocate(rebootloop(2))
oporder(:)=-1
frststateop(:)=-1
custstateop(:)=-1
laststateop(:)=-1
rebootloop(:)=0d0
rebootnum=0d0
allocate(crr(int(lx/2)+1,int(ly/2)+1))
crr(:,:)=0
allocate(spin(int(sun),2))
allocate(vec(int(sun),2))
do i=1,int(sun)
spin(i,1)=(dble(i-1d0)-dble(sun-1d0)*0.5d0)
spin(i,2)=-(dble(i-1d0)-dble(sun-1d0)*0.5d0)
print*,spin(i,:)
vec(i,1)=cos(2d0*pi/sun*(i-1d0))
vec(i,2)=sin(2d0*pi/sun*(i-1d0))
!print*,2d0*pi/sun*i,vec(i,:)
enddo
!pause
vertexlist(:,:)=0
vertexlist_map(:)=-1
loopnum0=nn
loopnum1=0d0
loopnummax=0d0
loopnumber=loopnum0+loopnum1
end subroutine initconfig
!==================================================!
!==================================================!
subroutine makelattice()
use configuration
implicit none
integer :: s,x1,x2,y1,y2,s1,s2,s3,s4,s5,s6,t
nn=lx*ly
if (ly==1) then
nb=lx
allocate(bsites(2,nb))
do x1=0,lx-1
s=x1+1
x2=mod(x1+1,lx)
bsites(1,s)=s
bsites(2,s)=x2+1
enddo
mxl=2
dxl=2*mxl
elseif (ly==2) then
allocate(bsites(2,nb))
do y1=0,ly-1
do x1=0,lx-1
s=1+x1+y1*lx
x2=mod(x1+1,lx)
y2=y1
bsites(1,s)=s
bsites(2,s)=1+x2+y2*lx
if (y1==0) then
x2=x1
y2=mod(y1+1,ly)
bsites(1,s+nn)=s
bsites(2,s+nn)=1+x2+y2*lx
endif
enddo
enddo
mxl=2
dxl=2*mxl
else
nb=(2+2+2)*nn
allocate(bsites(2*bnd,nb))
do y1=0,ly-1
do x1=0,lx-1
s=1+x1+y1*lx
x2=mod(x1+1,lx)
y2=y1
bsites(1,s)=s
bsites(2,s)=1+x2+y2*lx
bsites(3:2*bnd,s)=-1
x2=x1
y2=mod(y1+1,ly)
bsites(1,s+nn)=s
bsites(2,s+nn)=1+x2+y2*lx
bsites(3:2*bnd,s+nn)=-1
x2=mod(x1+1,lx)
y2=mod(y1+1,ly)
bsites(1,s+2*nn)=s
bsites(2,s+2*nn)=1+x2+y2*lx
bsites(3:2*bnd,s+2*nn)=-1
x2=mod(x1+1,lx)
y2=mod(ly+y1-1,ly)
bsites(1,s+3*nn)=s
bsites(2,s+3*nn)=1+x2+y2*lx
bsites(3:2*bnd,s+3*nn)=-1
do t=0,bnd-1
s1=1+mod(x1+0,lx)+mod(y1+t,ly)*lx
bsites(2*t+1,s+4*nn)=s1
s1=1+mod(x1+1,lx)+mod(y1+t,ly)*lx
bsites(2*t+2,s+4*nn)=s1
s1=1+mod(x1+t,lx)+mod(y1+0,ly)*lx
bsites(2*t+1,s+5*nn)=s1
s1=1+mod(x1+t,lx)+mod(y1+1,ly)*lx
bsites(2*t+2,s+5*nn)=s1
enddo
enddo
enddo
mxl=2*bnd
dxl=2*mxl
nb=2*nn
endif
allocate(phase(nn))
do s=1,nn
phase(s)=int(0.5d0*(1+(-1)**(1+mod(s-1,lx)+(s-1)/lx))+1)
!print*,phase(s)
enddo
!pause
call makelinktype()
end subroutine makelattice
!==================================================!
!==================================================!
subroutine makelinktype()
use configuration
implicit none
integer :: s,x1,x2,y1,y2,s1,s2,s3,s4,s5,s6,t,i
allocate(linktable(0:dxl-1,0:2))
do i=0,dxl-1
linktable(i,0)=mod(i+mxl,dxl)
linktable(i,1)=ieor(i,1)
linktable(i,2)=ieor(mod(i+mxl,dxl),1)
enddo
!do i=0,dxl-1
! print*,"0",i,linktable(i,0)
!enddo
!do i=0,dxl-1
! print*,"1",i,linktable(i,1)
!enddo
!do i=0,dxl-1
! print*,"2",i,linktable(i,2)
!enddo
end subroutine makelinktype
!==================================================!
subroutine Bilibiliupdate(rank,update_type,lim_counter)
use configuration
use measurementdata
implicit none
integer :: i,j,s,b,op,rank,cs,s1,k,bs,sig,crsign,update_type,lim_counter,update_counter
integer :: mm_sug,mm_tmp,opod_sug,opod_pre,opod_aft
real(8) :: wght1,wght2,wght3,wghtq3
integer, allocatable :: tmststateop(:)
real(8), external :: ran
real(8), external :: hf
allocate(tmststateop(nn))
tmststateop(:)=0d0
!if ( rank==0 ) then
!do i=1,nb
!print*,int(hf(i)),i,mod(i-1,lx),int((i-1)/lx),rank
!enddo
!endif
wght1=g2*0.5d0
wght2=jq1*0.5d0
wght3=0d0
wghtq3=qq3*((0.5d0)**3d0)
update_counter=0d0
i=mm-1
!do i=0,mm-1
!mm_sug=int(mm*ran())
!print*,"======================================"
!tmststateop(:)=custstateop(:)
!do j=1,nh
! mm_tmp=oporder(j)
! print*,j,mm_tmp,nh
! if (opstring(mm_tmp)==0) pause
! b=opstring(mm_tmp)/4
! call gencurstateop(mm_tmp,b,0)
!enddo
!print*,nh+1,oporder(nh+1),nh
!do j=1,nn
! if (custstateop(j)/=tmststateop(j)) then
! print*,"miss"
! else
! !print*,"check"
! endif
!enddo
!print*,"0000000000000000000000000000000000"
do
if (update_type==0) then
i=mod(i+1,mm)
if (update_counter>mm) then
exit
endif
elseif (update_type==1) then
mm_sug=int(mm*ran())
opod_sug=tauscale(mm_sug)
if (update_counter>lim_counter) then
exit
endif
!print*,mm_sug,opod_sug,opstring(mm_sug),nh
if (nh==0) then
else
if (opstring(mm_sug)==0) then
opod_pre=mod(opod_sug+nh-1,nh)+1
else
opod_pre=mod(opod_sug+nh-2,nh)+1
endif
!print*,"pre",mm_sug,opod_sug,opod_pre,opstring(mm_sug)
do j=1,opod_pre
mm_tmp=oporder(j)
!print*,j,mm_tmp,nh
if (opstring(mm_tmp)==0) pause
b=opstring(mm_tmp)/4
call gencurstateop(mm_tmp,b,0)
enddo
endif
i=mm_sug
endif
!print*,"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",opstring(mm_sug),nh
update_counter=update_counter+1
!print*,i,update_type,update_counter,lim_counter,mm
!=============================================================================================================================!
op=opstring(i)
if ( op==0 ) then
b=int(ran()*nb)+1
call caldloop(i,b,1)
if (b<=2*nn) then
if ( ran()*(mm-nh)<=(wght2)*prob*(sun**dloop) ) then
!print*,"add1",sun,dloop,wght2,(wght2)*(sun**dloop),
opstring(i)=4*b
nh=nh+1
call addoperator(i,b,rank)
endif
elseif (b>2*nn .and. b<=4*nn) then
if ( ran()*(mm-nh)<=(wght1)*prob*(sun**dloop) ) then
!print*,"add1",sun,dloop,(wght1)*prob*(sun**dloop)
opstring(i)=4*b
nh=nh+1
call addoperator(i,b,rank)
endif
elseif (b>4*nn) then
if ( ran()*(mm-nh)<=(wghtq3)*prob*(sun**dloop) ) then
!print*,"add1",sun,dloop,(wghtq3)*prob*(sun**dloop)
opstring(i)=4*b+2
nh=nh+1
call addoperator(i,b,rank)
endif
endif
elseif ( op/=0 ) then
b=op/4
call caldloop(i,b,-1)
if (b<=2*nn) then
if ( ran()*prob*(wght2)<=(mm-nh+1)*(sun**dloop) ) then
opstring(i)=0
opstfp(i,:)=0
nh=nh-1
call remoperator(i,b,rank)
!call gencurstateop(i,b,0)
!print*,"checkpoint1"
else
call gencurstateop(i,b,0)
!print*,"checkpoint2"
endif
elseif (b>2*nn .and. b<=4*nn) then
if ( ran()*prob*(wght1)<=(mm-nh+1)*(sun**dloop) ) then
opstring(i)=0
opstfp(i,:)=0
nh=nh-1
call remoperator(i,b,rank)
!call gencurstateop(i,b,0)
!print*,"checkpoint3"
else
call gencurstateop(i,b,0)
!print*,"checkpoint4"
endif
elseif (b>4*nn) then
if ( ran()*(wghtq3)*prob<=(mm-nh+1)*(sun**dloop) ) then
opstring(i)=0
opstfp(i,:)=0
nh=nh-1
call remoperator(i,b,rank)
!call gencurstateop(i,b,0)
!print*,"checkpoint5"
else
call gencurstateop(i,b,0)
!print*,"checkpoint6"
endif
endif
endif
!print*,"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",opstring(mm_sug),nh
!=============================================================================================================================!
if (update_type==0) then
elseif (update_type==1) then
if (nh==0) then
else
opod_sug=tauscale(mm_sug)
opod_aft=mod(opod_sug,nh)+1
!print*,"aft",mm_sug,opod_sug,opod_aft,opstring(mm_sug)
if (opod_sug==opod_aft) then
else
!print*,opod_sug,mm_sug,nh,"sug"
do j=opod_aft,nh
mm_tmp=oporder(j)
!print*,j,mm_tmp,nh
if (opstring(mm_tmp)==0) pause
b=opstring(mm_tmp)/4
call gencurstateop(mm_tmp,b,0)
enddo
endif
endif
endif
enddo
if (loopnumber/=loopnum0+loopnum1) then
print*,loopnumber,loopnum0,loopnum1,"neq"
pause
endif
if (update_type==0) then
do j=1,nh
mm_tmp=oporder(j)
b=opstring(mm_tmp)/4
call gencurstateop(mm_tmp,b,0)
enddo
else
do j=1,nh
mm_tmp=oporder(j)
b=opstring(mm_tmp)/4
call gencurstateop(mm_tmp,b,0)
enddo
endif
do i=1,nn
if (frststateop(i)/=-1) then
if (frststateop(i)/=vertexlist_map(custstateop(i))) then
print*,"boundary lost",frststateop(i),custstateop(i),vertexlist_map(custstateop(i)),&
&vertexlist_map(frststateop(i)),i
print*,"boundary lost",int(frststateop(i)/dxl),int(custstateop(i)/dxl),&
&mod(opstring(int(frststateop(i)/dxl)),2),mod(opstring(int(custstateop(i)/dxl)),2)
pause
endif
else
if (frststateop(i)/=custstateop(i)) then
print*,"boundary lost",frststateop(i),custstateop(i),i
pause
endif
endif
enddo
end subroutine Bilibiliupdate
!==================================================!
!==================================================!
subroutine caldloop(mm_pos,b_pos,crsign)
use configuration
use measurementdata
implicit none
integer :: i,k,b_pos,s,mm_pos,vt0,vt1,vt2,vt3,crsign,up_pos,leg_pos,j,si,sortmp,l,sortmp2
integer :: mmt2,mmt3,tt,lp0,mrk1,loopaft,loopbef,loopmid,mrk2,mrk3,mrk4,vtt,l0,l1
integer, allocatable :: legtag(:,:)
integer, allocatable :: md(:,:)
integer, allocatable :: headsort(:,:)
integer, allocatable :: revtab(:)
allocate(legtag(0:dxl-1,0:2))
legtag(:,0)=-1
legtag(:,1)=0
legtag(:,2)=-1
allocate(headsort(0:dxl-1,0:4))
headsort(:,0)=-1
headsort(:,1)=0
headsort(:,2)=-1
headsort(:,3)=-1
headsort(:,4)=-1
allocate(revtab(0:dxl-1))
revtab(:)=-1
allocate(md(0:3,2))
md(:,:)=0d0
if (crsign==1) then
if (b_pos<=2*nn ) then
tt=1
elseif (b_pos>4*nn .and. b_pos<=6*nn) then
tt=1
elseif (b_pos>2*nn .and. b_pos<=4*nn) then
tt=2
endif
elseif (crsign==-1) then
tt=0
endif
loopbef=0d0
loopaft=0d0
loopmid=0d0
si=0d0
lp0=0d0
do k=1,mxl
s=bsites(k,b_pos)
if (s==-1) cycle
if (crsign==1) then
if (custstateop(s)/=-1) then
vt0=custstateop(s)
legtag(k-1,1:2)=vertexlist(vt0,1:2)
vt1=vertexlist_map(vt0)
!print*,"------add------",int(vt0/dxl),k-1,vertexlist(vt0,1:2),int(vt1/dxl),k-1+mxl,vertexlist(vt1,1:2)
legtag(k-1+mxl,1:2)=vertexlist(vt1,1:2)
else
lp0=lp0+1
legtag(k-1,1)=-lp0
legtag(k-1+mxl,1)=-lp0
legtag(k-1,2)=0
legtag(k-1+mxl,2)=1
endif
elseif (crsign==-1) then
vt0=dxl*mm_pos+k-1
legtag(k-1,1:2)=vertexlist(vt0,1:2)
vt1=dxl*mm_pos+k-1+mxl
!print*,"------rem------",int(vt0/dxl),k-1,vertexlist(vt0,1:2),int(vt1/dxl),k-1+mxl,vertexlist(vt1,1:2)
legtag(k-1+mxl,1:2)=vertexlist(vt1,1:2)
endif
enddo
sortmp=0d0
sortmp2=0d0
do i=0,dxl-1
si=bsites(mod(i,mxl)+1,b_pos)
if (si==-1) cycle
if (legtag(i,0)==-1) then
mrk1=legtag(i,1)
headsort(sortmp,0)=i
headsort(sortmp,1)=legtag(i,1)
headsort(sortmp,2)=legtag(i,2)
headsort(sortmp,3)=sortmp
revtab(i)=sortmp
legtag(i,0)=legtag(i,0)+1
loopbef=loopbef+1
do j=0,dxl-1
si=bsites(mod(j,mxl)+1,b_pos)
if (si==-1) cycle
mrk2=legtag(j,1)
if (legtag(j,0)==-1 .and. mrk1==mrk2) then
l=j
md(0,1)=l
md(1,1)=mrk2
md(2,1)=legtag(l,2)
md(3,1)=sortmp
do k=sortmp,dxl-1
if (headsort(k,1)/=mrk2 .and. headsort(k,1)/=0) then
print*,"sort error",headsort(k,1),mrk2
pause
endif
if (headsort(k,2)==-1) then
headsort(k,:)=md(:,1)
revtab(l)=k
sortmp2=k
exit
elseif (headsort(k,2)<legtag(j,2)) then
elseif (headsort(k,2)>legtag(j,2)) then
md(:,2)=headsort(k,:)
headsort(k,:)=md(:,1)
md(:,1)=md(:,2)
revtab(l)=k
l=md(0,2)
endif
enddo
legtag(j,0)=legtag(j,0)+1
endif
enddo
sortmp=sortmp2+1
!print*,sortmp,sortmp2
endif
enddo
do i=0,dxl-1
if (headsort(i,2)==-1) exit
l0=headsort(i,0)
l1=headsort(mod(i+1,dxl),0)
!print*,"i",i
if (i==headsort(i,3) .and. &
&(headsort(headsort(i,3),2)/=1 .or. crsign==-1)) then
loopmid=loopmid+1
headsort(i,4)=loopmid
legtag(l0,0)=legtag(l0,0)+1
elseif ((headsort(i,3)/=headsort(mod(i+1,dxl),3) .or. mod(i+1,dxl)==headsort(i,3)) .and. &
&(headsort(headsort(i,3),2)/=1 .or. crsign==-1)) then
headsort(i,4)=headsort(headsort(i,3),4)
legtag(l0,0)=legtag(l0,0)+1
elseif (headsort(i,3)==headsort(mod(i+1,dxl),3)) then
!print*,"l0,l1",l0,l1,loopmid
!print*,"con",legtag(:,0)
!print*,headsort(:,0)
!print*,"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
if (legtag(l0,0)==0) then
vt0=i-headsort(i,3)
vt1=i+1-headsort(mod(i+1,dxl),3)
if (vt1==vt0+1 .and. headsort(i,3)==headsort(mod(i+1,dxl),3)) then
loopmid=loopmid+1
headsort(i,4)=loopmid
headsort(mod(i+1,dxl),4)=loopmid
legtag(l1,0)=legtag(l1,0)+1
!print*,"add l1",l1,legtag(l1,0)
else
endif
legtag(l0,0)=legtag(l0,0)+1
!print*,"add l0",l0,legtag(l0,0)
elseif (legtag(l0,0)==1) then
endif
endif
enddo
!print*,"00000000000000000000000000000000000000000000000000000"
!print*,"l0",legtag(:,0)
!print*,"l1",legtag(:,1)
!print*,"l2",legtag(:,2)
!print*,"-----------------------------------------------------"
!print*,"0",headsort(:,0)
!print*,"1",headsort(:,1)
!print*,"2",headsort(:,2)
!print*,"3",headsort(:,3)
!print*,"4",headsort(:,4)
!print*,"rev",revtab(:)
!print*,"loopbef",loopbef
do i=0,dxl-1
si=bsites(mod(i,mxl)+1,b_pos)
if (si==-1) cycle
!print*,i,legtag(revtab(i),0),headsort(revtab(i),4)
if (legtag(i,0)==1 .and. (headsort(revtab(i),4)/=0 .and. headsort(revtab(i),4)/=-1)) then
l0=i
l1=linktable(l0,tt)
vt0=headsort(revtab(l0),4)
vt1=headsort(revtab(l1),4)
!print*,vt0,vt1
if (vt0/=vt1) then
do j=0,dxl-1
if (headsort(j,4)==vt1) then
if (j==revtab(l1)) then
headsort(j,4)=0d0
else
headsort(j,4)=vt0
endif
endif
if (headsort(j,4)==vt0) then
if (j==revtab(l0)) then
headsort(j,4)=0d0
else
headsort(j,4)=vt0
endif
endif
enddo
elseif (vt0==vt1) then
loopaft=loopaft+1
do j=0,dxl-1
if (headsort(j,4)==vt0) then
headsort(j,4)=0
endif
enddo
endif
!print*,"l0",legtag(:,0)
!print*,"4",headsort(:,4)
!print*,"4444444444444444444444444444444",loopaft
endif
enddo
dloop=loopaft-loopbef
!print*,"loopaft,loopbef,loopmid,dloop,crsign,tt"
!print*,loopaft,loopbef,loopmid,dloop,crsign,tt
!print*,"1",headsort(:,1)
!print*,"2",headsort(:,2)
!print*,"3",headsort(:,3)
!print*,"4",headsort(:,4)
if ((dloop/=1 .and. dloop/=0 .and. dloop/=-1) .or. loopaft==0) then
!print*,"limit",dloop
endif
end subroutine caldloop
!==================================================!
!==================================================!
subroutine addoperator(mm_pos,b_pos,rank)
use configuration
use vertexupdate
implicit none
integer :: i,j,k,mm_pos,b_pos,s0,s1,leg_pos,up_pos,rank
integer :: vt
loopnumper=loopnumber
!print*,"loop",loopnumber,loopnumper
!print*,"start add"
call gencurstateop(mm_pos,b_pos,1)
!print*,"gennet"
do k=1,mxl
s0=bsites(k,b_pos)
if (s0==-1) cycle
do i=0,1
leg_pos=k-1+i*mxl
vt=mm_pos*dxl+leg_pos
!print*,vt,vertexlist(vt,2),custstateop(s0),frststateop(s0)
if (vertexlist(vt,3)==2) then
!print*,vertexlist(vt,2)
!print*,"--------------------------------"
call markloop(vt,0,rank)
endif
enddo
enddo
if (dloop/=loopnumber-loopnumper) then
print*,"loopnumber_error_add",loopnumber-loopnumper,dloop,loopnumber,loopnumper,nn
print*,"loopnumber_error_add",loopnumber-loopnumper,dloop,loopnumt,loopnum1,loopnum0
pause
endif
!print*,"markloop"
call updateoporder(mm_pos,1)
end subroutine addoperator
!==================================================!
!==================================================!
subroutine remoperator(mm_pos,b_pos,rank)
use configuration
use vertexupdate