-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.f90
336 lines (279 loc) · 12.2 KB
/
response.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
module responsefunc
complex*16, save, public, allocatable :: r(:,:,:,:,:,:,:), ur(:,:,:,:,:,:,:,:), invur(:,:,:,:,:,:,:,:)
public :: calc_response_tensor
public :: calc_response_instable
public :: io_response
public :: calc_uporr
public :: calc_invur
contains
subroutine calc_response_tensor()
use param, only : norb, nsub, nsite, ntot, hf_vec, hf_val, nkpt, efermi
use constants, only : nspin, cmplx_0, cmplx_i, delta
implicit none
integer :: isub, isub1, ikpt, iorb, iorb1, iorb2, iorb3, ispin, ispin1, isite, isite1, is, is1
complex*16 :: term1(norb,norb,nsite,norb,norb,nsite), term2(norb,norb,nsite,norb,norb,nsite)
real*8 :: diff, fac
allocate(r(norb,norb,nsite,norb,norb,nsite,nspin*nspin))
! up-up ispin = 1
! dw-up ispin = 2
! up-dw ispin = 3
! dw-dw ispin = 4
r = cmplx_0
do ispin = 1, nspin
do ispin1 = 1, nspin
do ikpt = 1, nkpt
do isub = 1, nsub
if ((hf_val(isub,ispin,ikpt)-efermi) .ge. 0.0) cycle
do isub1 = 1, nsub
if ((hf_val(isub1,ispin1,ikpt)-efermi) .le. 0.0) cycle
do isite = 1, nsite
do isite1 = 1, nsite
do iorb = 1, norb
do iorb1 = 1, norb
do iorb2 = 1, norb
do iorb3 = 1, norb
term1(iorb,iorb1,isite,iorb2,iorb3,isite1) = &
dconjg(hf_vec(iorb+(isite-1)*norb,isub,ispin,ikpt)) *&
hf_vec(iorb1+(isite-1)*norb,isub1,ispin1,ikpt) *&
dconjg(hf_vec(iorb2+(isite1-1)*norb,isub1,ispin1,ikpt))*&
hf_vec(iorb3+(isite1-1)*norb,isub,ispin,ikpt)
term2(iorb,iorb1,isite,iorb2,iorb3,isite1) = &
dconjg(hf_vec(iorb+(isite-1)*norb,isub1,ispin1,ikpt)) *&
hf_vec(iorb1+(isite-1)*norb,isub,ispin,ikpt) *&
dconjg(hf_vec(iorb2+(isite1-1)*norb,isub,ispin,ikpt)) *&
hf_vec(iorb3+(isite1-1)*norb,isub1,ispin1,ikpt)
end do
end do
end do
end do
end do
end do
diff = hf_val(isub,ispin,ikpt) - hf_val(isub1,ispin1,ikpt)
fac = (1.0/real(nkpt))*(1.0/(diff + cmplx_i*delta))
if (ispin .eq. ispin1) then
if (ispin .eq. 1) is = 1
if (ispin .eq. 2) is = 4
r(:,:,:,:,:,:,is) = r(:,:,:,:,:,:,is) + term1(:,:,:,:,:,:)*fac
r(:,:,:,:,:,:,is) = r(:,:,:,:,:,:,is) + term2(:,:,:,:,:,:)*fac
else
if (ispin .eq. 1) then
is = 3
is1 = 2
end if
if (ispin .eq. 2) then
is = 2
is1 = 3
end if
r(:,:,:,:,:,:,is) = r(:,:,:,:,:,:,is) + term1(:,:,:,:,:,:)*fac
r(:,:,:,:,:,:,is1) = r(:,:,:,:,:,:,is1) + term2(:,:,:,:,:,:)*fac
end if
end do
end do
end do
end do
end do
end subroutine calc_response_tensor
subroutine calc_response_instable(mag0)
use param, only : norb, nsite, ntot, nkpt, sigma_x, sigma_y, sigma_z
use constants, only : nspin, cmplx_0, cmplx_i
use utilities, only : trace
implicit none
integer :: itot, itot1, ikpt, iorb, iorb1, iorb2, iorb3, ispin, ispin1, isite, isite1
complex*16 :: cx,cy,c2,c3,trx, try, trxmu, trymu, mu2, lmbx, lmby, fact(norb,norb,nspin,nspin)
real*8, intent(in) :: mag0(nsite)
mu2 = cmplx_0
do isite = 1, nsite
mu2 = mu2 + mag0(isite)*mag0(isite)
end do
mu2 = mu2*real(norb)*2.0
do isite1 = 1, nsite
do iorb2 = 1, norb
do iorb3 = 1, norb
lmbx = cmplx_0
lmby = cmplx_0
trxmu = cmplx_0
trymu = cmplx_0
do isite = 1, nsite
trx = cmplx_0
try = cmplx_0
do iorb = 1, norb
trx = trx + r(iorb,iorb,isite,iorb2,iorb3,isite1,2) + &
r(iorb,iorb,isite,iorb2,iorb3,isite1,3)
try = try - cmplx_i*(r(iorb,iorb,isite,iorb2,iorb3,isite1,2) - &
r(iorb,iorb,isite,iorb2,iorb3,isite1,3))
end do
trymu = trymu + trx*mag0(isite)
trxmu = trxmu - try*mag0(isite)
end do
lmby = trxmu/mu2
lmbx = trymu/mu2
do isite = 1, nsite
cx = lmby*mag0(isite)
cy = -lmbx*mag0(isite)
c2 = cmplx(real(cx),real(-cy))
c3 = cmplx(real(cx),real(cy))
do iorb = 1, norb
r(iorb,iorb,isite,iorb2,iorb3,isite1,2) = r(iorb,iorb,isite,iorb2,iorb3,isite1,2) - c2
r(iorb,iorb,isite,iorb2,iorb3,isite1,3) = r(iorb,iorb,isite,iorb2,iorb3,isite1,3) - c3
end do
end do
end do
end do
end do
end subroutine calc_response_instable
subroutine io_response(mode)
use param, only : norb, nsite
use constants, only : nspin, rname, cmplx_0
implicit none
character(len=1), intent(in) :: mode
integer :: iorb,iorb1,iorb2,iorb3,isite,isite1,ispin,ispin1, i
real*8 :: A,B
! Read and write, the FASTEST INDEX IS THE FIRST ONE
! THE SLOWEST IS THE LAST ONE
if (mode=='w') then
open(unit=11, file=rname, status='replace')
do ispin = 1, nspin*nspin
do isite = 1, nsite
do isite1 = 1, nsite
do iorb = 1, norb
do iorb1 = 1, norb
do iorb2 = 1, norb
do iorb3 = 1, norb
write(11,'(7i,2ES18.10)') iorb, iorb1, isite, iorb2, iorb3, isite1, ispin, &
& real(r(iorb,iorb1,isite,iorb2,iorb3,isite1,ispin)), &
& aimag(r(iorb,iorb1,isite,iorb2,iorb3,isite1,ispin))
end do
end do
end do
end do
end do
end do
end do
close(11)
else if (mode=='r') then
allocate(r(norb,norb,nsite,norb,norb,nsite,nspin*nspin))
r = cmplx_0
open(unit=11, file=rname, status='old')
do i = 1, (norb**4)*(nsite**2)*(nspin**2)
read(11,*) iorb, iorb1, isite, iorb2, iorb3, isite1, ispin, A, B
r(iorb,iorb1,isite,iorb2,iorb3,isite1,ispin) = cmplx(A,B)
end do
close(11)
end if
end subroutine io_response
subroutine calc_uporr()
use param, only : norb, nsite, u_mat
use constants, only : nspin, cmplx_0
implicit none
integer :: iorb, iorb1, iorb2, iorb3, iorb4, iorb5, ispin, ispin1, isite, isite1
complex*16 :: u(norb,norb,norb,norb,nsite), j(norb,norb,norb,norb,nsite)
allocate(ur(norb,norb,nsite,norb,norb,nsite,nspin*2,nspin*2))
do isite = 1, nsite
do iorb = 1, norb
do iorb1 = 1, norb
do iorb2 = 1, norb
do iorb3 = 1, norb
u(iorb,iorb1,iorb2,iorb3,isite) = u_mat(iorb,iorb1,iorb2,iorb3,isite)
j(iorb,iorb1,iorb2,iorb3,isite) = u_mat(iorb,iorb3,iorb2,iorb1,isite)
end do
end do
end do
end do
end do
ur = cmplx_0
do isite = 1, nsite
! \sum_cd U_abcd_i * R_cd_i_ef_j
do iorb = 1, norb
do iorb1 = 1, norb
do isite1 = 1, nsite
do iorb4 = 1, norb
do iorb5 = 1, norb
! Begin summation over cd
do iorb2 = 1, norb
do iorb3 = 1, norb
ur(iorb,iorb1,isite,iorb4,iorb5,isite1,1,1) = ur(iorb,iorb1,isite,iorb4,iorb5,isite1,1,1) + &
(u(iorb,iorb1,iorb2,iorb3,isite)-j(iorb,iorb1,iorb2,iorb3,isite))*&
r(iorb2,iorb3,isite,iorb4,iorb5,isite1,1)
ur(iorb,iorb1,isite,iorb4,iorb5,isite1,1,4) = ur(iorb,iorb1,isite,iorb4,iorb5,isite1,1,4) + &
u(iorb,iorb1,iorb2,iorb3,isite)*r(iorb2,iorb3,isite,iorb4,iorb5,isite1,4)
ur(iorb,iorb1,isite,iorb4,iorb5,isite1,2,2) = ur(iorb,iorb1,isite,iorb4,iorb5,isite1,2,2) - &
j(iorb,iorb1,iorb2,iorb3,isite)*r(iorb2,iorb3,isite,iorb4,iorb5,isite1,3)
ur(iorb,iorb1,isite,iorb4,iorb5,isite1,3,3) = ur(iorb,iorb1,isite,iorb4,iorb5,isite1,3,3) - &
j(iorb,iorb1,iorb2,iorb3,isite)*r(iorb2,iorb3,isite,iorb4,iorb5,isite1,2)
ur(iorb,iorb1,isite,iorb4,iorb5,isite1,4,1) = ur(iorb,iorb1,isite,iorb4,iorb5,isite1,4,1) + &
u(iorb,iorb1,iorb2,iorb3,isite)*r(iorb2,iorb3,isite,iorb4,iorb5,isite1,1)
ur(iorb,iorb1,isite,iorb4,iorb5,isite1,4,4) = ur(iorb,iorb1,isite,iorb4,iorb5,isite1,4,4) + &
(u(iorb,iorb1,iorb2,iorb3,isite)-j(iorb,iorb1,iorb2,iorb3,isite))*&
r(iorb2,iorb3,isite,iorb4,iorb5,isite1,4)
end do
end do
end do
end do
end do
end do
end do
end do
end subroutine calc_uporr
subroutine calc_invur()
use param, only : norb, nsite
use constants, only : nspin, cmplx_0
use utilities, only : call_invert
implicit none
integer :: iorb, iorb1, iorb2, iorb3, isite, isite1, ispin, ispin1, flat1, flat2
complex*16 :: urflat(norb*norb*nsite*nspin*2,norb*norb*nsite*nspin*2), imat(norb*norb*nsite*nspin*2,norb*norb*nsite*nspin*2)
allocate(invur(norb,norb,nsite,norb,norb,nsite,nspin*2,nspin*2))
urflat = cmplx_0
imat = cmplx_0
invur = cmplx_0
! Reshape to flatten rank6 tensors into rank2 matrices
flat1 = 0
do ispin = 1, nspin*2
do isite = 1, nsite
do iorb = 1, norb
do iorb1 = 1, norb
flat1 = flat1 + 1
flat2 = 0
do ispin1 = 1, nspin*2
do isite1 = 1, nsite
do iorb2 = 1, norb
do iorb3 = 1, norb
flat2 = flat2 + 1
urflat(flat1,flat2) = ur(iorb,iorb1,isite,iorb2,iorb3,isite1,ispin,ispin1)
end do
end do
end do
end do
end do
end do
end do
end do
flat1 = 0
do flat1 = 1, norb*norb*nsite*nspin*2
imat(flat1,flat1) = 1.0
end do
urflat(:,:) = imat(:,:) - urflat(:,:)
call call_invert(urflat,norb*norb*nsite*nspin*2)
! Reconvert rank2 matrix to rank6 tensor
flat1 = 0
do ispin = 1, nspin*2
do isite = 1, nsite
do iorb = 1, norb
do iorb1 = 1, norb
flat1 = flat1 + 1
flat2 = 0
do ispin1 = 1, nspin*2
do isite1 = 1, nsite
do iorb2 = 1, norb
do iorb3 = 1, norb
flat2 = flat2 + 1
invur(iorb,iorb1,isite,iorb2,iorb3,isite1,ispin,ispin1) = urflat(flat1,flat2)
end do
end do
end do
end do
end do
end do
end do
end do
end subroutine calc_invur
end module responsefunc