The Elk Code
zfpts.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2018 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 zfpts(np,vrl,zfmt,zfir,fp)
7 use modmain
8 use modomp
9 implicit none
10 ! arguments
11 integer, intent(in) :: np
12 real(8), intent(in) :: vrl(3,np)
13 complex(8), intent(in) :: zfmt(npcmtmax,natmtot),zfir(ngtot)
14 complex(8), intent(out) :: fp(np)
15 ! local variables
16 integer ip,nthd
17 ! allocatable arrays
18 complex(8), allocatable :: zfft(:)
19 ! Fourier transform zfir to G-space
20 allocate(zfft(ngtot))
21 zfft(1:ngtot)=zfir(1:ngtot)
22 call zfftifc(3,ngridg,-1,zfft)
23 ! begin loop over all points
24 call holdthd(np,nthd)
25 !$OMP PARALLEL DO DEFAULT(SHARED) &
26 !$OMP SCHEDULE(DYNAMIC) &
27 !$OMP NUM_THREADS(nthd)
28 do ip=1,np
29  call zfip(ip)
30 end do
31 !$OMP END PARALLEL DO
32 call freethd(nthd)
33 deallocate(zfft)
34 
35 contains
36 
37 subroutine zfip(ip)
38 implicit none
39 ! arguments
40 integer, intent(in) :: ip
41 ! local variables
42 integer is,ias,nrc,nrci
43 integer ir,irc,irc0,i0,j
44 integer lmax,lmmax,lm,ig
45 real(8) v(3),r,t1
46 complex(8) zsm,z1
47 ! automatic arrays
48 complex(8) ya(4,lmmaxo),ylm(lmmaxo)
49 ! check if point is in a muffin-tin
50 call findmtpt(vrl(:,ip),ias,ir,v,r)
51 if (ir > 0) then
52 ! point is inside a muffin-tin
53  is=idxis(ias)
54  nrc=nrcmt(is)
55  nrci=nrcmti(is)
56  irc=(ir-1)/lradstp+1
57  if (irc <= 3) then
58  irc0=1
59  else if (irc > nrc-2) then
60  irc0=nrc-3
61  else
62  irc0=irc-2
63  end if
64  r=max(r,rcmt(1,is))
65  if (irc0 <= nrci) then
66  lmax=lmaxi
67  lmmax=lmmaxi
68  else
69  lmax=lmaxo
70  lmmax=lmmaxo
71  end if
72  do j=1,4
73  irc=irc0+j-1
74  if (irc <= nrci) then
75  i0=lmmaxi*(irc-1)
76  else
77  i0=lmmaxi*nrci+lmmaxo*(irc-nrci-1)
78  end if
79  ya(j,1:lmmax)=zfmt(i0+1:i0+lmmax,ias)
80  end do
81 ! generate complex spherical harmonics
82  call genylmv(.false.,lmaxo,v,ylm)
83  zsm=0.d0
84  do lm=1,lmmax
85  z1=poly4(rcmt(irc0,is),ya(:,lm),r)
86  zsm=zsm+z1*ylm(lm)
87  end do
88 else
89 ! otherwise use direct Fourier transform of interstitial function
90  v(1:3)=vrl(1,ip)*avec(1:3,1)+vrl(2,ip)*avec(1:3,2)+vrl(3,ip)*avec(1:3,3)
91  zsm=0.d0
92 !$OMP SIMD PRIVATE(t1) REDUCTION(+:zsm)
93  do ig=1,ngvec
94  t1=vgc(1,ig)*v(1)+vgc(2,ig)*v(2)+vgc(3,ig)*v(3)
95  zsm=zsm+zfft(igfft(ig))*cmplx(cos(t1),sin(t1),8)
96  end do
97 end if
98 fp(ip)=zsm
99 end subroutine
100 
101 pure complex(8) function poly4(xa,ya,x)
102 implicit none
103 ! arguments
104 real(8), intent(in) :: xa(4),x
105 complex(8), intent(in) :: ya(4)
106 ! local variables
107 real(8) x0,x1,x2,x3,t0,t1,t2,t3,t4
108 complex(8) y0,y1,y2,y3,z1,z2,z3,c1,c2,c3
109 ! evaluate the polynomial coefficients
110 x0=xa(1)
111 x1=xa(2)-x0; x2=xa(3)-x0; x3=xa(4)-x0
112 t1=x1-x2; t2=x1-x3; t3=x2-x3
113 y0=ya(1)
114 y1=ya(2)-y0; y2=ya(3)-y0; y3=ya(4)-y0
115 z1=x1*x2*y3; z2=x2*x3*y1; t4=x1*x3
116 t0=1.d0/(x2*t1*t2*t3*t4)
117 z3=t4*y2
118 c3=z1*t1+z2*t3-z3*t2
119 t1=x1**2; t2=x2**2; t3=x3**2
120 c2=z1*(t2-t1)+z2*(t3-t2)+z3*(t1-t3)
121 c1=z1*(x2*t1-x1*t2)+z2*(x3*t2-x2*t3)+z3*(x1*t3-x3*t1)
122 t1=x-x0
123 ! evaluate the polynomial
124 poly4=y0+t0*t1*(c1+t1*(c2+c3*t1))
125 end function
126 
127 end subroutine
128 
real(8), dimension(:,:), allocatable rcmt
Definition: modmain.f90:177
integer, dimension(3) ngridg
Definition: modmain.f90:386
subroutine zfip(ip)
Definition: zfpts.f90:38
subroutine findmtpt(vrl, ias, ir, v, r)
Definition: findmtpt.f90:7
Definition: modomp.f90:6
integer lmaxo
Definition: modmain.f90:201
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
subroutine zfpts(np, vrl, zfmt, zfir, fp)
Definition: zfpts.f90:7
integer, dimension(:), allocatable igfft
Definition: modmain.f90:406
real(8), dimension(3, 3) avec
Definition: modmain.f90:12
integer ngvec
Definition: modmain.f90:396
integer lradstp
Definition: modmain.f90:171
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
integer lmmaxi
Definition: modmain.f90:207
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
pure real(8) function poly4(xa, ya, x)
Definition: rfpts.f90:99
integer lmaxi
Definition: modmain.f90:205