The Elk Code
drhomagk.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2012 J. K. Dewhurst, S. Sharma and E. K. U. Gross.
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 drhomagk(ngp,ngpq,igpig,igpqig,occsvp,doccsvp,apwalm,apwalmq, &
7  dapwalm,evecfv,devecfv,evecsv,devecsv)
8 use modmain
9 use modphonon
10 implicit none
11 ! arguments
12 integer, intent(in) :: ngp(nspnfv),ngpq(nspnfv)
13 integer, intent(in) :: igpig(ngkmax,nspnfv),igpqig(ngkmax,nspnfv)
14 real(8), intent(in) :: occsvp(nstsv),doccsvp(nstsv)
15 complex(8), intent(in) :: apwalm(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv)
16 complex(8), intent(in) :: apwalmq(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv)
17 complex(8), intent(in) :: dapwalm(ngkmax,apwordmax,lmmaxapw,nspnfv)
18 complex(8), intent(in) :: evecfv(nmatmax,nstfv,nspnfv)
19 complex(8), intent(in) :: devecfv(nmatmax,nstfv,nspnfv)
20 complex(8), intent(in) :: evecsv(nstsv,nstsv),devecsv(nstsv,nstsv)
21 ! local variables
22 integer nst,ist,jst
23 integer is,ias,npc
24 real(8) wo,dwo
25 ! automatic arrays
26 integer idx(nstsv)
27 ! allocatable arrays
28 complex(8), allocatable :: wfmt(:,:,:,:),wfir(:,:,:)
29 complex(8), allocatable :: dwfmt(:,:,:,:),dwfir(:,:,:)
30 ! count and index the occupied states
31 nst=0
32 do ist=1,nstsv
33  if (abs(occsvp(ist)) < epsocc) cycle
34  nst=nst+1
35  idx(nst)=ist
36 end do
37 ! generate the wavefunctions
38 allocate(wfmt(npcmtmax,natmtot,nspinor,nst),wfir(ngtc,nspinor,nst))
39 call genwfsv(.false.,.false.,nst,idx,ngdgc,igfc,ngp,igpig,apwalm,evecfv,evecsv,&
40  wfmt,ngtc,wfir)
41 ! generate the wavefunction derivatives
42 allocate(dwfmt(npcmtmax,natmtot,nspinor,nst),dwfir(ngtc,nspinor,nst))
43 call gendwfsv(.false.,.false.,nst,idx,ngp,ngpq,igpqig,apwalmq,dapwalm,evecfv, &
44  devecfv,evecsv,devecsv,dwfmt,ngtc,dwfir)
45 ! loop over occupied states
46 do ist=1,nst
47  jst=idx(ist)
48  wo=2.d0*wkptnr*occsvp(jst)
49  dwo=wkptnr*doccsvp(jst)
50 !----------------------------------------------!
51 ! muffin-tin density and magnetisation !
52 !----------------------------------------------!
53  do ias=1,natmtot
54  is=idxis(ias)
55  npc=npcmt(is)
56 !$OMP CRITICAL(drhomagk_1)
57  if (spinpol) then
58 ! spin-polarised
59  if (ncmag) then
60 ! non-collinear
61  call drmk1(npc,wo,wfmt(:,ias,1,jst),wfmt(:,ias,2,jst), &
62  dwfmt(:,ias,1,jst),dwfmt(:,ias,2,jst),drhomt(:,ias),dmagmt(:,ias,1), &
63  dmagmt(:,ias,2),dmagmt(:,ias,3))
64  if (tphq0) then
65  call drmk01(npc,dwo,wfmt(:,ias,1,jst),wfmt(:,ias,2,jst), &
66  drhomt(:,ias),dmagmt(:,ias,1),dmagmt(:,ias,2),dmagmt(:,ias,3))
67  end if
68  else
69 ! collinear
70  call drmk2(npc,wo,wfmt(:,ias,1,jst),wfmt(:,ias,2,jst), &
71  dwfmt(:,ias,1,jst),dwfmt(:,ias,2,jst),drhomt(:,ias),dmagmt(:,ias,1))
72  if (tphq0) then
73  call drmk02(npc,dwo,wfmt(:,ias,1,jst),wfmt(:,ias,2,jst), &
74  drhomt(:,ias),dmagmt(:,ias,1))
75  end if
76  end if
77  else
78 ! spin-unpolarised
79  call drmk3(npc,wo,wfmt(:,ias,1,jst),dwfmt(:,ias,1,jst),drhomt(:,ias))
80  if (tphq0) then
81  call drmk03(npc,dwo,wfmt(:,ias,1,jst),drhomt(:,ias))
82  end if
83  end if
84 !$OMP END CRITICAL(drhomagk_1)
85  end do
86 !------------------------------------------------!
87 ! interstitial density and magnetisation !
88 !------------------------------------------------!
89 !$OMP CRITICAL(drhomagk_2)
90  if (spinpol) then
91 ! spin-polarised
92  if (ncmag) then
93  call drmk1(ngtc,wo,wfir(:,1,jst),wfir(:,2,jst),dwfir(:,1,jst), &
94  dwfir(:,2,jst),drhoir,dmagir,dmagir(:,2),dmagir(:,3))
95  if (tphq0) then
96  call drmk01(ngtc,dwo,wfir(:,1,jst),wfir(:,2,jst),drhoir,dmagir, &
97  dmagir(:,2),dmagir(:,3))
98  end if
99  else
100 ! collinear
101  call drmk2(ngtc,wo,wfir(:,1,jst),wfir(:,2,jst),dwfir(:,1,jst), &
102  dwfir(:,2,jst),drhoir,dmagir)
103  if (tphq0) then
104  call drmk02(ngtc,dwo,wfir(:,1,jst),wfir(:,2,jst),drhoir,dmagir)
105  end if
106  end if
107  else
108 ! spin-unpolarised
109  call drmk3(ngtc,wo,wfir(:,1,jst),dwfir(:,1,jst),drhoir)
110  if (tphq0) then
111  call drmk03(ngtc,dwo,wfir(:,1,jst),drhoir)
112  end if
113  end if
114 !$OMP END CRITICAL(drhomagk_2)
115 ! end loop over states
116 end do
117 deallocate(wfmt,wfir,dwfmt,dwfir)
118 
119 contains
120 
121 pure subroutine drmk1(n,wo,wf1,wf2,dwf1,dwf2,drho,dmag1,dmag2,dmag3)
122 implicit none
123 ! arguments
124 integer, intent(in) :: n
125 real(8), intent(in) :: wo
126 complex(8), intent(in) :: wf1(n),wf2(n)
127 complex(8), intent(in) :: dwf1(n),dwf2(n)
128 complex(8), intent(inout) :: drho(n)
129 complex(8), intent(inout) :: dmag1(n),dmag2(n),dmag3(n)
130 ! local variables
131 integer i
132 complex(8) z1,z2,z3,z4,z5,z6
133 do i=1,n
134  z1=conjg(wf1(i))
135  z2=conjg(wf2(i))
136  z3=dwf1(i)
137  z4=dwf2(i)
138  z5=z1*z3
139  z6=z2*z4
140  drho(i)=drho(i)+wo*(z5+z6)
141  dmag3(i)=dmag3(i)+wo*(z5-z6)
142  z5=z1*z4
143  z6=z2*z3
144  dmag1(i)=dmag1(i)+wo*(z5+z6)
145  z5=z5-z6
146  dmag2(i)=dmag2(i)+wo*cmplx(z5%im,-z5%re,8)
147 end do
148 end subroutine
149 
150 pure subroutine drmk01(n,dwo,wf1,wf2,drho,dmag1,dmag2,dmag3)
151 implicit none
152 ! arguments
153 integer, intent(in) :: n
154 real(8), intent(in) :: dwo
155 complex(8), intent(in) :: wf1(n),wf2(n)
156 complex(8), intent(inout) :: drho(n)
157 complex(8), intent(inout) :: dmag1(n),dmag2(n),dmag3(n)
158 ! local variables
159 integer i
160 real(8) t1,t2
161 complex(8) z1,z2
162 do i=1,n
163  z1=wf1(i)
164  z2=wf2(i)
165  t1=z1%re**2+z1%im**2
166  t2=z2%re**2+z2%im**2
167  z1=conjg(z1)*z2
168  drho(i)=drho(i)+dwo*(t1+t2)
169  dmag1(i)=dmag1(i)+dwo*2.d0*z1%re
170  dmag2(i)=dmag2(i)+dwo*2.d0*z1%im
171  dmag3(i)=dmag3(i)+dwo*(t1-t2)
172 end do
173 end subroutine
174 
175 pure subroutine drmk2(n,wo,wf1,wf2,dwf1,dwf2,drho,dmag)
176 implicit none
177 ! arguments
178 integer, intent(in) :: n
179 real(8), intent(in) :: wo
180 complex(8), intent(in) :: wf1(n),wf2(n)
181 complex(8), intent(in) :: dwf1(n),dwf2(n)
182 complex(8), intent(inout) :: drho(n),dmag(n)
183 ! local variables
184 integer i
185 complex(8) z1,z2
186 do i=1,n
187  z1=conjg(wf1(i))*dwf1(i)
188  z2=conjg(wf2(i))*dwf2(i)
189  drho(i)=drho(i)+wo*(z1+z2)
190  dmag(i)=dmag(i)+wo*(z1-z2)
191 end do
192 end subroutine
193 
194 pure subroutine drmk02(n,dwo,wf1,wf2,drho,dmag)
195 implicit none
196 ! arguments
197 integer, intent(in) :: n
198 real(8), intent(in) :: dwo
199 complex(8), intent(in) :: wf1(n),wf2(n)
200 complex(8), intent(inout) :: drho(n),dmag(n)
201 ! local variables
202 integer i
203 real(8) t1,t2
204 do i=1,n
205  t1=dble(wf1(i))**2+aimag(wf1(i))**2
206  t2=dble(wf2(i))**2+aimag(wf2(i))**2
207  drho(i)=drho(i)+dwo*(t1+t2)
208  dmag(i)=dmag(i)+dwo*(t1-t2)
209 end do
210 end subroutine
211 
212 pure subroutine drmk3(n,wo,wf,dwf,drho)
213 implicit none
214 ! arguments
215 integer, intent(in) :: n
216 real(8), intent(in) :: wo
217 complex(8), intent(in) :: wf(n),dwf(n)
218 complex(8), intent(inout) :: drho(n)
219 drho(1:n)=drho(1:n)+wo*conjg(wf(1:n))*dwf(1:n)
220 end subroutine
221 
222 pure subroutine drmk03(n,dwo,wf,drho)
223 implicit none
224 ! arguments
225 integer, intent(in) :: n
226 real(8), intent(in) :: dwo
227 complex(8), intent(in) :: wf(n)
228 complex(8), intent(inout) :: drho(n)
229 drho(1:n)=drho(1:n)+dwo*(dble(wf(1:n))**2+aimag(wf(1:n))**2)
230 end subroutine
231 
232 end subroutine
233 
logical tphq0
Definition: modphonon.f90:17
subroutine drhomagk(ngp, ngpq, igpig, igpqig, occsvp, doccsvp, apwalm, apwalmq, dapwalm, evecfv, devecfv, evecsv, devecsv)
Definition: drhomagk.f90:8
complex(8), dimension(:,:), pointer, contiguous dmagir
Definition: modphonon.f90:102
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:214
integer npcmtmax
Definition: modmain.f90:216
subroutine genwfsv(tsh, tgp, nst, idx, ngridg_, igfft_, ngp, igpig, apwalm, evecfv, evecsv, wfmt, ld, wfir)
Definition: genwfsv.f90:11
integer ngtc
Definition: modmain.f90:392
logical spinpol
Definition: modmain.f90:228
complex(8), dimension(:,:), pointer, contiguous drhomt
Definition: modphonon.f90:100
pure subroutine drmk1(n, wo, wf1, wf2, dwf1, dwf2, drho, dmag1, dmag2, dmag3)
Definition: drhomagk.f90:122
pure subroutine drmk02(n, dwo, wf1, wf2, drho, dmag)
Definition: drhomagk.f90:195
real(8) epsocc
Definition: modmain.f90:901
pure subroutine drmk01(n, dwo, wf1, wf2, drho, dmag1, dmag2, dmag3)
Definition: drhomagk.f90:151
complex(8), dimension(:,:,:), pointer, contiguous dmagmt
Definition: modphonon.f90:102
pure subroutine drmk3(n, wo, wf, dwf, drho)
Definition: drhomagk.f90:213
integer, dimension(:), allocatable igfc
Definition: modmain.f90:410
integer nspinor
Definition: modmain.f90:267
subroutine gendwfsv(tsh, tgp, nst, idx, ngp, ngpq, igpqig, apwalmq, dapwalm, evecfv, devecfv, evecsv, devecsv, dwfmt, ld, dwfir)
Definition: gendwfsv.f90:8
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
pure subroutine drmk03(n, dwo, wf, drho)
Definition: drhomagk.f90:223
complex(8), dimension(:), pointer, contiguous drhoir
Definition: modphonon.f90:100
integer, dimension(3) ngdgc
Definition: modmain.f90:388
real(8) wkptnr
Definition: modmain.f90:477
pure subroutine drmk2(n, wo, wf1, wf2, dwf1, dwf2, drho, dmag)
Definition: drhomagk.f90:176
logical ncmag
Definition: modmain.f90:240