The Elk Code
init4.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2012 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 init4
7 use modmain
8 use modphonon
9 use modpw
10 use modvars
11 implicit none
12 ! local variables
13 integer ik,jspn,n,i
14 integer l1,l2,l3,m1,m2,m3
15 integer lm1,lm2,lm3
16 real(8) vl(3),vc(3)
17 ! external functions
18 real(8), external :: gaunt
19 
20 !---------------------------!
21 ! H+k-vector arrays !
22 !---------------------------!
23 if (any(task == [135,170,171,172,173])) then
24  if (task == 135) hkmax=0.5d0*gmaxvr-epslat
26 ! allocate the H+k-vector arrays
27  if (allocated(nhk)) deallocate(nhk)
28  allocate(nhk(nspnfv,nkpt))
29  if (allocated(ihkig)) deallocate(ihkig)
30  allocate(ihkig(nhkmax,nspnfv,nkpt))
31  if (allocated(vhkl)) deallocate(vhkl)
32  allocate(vhkl(3,nhkmax,nspnfv,nkpt))
33  if (allocated(vhkc)) deallocate(vhkc)
34  allocate(vhkc(3,nhkmax,nspnfv,nkpt))
35  if (allocated(hkc)) deallocate(hkc)
36  allocate(hkc(nhkmax,nspnfv,nkpt))
37  if (allocated(sfachk)) deallocate(sfachk)
38  allocate(sfachk(nhkmax,natmtot,nspnfv,nkpt))
39 ! initialise H+k-vectors arrays
40  do ik=1,nkpt
41  do jspn=1,nspnfv
42  vl(:)=vkl(:,ik)
43  vc(:)=vkc(:,ik)
44 ! spin-spiral case
45  if (spinsprl) then
46  if (jspn == 1) then
47  vl(:)=vl(:)+0.5d0*vqlss(:)
48  vc(:)=vc(:)+0.5d0*vqcss(:)
49  else
50  vl(:)=vl(:)-0.5d0*vqlss(:)
51  vc(:)=vc(:)-0.5d0*vqcss(:)
52  end if
53  end if
54 ! generate the H+k-vectors
55  call gengkvec(ngvec,ivg,vgc,vl,vc,hkmax,nhkmax,nhk(jspn,ik), &
56  ihkig(:,jspn,ik),vhkl(:,:,jspn,ik),vhkc(:,:,jspn,ik),hkc(:,jspn,ik))
57 ! generate structure factors for H+k-vectors
58  call gensfacgp(nhk(jspn,ik),vhkc(:,:,jspn,ik),nhkmax,sfachk(:,:,jspn,ik))
59  end do
60  end do
61 ! write to VARIABLES.OUT
62  if (wrtvars) then
63  call writevars('hkmax',rv=hkmax)
64  call writevars('nhk',nv=nspnfv*nkpt,iva=nhk)
65  do ik=1,nkpt
66  do jspn=1,nspnfv
67  call writevars('ihkig',n1=jspn,n2=ik,nv=nhk(jspn,ik), &
68  iva=ihkig(:,jspn,ik))
69  end do
70  end do
71  end if
72 end if
73 
74 !-----------------------------!
75 ! G+k+q-vector arrays !
76 !-----------------------------!
77 if (task == 205) then
78  if (allocated(vkql)) deallocate(vkql)
79  allocate(vkql(3,nkptnr))
80  if (allocated(vkqc)) deallocate(vkqc)
81  allocate(vkqc(3,nkptnr))
82  if (allocated(ngkq)) deallocate(ngkq)
83  allocate(ngkq(nspnfv,nkptnr))
84  if (allocated(igkqig)) deallocate(igkqig)
85  allocate(igkqig(ngkmax,nspnfv,nkptnr))
86  if (allocated(vgkql)) deallocate(vgkql)
87  allocate(vgkql(3,ngkmax,nspnfv,nkptnr))
88  if (allocated(vgkqc)) deallocate(vgkqc)
89  allocate(vgkqc(3,ngkmax,nspnfv,nkptnr))
90  if (allocated(gkqc)) deallocate(gkqc)
91  allocate(gkqc(ngkmax,nspnfv,nkptnr))
92  if (allocated(sfacgkq)) deallocate(sfacgkq)
94 end if
95 
96 !---------------------------!
97 ! G+q-vector arrays !
98 !---------------------------!
99 if (task == 205) then
100  if (allocated(vgqc)) deallocate(vgqc)
101  allocate(vgqc(3,ngvec))
102  if (allocated(gqc)) deallocate(gqc)
103  allocate(gqc(ngvec))
104  if (allocated(gclgq)) deallocate(gclgq)
105  allocate(gclgq(ngvec))
106  if (allocated(jlgqrmt)) deallocate(jlgqrmt)
107  allocate(jlgqrmt(0:lnpsd,ngvec,nspecies))
108  if (allocated(ylmgq)) deallocate(ylmgq)
109  allocate(ylmgq(lmmaxo,ngvec))
110  if (allocated(sfacgq)) deallocate(sfacgq)
111  allocate(sfacgq(ngvec,natmtot))
112  if (allocated(ffacgq)) deallocate(ffacgq)
113  allocate(ffacgq(ngvec,nspecies))
114  if (allocated(dcfunig)) deallocate(dcfunig)
115  allocate(dcfunig(ngvec))
116  if (allocated(dcfunir)) deallocate(dcfunir)
117  allocate(dcfunir(ngtot))
118 end if
119 
120 !-----------------------------------------------------------------!
121 ! phonon density functional perturbation theory variables !
122 !-----------------------------------------------------------------!
123 if (task == 205) then
124  if (allocated(drhmg)) deallocate(drhmg)
125  n=npmtmax*(natmtot+1)+ngtot
126  if (spinpol) n=n*(1+ndmag)
127  allocate(drhmg(n))
128  drhomt(1:npmtmax,1:natmtot+1) => drhmg(1:)
129  i=size(drhomt)+1
130  drhoir(1:ngtot) => drhmg(i:)
131  if (spinpol) then
132  i=i+size(drhoir)
133  dmagmt(1:npmtmax,1:natmtot+1,1:ndmag) => drhmg(i:)
134  i=i+size(dmagmt)
135  dmagir(1:ngtot,1:ndmag) => drhmg(i:)
136  end if
137  if (allocated(dvclmt)) deallocate(dvclmt)
138  allocate(dvclmt(npmtmax,natmtot))
139  if (allocated(dvclir)) deallocate(dvclir)
140  allocate(dvclir(ngtot))
141  if (allocated(gvsmt)) deallocate(gvsmt)
142  allocate(gvsmt(npmtmax))
143 ! combined target array for Kohn-Sham potential and magnetic field derivative
144  if (allocated(dvsbs)) deallocate(dvsbs)
146  if (spinpol) n=n+(npcmtmax*natmtot+ngtot)*ndmag
147  allocate(dvsbs(n))
148 ! zero the array
149  dvsbs(:)=0.d0
150 ! associate pointer arrays with target
151  dvsmt(1:npmtmax,1:natmtot) => dvsbs(1:)
152  i=size(dvsmt)+1
153  dvsig(1:ngvc) => dvsbs(i:)
154  if (spinpol) then
155  i=i+size(dvsig)
156  dbsmt(1:npcmtmax,1:natmtot,1:ndmag) => dvsbs(i:)
157  i=i+size(dbsmt)
158  dbsir(1:ngtot,1:ndmag) => dvsbs(i:)
159  end if
160  if (allocated(dvsir)) deallocate(dvsir)
161  allocate(dvsir(ngtot))
162  if (allocated(dsocfr)) deallocate(dsocfr)
163  if (spinorb) then
164  allocate(dsocfr(nrcmtmax,natmtot))
165  end if
166  if (allocated(dhaa)) deallocate(dhaa)
168  if (allocated(dhloa)) deallocate(dhloa)
170  if (allocated(dhlolo)) deallocate(dhlolo)
171  allocate(dhlolo(lmmaxo,nlomax,nlomax,natmtot))
172 ! allocate and generate real Gaunt coefficient array
173  if (allocated(gntyyy)) deallocate(gntyyy)
174  allocate(gntyyy(lmmaxo,lmmaxapw,lmmaxapw))
175  do l1=0,lmaxapw
176  do m1=-l1,l1
177  lm1=l1*(l1+1)+m1+1
178  do l3=0,lmaxapw
179  do m3=-l3,l3
180  lm3=l3*(l3+1)+m3+1
181  do l2=0,lmaxo
182  do m2=-l2,l2
183  lm2=l2*(l2+1)+m2+1
184  gntyyy(lm2,lm3,lm1)=gaunt(l1,l2,l3,m1,m2,m3)
185  end do
186  end do
187  end do
188  end do
189  end do
190  end do
191  if (allocated(devalfv)) deallocate(devalfv)
192  allocate(devalfv(nstfv,nspnfv,nkptnr))
193  if (allocated(devalsv)) deallocate(devalsv)
194  allocate(devalsv(nstsv,nkptnr))
195  if (allocated(doccsv)) deallocate(doccsv)
196  allocate(doccsv(nstsv,nkptnr))
197 end if
198 
199 end subroutine
200 
complex(8), dimension(:,:), pointer, contiguous dmagir
Definition: modphonon.f90:102
real(8), dimension(:,:,:,:), allocatable vhkc
Definition: modpw.f90:48
integer npcmtmax
Definition: modmain.f90:216
pure subroutine gensfacgp(ngp, vgpc, ld, sfacgp)
Definition: gensfacgp.f90:10
integer task
Definition: modmain.f90:1299
real(8), dimension(:,:,:), allocatable jlgqrmt
Definition: modphonon.f90:68
integer ngtot
Definition: modmain.f90:390
integer lmmaxo
Definition: modmain.f90:203
logical spinpol
Definition: modmain.f90:228
complex(8), dimension(:,:), pointer, contiguous drhomt
Definition: modphonon.f90:100
integer lmmaxapw
Definition: modmain.f90:199
integer nkpt
Definition: modmain.f90:461
complex(8), dimension(:,:), allocatable dvclmt
Definition: modphonon.f90:104
real(8), dimension(:,:,:), allocatable gkqc
Definition: modphonon.f90:90
complex(8), dimension(:), allocatable dvsir
Definition: modphonon.f90:112
integer ndmag
Definition: modmain.f90:238
complex(8), dimension(:), allocatable dcfunir
Definition: modphonon.f90:78
integer ngkmax
Definition: modmain.f90:499
pure subroutine findngkmax(nkpt, vkc, nspnfv, vqcss, ngv, vgc, gkmax, ngkmax)
Definition: findngkmax.f90:10
logical spinsprl
Definition: modmain.f90:283
real(8), dimension(:,:), allocatable vkqc
Definition: modphonon.f90:56
complex(8), dimension(:,:,:), pointer, contiguous dbsmt
Definition: modphonon.f90:116
integer, dimension(:,:,:), allocatable ihkig
Definition: modpw.f90:44
real(8), dimension(:,:), allocatable devalsv
Definition: modphonon.f90:134
integer lmaxo
Definition: modmain.f90:201
real(8), dimension(3) vqlss
Definition: modmain.f90:293
complex(8), dimension(:), allocatable gvsmt
Definition: modphonon.f90:106
complex(8), dimension(:,:,:,:,:), allocatable dhloa
Definition: modphonon.f90:122
integer nkptnr
Definition: modmain.f90:463
real(8), dimension(:,:,:), allocatable gntyyy
Definition: modphonon.f90:126
integer ngvc
Definition: modmain.f90:398
complex(8), dimension(:,:), allocatable dsocfr
Definition: modphonon.f90:118
integer lmaxapw
Definition: modmain.f90:197
real(8), dimension(:,:), allocatable vkc
Definition: modmain.f90:473
integer nlomax
Definition: modmain.f90:788
real(8), dimension(:,:), allocatable vgc
Definition: modmain.f90:420
integer, dimension(:,:), allocatable nhk
Definition: modpw.f90:40
integer nrcmtmax
Definition: modmain.f90:175
integer nstsv
Definition: modmain.f90:889
complex(8), dimension(:,:,:), pointer, contiguous dmagmt
Definition: modphonon.f90:102
complex(8), dimension(:), pointer, contiguous dvsig
Definition: modphonon.f90:114
complex(8), dimension(:,:,:,:), allocatable sfacgkq
Definition: modphonon.f90:92
real(8), dimension(:,:,:,:), allocatable vgkql
Definition: modphonon.f90:88
real(8), dimension(:,:), allocatable doccsv
Definition: modphonon.f90:136
complex(8), dimension(:), allocatable, target drhmg
Definition: modphonon.f90:98
complex(8), dimension(:,:), pointer, contiguous dvsmt
Definition: modphonon.f90:110
real(8), dimension(:,:,:), allocatable devalfv
Definition: modphonon.f90:132
complex(8), dimension(:,:), pointer, contiguous dbsir
Definition: modphonon.f90:116
integer ngvec
Definition: modmain.f90:396
real(8), dimension(:,:), allocatable vgqc
Definition: modphonon.f90:62
integer, dimension(:,:), allocatable ivg
Definition: modmain.f90:400
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
real(8), dimension(3) vqcss
Definition: modmain.f90:295
pure subroutine gengkvec(ngv, ivg, vgc, vkl, vkc, gkmax, ngkmax, ngk, igkig, vgkl, vgkc, gkc)
Definition: gengkvec.f90:11
real(8), dimension(:,:,:), allocatable hkc
Definition: modpw.f90:50
integer apwordmax
Definition: modmain.f90:760
logical wrtvars
Definition: modvars.f90:9
real(8) epslat
Definition: modmain.f90:24
real(8), dimension(:,:), allocatable ffacgq
Definition: modphonon.f90:74
subroutine init4
Definition: init4.f90:7
complex(8), dimension(:), pointer, contiguous drhoir
Definition: modphonon.f90:100
Definition: modpw.f90:6
complex(8), dimension(:), allocatable, target dvsbs
Definition: modphonon.f90:108
complex(8), dimension(:), allocatable dcfunig
Definition: modphonon.f90:76
logical spinorb
Definition: modmain.f90:230
complex(8), dimension(:,:), allocatable sfacgq
Definition: modphonon.f90:72
integer lnpsd
Definition: modmain.f90:628
integer nspecies
Definition: modmain.f90:34
real(8), dimension(:,:,:,:), allocatable vhkl
Definition: modpw.f90:46
integer, dimension(:,:), allocatable ngkq
Definition: modphonon.f90:84
real(8), dimension(:,:,:,:), allocatable vgkqc
Definition: modphonon.f90:88
integer npmtmax
Definition: modmain.f90:216
integer natmtot
Definition: modmain.f90:40
real(8), dimension(:,:), allocatable vkql
Definition: modphonon.f90:54
complex(8), dimension(:,:,:,:,:,:), allocatable dhaa
Definition: modphonon.f90:120
real(8), dimension(:), allocatable gqc
Definition: modphonon.f90:64
complex(8), dimension(:,:,:,:), allocatable sfachk
Definition: modpw.f90:52
integer nhkmax
Definition: modpw.f90:42
integer nstfv
Definition: modmain.f90:887
complex(8), dimension(:), allocatable dvclir
Definition: modphonon.f90:104
subroutine writevars(vname, n1, n2, n3, n4, n5, n6, nv, iv, iva, rv, rva, zv, zva, sv, sva)
Definition: modvars.f90:16
integer nspnfv
Definition: modmain.f90:289
integer, dimension(:,:,:), allocatable igkqig
Definition: modphonon.f90:86
real(8), dimension(:), allocatable gclgq
Definition: modphonon.f90:66
complex(8), dimension(:,:), allocatable ylmgq
Definition: modphonon.f90:70
real(8) hkmax
Definition: modpw.f90:38
real(8) gmaxvr
Definition: modmain.f90:384
complex(8), dimension(:,:,:,:), allocatable dhlolo
Definition: modphonon.f90:124