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