-
Notifications
You must be signed in to change notification settings - Fork 1
/
nplus.f90
1275 lines (986 loc) · 32.8 KB
/
nplus.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: prec
! COMMENT: Define parameter for NRG subroutine
!****************************************************************************
module prec
implicit none
integer,parameter::Rkind=8
end module prec
!****************************************************************************
! module: precnpl
! COMMENT: Define parameter for NRG subroutine
!****************************************************************************
module precnpl
use prec
implicit none
integer,parameter:: Nit=200, Nnit=30 ! Max iteration numbers.
integer,parameter:: Nb0=2000, Ns=80, Nb=30, Dim=2400
real(kind=Rkind), parameter:: Pi=3.141526535_Rkind
real(kind=Rkind), parameter:: Lamda=10.0_Rkind
real(kind=Rkind), parameter:: wc=1.0_Rkind, s=0.5_Rkind
real(kind=Rkind):: dta_loc=0.1_Rkind, epi_loc=0.0_Rkind ! local term
real(kind=Rkind):: g1_cps=0.0_Rkind, g2_cps=1.0_Rkind ! coupling strenth
end module precnpl
!****************************************************************************
! PROGRAM: NPL_NRG
! TYPE : Main
! PURPOSE: Nonlear + Linear
!****************************************************************************
program NPL_NRG
use precnpl
implicit none
integer:: i, j, k, ierror, ierror2, jishu
real(kind=Rkind):: time_begin, time_end
real(kind=Rkind):: eta0, epi0, t0, epin, tn
real(kind=Rkind):: alpha
real(kind=Rkind),dimension(0:Nit):: epi, t
real(kind=Rkind),dimension(Ns):: Eigenv
real(kind=Rkind),dimension(Ns, Ns):: bmatrixc, bmatrixa, qzmatrix, qxmatrix, b0matrixa, b0matrixc, x2matrix, nmatrix
real(kind=Rkind),dimension(50, 0:Nit, Ns):: Eigenv_all, w_all, cw_all, cwx_all, cwsx_all
!--- Begin ---
call cpu_time(time_begin)
alpha=0.0000265392_Rkind
!--- Begin Caculation
Eigenv_all=0.0_Rkind
w_all=0.0_Rkind
cw_all=0.0_Rkind
cwx_all=0.0_Rkind
cwsx_all=0.0_Rkind
!$omp do
do j=1, 1
call param(alpha, eta0, epi, t)
!--- First iteration
epi0=epi(0)
call diag_H0(eta0, epi0, Eigenv, bmatrixc, bmatrixa, qzmatrix, qxmatrix, b0matrixa, b0matrixc, x2matrix, nmatrix)
print *, "<qz>:", qzmatrix(1, 1), qxmatrix(1, 1), abs(b0matrixa(1, 1)+b0matrixc(1, 1)), x2matrix(1, 1), nmatrix(1, 1)
do k=1, Ns
Eigenv_all(j, 0, k)=Eigenv(k) !--- Save eigenv
w_all(j, 0, k)=Eigenv(k)
cw_all(j, 0, k)=0.5_Rkind*(qzmatrix(1, k)**2)
cwsx_all(j, 0, k)=0.5_Rkind*(qxmatrix(1, k)**2)
cwx_all(j, 0, k)=0.5_Rkind*((b0matrixa(1, k)+b0matrixc(1, k))**2)
end do
!--- Later iterations
do i=1, Nnit
epin=epi(i)
tn=Lamda*t(i-1)
call diag_Hn(epin, tn, Eigenv, bmatrixc, bmatrixa, qzmatrix, qxmatrix, b0matrixa, b0matrixc, x2matrix, nmatrix)
print *, "<qz>:", qzmatrix(1, 1), abs(b0matrixa(1, 1)+b0matrixc(1, 1)), x2matrix(1, 1), nmatrix(1, 1)
do k=1, Ns
Eigenv_all(j, i, k)=Eigenv(k) !--- Save eigenv
w_all(j, i, k)=Eigenv(k)*(Lamda**(-i))
cw_all(j, i, k)=0.5_Rkind*(qzmatrix(1, k)**2)
cwsx_all(j, i, k)=0.5_Rkind*(qxmatrix(1, k)**2)
cwx_all(j, i, k)=0.5_Rkind*((b0matrixa(1, k)+b0matrixc(1, k))**2)
end do
end do
!--- Physical information. Saved to disk.
OPEN (UNIT=2, FILE='m.TXT', STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror2)
WRITE (2,900) alpha, qzmatrix(1, 1), qxmatrix(1, 1), (b0matrixa(1, 1)+b0matrixc(1, 1)), x2matrix(1, 1), nmatrix(1, 1), (abs(b0matrixa(1, 1)+b0matrixc(1, 1))**2)/x2matrix(1, 1)
900 FORMAT (F, F, F, F, F, F, F)
alpha = alpha + 0.0000001_Rkind
end do
!$omp end do
!--- Flow diagrams. Saved to disk.
jishu=0
do i=0, Nnit
OPEN (UNIT=1, FILE="flow.TXT", STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror)
WRITE (1,700) jishu, Eigenv_all(1, i, 2), Eigenv_all(2, i, 2), Eigenv_all(3, i, 2), Eigenv_all(4, i, 2), Eigenv_all(5, i, 2), Eigenv_all(6, i, 2), Eigenv_all(7, i, 2), Eigenv_all(8, i, 2)
700 FORMAT (I, F, F, F, F, F, F, F, F)
jishu=jishu+1
end do
!call calc_cw(w_all, cw_all)
!call calc_cwx(w_all, cwx_all)
call calc_cwsx(w_all, cwsx_all)
!--- End----
call cpu_time(time_end)
print *, 'Time of operation was : ', time_end - time_begin, ' seconds'
end program NPL_NRG
!========+=========+===============+=========+=$
! PROGRAM: calc_cwsx
! TYPE : subroutine
! PURPOSE:
!========+=========+===============+=========+=$
subroutine calc_cwsx(w_all, cwsx_all)
use precnpl
implicit none
integer:: i, j, k, ierror3, ierror4, ierror8
real(kind=Rkind):: sum, w, res_cwsx, dlt_tmp
real(kind=Rkind),dimension(50, 0:Nit, Ns):: w_all, cwsx_all
do i=0, Nnit
print *, 'w_max: ', w_all(1, i, Ns)
end do
do i=0, Nnit
do j=1, Ns
OPEN (UNIT=18, FILE="cwsx_origin.TXT", STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror8)
WRITE (18,2018) w_all(1, i, j), cwsx_all(1, i, j)
2018 FORMAT (F, F)
end do
end do
do i=1, Nnit
do j=0, i-1
k=1
do
if(w_all(1, j, k)>w_all(1, i, Ns)) exit
cwsx_all(1, j, k)=cwsx_all(1, j, k)*(w_all(1, j, k)/w_all(1, i, Ns))
k=k+1
end do
end do
do j=1, Ns
cwsx_all(1, i, j)=cwsx_all(1, i, j)*(1-(w_all(1, i, j)/w_all(1, i, Ns)))
end do
end do
do i=0, Nnit
print *, 'cw_0: ', cwsx_all(1, i, 1)
end do
sum=0.0_Rkind
do i=0, Nnit
do j=1, Ns
sum=sum+cwsx_all(1, i, j)
end do
end do
print *, 'sum: ', sum
w=0.0_Rkind
do k=1, 90
res_cwsx=0.0_Rkind
do i=0, Nnit
do j=1, Ns
if(w_all(1, i, j)==0.0_Rkind) then
dlt_tmp=0.0_Rkind
else
dlt_tmp=0.6_Rkind**2
dlt_tmp=exp(-(dlt_tmp/4))/(0.6_Rkind*w_all(1, i, j)*sqrt(Pi))
dlt_tmp=dlt_tmp*exp(-((log(w)-log(w_all(1, i, j)))**2)/(0.6_Rkind**2))
end if
res_cwsx=res_cwsx+cwsx_all(1, i, j)*dlt_tmp
end do
end do
OPEN (UNIT=28, FILE="res_cwsx.TXT", STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror3)
WRITE (28,2028) w, res_cwsx
2028 FORMAT (F, F)
w=0.00000000000001_Rkind*1.5_Rkind**k
end do
do i=0, Nnit
do j=1, Ns
OPEN (UNIT=29, FILE="cwsx.TXT", STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror4)
WRITE (29 ,2029) w_all(1, i, j), cwsx_all(1, i, j)
2029 FORMAT (F, F)
if(cwsx_all(1, i, j)>0.01_Rkind) then
print *, 'i j', i, j, w_all(1, i, j), cwsx_all(1, i, j)
end if
end do
end do
end subroutine calc_cwsx
!========+=========+===============+=========+=$
! PROGRAM: calc_cw
! TYPE : subroutine
! PURPOSE:
!========+=========+===============+=========+=$
subroutine calc_cw(w_all, cw_all)
use precnpl
implicit none
integer:: i, j, k, ierror3, ierror4, ierror8
real(kind=Rkind):: sum, w, res_cw, dlt_tmp
real(kind=Rkind),dimension(50, 0:Nit, Ns):: w_all, cw_all
do i=0, Nnit
print *, 'w_max: ', w_all(1, i, Ns)
end do
do i=0, Nnit
do j=1, Ns
OPEN (UNIT=8, FILE="cw_origin.TXT", STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror8)
WRITE (8,2000) w_all(1, i, j), cw_all(1, i, j)
2000 FORMAT (F, F)
end do
end do
do i=1, Nnit
do j=0, i-1
k=1
do
if(w_all(1, j, k)>w_all(1, i, Ns)) exit
cw_all(1, j, k)=cw_all(1, j, k)*(w_all(1, j, k)/w_all(1, i, Ns))
k=k+1
end do
end do
do j=1, Ns
cw_all(1, i, j)=cw_all(1, i, j)*(1-(w_all(1, i, j)/w_all(1, i, Ns)))
end do
end do
do i=0, Nnit
print *, 'cw_0: ', cw_all(1, i, 1)
end do
sum=0.0_Rkind
do i=0, Nnit
do j=1, Ns
sum=sum+cw_all(1, i, j)
end do
end do
print *, 'sum: ', sum
w=0.0_Rkind
do k=1, 90
res_cw=0.0_Rkind
do i=0, Nnit
do j=1, Ns
if(w_all(1, i, j)==0.0_Rkind) then
dlt_tmp=0.0_Rkind
else
dlt_tmp=0.6_Rkind**2
dlt_tmp=exp(-(dlt_tmp/4))/(0.6_Rkind*w_all(1, i, j)*sqrt(Pi))
dlt_tmp=dlt_tmp*exp(-((log(w)-log(w_all(1, i, j)))**2)/(0.6_Rkind**2))
end if
res_cw=res_cw+cw_all(1, i, j)*dlt_tmp
end do
end do
OPEN (UNIT=3, FILE="res_cw.TXT", STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror3)
WRITE (3,900) w, res_cw
900 FORMAT (F, F)
w=0.00000000000001_Rkind*1.5_Rkind**k
end do
do i=0, Nnit
do j=1, Ns
OPEN (UNIT=4, FILE="cw.TXT", STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror4)
WRITE (4,1000) w_all(1, i, j), cw_all(1, i, j)
1000 FORMAT (F, F)
if(cw_all(1, i, j)>0.01_Rkind) then
print *, 'i j', i, j, w_all(1, i, j), cw_all(1, i, j)
end if
end do
end do
end subroutine calc_cw
!========+=========+===============+=========+=$
! PROGRAM: calc_cwx
! TYPE : subroutine
! PURPOSE:
!========+=========+===============+=========+=$
subroutine calc_cwx(w_all, cwx_all)
use precnpl
implicit none
integer:: i, j, k, ierror5, ierror6
real(kind=Rkind):: sum, w, res_cwx, dlt_tmp
real(kind=Rkind),dimension(50, 0:Nit, Ns):: w_all, cwx_all
do i=0, Nnit
print *, 'w_max: ', w_all(1, i, Ns)
end do
do i=1, Nnit
do j=0, i-1
k=1
do
if(w_all(1, j, k)>w_all(1, i, Ns)) exit
cwx_all(1, j, k)=cwx_all(1, j, k)*(w_all(1, j, k)/w_all(1, i, Ns))
k=k+1
end do
end do
do j=1, Ns
cwx_all(1, i, j)=cwx_all(1, i, j)*(1-(w_all(1, i, j)/w_all(1, i, Ns)))
end do
end do
do i=0, Nnit
print *, 'cwx_0: ', cwx_all(1, i, 1)
end do
sum=0.0_Rkind
do i=0, Nnit
do j=1, Ns
sum=sum+cwx_all(1, i, j)
end do
end do
print *, 'sum: ', sum
do k=1, 90
w=0.00000000000001_Rkind*1.5_Rkind**k
res_cwx=0.0_Rkind
do i=0, Nnit
do j=1, Ns
if(w_all(1, i, j)<0.0000000000000001_Rkind) then
! dlt_tmp=(0.5_Rkind/Pi)*0.6_Rkind/((w-w_all(1, i, j))**2+0.6_Rkind**2)
dlt_tmp=0.0_Rkind
else
dlt_tmp=0.6_Rkind**2
dlt_tmp=exp(-(dlt_tmp/4))/(0.6_Rkind*w_all(1, i, j)*sqrt(Pi))
dlt_tmp=dlt_tmp*exp(-((log(w)-log(w_all(1, i, j)))**2)/(0.6_Rkind**2))
end if
res_cwx=res_cwx+cwx_all(1, i, j)*dlt_tmp
end do
end do
OPEN (UNIT=5, FILE="res_cwx.TXT", STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror5)
WRITE (5,1100) w, res_cwx
1100 FORMAT (F, F)
end do
do i=0, Nnit
do j=1, Ns
OPEN (UNIT=6, FILE="cwx.TXT", STATUS='UNKNOWN', ACTION='WRITE', IOSTAT=ierror6)
WRITE (6,1200) w_all(1, i, j), cwx_all(1, i, j)
1200 FORMAT (F, F)
if(cwx_all(1, i, j)>0.01_Rkind) then
print *, 'i j', i, j, w_all(1, i, j), cwx_all(1, i, j)
end if
end do
end do
end subroutine calc_cwx
!========+=========+===============+=========+=$
! PROGRAM: param
! TYPE : subroutine
! PURPOSE: Produce NRG Paranmeters
!========+=========+===============+=========+=$
subroutine param(alpha, eta0, epi, t)
use precnpl
implicit none
!--- Define parameter----
integer:: i, j, k, Isign
real(kind=Rkind):: alpha
real(kind=Rkind):: eta0, tmp1, tmp2
real(kind=Rkind),dimension(0:Nit):: xi, gama2, epi, t, orth
real(kind=Rkind),dimension(0:Nit,0:Nit):: Umatrix
do i=0, Nit-1
gama2(i)=(2*Pi*alpha)*(wc**2)*(1-lamda**(-(s+1)))*(lamda**(-i*(s+1)))/(s+1)
xi(i)=((s+1)/(s+2))*((1-lamda**(-(s+2)))/(1-lamda**(-(s+1))))*wc*(lamda**(-i))
end do
eta0=0.0_Rkind
do i=0, Nit-1
eta0=eta0+gama2(i)
end do
Umatrix=0.0_Rkind
epi=0.0_Rkind
do i=0, Nit-1
tmp1=gama2(i)/eta0
Umatrix(0, i)=sqrt(tmp1)
epi(0)=epi(0)+xi(i)*tmp1
end do
t=0.0_Rkind
do i=0, Nit-1
t(0)=((xi(i)-epi(0))*Umatrix(0, i))**2+t(0)
end do
t(0)=sqrt(t(0))
do i=0, Nit-1
Umatrix(1, i)=(xi(i)-epi(0))*Umatrix(0, i)/t(0)
epi(1)=epi(1)+xi(i)*(Umatrix(1, i)**2)
end do
do i=0, Nit-1
t(1)=((xi(i)-epi(1))*Umatrix(1, i)-t(0)*Umatrix(0, i))**2+t(1)
end do
t(1)=sqrt(t(1))
!----------iteration-----------
do i=2, Nit-1
do j=0, Nit-1
Umatrix(i, j)=((xi(j)-epi(i-1))*Umatrix(i-1, j)-t(i-2)*Umatrix(i-2, j))/t(i-1)
end do
!----------orth-----------
orth=0.0_Rkind
do j=0, i-1
tmp2=0.0_Rkind
do k=0, Nit-1
tmp2=tmp2+Umatrix(i, k)*Umatrix(j, k)
end do
do k=0, Nit-1
orth(k)=orth(k)+tmp2*Umatrix(j, k)
end do
end do
do j=0, Nit-1
Umatrix(i, j)=Umatrix(i, j)-orth(j)
end do
tmp2=0.0_Rkind
do j=0, Nit-1
tmp2=tmp2+Umatrix(i, j)*Umatrix(i, j)
end do
tmp2=sqrt(tmp2)
do j=0, Nit-1
Umatrix(i, j)=Umatrix(i, j)/tmp2
end do
do j=0, Nit-1
epi(i)=epi(i)+xi(j)*(Umatrix(i, j)**2)
end do
do j=0, Nit-1
t(i)=((xi(j)-epi(i))*Umatrix(i, j)-t(i-1)*Umatrix(i-1, j))**2+t(i)
end do
t(i)=sqrt(t(i))
end do
do i=0, Nit-1
t(i)=t(i)*(lamda**i)
epi(i)=epi(i)*(lamda**i)
print *, i, t(i), epi(i)
end do
Isign=15
! print *, Isign-4, t(Isign-4)
! print *, Isign-3, t(Isign-3)
! print *, Isign-2, t(Isign-2)
! print *, Isign-1, t(Isign-1)
! print *, Isign, t(Isign)
! print *, Isign+1, t(Isign+1)
! print *, Isign+2, t(Isign+2)
! pause
do i=Isign+1, Nit-1
epi(i)=epi(Isign)
t(i)=t(Isign)
end do
end subroutine param
!========+=========+===============+=========+=$
! PROGRAM: diag_H0
! TYPE : subroutine
! PURPOSE:
!========+=========+===============+=========+=$
subroutine diag_H0(eta0, epi0, Eigenv, bmatrixc, bmatrixa, qzmatrix, qxmatrix, b0matrixa, b0matrixc, x2matrix, nmatrix)
use precnpl
implicit none
integer:: i, j, k
real(kind=Rkind):: eta0, epi0, t0, Coeff0, Coeff1, tmp, sum1, sum2
real(kind=Rkind),dimension(Ns):: Eigenv
real(kind=Rkind),dimension(Nb0):: vec_mid, vec_mid1, vec_mid2
real(kind=Rkind),dimension(Ns, Ns):: bmatrixc, bmatrixa, qzmatrix, qxmatrix, b0matrixa, b0matrixc, x2matrix, nmatrix
real(kind=Rkind),dimension(Nb0, Nb0):: H0
real(kind=Rkind),dimension(Nb0/2, Nb0/2):: H01
integer:: cevec=1
integer:: ierr
real(kind=Rkind),dimension(Nb0):: eigvalue, fv1, fv2
real(kind=Rkind),dimension(Nb0, Nb0):: eigvector
! print *, "eta0, epi0:", eta0, epi0
H0=0.0_Rkind
!----------loc term-----------
do i=1, Nb0/2
H0(i, i)=H0(i, i)+(epi_loc/2)
H0(i+Nb0/2, i+Nb0/2)=H0(i+Nb0/2, i+Nb0/2)-(epi_loc/2)
H0(i+Nb0/2, i)=H0(i+Nb0/2, i)-(dta_loc/2)
H0(i, i+Nb0/2)=H0(i, i+Nb0/2)-(dta_loc/2)
end do
!----------linear term-----------
Coeff0=g1_cps*sqrt(eta0/Pi)/2
do i=1, Nb0/2-1
tmp=i
tmp=sqrt(tmp)
tmp=Coeff0*tmp
H0(i, i+1)=H0(i, i+1)+tmp
H0(i+1, i)=H0(i+1, i)+tmp
H0(i+Nb0/2, i+Nb0/2+1)=H0(i+Nb0/2, i+Nb0/2+1)-tmp
H0(i+Nb0/2+1, i+Nb0/2)=H0(i+Nb0/2+1, i+Nb0/2)-tmp
end do
!----------nonlinearg term-----------
Coeff1=g2_cps*eta0/Pi/2
H01=0.0_Rkind
do i=1, Nb0/2-1
tmp=i
tmp=sqrt(tmp)
H01(i, i+1)=H01(i, i+1)+tmp
H01(i+1, i)=H01(i+1, i)+tmp
end do
do i=1, Nb0/2
do j=1, Nb0/2
tmp=0.0_Rkind
do k=1, Nb0/2
tmp=tmp+H01(i, k)*H01(k, j)
end do
H0(i, j)=H0(i, j)+Coeff1*tmp
H0(i+Nb0/2, j+Nb0/2)=H0(i+Nb0/2, j+Nb0/2)-Coeff1*tmp
end do
end do
!----------bath term-----------
do i=1, Nb0/2
H0(i, i)=H0(i, i)+epi0*(i-1)
H0(i+Nb0/2, i+Nb0/2)=H0(i+Nb0/2, i+Nb0/2)+epi0*(i-1)
end do
do i=1, Nb0
do j=1, Nb0
if(H0(i, j)/=H0(j, i)) then
print *, "e"
pause
end if
end do
end do
! print *, H0
!-------------- diagonalize Hamilt matrix ------------------
!---- Call RS subroutine --------
!--using slatec in 1976: slower, but independent of compiler ----
! call rs (Nb0, Nb0, H0, eigvalue, &
! cevec, eigvector, fv1, fv2, ierr)
!--using Lapack: faster, but must with intel + Lapack ----
call rs_cpu (Nb0, Nb0, H0, eigvalue, &
cevec, eigvector, fv1, fv2, ierr)
!---------------------
if (ierr/=0) then
print *, 'error'
stop
endif
!----------------------------------------------------
!---- Output eigenvalues --------
do i=1, Ns
Eigenv(i)=eigvalue(i)
end do
tmp=Eigenv(1)
do i=1, Ns
Eigenv(i)=Eigenv(i)-tmp
end do
!---- Write b0 matrix --------
do i=1, Ns
vec_mid1=0.0_Rkind
do j=1, Nb0/2-1
tmp=j
tmp=sqrt(tmp)
vec_mid1(j)=tmp*eigvector(j+1, i)
vec_mid1(j+Nb0/2)=tmp*eigvector(j+Nb0/2+1, i)
end do
do j=1, Ns
sum1=0.0_Rkind
do k=1, Nb0
sum1=sum1+vec_mid1(k)*eigvector(k, j)
end do
bmatrixa(j, i)=sum1
end do
end do
!---- Write b0+ matrix --------
do i=1, Ns
do j=1, Ns
bmatrixc(i, j)=bmatrixa(j, i)
b0matrixa(j, i)=bmatrixa(j, i)
b0matrixc(i, j)=bmatrixa(j, i)
end do
end do
!---- Write x^2 matrix --------
do i=1, Ns
vec_mid=0.0_Rkind
vec_mid1=0.0_Rkind
vec_mid2=0.0_Rkind
do j=1, Nb0/2-1
tmp=j
tmp=sqrt(tmp)
vec_mid1(j)=tmp*eigvector(j+1, i)
vec_mid1(j+Nb0/2)=tmp*eigvector(j+Nb0/2+1, i)
vec_mid2(j+1)=tmp*eigvector(j, i)
vec_mid2(j+Nb0/2+1)=tmp*eigvector(j+Nb0/2, i)
end do
do j=1, Nb0
vec_mid(j)=vec_mid1(j)+vec_mid2(j)
end do
vec_mid1=0.0_Rkind
vec_mid2=0.0_Rkind
do j=1, Nb0/2-1
tmp=j
tmp=sqrt(tmp)
vec_mid1(j)=tmp*vec_mid(j+1)
vec_mid1(j+Nb0/2)=tmp*vec_mid(j+Nb0/2+1)
vec_mid2(j+1)=tmp*vec_mid(j)
vec_mid2(j+Nb0/2+1)=tmp*vec_mid(j+Nb0/2)
end do
do j=1, Nb0
vec_mid(j)=vec_mid1(j)+vec_mid2(j)
end do
do j=1, Ns
sum1=0.0_Rkind
do k=1, Nb0
sum1=sum1+vec_mid(k)*eigvector(k, j)
end do
x2matrix(j, i)=sum1
end do
end do
!---- Write <a+a> matrix --------
do i=1, Ns
do j=1, Ns
sum1=0.0_Rkind
do k=1, Nb0/2
tmp=k-1
sum1=sum1+tmp*eigvector(k, i)*eigvector(k, j)+tmp*eigvector(k+Nb0/2, i)*eigvector(k+Nb0/2, j)
end do
nmatrix(j, i)=sum1
end do
end do
!---- Write qx matrix --------
do i=1, Ns
do j=1, Ns
sum2=0.0_Rkind
do k=1, Nb0/2
sum2=sum2+eigvector(k+Nb0/2, i)*eigvector(k, j)+eigvector(Nb0/2, i)*eigvector(k+Nb0/2, j)
end do
qxmatrix(j, i)=sum2
end do
end do
!---- Write qz matrix --------
do i=1, Ns
do j=1, Ns
sum2=0.0_Rkind
do k=1, Nb0/2
sum2=sum2+eigvector(k, i)*eigvector(k, j)+eigvector(k+Nb0/2, i)*(-eigvector(k+Nb0/2, j))
end do
qzmatrix(j, i)=sum2
end do
end do
!---- Test Hermite --------
! do i=1, Ns
! do j=1, Ns
! if(qzmatrix(i, j)/=qzmatrix(j, i)) then
! print *, "e"
! pause
! end if
! end do
! end do
! do i=1, Ns
! do j=1, Ns
! if(b0matrixa(i, j)/=b0matrixc(j, i)) then
! print *, "e"
! pause
! end if
! end do
! end do
end subroutine diag_H0
!========+=========+===============+=========+=$
! PROGRAM: diag_Hn
! TYPE : subroutine
! PURPOSE:
!========+=========+===============+=========+=$
subroutine diag_Hn(epin, tn, Eigenv, bmatrixc, bmatrixa, qzmatrix, qxmatrix, b0matrixa, b0matrixc, x2matrix, nmatrix)
use precnpl
implicit none
integer:: i, j, k, l
real(kind=Rkind):: epin, tn, tmp, sum1, sum2
real(kind=Rkind),dimension(Nb, Nb):: bmatrixan1, bmatrixcn1
real(kind=Rkind),dimension(Ns):: Eigenv
real(kind=Rkind),dimension(Ns, Ns):: bmatrixc, bmatrixa, qzmatrix, newqzmatrix, qxmatrix, newqxmatrix, b0matrixa, newb0matrixa, b0matrixc, newb0matrixc, x2matrix, newx2matrix, nmatrix, newnmatrix
real(kind=Rkind),dimension(Dim):: vec_mid1, vec_mid2
real(kind=Rkind),dimension(Dim, Dim):: Hn
integer:: cevec=1
integer:: ierr
real(kind=Rkind),dimension(Dim):: eigvalue, fv1, fv2
real(kind=Rkind),dimension(Dim, Dim):: eigvector
do i=1, Ns
Eigenv(i)=Lamda*Eigenv(i)
end do
Hn=0.0_Rkind
!----------loc term-----------
do i=1, Nb
do j=1, Ns
Hn(Ns*(i-1)+j, Ns*(i-1)+j)=Hn(Ns*(i-1)+j, Ns*(i-1)+j)+Eigenv(j)
end do
end do
!----------coupling term-----------
bmatrixan1=0.0_Rkind
bmatrixcn1=0.0_Rkind
do i=1, Nb-1
tmp=i
tmp=sqrt(tmp)
bmatrixan1(i, i+1)=bmatrixan1(i, i+1)+tmp
bmatrixcn1(i+1, i)=bmatrixcn1(i+1, i)+tmp
end do
do i=1, Nb-1
do j=1, Ns
do k=1, Ns
Hn(Ns*i+j, Ns*(i-1)+k)=Hn(Ns*i+j, Ns*(i-1)+k)+tn*bmatrixa(j, k)*bmatrixcn1(i+1, i)
Hn(Ns*(i-1)+k, Ns*i+j)=Hn(Ns*(i-1)+k, Ns*i+j)+tn*bmatrixa(j, k)*bmatrixcn1(i+1, i)
end do
end do
end do
!----------bath term-----------
do i=1, Nb
do j=1, Ns
Hn(Ns*(i-1)+j, Ns*(i-1)+j)=Hn(Ns*(i-1)+j, Ns*(i-1)+j)+epin*(i-1)
end do
end do
!-------------- diagonalize Hamilt matrix ------------------
!---- Call RS subroutine --------
!--using slatec in 1976: slower, but independent of compiler ----
! call rs (Dim, Dim, Hn, eigvalue, &
! cevec, eigvector, fv1, fv2, ierr)
!--using Lapack: faster, but must with intel + Lapack ----
call rs_cpu (Dim, Dim, Hn, eigvalue, &
cevec, eigvector, fv1, fv2, ierr)
!---------------------
if (ierr/=0) then
print *, 'error'
stop
endif
!----------------------------------------------------
do i=1, Ns
Eigenv(i)=eigvalue(i)
end do
tmp=Eigenv(1)
do i=1, Ns
Eigenv(i)=Eigenv(i)-tmp
end do
do i=1, Ns
vec_mid1=0.0_Rkind
do j=1, Nb-1
tmp=j
tmp=sqrt(tmp)
do k=1, Ns
vec_mid1(Ns*(j-1)+k)=tmp*eigvector(Ns*j+k, i)
end do
end do
do j=1, Ns
sum1=0.0_Rkind
do k=1, Dim
sum1=sum1+eigvector(k, j)*vec_mid1(k)
end do
bmatrixa(j, i)=sum1
end do
end do
do i=1, Ns
do j=1, Ns
bmatrixc(i, j)=bmatrixa(j, i)
end do
end do
!---- Write qx matrix --------
do i=1, Ns
vec_mid2=0.0_Rkind
do j=1, Nb
do k=1, Ns
tmp=0.0_Rkind
do l=1, Ns
tmp=tmp+eigvector(Ns*(j-1)+l ,i)*qxmatrix(k ,l)
end do
vec_mid2(Ns*(j-1)+k)=tmp
end do
end do
do j=1, Ns
sum2=0.0_Rkind
do k=1, Dim
sum2=sum2+eigvector(k, j)*vec_mid2(k)
end do
newqxmatrix(j, i)=sum2
end do
end do
do i=1, Ns
do j=1, Ns
qxmatrix(i, j)=newqxmatrix(i, j)
end do
end do
!---- Write qz matrix --------
do i=1, Ns
vec_mid2=0.0_Rkind
do j=1, Nb
do k=1, Ns
tmp=0.0_Rkind
do l=1, Ns
tmp=tmp+eigvector(Ns*(j-1)+l ,i)*qzmatrix(k ,l)
end do
vec_mid2(Ns*(j-1)+k)=tmp
end do
end do
do j=1, Ns
sum2=0.0_Rkind
do k=1, Dim
sum2=sum2+eigvector(k, j)*vec_mid2(k)
end do
newqzmatrix(j, i)=sum2
end do
end do
do i=1, Ns
do j=1, Ns
qzmatrix(i, j)=newqzmatrix(i, j)
end do
end do
! do i=1, Ns
! do j=1, Ns
! if(abs(qzmatrix(i, j)-qzmatrix(j, i))>=0.00000001) then
! print *, "e"
! pause