The Elk Code
cpotcoul.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2023 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 cpotcoul(nrmt_,nrmti_,npmt_,ld1,rl,ngridg_,igfft_,ngp,gpc,gclgp,ld2,&
7  jlgprmt,ylmgp,sfacgp,crhoir,ld3,cvclmt,cvclir)
8 use modmain
9 use modphonon
10 implicit none
11 ! arguments
12 integer, intent(in) :: nrmt_(nspecies),nrmti_(nspecies),npmt_(nspecies)
13 integer, intent(in) :: ld1
14 real(8), intent(in) :: rl(ld1,-lmaxo-1:lmaxo+2,nspecies)
15 integer, intent(in) :: ngridg_(3),igfft_(*),ngp
16 real(8), intent(in) :: gpc(ngp),gclgp(ngp)
17 integer, intent(in) :: ld2
18 real(8), intent(in) :: jlgprmt(0:lnpsd,ld2,nspecies)
19 complex(8), intent(in) :: ylmgp(lmmaxo,ngp),sfacgp(ld2,natmtot)
20 complex(4), intent(in) :: crhoir(*)
21 integer, intent(in) :: ld3
22 complex(4), intent(inout) :: cvclmt(ld3,natmtot)
23 complex(4), intent(out) :: cvclir(*)
24 ! local variables
25 integer is,ia,ias
26 integer nr,nri,iro
27 integer l,lm,lma,lmb
28 integer ig,jg,i,i0,i1
29 real(8) t1,t2,t3
30 complex(8) z1,z2
31 ! automatic arrays
32 real(8) rl2(0:lmaxo)
33 complex(8) qlm(lmmaxo,natmtot),zlm(lmmaxo)
34 ! external functions
35 real(8), external :: factn2
36 ! compute the multipole moments from the muffin-tin potentials
37 t1=1.d0/fourpi
38 do ias=1,natmtot
39  is=idxis(ias)
40  i=npmt_(is)-lmmaxo
41  do l=0,lmaxo
42  t2=t1*dble(2*l+1)*rmtl(l+1,is)
43  lma=l**2+1; lmb=lma+2*l
44  qlm(lma:lmb,ias)=t2*cvclmt(i+lma:i+lmb,ias)
45  end do
46 end do
47 ! Fourier transform density to G-space and store in zvclir
48 call ccopy(ngridg_(1)*ngridg_(2)*ngridg_(3),crhoir,1,cvclir,1)
49 call cfftifc(3,ngridg_,-1,cvclir)
50 ! subtract the multipole moments of the interstitial charge density
51 do is=1,nspecies
52  rl2(0:lmaxo)=rmtl(2:lmaxo+2,is)
53  t1=rl2(0)*fourpi*y00
54  do ia=1,natoms(is)
55  ias=idxas(ia,is)
56  zlm(1:lmmaxo)=0.d0
57  do ig=1,ngp
58  jg=igfft_(ig)
59  if (gpc(ig) > epslat) then
60  z1=cvclir(jg)*sfacgp(ig,ias)/gpc(ig)
61  zlm(1)=zlm(1)+jlgprmt(1,ig,is)*t1*z1
62  do l=1,lmaxo
63  lma=l**2+1; lmb=lma+2*l
64  z2=jlgprmt(l+1,ig,is)*rl2(l)*z1
65  zlm(lma:lmb)=zlm(lma:lmb)+z2*conjg(ylmgp(lma:lmb,ig))
66  end do
67  else
68  t2=(fourpi/3.d0)*rmtl(3,is)*y00
69  zlm(1)=zlm(1)+t2*cvclir(jg)
70  end if
71  end do
72  qlm(1:lmmaxo,ias)=qlm(1:lmmaxo,ias)-zlm(1:lmmaxo)
73  end do
74 end do
75 ! find the smooth pseudocharge within the muffin-tin whose multipoles are the
76 ! difference between the real muffin-tin and interstitial multipoles
77 t1=factn2(2*lnpsd+1)/omega
78 do ias=1,natmtot
79  is=idxis(ias)
80  do l=0,lmaxo
81  t2=t1/(factn2(2*l+1)*rmtl(l,is))
82  lma=l**2+1; lmb=lma+2*l
83  zlm(lma:lmb)=t2*qlm(lma:lmb,ias)
84  end do
85 ! add the pseudocharge and real interstitial densities in G-space
86  do ig=1,ngp
87  jg=igfft_(ig)
88  if (gpc(ig) > epslat) then
89  t2=gpc(ig)*rmt(is)
90  t3=1.d0/t2**lnpsd
91  z1=t3*fourpi*y00*zlm(1)
92  do l=1,lmaxo
93  lma=l**2+1; lmb=lma+2*l
94  t3=t3*t2
95  z1=z1+t3*sum(zlm(lma:lmb)*ylmgp(lma:lmb,ig))
96  end do
97  z2=jlgprmt(lnpsd,ig,is)*conjg(sfacgp(ig,ias))
98  cvclir(jg)=cvclir(jg)+z1*z2
99  else
100  t2=fourpi*y00/factn2(2*lnpsd+1)
101  cvclir(jg)=cvclir(jg)+t2*zlm(1)
102  end if
103  end do
104 end do
105 ! solve Poisson's equation in G+p-space for the pseudocharge
106 do ig=1,ngp
107  jg=igfft_(ig)
108  cvclir(jg)=gclgp(ig)*cvclir(jg)
109 end do
110 ! match potentials at muffin-tin boundary by adding homogeneous solution
111 do ias=1,natmtot
112  is=idxis(ias)
113  nr=nrmt_(is)
114  nri=nrmti_(is)
115  iro=nri+1
116 ! find the spherical harmonic expansion of the interstitial potential at the
117 ! muffin-tin radius
118  zlm(1:lmmaxo)=0.d0
119  do ig=1,ngp
120  z1=cvclir(igfft_(ig))*sfacgp(ig,ias)
121  zlm(1)=zlm(1)+jlgprmt(0,ig,is)*fourpi*y00*z1
122  do l=1,lmaxo
123  lma=l**2+1; lmb=lma+2*l
124  z2=jlgprmt(l,ig,is)*z1
125  zlm(lma:lmb)=zlm(lma:lmb)+z2*conjg(ylmgp(lma:lmb,ig))
126  end do
127  end do
128 ! add the homogenous solution
129  i=npmt_(is)-lmmaxo
130  do l=0,lmaxi
131  t1=1.d0/rmtl(l,is)
132  do lm=l**2+1,(l+1)**2
133  z1=t1*(zlm(lm)-cvclmt(i+lm,ias))
134  i1=lmmaxi*(nri-1)+lm
135  cvclmt(lm:i1:lmmaxi,ias)=cvclmt(lm:i1:lmmaxi,ias)+z1*rl(1:nri,l,is)
136  i0=i1+lmmaxi
137  i1=lmmaxo*(nr-iro)+i0
138  cvclmt(i0:i1:lmmaxo,ias)=cvclmt(i0:i1:lmmaxo,ias)+z1*rl(iro:nr,l,is)
139  end do
140  end do
141  do l=lmaxi+1,lmaxo
142  t1=1.d0/rmtl(l,is)
143  do lm=l**2+1,(l+1)**2
144  z1=t1*(zlm(lm)-cvclmt(i+lm,ias))
145  i0=lmmaxi*nri+lm
146  i1=lmmaxo*(nr-iro)+i0
147  cvclmt(i0:i1:lmmaxo,ias)=cvclmt(i0:i1:lmmaxo,ias)+z1*rl(iro:nr,l,is)
148  end do
149  end do
150 end do
151 ! Fourier transform interstitial potential to real-space
152 call cfftifc(3,ngridg_,1,cvclir)
153 end subroutine
154 
integer, dimension(maxatoms, maxspecies) idxas
Definition: modmain.f90:42
real(8) omega
Definition: modmain.f90:20
subroutine cfftifc(nd, n, sgn, c)
Definition: cfftifc_fftw.f90:7
real(8), dimension(:,:), allocatable rmtl
Definition: modmain.f90:167
real(8), dimension(maxspecies) rmt
Definition: modmain.f90:162
subroutine cpotcoul(nrmt_, nrmti_, npmt_, ld1, rl, ngridg_, igfft_, ngp, gpc, gclgp, ld2, jlgprmt, ylmgp, sfacgp, crhoir, ld3, cvclmt, cvclir)
Definition: cpotcoul.f90:8
integer, dimension(maxspecies) natoms
Definition: modmain.f90:36
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
integer lmmaxi
Definition: modmain.f90:207
real(8) epslat
Definition: modmain.f90:24
real(8), parameter fourpi
Definition: modmain.f90:1234
real(8), parameter y00
Definition: modmain.f90:1236
integer lmaxi
Definition: modmain.f90:205