The Elk Code
initulr.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2018 T. Mueller, 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 initulr
7 use modmain
8 use modulr
9 use modomp
10 implicit none
11 ! local variables
12 integer ik0,ik,ist,jst
13 integer iq,jq,ifq,ig
14 integer n,i,i1,i2,i3,nthd
15 ! allocatable arrays
16 real(8), allocatable :: jlgqr(:,:)
17 if (xctype(1) < 0) then
18  write(*,*)
19  write(*,'("Error(initulr): ultra long-range does not work with OEP")')
20  write(*,*)
21  stop
22 end if
23 if (spincore) then
24  write(*,*)
25  write(*,'("Error(initulr): ultra long-range does not work with &
26  &spin-polarised cores")')
27  write(*,*)
28  stop
29 end if
30 if (allocated(rhormt)) deallocate(rhormt)
31 allocate(rhormt(npcmtmax,natmtot,nqpt))
32 if (allocated(rhorir)) deallocate(rhorir)
33 allocate(rhorir(ngtc,nqpt))
34 if (allocated(magrmt)) deallocate(magrmt)
35 if (allocated(magrir)) deallocate(magrir)
36 if (spinpol) then
37  allocate(magrmt(npcmtmax,natmtot,ndmag,nqpt))
38  allocate(magrir(ngtc,ndmag,nqpt))
39 else
40  allocate(magrmt(1,1,1,1))
41  allocate(magrir(1,1,1))
42 end if
43 if (allocated(rhoqmt)) deallocate(rhoqmt)
44 allocate(rhoqmt(npcmtmax,natmtot,nfqrz))
45 if (allocated(rhoqir)) deallocate(rhoqir)
46 allocate(rhoqir(ngtc,nfqrz))
47 if (allocated(chgmtru)) deallocate(chgmtru)
48 allocate(chgmtru(natmtot,nqpt))
49 if (allocated(chgirru)) deallocate(chgirru)
50 allocate(chgirru(nqpt))
51 if (allocated(chgtotru)) deallocate(chgtotru)
52 allocate(chgtotru(nqpt))
53 if (allocated(chgmtqu)) deallocate(chgmtqu)
54 allocate(chgmtqu(natmtot,nfqrz))
55 if (allocated(chgirqu)) deallocate(chgirqu)
56 allocate(chgirqu(nfqrz))
57 if (allocated(chgtotqu)) deallocate(chgtotqu)
58 allocate(chgtotqu(nfqrz))
59 if (allocated(magqmt)) deallocate(magqmt)
60 if (allocated(magqir)) deallocate(magqir)
61 if (allocated(mommtru)) deallocate(mommtru)
62 if (allocated(momirru)) deallocate(momirru)
63 if (allocated(momtotru)) deallocate(momtotru)
64 if (allocated(mommtqu)) deallocate(mommtqu)
65 if (allocated(momirqu)) deallocate(momirqu)
66 if (allocated(momtotqu)) deallocate(momtotqu)
67 if (spinpol) then
68  allocate(magqmt(npcmtmax,natmtot,ndmag,nfqrz))
69  allocate(magqir(ngtc,ndmag,nfqrz))
70  allocate(mommtru(ndmag,natmtot,nqpt))
71  allocate(momirru(ndmag,nqpt))
72  allocate(momtotru(ndmag,nqpt))
73  allocate(mommtqu(ndmag,natmtot,nfqrz))
74  allocate(momirqu(ndmag,nfqrz))
75  allocate(momtotqu(ndmag,nfqrz))
76 end if
77 ! allocate Q-dependent potential and magnetic field arrays
78 if (allocated(vclq)) deallocate(vclq)
79 allocate(vclq(nfqrz))
80 if (allocated(bfcq)) deallocate(bfcq)
81 if (allocated(bfcmtq)) deallocate(bfcmtq)
82 if (allocated(bdipq)) deallocate(bdipq)
83 if (spinpol) then
84  allocate(bfcq(ndmag,nfqrz))
85  allocate(bfcmtq(natmtot,ndmag,nfqrz))
86  if (tbdipu) allocate(bdipq(ndmag,nfqrz))
87 end if
88 ! combined target array for Kohn-Sham potential and magnetic field
89 if (allocated(vsbsq)) deallocate(vsbsq)
91 if (spinpol) n=n*(1+ndmag)
92 allocate(vsbsq(n))
93 ! zero the array
94 vsbsq(1:n)=0.d0
95 ! associate pointer arrays with target
96 vsqmt(1:npcmtmax,1:natmtot,1:nfqrz) => vsbsq(1:)
97 i=size(vsqmt)+1
98 vsqir(1:ngtot,1:nfqrz) => vsbsq(i:)
99 if (spinpol) then
100  i=i+size(vsqir)
101  bsqmt(1:npcmtmax,1:natmtot,1:ndmag,1:nfqrz) => vsbsq(i:)
102  i=i+size(bsqmt)
103  bsqir(1:ngtot,1:ndmag,1:nfqrz) => vsbsq(i:)
104 end if
105 ! generate the Coulomb Green's function in Q-space with small Q cut-off
106 if (allocated(gclq)) deallocate(gclq)
107 allocate(gclq(nqpt))
108 call gengclqu
109 ! G+Q-vector arrays
110 if (allocated(vgqc)) deallocate(vgqc)
111 allocate(vgqc(3,ngvec,nfqrz))
112 if (allocated(gqc)) deallocate(gqc)
113 allocate(gqc(ngvec,nfqrz))
114 if (allocated(ylmgq)) deallocate(ylmgq)
115 allocate(ylmgq(lmmaxo,ngvec,nfqrz))
116 if (allocated(sfacgq)) deallocate(sfacgq)
117 allocate(sfacgq(ngvec,natmtot,nfqrz))
118 if (allocated(gclgq)) deallocate(gclgq)
119 allocate(gclgq(ngvec,nfqrz))
120 if (allocated(jlgqrmt)) deallocate(jlgqrmt)
121 allocate(jlgqrmt(0:lnpsd,ngvec,nspecies,nfqrz))
122 if (allocated(expqmt)) deallocate(expqmt)
123 allocate(expqmt(npcmtmax,natmtot,nqpt))
124 call holdthd(nfqrz,nthd)
125 !$OMP PARALLEL DEFAULT(SHARED) &
126 !$OMP PRIVATE(jlgqr,iq,ig) &
127 !$OMP PRIVATE(i1,i2,i3,jq) &
128 !$OMP NUM_THREADS(nthd)
129 allocate(jlgqr(njcmax,nspecies))
130 !$OMP DO SCHEDULE(DYNAMIC)
131 do ifq=1,nfqrz
132  iq=iqrzf(ifq)
133  do ig=1,ngvec
134 ! determine the G+Q-vectors
135  vgqc(1:3,ig,ifq)=vgc(1:3,ig)+vqc(1:3,iq)
136 ! G+Q-vector length
137  gqc(ig,ifq)=sqrt(vgqc(1,ig,ifq)**2+vgqc(2,ig,ifq)**2+vgqc(3,ig,ifq)**2)
138 ! spherical harmonics for G+Q-vectors
139  call genylmv(.true.,lmaxo,vgqc(:,ig,ifq),ylmgq(:,ig,ifq))
140  end do
141 ! generate the spherical Bessel functions j_l(|G+Q|r)
142  call genjlgpr(1,gqc(1,ifq),jlgqr)
143 ! structure factors for G+Q-vectors
144  call gensfacgp(ngvec,vgqc(:,:,ifq),ngvec,sfacgq(:,:,ifq))
145 ! generate the Coulomb Green's function in G+Q-space
146  call gengclgq(.true.,iq,ngvec,gqc(:,ifq),gclgq(:,ifq))
147 ! compute the spherical Bessel functions j_l(|G+Q|R_mt)
148  call genjlgprmt(lnpsd,ngvec,gqc(:,ifq),ngvec,jlgqrmt(:,:,:,ifq))
149 ! generate phase factor functions exp(iQ⋅r) in each muffin-tin
150  call genexpmt(1,jlgqr,ylmgq(:,:,ifq),ngvec,sfacgq(:,:,ifq),expqmt(:,:,iq))
151 ! store the phase factor function for -Q
152  i1=-ivq(1,iq); i2=-ivq(2,iq); i3=-ivq(3,iq)
153  if ((i1 >= intq(1,1)).and.(i1 <= intq(2,1)).and. &
154  (i2 >= intq(1,2)).and.(i2 <= intq(2,2)).and. &
155  (i3 >= intq(1,3)).and.(i3 <= intq(2,3)).and.(ifq > 1)) then
156  jq=ivqiq(i1,i2,i3)
157  expqmt(:,:,jq)=conjg(expqmt(:,:,iq))
158  end if
159 end do
160 !$OMP END DO
161 deallocate(jlgqr)
162 !$OMP END PARALLEL
163 call freethd(nthd)
164 ! number of long-range states
166 ! allocate eigenvalue array
167 if (allocated(evalu)) deallocate(evalu)
168 allocate(evalu(nstulr,nkpt0))
169 ! allocate the occupation number array
170 if (allocated(occulr)) deallocate(occulr)
171 allocate(occulr(nstulr,nkpt0))
172 ! initialise the occupation numbers if required
173 if (any(task == [700,701])) then
174 block
175  integer idx(nstulr)
176  do ik0=1,nkpt0
177  ik=(ik0-1)*nkpa+1
178  call sortidx(nstulr,occsv(1,ik),idx)
179  do ist=1,nstulr
180  i=idx(nstulr-ist+1)-1
181  ik=(ik0-1)*nkpa+i/nstsv+1
182  jst=mod(i,nstsv)+1
183  occulr(ist,ik0)=occsv(jst,ik)
184  end do
185  end do
186 end block
187 end if
188 ! zero the timing variables
189 timemat=0.d0
190 timesv=0.d0
191 timerho=0.d0
192 timepot=0.d0
193 end subroutine
194 
complex(8), dimension(:,:,:), pointer, contiguous vsqmt
Definition: modulr.f90:86
complex(8), dimension(:,:,:), allocatable sfacgq
Definition: modulr.f90:44
real(8), dimension(:,:,:,:), allocatable jlgqrmt
Definition: modulr.f90:40
integer npcmtmax
Definition: modmain.f90:218
pure subroutine gensfacgp(ngp, vgpc, ld, sfacgp)
Definition: gensfacgp.f90:10
integer task
Definition: modmain.f90:1299
complex(8), dimension(:,:,:), allocatable mommtqu
Definition: modulr.f90:63
integer ngtot
Definition: modmain.f90:393
integer lmmaxo
Definition: modmain.f90:205
integer, dimension(3) xctype
Definition: modmain.f90:591
integer ngtc
Definition: modmain.f90:395
logical spinpol
Definition: modmain.f90:230
integer nqpt
Definition: modmain.f90:528
complex(8), dimension(:,:), pointer, contiguous vsqir
Definition: modulr.f90:86
integer nstulr
Definition: modulr.f90:97
integer ndmag
Definition: modmain.f90:240
integer, dimension(:,:), allocatable ivq
Definition: modmain.f90:532
complex(8), dimension(:,:), allocatable bdipq
Definition: modulr.f90:83
Definition: modomp.f90:6
integer nkpt0
Definition: modulr.f90:18
complex(8), dimension(:), allocatable chgirqu
Definition: modulr.f90:62
integer, dimension(:), allocatable iqrzf
Definition: modmain.f90:546
integer lmaxo
Definition: modmain.f90:203
complex(8), dimension(:,:), allocatable chgmtqu
Definition: modulr.f90:62
complex(8), dimension(:,:,:,:), allocatable magqmt
Definition: modulr.f90:60
complex(8), dimension(:,:,:), pointer, contiguous bsqir
Definition: modulr.f90:87
pure subroutine genylmv(t4pil, lmax, v, ylm)
Definition: genylmv.f90:10
complex(8), dimension(:,:,:), allocatable magqir
Definition: modulr.f90:60
subroutine gengclqu
Definition: gengclqu.f90:7
real(8), dimension(:,:), allocatable chgmtru
Definition: modulr.f90:55
real(8), dimension(:,:), allocatable vgc
Definition: modmain.f90:423
real(8), dimension(:,:), allocatable momirru
Definition: modulr.f90:57
pure subroutine gengclgq(treg, iq, ngq, gqc, gclgq)
Definition: gengclgq.f90:7
integer nstsv
Definition: modmain.f90:885
real(8), dimension(:,:), allocatable vqc
Definition: modmain.f90:550
complex(8), dimension(:), allocatable vclq
Definition: modulr.f90:68
real(8), dimension(:,:), allocatable rhorir
Definition: modulr.f90:52
real(8), dimension(:,:,:), allocatable rhormt
Definition: modulr.f90:52
real(8), dimension(:,:), allocatable occulr
Definition: modulr.f90:101
integer ngvec
Definition: modmain.f90:399
real(8), dimension(:,:), allocatable occsv
Definition: modmain.f90:901
complex(8), dimension(:,:,:), allocatable ylmgq
Definition: modulr.f90:42
pure subroutine sortidx(n, x, idx)
Definition: sortidx.f90:10
real(8), dimension(:,:,:), allocatable vgqc
Definition: modulr.f90:34
integer, dimension(:,:,:), allocatable ivqiq
Definition: modmain.f90:534
subroutine genexpmt(ngp, jlgpr, ylmgp, ld, sfacgp, expmt)
Definition: genexpmt.f90:7
complex(8), dimension(:,:,:,:), pointer, contiguous bsqmt
Definition: modulr.f90:87
real(8), dimension(:,:), allocatable gqc
Definition: modulr.f90:36
integer nfqrz
Definition: modmain.f90:542
integer, dimension(2, 3) intq
Definition: modmain.f90:520
complex(8), dimension(:,:,:), allocatable bfcmtq
Definition: modulr.f90:75
subroutine genjlgpr(ngp, gpc, jlgpr)
Definition: genjlgpr.f90:7
real(8), dimension(:), allocatable gclq
Definition: modmain.f90:558
complex(8), dimension(:,:,:), allocatable rhoqmt
Definition: modulr.f90:59
integer lnpsd
Definition: modmain.f90:631
real(8), dimension(:,:,:), allocatable mommtru
Definition: modulr.f90:57
complex(8), dimension(:,:), allocatable bfcq
Definition: modulr.f90:73
integer nspecies
Definition: modmain.f90:34
subroutine freethd(nthd)
Definition: modomp.f90:112
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
subroutine genjlgprmt(lmax, ngp, gpc, ld, jlgprmt)
Definition: genjlgprmt.f90:10
integer njcmax
Definition: modmain.f90:1173
real(8), dimension(:,:,:,:), allocatable magrmt
Definition: modulr.f90:53
complex(8), dimension(:,:), allocatable momirqu
Definition: modulr.f90:63
real(8), dimension(:,:,:), allocatable magrir
Definition: modulr.f90:53
integer natmtot
Definition: modmain.f90:40
real(8), dimension(:,:), allocatable gclgq
Definition: modulr.f90:38
Definition: modulr.f90:6
real(8), dimension(:), allocatable chgtotru
Definition: modulr.f90:55
real(8), dimension(:), allocatable chgirru
Definition: modulr.f90:55
integer nkpa
Definition: modulr.f90:24
complex(8), dimension(:), allocatable, target vsbsq
Definition: modulr.f90:85
complex(8), dimension(:,:), allocatable momtotqu
Definition: modulr.f90:63
real(8), dimension(:,:), allocatable evalu
Definition: modulr.f90:99
complex(8), dimension(:,:,:), allocatable expqmt
Definition: modulr.f90:46
real(8), dimension(:,:), allocatable momtotru
Definition: modulr.f90:57
logical spincore
Definition: modmain.f90:937
subroutine initulr
Definition: initulr.f90:7
complex(8), dimension(:), allocatable chgtotqu
Definition: modulr.f90:62
logical tbdipu
Definition: modulr.f90:81
complex(8), dimension(:,:), allocatable rhoqir
Definition: modulr.f90:59