The Elk Code
zftrf.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2010 Alexey I. Baranov.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 !BOP
7 ! !ROUTINE: zftrf
8 ! !INTERFACE:
9 subroutine zftrf(npv,ivp,vpc,rfmt,rfir,zfp)
10 ! !USES:
11 use modmain
12 ! !INPUT/OUTPUT PARAMETERS:
13 ! npv : number of P-vectors (in,integer)
14 ! ivp : integer coordinates of the P-vectors (in,integer(3,npv))
15 ! vpc : P-vectors in Cartesian coordinates (in,real(3,npv))
16 ! rfmt : real muffin-tin function (in,real(npmtmax,natmtot))
17 ! rfir : real interstitial function (in,real(ngtot))
18 ! zfp : Fourier expansion coefficients of the real-space function
19 ! (out,complex(npv))
20 ! !DESCRIPTION:
21 ! Given a real function periodic in the unit cell, $f({\bf r})$, this routine
22 ! calculates its complex Fourier expansion coefficients:
23 ! $$ f({\bf P})=\frac{1}{\Omega}\int d^3r\,f({\bf r})\tilde{\Theta}({\bf r})
24 ! e^{-i{\bf P}\cdot{\bf r}}
25 ! +\frac{4\pi}{\Omega}\sum_{\alpha}e^{-i{\bf P}\cdot{\bf R}_{\alpha}}
26 ! \sum_{lm}(-i)^l Y_{lm}(\hat{\bf P})
27 ! \int_{0}^{R_{\alpha}}dr\,r^2 j_{l}(|{\bf P}|r)f_{lm}^{\alpha}(r), $$
28 ! where $\tilde{\Theta}$ is the smooth characteristic function of the
29 ! interstitial region, $\Omega$ is the unit cell volume and $R_{\alpha}$ is
30 ! the muffin-tin radius of atom $\alpha$.
31 !
32 ! !REVISION HISTORY:
33 ! Created July 2010 (Alexey I. Baranov)
34 ! Modified, November 2010 (JKD)
35 ! Optimised, May 2024 (JKD)
36 !EOP
37 !BOC
38 implicit none
39 ! arguments
40 integer, intent(in) :: npv,ivp(3,npv)
41 real(8), intent(in) :: vpc(3,npv),rfmt(npmtmax,natmtot),rfir(ngtot)
42 complex(8), intent(out) :: zfp(npv)
43 ! local variables
44 integer is,ia,ias,ip,ig,ifg
45 integer nrc,nrci,irco,irc
46 integer l,lm,n,i
47 real(8) p,t0,t1
48 complex(8) zsm,z1,z2
49 ! automatic arrays
50 real(8) jl(0:lmaxo,nrcmtmax),rfmt1(npcmtmax)
51 complex(8) ylm(lmmaxo)
52 ! allocatable arrays
53 complex(8), allocatable :: zfft(:),zfmt(:,:)
54 allocate(zfft(ngtot),zfmt(npcmtmax,natmtot))
55 ! zero the coefficients
56 zfp(1:npv)=0.d0
57 !---------------------------!
58 ! interstitial part !
59 !---------------------------!
60 ! Fourier transform to G-space
61 zfft(1:ngtot)=rfir(1:ngtot)
62 call zfftifc(3,ngridg,-1,zfft)
63 ! find coefficients for all required input vectors
64 do ip=1,npv
65  if ((ivp(1,ip) < intgv(1,1)).or.(ivp(1,ip) > intgv(2,1)).or. &
66  (ivp(2,ip) < intgv(1,2)).or.(ivp(2,ip) > intgv(2,2)).or. &
67  (ivp(3,ip) < intgv(1,3)).or.(ivp(3,ip) > intgv(2,3))) cycle
68  ig=ivgig(ivp(1,ip),ivp(2,ip),ivp(3,ip))
69  zfp(ip)=zfft(igfft(ig))
70 end do
71 !-------------------------!
72 ! muffin-tin part !
73 !-------------------------!
74 ! convert function from real to complex spherical harmonic expansion on coarse
75 ! radial mesh
76 do ias=1,natmtot
77  is=idxis(ias)
78  nrc=nrcmt(is)
79  nrci=nrcmti(is)
80  call rfmtftoc(nrc,nrci,rfmt(:,ias),rfmt1)
81  call rtozfmt(nrc,nrci,rfmt1,zfmt(:,ias))
82 end do
83 ! remove continuation of interstitial function into muffin-tin
84 do ig=1,ngvec
85  ifg=igfft(ig)
86 ! conjugate spherical harmonics 4π iˡ Yₗₘ(G)*
87  call genylmv(.true.,lmaxo,vgc(:,ig),ylm)
88  ylm(1:lmmaxo)=conjg(ylm(1:lmmaxo))
89  do is=1,nspecies
90  nrc=nrcmt(is)
91  nrci=nrcmti(is)
92  irco=nrci+1
93 ! generate spherical Bessel functions
94  do irc=1,nrci
95  t1=gc(ig)*rcmt(irc,is)
96  call sbessel(lmaxi,t1,jl(:,irc))
97  end do
98  do irc=irco,nrc
99  t1=gc(ig)*rcmt(irc,is)
100  call sbessel(lmaxo,t1,jl(:,irc))
101  end do
102  do ia=1,natoms(is)
103  ias=idxas(ia,is)
104 ! structure factor
105  t1=vgc(1,ig)*atposc(1,ia,is) &
106  +vgc(2,ig)*atposc(2,ia,is) &
107  +vgc(3,ig)*atposc(3,ia,is)
108  z1=zfft(ifg)*cmplx(cos(t1),sin(t1),8)
109  i=1
110  do irc=1,nrci
111  do l=0,lmaxi
112  n=2*l
113  lm=l**2+1
114  z2=z1*jl(l,irc)
115  zfmt(i:i+n,ias)=zfmt(i:i+n,ias)-z2*ylm(lm:lm+n)
116  i=i+n+1
117  end do
118  end do
119  do irc=irco,nrc
120  do l=0,lmaxo
121  n=2*l
122  lm=l**2+1
123  z2=z1*jl(l,irc)
124  zfmt(i:i+n,ias)=zfmt(i:i+n,ias)-z2*ylm(lm:lm+n)
125  i=i+n+1
126  end do
127  end do
128  end do
129  end do
130 end do
131 t0=1.d0/omega
132 ! loop over input P-vectors
133 do ip=1,npv
134 ! length of P-vector
135  p=sqrt(vpc(1,ip)**2+vpc(2,ip)**2+vpc(3,ip)**2)
136 ! spherical harmonics 4π (-i)ˡ Yₗₘ(P)
137  call genylmv(.true.,lmaxo,vpc(:,ip),ylm)
138  do is=1,nspecies
139  nrc=nrcmt(is)
140  nrci=nrcmti(is)
141  irco=nrci+1
142 ! generate spherical Bessel functions
143  do irc=1,nrci
144  t1=p*rcmt(irc,is)
145  call sbessel(lmaxi,t1,jl(:,irc))
146  end do
147  do irc=irco,nrc
148  t1=p*rcmt(irc,is)
149  call sbessel(lmaxo,t1,jl(:,irc))
150  end do
151  do ia=1,natoms(is)
152  ias=idxas(ia,is)
153  zsm=0.d0
154  i=1
155  do irc=1,nrci
156  z1=jl(0,irc)*zfmt(i,ias)*ylm(1)
157  i=i+1
158  do l=1,lmaxi
159  n=2*l
160  lm=l**2+1
161  z1=z1+jl(l,irc)*sum(zfmt(i:i+n,ias)*ylm(lm:lm+n))
162  i=i+n+1
163  end do
164  zsm=zsm+wr2cmt(irc,is)*z1
165  end do
166  do irc=irco,nrc
167  z1=jl(0,irc)*zfmt(i,ias)*ylm(1)
168  i=i+1
169  do l=1,lmaxo
170  n=2*l
171  lm=l**2+1
172  z1=z1+jl(l,irc)*sum(zfmt(i:i+n,ias)*ylm(lm:lm+n))
173  i=i+n+1
174  end do
175  zsm=zsm+wr2cmt(irc,is)*z1
176  end do
177 ! conjugate structure factor
178  t1=vpc(1,ip)*atposc(1,ia,is) &
179  +vpc(2,ip)*atposc(2,ia,is) &
180  +vpc(3,ip)*atposc(3,ia,is)
181  z1=t0*cmplx(cos(t1),-sin(t1),8)
182  zfp(ip)=zfp(ip)+z1*zsm
183  end do
184  end do
185 end do
186 deallocate(zfft,zfmt)
187 end subroutine
188 ! EOC
189 
real(8), dimension(:,:), allocatable rcmt
Definition: modmain.f90:177
subroutine sbessel(lmax, x, jl)
Definition: sbessel.f90:10
integer, dimension(3) ngridg
Definition: modmain.f90:386
integer, dimension(maxatoms, maxspecies) idxas
Definition: modmain.f90:42
integer, dimension(:,:,:), allocatable ivgig
Definition: modmain.f90:402
real(8) omega
Definition: modmain.f90:20
pure subroutine rtozfmt(nr, nri, rfmt, zfmt)
Definition: rtozfmt.f90:7
pure subroutine genylmv(t4pil, lmax, v, ylm)
Definition: genylmv.f90:10
real(8), dimension(:,:), allocatable vgc
Definition: modmain.f90:420
subroutine zfftifc(nd, n, sgn, z)
Definition: zfftifc_fftw.f90:7
integer, dimension(:), allocatable igfft
Definition: modmain.f90:406
integer ngvec
Definition: modmain.f90:396
subroutine zftrf(npv, ivp, vpc, rfmt, rfir, zfp)
Definition: zftrf.f90:10
integer, dimension(maxspecies) natoms
Definition: modmain.f90:36
integer, dimension(2, 3) intgv
Definition: modmain.f90:394
real(8), dimension(:,:), allocatable wr2cmt
Definition: modmain.f90:189
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
real(8), dimension(:), allocatable gc
Definition: modmain.f90:422
integer nspecies
Definition: modmain.f90:34
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
pure subroutine rfmtftoc(nrc, nrci, rfmt, rfcmt)
Definition: rfmtftoc.f90:7
real(8), dimension(3, maxatoms, maxspecies) atposc
Definition: modmain.f90:54
integer lmaxi
Definition: modmain.f90:205