The Elk Code
genvchi0u.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2026 Wenhan Chen, J. K. Dewhurst and S. Sharma.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 subroutine genvchi0u(ik0,lock,pmat,evecu,vchi0)
7 use modmain
8 use modulr
9 use modomp
10 implicit none
11 ! arguments
12 integer, intent(in) :: ik0
13 integer(omp_lock_kind), intent(inout) :: lock(nwrf)
14 complex(8), intent(in) :: pmat(nstsv,nstsv,3),evecu(nstulr,nstulr)
15 complex(4), intent(inout) :: vchi0(nqpt+2,nqpt+2,nwrf)
16 ! local variables
17 integer nm,nm2,ist,jst,iw,nthd
18 integer ikpa,jkpa,iq,jq,i,j,k
19 integer i1,i2,i3,j1,j2,j3
20 real(8) ei,ej,eij,t1
21 complex(8) pmatu(3),a(3,3),z1,z2
22 ! automatic arrays
23 complex(8) zrq(nqpt),y(nstsv)
24 complex(4) cw(nwrf),b(-1:nqpt,-1:nqpt)
25 ! external functions
26 complex(8), external :: zdotc
27 ! matrix size
28 nm=nqpt+2
29 nm2=nm**2
30 call holdthd(nstulr,nthd)
31 !$OMP PARALLEL DO DEFAULT(SHARED) &
32 !$OMP PRIVATE(zrq,y,cw,a,b,pmatu) &
33 !$OMP PRIVATE(jst,ei,ej,eij,t1) &
34 !$OMP PRIVATE(ikpa,jkpa,i1,i2,i3,j1,j2,j3) &
35 !$OMP PRIVATE(iq,jq,i,j,k,z1,z2,iw) &
36 !$OMP SCHEDULE(DYNAMIC) &
37 !$OMP NUM_THREADS(nthd)
38 do ist=1,nstulr
39  ei=evalu(ist,ik0)
40  do jst=1,nstulr
41  t1=(wkptnr/(nkpa*omega))*(occulr(ist,ik0)-occulr(jst,ik0))
42  if (abs(t1) < 1.d-8) cycle
43  ej=evalu(jst,ik0)
44  eij=ei-ej
45 ! frequency-dependent part in response function formula for all frequencies
46  cw(1:nwrf)=t1/(eij+wrf(1:nwrf))
47 ! determine ρ(Q) = ⟨α|exp(-iQ⋅r)|β⟩ and P = ⟨α|-i∇|β⟩
48  zrq(1:nqpt)=0.d0
49  pmatu(1:3)=0.d0
50  do jkpa=1,nkpa
51  j1=ivq(1,jkpa); j2=ivq(2,jkpa); j3=ivq(3,jkpa)
52  do ikpa=1,nkpa
53  i1=j1-ivq(1,ikpa); i2=j2-ivq(2,ikpa); i3=j3-ivq(3,ikpa)
54  iq=ivqiq(i1,i2,i3)
55  i=(ikpa-1)*nstsv+1
56  j=(jkpa-1)*nstsv+1
57  z1=zdotc(nstsv,evecu(i,ist),1,evecu(j,jst),1)
58  zrq(iq)=zrq(iq)+z1
59  if (ikpa == jkpa) then
60  do k=1,3
61  call zgemv('N',nstsv,nstsv,zone,pmat(:,:,k),nstsv,evecu(i,jst),1, &
62  zzero,y,1)
63  z2=zdotc(nstsv,evecu(i,ist),1,y,1)
64  pmatu(k)=pmatu(k)+z1*vqc(k,ikpa)+z2
65  end do
66  end if
67  end do
68  end do
69 ! Hermitian part of body
70  do jq=2,nqpt
71  b(2:jq-1,jq)=conjg(b(jq,2:jq-1))
72  z1=gclq(jq)*conjg(zrq(jq))
73  b(jq:nqpt,jq)=gclq(jq:nqpt)*zrq(jq:nqpt)*z1
74  end do
75  b(-1:1,-1:1)=0.e0
76 ! calculate 3 × ngrf wings of matrix
77  t1=-sqrt(fourpi)/eij
78  do i=-1,1
79  z1=t1*pmatu(i+2)
80  b(i,2:nqpt)=z1*conjg(zrq(2:nqpt))*gclq(2:nqpt)
81  do j=2,nqpt
82  b(j,i)=conjg(b(i,j))
83  end do
84  end do
85 ! add to body and wings of the response function
86  do iw=1,nwrf
87  call omp_set_lock(lock(iw))
88  call caxpy(nm2,cw(iw),b,1,vchi0(1,1,iw),1)
89  call omp_unset_lock(lock(iw))
90  end do
91 ! add to the head of the response function
92  t1=fourpi/eij**2
93  do j=1,3
94  z1=t1*conjg(pmatu(j))
95  a(1:3,j)=z1*pmatu(1:3)
96  end do
97  do iw=1,nwrf
98  call omp_set_lock(lock(iw))
99  vchi0(1:3,1:3,iw)=vchi0(1:3,1:3,iw)+cw(iw)*a(1:3,1:3)
100  call omp_unset_lock(lock(iw))
101  end do
102  end do
103 end do
104 !$OMP END PARALLEL DO
105 call freethd(nthd)
106 end subroutine
107 
integer, dimension(:,:), allocatable ivq
Definition: modmain.f90:532
real(8) omega
Definition: modmain.f90:20
Definition: modomp.f90:6
complex(8), dimension(:), allocatable wrf
Definition: modmain.f90:1170
complex(8), parameter zone
Definition: modmain.f90:1240
real(8), dimension(:,:), allocatable vqc
Definition: modmain.f90:550
real(8), dimension(:,:), allocatable occulr
Definition: modulr.f90:101
subroutine genvchi0u(ik0, lock, pmat, evecu, vchi0)
Definition: genvchi0u.f90:7
integer, dimension(:,:,:), allocatable ivqiq
Definition: modmain.f90:534
complex(8), parameter zzero
Definition: modmain.f90:1240
real(8), dimension(:), allocatable gclq
Definition: modmain.f90:558
subroutine freethd(nthd)
Definition: modomp.f90:112
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
real(8) wkptnr
Definition: modmain.f90:480
real(8), parameter fourpi
Definition: modmain.f90:1234
Definition: modulr.f90:6
integer nkpa
Definition: modulr.f90:24
real(8), dimension(:,:), allocatable evalu
Definition: modulr.f90:99