-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculators.f90
511 lines (437 loc) · 15.7 KB
/
calculators.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
module calculators
use readers, only: hsx_t
implicit none
double precision, parameter, private :: RyToEv = 13.605698066
type, public :: Hlayer
double complex, pointer :: the_h(:,:,:) => null()
end type
type, public :: Slayer
double complex, pointer :: the_s(:,:) => null()
end type
contains
subroutine CBSfixedK(hw,dir,isc,k,emin,emax,nbin,dist)
type(hsx_t), intent(in) :: hw
integer, dimension(:,:), intent(in) :: isc
integer, intent(in) :: dir, nbin
double precision, intent(in) :: emin, emax, dist
double precision, intent(in) :: k(:)
type(Hlayer), allocatable :: hes(:)
type(Slayer), allocatable :: ses(:)
type(Hlayer), allocatable :: trans_hes(:)
type(Slayer), allocatable :: trans_ses(:)
complex :: i, phase
integer :: io,j,ij,jos,jo,layers,l,m,dime,nspin,lwork,info,spin,lay,integg,start_eig
integer, allocatable :: count_fail(:)
double precision :: dummyemax,dummyemin,E,step,thek
double complex,allocatable :: BB(:,:),AA(:,:),work(:)
double complex,allocatable :: alpha(:),beta(:)
double complex :: VL(1,1)
double complex,allocatable :: VR(:,:)
double precision,allocatable :: rwork(:)
character(len=21) :: filename, filename2
i=(0,1)
! First count how many layers in direction dir
layers = 1
do l=1,hw%no_s
if (isc(l,dir).gt.layers) then
layers=isc(l,dir)
endif
enddo
! Refering to theory hes(1) is HD, hes(2) is HS, hes(3) is HSBIS and so on..
! They are one more that the layers since also HD is included. Same for ses
allocate(ses(layers+1))
allocate(hes(layers+1))
! Allocate every matrix of ses and hes and initialize to zero
do l=1,layers+1
allocate(ses(l)%the_s(hw%no_u,hw%no_u),hes(l)%the_h(hw%no_u,hw%no_u,hw%nspin))
ses(l)%the_s(1:hw%no_u,1:hw%no_u) = 0
hes(l)%the_h(1:hw%no_u,1:hw%no_u,1:hw%nspin) = 0
enddo
do io = 1,hw%no_u ! loop on unit cell orbitals
do j = 1,hw%numh(io) ! loop on connected orbitals
ij = hw%listhptr(io)+j ! sparse-matrix array index
jos = hw%listh(ij) ! index of connected orbital
jo = hw%indxuo(jos) ! equiv. orbital in unit cell
phase = exp(i*sum(k(:)*hw%xij(:,ij))) !exp(i*(k(1)*hw%xij(1,ij)+k(2)*hw%xij(2,ij)))
do l=1,layers+1
if (isc(jos,dir).eq.-(l-1)) then
hes(l)%the_h(io,jo,1:hw%nspin) = hes(l)%the_h(io,jo,1:hw%nspin) + phase*hw%hamilt(ij,1:hw%nspin)
ses(l)%the_s(io,jo) = ses(l)%the_s(io,jo) + phase*hw%Sover(ij) ! overlap matrix element
endif
enddo
enddo
enddo
dime = hw%no_u
nspin = hw%nspin
allocate(count_fail(nspin))
!Create conjugate transpose, now we do not have the HD/SD
allocate(trans_ses(layers))
allocate(trans_hes(layers))
! Allocate every matrix and give value
do lay=1,layers
allocate(trans_ses(lay)%the_s(hw%no_u,hw%no_u),trans_hes(lay)%the_h(hw%no_u,hw%no_u,hw%nspin))
do m=1,dime
do l=1,dime
trans_ses(lay)%the_s(m,l) = CONJG(ses(lay+1)%the_s(l,m))
do spin=1,nspin
trans_hes(lay)%the_h(m,l,spin) = CONJG(hes(lay+1)%the_h(l,m,spin))
enddo
enddo
enddo
enddo
allocate(BB(dime*layers*2,dime*layers*2),AA(dime*layers*2,dime*layers*2))
allocate(alpha(dime*layers*2),beta(dime*layers*2))
lwork=4*2*layers*dime-1
allocate(work(lwork),rwork(8*2*layers*dime))
allocate(VR(dime*2*layers,dime*2*layers))
do spin=1,nspin
count_fail(spin) = 0
write(filename,'("spin",I1,"layer",I1)')spin,layers
write(filename2,'("spin",I1,"layer",I1,"purereal")')spin,layers
open(unit=spin+100,file=filename,status="unknown")
open(unit=spin+200,file=filename2,status="unknown")
!change energy in Ry
dummyemax=emax/RyToEv
dummyemin=emin/RyToEv
step=(dummyemax-dummyemin)/nbin
do j=1,nbin+1
alpha(:)=1.d0
beta(:)=1.d0
BB(:,:)=0.d0
do l=1,(2*layers-1)*dime
BB(dime+l,dime+l)=1.d0
enddo
AA(:,:)=0.d0
do l=1,(2*layers-1)*dime
AA(dime+l,l)=1.d0
enddo
E=dummyemin+(j-1)*step
do m=1,dime
do l=1,dime
do integg=1,layers+1
AA(m,(layers-2+integg)*dime+l) = E*ses(integg)%the_s(m,l)-hes(integg)%the_h(m,l,spin)
enddo
do integg=1,layers
BB(m,l+dime*(integg-1)) = trans_hes(layers+1-integg)%the_h(m,l,spin) - E*trans_ses(layers+1-integg)%the_s(m,l)
enddo
enddo
enddo
start_eig = 1
call ZGGEV('N', 'V', 2*layers*dime, AA, 2*layers*dime, BB, 2*layers*dime, &
alpha, beta, VL, 1, VR, dime*2*layers, work, lwork, rwork, info)
if (info .ne. 0) then
if (info .gt. 2*layers*dime .or. info .lt. 0) then
write(*,*) info
stop 'Failed zggev diagonalisation with error other than QZ iteration fail.'
endif
start_eig = info+1
count_fail(spin) = count_fail(spin)+1
end if
do m=start_eig,2*layers*dime
thek=-real(real(log(alpha(m)/beta(m))))/dist
if (thek.gt.10000000) cycle
if (thek.ne.thek) cycle
write(spin+100,*) E*RyToEv, thek, real(aimag(log(alpha(m)/beta(m))))/dist
if (thek.le.0.001.and.thek.ge.-0.001) then
write(spin+200,*) E*RyToEv, real(aimag(log(alpha(m)/beta(m))))/dist, thek
endif
enddo
enddo
close(spin+100)
close(spin+200)
enddo
if (any(count_fail>0)) then
write(*,*) "WARNINGS"
do jo=1,nspin
write(*,*) " For spin", jo, ",", count_fail(jo), "bins out of", nbin, "could not produce all the eigenvalues."
enddo
write(*,*) " Problem due to a failure of LAPACK routine ZGGEV, &
probably linked to numerical instability of Schur decomposition within LAPACK."
endif
deallocate(AA,BB,alpha,beta)
deallocate(work,rwork,VR)
deallocate(trans_ses,trans_hes,hes,ses,count_fail)
end subroutine CBSfixedK
subroutine CBSvariableK(hw,dir,isc,E,dist,b1,b2)
type(hsx_t), intent(in) :: hw
integer, dimension(:,:), intent(in) :: isc
integer, intent(in) :: dir
double precision, intent(in) :: E, dist
double precision, intent(in) :: b1(:), b2(:)
type(Hlayer), allocatable :: hes(:)
type(Slayer), allocatable :: ses(:)
type(Hlayer), allocatable :: trans_hes(:)
type(Slayer), allocatable :: trans_ses(:)
logical :: warntag
complex :: i, phase
integer :: io,j,ij,jos,jo,layers,l,m,dime,nspin,lwork,info,spin,lay,sidex,sidey,start_eig,integg
double precision :: Eok,thek,posmin,reposmin,p1,p2,k(3)
double complex,allocatable :: BB(:,:),AA(:,:),work(:)
double complex,allocatable :: alpha(:),beta(:)
double complex :: VL(1,1)
double complex,allocatable :: VR(:,:)
double precision,allocatable :: rwork(:)
character(len=21) :: filename, filename2
i=(0,1)
dime = hw%no_u
nspin = hw%nspin
warntag=.TRUE.
! First count how many layers in direction dir
layers = 1
do l=1,hw%no_s
if (isc(l,dir).gt.layers) then
layers=isc(l,dir)
endif
enddo
! Refering to theory hes(1) is HD, hes(2) is HS, hes(3) is HSBIS and so on..
! They are one more that the layers since also HD is included. Same for ses
allocate(ses(layers+1))
allocate(hes(layers+1))
! Allocate every matrix of ses and hes and initialize to zero
do l=1,layers+1
allocate(ses(l)%the_s(hw%no_u,hw%no_u),hes(l)%the_h(hw%no_u,hw%no_u,hw%nspin))
enddo
allocate(trans_ses(layers))
allocate(trans_hes(layers))
do lay=1,layers
allocate(trans_ses(lay)%the_s(hw%no_u,hw%no_u),trans_hes(lay)%the_h(hw%no_u,hw%no_u,hw%nspin))
enddo
allocate(BB(dime*layers*2,dime*layers*2),AA(dime*layers*2,dime*layers*2))
allocate(alpha(dime*layers*2),beta(dime*layers*2))
lwork=4*2*layers*dime-1
allocate(work(lwork),rwork(8*2*layers*dime))
allocate(VR(dime*2*layers,dime*2*layers))
do spin=1,hw%nspin
write(filename,'("Kspin",I1,"layer",I1)')spin,layers
write(filename2,'("Kspin",I1,"layer",I1,"minimum")')spin,layers
open(unit=spin+100,file=filename,status="unknown")
open(unit=spin+200,file=filename2,status="unknown")
enddo
k(:)=0.d0
p1=0.d0
p2=0.d0
do sidex=-15,15 ! loop on the k_x
do sidey=-15,15 ! loop on the k_y
p1=sidex*0.5/15.d0
p2=sidey*0.5/15.d0
k(:)=p1*b1(:)+p2*b2(:)
do l=1,layers+1
ses(l)%the_s(1:hw%no_u,1:hw%no_u) = 0
hes(l)%the_h(1:hw%no_u,1:hw%no_u,1:hw%nspin) = 0
enddo
do io = 1,hw%no_u ! loop on unit cell orbitals
do j = 1,hw%numh(io) ! loop on connected orbitals
ij = hw%listhptr(io)+j ! sparse-matrix array index
jos = hw%listh(ij) ! index of connected orbital
jo = hw%indxuo(jos) ! equiv. orbital in unit cell
phase = exp(i*sum(k(:)*hw%xij(:,ij))) ! exp(i*(k(1)*hw%xij(1,ij)+k(2)*hw%xij(2,ij)))
do l=1,layers+1
if (isc(jos,dir).eq.-(l-1)) then
hes(l)%the_h(io,jo,1:hw%nspin) = hes(l)%the_h(io,jo,1:hw%nspin) + phase*hw%hamilt(ij,1:hw%nspin)
ses(l)%the_s(io,jo) = ses(l)%the_s(io,jo) + phase*hw%Sover(ij) ! overlap matrix element
endif
enddo
enddo
enddo
do lay=1,layers
do m=1,dime
do l=1,dime
trans_ses(lay)%the_s(m,l) = CONJG(ses(lay+1)%the_s(l,m))
do spin=1,nspin
trans_hes(lay)%the_h(m,l,spin) = CONJG(hes(lay+1)%the_h(l,m,spin))
enddo
enddo
enddo
enddo
do spin=1,nspin !loop spin
Eok=E/RyToEv !change energy in Ry
alpha(:)=1.d0
beta(:)=1.d0
BB(:,:)=0.d0
do l=1,(2*layers-1)*dime
BB(dime+l,dime+l)=1.d0
enddo
AA(:,:)=0.d0
do l=1,(2*layers-1)*dime
AA(dime+l,l)=1.d0
enddo
do m=1,dime
do l=1,dime
do integg=1,layers+1
AA(m,(layers-2+integg)*dime+l) = Eok*ses(integg)%the_s(m,l)-hes(integg)%the_h(m,l,spin)
enddo
do integg=1,layers
BB(m,l+dime*(integg-1)) = trans_hes(layers+1-integg)%the_h(m,l,spin) - Eok*trans_ses(layers+1-integg)%the_s(m,l)
enddo
enddo
enddo
start_eig = 1
call ZGGEV('N', 'V', 2*layers*dime, AA, 2*layers*dime, BB, 2*layers*dime, &
alpha, beta, VL, 1, VR, dime*2*layers, work, lwork, rwork, info)
if (info .ne. 0) then
if (info .gt. 2*layers*dime .or. info .lt. 0) then
write(*,*) info
stop 'Failed zggev diagonalisation with error other than QZ iteration fail.'
endif
start_eig = info+1
if (warntag) then
write(*,*) "WARNINGS"
warntag = .FALSE.
endif
write(*,*) " Some eigenvalues could not be computed for k", p1, p2
end if
posmin=300
reposmin=0.d0
do m=start_eig,2*layers*dime
thek=-real(real(log(alpha(m)/beta(m))))/dist
if (thek.gt.10000000) cycle
if (thek.ne.thek) cycle
write(spin+100,*) p1,p2, thek, real(aimag(log(alpha(m)/beta(m))))/dist
if (thek.gt.0.d0.and.thek.lt.posmin) then
posmin=thek
reposmin=real(aimag(log(alpha(m)/beta(m))))/dist
endif
enddo
if (p2.eq.0.5) then
write(spin+200,'(2f16.8,2f16.8)') p1,p2, posmin, reposmin
write(spin+200,*)
else
write(spin+200,'(2f16.8,2f16.8)') p1,p2, posmin, reposmin
endif
enddo ! loop spin end
enddo ! loop on the k_y end
enddo ! loop on the k_x end
close(spin+100)
close(spin+200)
deallocate(AA,BB,alpha,beta)
deallocate(work,rwork,VR)
deallocate(trans_ses,trans_hes,hes,ses)
end subroutine CBSvariableK
subroutine CBSsymmetries(hw,dir,isc,k,E,dist)
type(hsx_t), intent(in) :: hw
integer, dimension(:,:), intent(in) :: isc
integer, intent(in) :: dir
double precision, intent(in) :: E, dist
double precision, intent(in) :: k(:)
type(Hlayer), allocatable :: hes(:)
type(Slayer), allocatable :: ses(:)
type(Hlayer), allocatable :: trans_hes(:)
type(Slayer), allocatable :: trans_ses(:)
complex :: i, phase
integer :: io,j,ij,jos,jo,layers,l,m,dime,nspin,lwork,info,spin,lay,integg,ll
double precision :: Eok
double complex,allocatable :: BB(:,:),AA(:,:),work(:)
double complex,allocatable :: alpha(:),beta(:)
double complex :: VL(1,1), llproj
double complex,allocatable :: VR(:,:)
double precision,allocatable :: rwork(:)
character(len=21) :: filename, filename2
i=(0,1)
! First count how many layers in direction dir
layers = 1
do l=1,hw%no_s
if (isc(l,dir).gt.layers) then
layers=isc(l,dir)
endif
enddo
! Refering to theory hes(1) is HD, hes(2) is HS, hes(3) is HSBIS and so on..
! They are one more that the layers since also HD is included. Same for ses
allocate(ses(layers+1))
allocate(hes(layers+1))
! Allocate every matrix of ses and hes and initialize to zero
do l=1,layers+1
allocate(ses(l)%the_s(hw%no_u,hw%no_u),hes(l)%the_h(hw%no_u,hw%no_u,hw%nspin))
ses(l)%the_s(1:hw%no_u,1:hw%no_u) = 0
hes(l)%the_h(1:hw%no_u,1:hw%no_u,1:hw%nspin) = 0
enddo
do io = 1,hw%no_u ! loop on unit cell orbitals
do j = 1,hw%numh(io) ! loop on connected orbitals
ij = hw%listhptr(io)+j ! sparse-matrix array index
jos = hw%listh(ij) ! index of connected orbital
jo = hw%indxuo(jos) ! equiv. orbital in unit cell
phase = exp(i*sum(k(:)*hw%xij(:,ij))) !exp(i*(k(1)*hw%xij(1,ij)+k(2)*hw%xij(2,ij)))
do l=1,layers+1
if (isc(jos,dir).eq.-(l-1)) then
hes(l)%the_h(io,jo,1:hw%nspin) = hes(l)%the_h(io,jo,1:hw%nspin) + phase*hw%hamilt(ij,1:hw%nspin)
ses(l)%the_s(io,jo) = ses(l)%the_s(io,jo) + phase*hw%Sover(ij) ! overlap matrix element
endif
enddo
enddo
enddo
dime = hw%no_u
nspin = hw%nspin
!Create conjugate transpose, now we do not have the HD/SD
allocate(trans_ses(layers))
allocate(trans_hes(layers))
! Allocate every matrix and give value
do lay=1,layers
allocate(trans_ses(lay)%the_s(hw%no_u,hw%no_u),trans_hes(lay)%the_h(hw%no_u,hw%no_u,hw%nspin))
do m=1,dime
do l=1,dime
trans_ses(lay)%the_s(m,l) = CONJG(ses(lay+1)%the_s(l,m))
do spin=1,nspin
trans_hes(lay)%the_h(m,l,spin) = CONJG(hes(lay+1)%the_h(l,m,spin))
enddo
enddo
enddo
enddo
allocate(BB(dime*layers*2,dime*layers*2),AA(dime*layers*2,dime*layers*2))
allocate(alpha(dime*layers*2),beta(dime*layers*2))
lwork=4*2*layers*dime-1
allocate(work(lwork),rwork(8*2*layers*dime))
allocate(VR(dime*2*layers,dime*2*layers))
do spin=1,nspin
write(filename,'("PROJspin",I1,"layer",I1)')spin,layers
open(unit=spin+100,file=filename,status="unknown")
write(spin+100,*) "#Orbitals has the same label of ORB_INDEX file"
!change energy in Ry
Eok=E/RyToEv
alpha(:)=1.d0
beta(:)=1.d0
BB(:,:)=0.d0
do l=1,(2*layers-1)*dime
BB(dime+l,dime+l)=1.d0
enddo
AA(:,:)=0.d0
do l=1,(2*layers-1)*dime
AA(dime+l,l)=1.d0
enddo
do m=1,dime
do l=1,dime
do integg=1,layers+1
AA(m,(layers-2+integg)*dime+l) = Eok*ses(integg)%the_s(m,l)-hes(integg)%the_h(m,l,spin)
enddo
do integg=1,layers
BB(m,l+dime*(integg-1)) = trans_hes(layers+1-integg)%the_h(m,l,spin) - Eok*trans_ses(layers+1-integg)%the_s(m,l)
enddo
enddo
enddo
call ZGGEV('N', 'V', 2*layers*dime, AA, 2*layers*dime, BB, 2*layers*dime, &
alpha, beta, VL, 1, VR, dime*2*layers, work, lwork, rwork, info)
if (info .ne. 0) then
write(*,*) info
stop 'Failed zggev diagonalization.'
endif
do m=1,2*layers*dime
write(spin+100,*) "eigenvalue", -real(real(log(alpha(m)/beta(m))))/dist, real(aimag(log(alpha(m)/beta(m))))/dist
do ll=1,dime
llproj=0.d0
do l=1,dime
do jo=1,2*layers
if (jo.lt.layers) then
llproj=llproj+VR(l+(jo-1)*dime,m)*trans_ses(layers-jo)%the_s(ll,l)
else
llproj=llproj+VR(l+(jo-1)*dime,m)*ses(jo-layers+1)%the_s(ll,l)
endif
enddo
enddo
write(spin+100,*) ll,llproj,(real(real(llproj)))**2+(real(aimag(llproj)))**2
enddo
enddo
close(spin+100)
enddo
deallocate(AA,BB,alpha,beta)
deallocate(work,rwork,VR)
deallocate(trans_ses,trans_hes,hes,ses)
end subroutine CBSsymmetries
end module calculators