The Elk Code
 
Loading...
Searching...
No Matches
readstate.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!BOP
7! !ROUTINE: readstate
8! !INTERFACE:
9subroutine readstate
10! !USES:
11use modmain
12use moddftu
13! !DESCRIPTION:
14! Reads in the charge density and other relevant variables from the file
15! {\tt STATE.OUT}. Checks for version and parameter compatibility.
16!
17! !REVISION HISTORY:
18! Created May 2003 (JKD)
19!EOP
20!BOC
21implicit none
22! local variables
23logical spinpol_
24integer is,ia,ias,lmmax,lm,ir,jr
25integer idm,jdm,mapidm(3),ios
26integer i1,i2,i3,j1,j2,j3,n
27integer version_(3)
28integer nspecies_,natoms_,lmmaxo_
29integer nrmt_(maxspecies),nrmtmax_
30integer nrcmt_(maxspecies),nrcmtmax_
31integer ngridg_(3),ngtot_,ngvec_
32integer ndmag_,nspinor_,fsmtype_,ftmtype_
33integer dftu_,lmmaxdm_,xcgrad_
34real(8) t1
35! allocatable arrays
36integer, allocatable :: mapir(:)
37real(8), allocatable :: rsp_(:,:),rcmt_(:,:)
38real(8), allocatable :: wcrmt_(:,:,:),wcrcmt_(:,:,:)
39real(8), allocatable :: rfmt_(:,:,:),rfir_(:)
40real(8), allocatable :: rvfmt_(:,:,:,:),rvfir_(:,:)
41real(8), allocatable :: rvfcmt_(:,:,:,:),rfmt(:,:)
42real(8), allocatable :: bfsmcmt_(:,:),fi(:),fo(:)
43complex(8), allocatable :: vsig_(:)
44complex(8), allocatable :: vmatmt_(:,:,:,:,:),vmftm_(:,:,:,:,:)
45open(100,file='STATE'//trim(filext),form='UNFORMATTED',action='READ', &
46 status='OLD',iostat=ios)
47if (ios /= 0) then
48 write(*,*)
49 write(*,'("Error(readstate): error opening ",A)') 'STATE'//trim(filext)
50 write(*,*)
51 stop
52end if
53read(100) version_
54if (version_(1) < 2) then
55 write(*,*)
56 write(*,'("Error(readstate): unable to read STATE.OUT from versions earlier &
57 &than 2.0.0")')
58 write(*,*)
59 stop
60end if
61if (any(version(:) /= version_(:))) then
62 write(*,*)
63 write(*,'("Warning(readstate): different versions")')
64 write(*,'(" current : ",I0,".",I0,".",I0)') version
65 write(*,'(" STATE.OUT : ",I0,".",I0,".",I0)') version_
66end if
67read(100) spinpol_
68read(100) nspecies_
69if (nspecies /= nspecies_) then
70 write(*,*)
71 write(*,'("Error(readstate): differing nspecies")')
72 write(*,'(" current : ",I4)') nspecies
73 write(*,'(" STATE.OUT : ",I4)') nspecies_
74 write(*,*)
75 stop
76end if
77read(100) lmmaxo_
78lmmax=min(lmmaxo,lmmaxo_)
79read(100) nrmtmax_
80read(100) nrcmtmax_
81allocate(rsp_(nrmtmax_,nspecies))
82allocate(rcmt_(nrcmtmax_,nspecies))
83do is=1,nspecies
84 read(100) natoms_
85 if (natoms(is) /= natoms_) then
86 write(*,*)
87 write(*,'("Error(readstate): differing natoms for species ",I4)') is
88 write(*,'(" current : ",I4)') natoms(is)
89 write(*,'(" STATE.OUT : ",I4)') natoms_
90 write(*,*)
91 stop
92 end if
93 read(100) nrmt_(is)
94 read(100) rsp_(1:nrmt_(is),is)
95 read(100) nrcmt_(is)
96 read(100) rcmt_(1:nrcmt_(is),is)
97end do
98read(100) ngridg_
99read(100) ngvec_
100read(100) ndmag_
101if (spinpol_.and.(ndmag_ /= 1).and.(ndmag_ /= 3)) then
102 write(*,*)
103 write(*,'("Error(readstate): invalid ndmag in STATE.OUT : ",I8)') ndmag_
104 write(*,*)
105 stop
106end if
107read(100) nspinor_
108read(100) fsmtype_
109if ((version_(1) > 2).or.(version_(2) >= 3)) then
110 read(100) ftmtype_
111else
112 ftmtype_=0
113end if
114read(100) dftu_
115read(100) lmmaxdm_
116if ((version_(1) > 5).or.((version_(1) == 5).and.(version_(2) >= 1))) then
117 read(100) xcgrad_
118else
119 xcgrad_=0
120end if
121if ((version_(1) >= 10).or.((version_(1) == 9).and.(version_(2) >= 6))) then
122 read(100) efermi
123else
124 call readfermi
125end if
126ngtot_=ngridg_(1)*ngridg_(2)*ngridg_(3)
127! map from old interstitial grid to new
128allocate(mapir(ngtot))
129do i3=0,ngridg(3)-1
130 t1=dble(i3*ngridg_(3))/dble(ngridg(3))
131 j3=modulo(nint(t1),ngridg_(3))
132 do i2=0,ngridg(2)-1
133 t1=dble(i2*ngridg_(2))/dble(ngridg(2))
134 j2=modulo(nint(t1),ngridg_(2))
135 do i1=0,ngridg(1)-1
136 t1=dble(i1*ngridg_(1))/dble(ngridg(1))
137 j1=modulo(nint(t1),ngridg_(1))
138 jr=j3*ngridg_(2)*ngridg_(1)+j2*ngridg_(1)+j1+1
139 ir=i3*ngridg(2)*ngridg(1)+i2*ngridg(1)+i1+1
140 mapir(ir)=jr
141 end do
142 end do
143end do
144! determine the spline coefficient weights on the old radial mesh
145allocate(wcrmt_(12,nrmtmax_,nspecies))
146allocate(wcrcmt_(12,nrcmtmax_,nspecies))
147do is=1,nspecies
148 call wspline(nrmt_(is),rsp_(:,is),wcrmt_(:,:,is))
149 call wspline(nrcmt_(is),rcmt_(:,is),wcrcmt_(:,:,is))
150end do
151allocate(rfmt_(lmmaxo_,nrmtmax_,natmtot),rfir_(ngtot_))
152allocate(rfmt(lmmaxo,nrmtmax))
153n=max(nrmtmax,nrmtmax_)
154allocate(fi(n),fo(n))
155! read the muffin-tin density
156read(100) rfmt_,rfir_
157! regrid and pack the muffin-tin function
158call rgfmt(rhomt)
159! regrid the interstitial function
160rhoir(1:ngtot)=rfir_(mapir(1:ngtot))
161! read the Coulomb potential, regrid and pack
162read(100) rfmt_,rfir_
163call rgfmt(vclmt)
164vclir(1:ngtot)=rfir_(mapir(1:ngtot))
165! read the exchange-correlation potential, regrid and pack
166read(100) rfmt_,rfir_
167call rgfmt(vxcmt)
168vxcir(1:ngtot)=rfir_(mapir(1:ngtot))
169! read the Kohn-Sham effective potential, regrid and pack
170if ((version_(1) > 2).or.(version_(2) >= 2)) then
171 read(100) rfmt_,rfir_
172else
173 allocate(vsig_(ngvec_))
174 read(100) rfmt_,rfir_,vsig_
175 deallocate(vsig_)
176end if
177call rgfmt(vsmt)
178vsir(1:ngtot)=rfir_(mapir(1:ngtot))
179! compute the Kohn-Sham potential on coarse interstitial grid
180call rfirftoc(vsir,vsirc)
181! read the magnetisation, exchange-correlation and effective magnetic fields
182if (spinpol_) then
183! component map for spin-polarised case
184 mapidm(:)=0
185 if (ndmag == ndmag_) then
186 do idm=1,ndmag
187 mapidm(idm)=idm
188 end do
189 else
190 mapidm(ndmag)=ndmag_
191 end if
192 allocate(rvfmt_(lmmaxo_,nrmtmax_,natmtot,ndmag_))
193 allocate(rvfir_(ngtot_,ndmag_))
194 allocate(rvfcmt_(lmmaxo_,nrcmtmax_,natmtot,ndmag_))
195 read(100) rvfmt_,rvfir_
196 call rgvfmt(magmt)
197 call rgvir(magir)
198 read(100) rvfmt_,rvfir_
199 call rgvfmt(bxcmt)
200 call rgvir(bxcir)
201 read(100) rvfcmt_,rvfir_
202 call rgvfcmt(bsmt)
203 call rgvir(bsir)
204! compute the Kohn-Sham magnetic field on coarse interstitial grid
205 do idm=1,ndmag
206 call rfirftoc(bsir(:,idm),bsirc(:,idm))
207 end do
208 deallocate(rvfmt_,rvfir_,rvfcmt_)
209! read fixed spin moment effective fields
210 if (fsmtype_ /= 0) then
211 allocate(bfsmcmt_(3,natmtot))
212 read(100) bfsmc
213 read(100) bfsmcmt_
214 if (fsmtype /= 0) bfsmcmt(:,:)=bfsmcmt_(:,:)
215! make sure that the constraining fields are perpendicular to the fixed moments
216! for fixed direction calculations (Y. Kvashnin and LN)
217 if (fsmtype < 0) then
218 if (ncmag) then
219 call r3vo(momfix,bfsmc)
220 do is=1,nspecies
221 do ia=1,natoms(is)
222 ias=idxas(ia,is)
223 call r3vo(mommtfix(:,ia,is),bfsmcmt(:,ias))
224 end do
225 end do
226 else
227 bfsmc(:)=0.d0
228 bfsmcmt(:,:)=0.d0
229 end if
230 end if
231 deallocate(bfsmcmt_)
232 end if
233end if
234if (any(xcgrad == [3,4,5,6])) then
235 if (any(xcgrad_ == [3,4,5,6])) then
236 read(100) rfmt_,rfir_
237 call rgfmt(wxcmt)
238 wxcir(1:ngtot)=rfir_(mapir(1:ngtot))
239 else
240 wxcmt(:,:)=0.d0
241 wxcir(1:ngtot)=0.d0
242 end if
243end if
244deallocate(wcrmt_,wcrcmt_,rfmt_,rfir_,rfmt,fi,fo)
245! read DFT+U potential matrix in each muffin-tin
246if (((dftu /= 0).and.(dftu_ /= 0)).or. &
247 ((ftmtype /= 0).and.(ftmtype_ /= 0))) then
248 allocate(vmatmt_(lmmaxdm_,nspinor_,lmmaxdm_,nspinor_,natmtot))
249 read(100) vmatmt_
250 lmmax=min(lmmaxdm,lmmaxdm_)
251 vmatmt(:,:,:,:,:)=0.d0
252 if (nspinor == nspinor_) then
253 vmatmt(1:lmmax,:,1:lmmax,:,:)=vmatmt_(1:lmmax,:,1:lmmax,:,:)
254 else if ((nspinor == 1).and.(nspinor_ == 2)) then
255 vmatmt(1:lmmax,1,1:lmmax,1,:)=0.5d0*(vmatmt_(1:lmmax,1,1:lmmax,1,:) &
256 +vmatmt_(1:lmmax,2,1:lmmax,2,:))
257 else
258 vmatmt(1:lmmax,1,1:lmmax,1,:)=vmatmt_(1:lmmax,1,1:lmmax,1,:)
259 vmatmt(1:lmmax,2,1:lmmax,2,:)=vmatmt_(1:lmmax,1,1:lmmax,1,:)
260 end if
261 deallocate(vmatmt_)
262end if
263! read fixed tensor moment potential matrix elements
264if ((ftmtype /= 0).and.(ftmtype_ /= 0)) then
265 allocate(vmftm_(lmmaxdm_,nspinor_,lmmaxdm_,nspinor_,natmtot))
266 read(100) vmftm_
267 lmmax=min(lmmaxdm,lmmaxdm_)
268 vmftm_(:,:,:,:,:)=0.d0
269 if (nspinor == nspinor_) then
270 vmftm(1:lmmax,:,1:lmmax,:,:)=vmftm_(1:lmmax,:,1:lmmax,:,:)
271 else if ((nspinor == 1).and.(nspinor_ == 2)) then
272 vmftm(1:lmmax,1,1:lmmax,1,:)=0.5d0*(vmftm_(1:lmmax,1,1:lmmax,1,:) &
273 +vmftm_(1:lmmax,2,1:lmmax,2,:))
274 else
275 vmftm(1:lmmax,1,1:lmmax,1,:)=vmftm_(1:lmmax,1,1:lmmax,1,:)
276 vmftm(1:lmmax,2,1:lmmax,2,:)=vmftm_(1:lmmax,1,1:lmmax,1,:)
277 end if
278 deallocate(vmftm_)
279end if
280close(100)
281return
282
283contains
284
285subroutine rgfmt(rfmtp)
286implicit none
287! arguments
288real(8), intent(out) :: rfmtp(npmtmax,natmtot)
289do ias=1,natmtot
290 is=idxis(ias)
291! regrid the muffin-tin function
292 do lm=1,lmmax
293 fi(1:nrmt_(is))=rfmt_(lm,1:nrmt_(is),ias)
294 call rfinterp(nrmt_(is),rsp_(:,is),wcrmt_(:,:,is),fi,nrmt(is),rsp(:,is),fo)
295 rfmt(lm,1:nrmt(is))=fo(1:nrmt(is))
296 end do
297 rfmt(lmmax+1:lmmaxo,1:nrmt(is))=0.d0
298! pack the muffin-tin function
299 call rfmtpack(.true.,nrmt(is),nrmti(is),rfmt,rfmtp(:,ias))
300end do
301end subroutine
302
303subroutine rgvfmt(rvfmt)
304implicit none
305! arguments
306real(8), intent(out) :: rvfmt(npmtmax,natmtot,ndmag)
307do idm=1,ndmag
308 jdm=mapidm(idm)
309 if (jdm == 0) then
310 rvfmt(:,:,idm)=0.d0
311 cycle
312 end if
313 do ias=1,natmtot
314 is=idxis(ias)
315 do lm=1,lmmax
316 fi(1:nrmt_(is))=rvfmt_(lm,1:nrmt_(is),ias,jdm)
317 call rfinterp(nrmt_(is),rsp_(:,is),wcrmt_(:,:,is),fi,nrmt(is),rsp(:,is), &
318 fo)
319 rfmt(lm,1:nrmt(is))=fo(1:nrmt(is))
320 end do
321 rfmt(lmmax+1:lmmaxo,1:nrmt(is))=0.d0
322 call rfmtpack(.true.,nrmt(is),nrmti(is),rfmt,rvfmt(:,ias,idm))
323 end do
324end do
325end subroutine
326
327subroutine rgvfcmt(rvfcmt)
328implicit none
329! arguments
330real(8), intent(out) :: rvfcmt(npcmtmax,natmtot,ndmag)
331do idm=1,ndmag
332 jdm=mapidm(idm)
333 if (jdm == 0) then
334 rvfcmt(:,:,idm)=0.d0
335 cycle
336 end if
337 do ias=1,natmtot
338 is=idxis(ias)
339 do lm=1,lmmax
340 fi(1:nrcmt_(is))=rvfcmt_(lm,1:nrcmt_(is),ias,jdm)
341 call rfinterp(nrcmt_(is),rcmt_(:,is),wcrcmt_(:,:,is),fi,nrcmt(is), &
342 rcmt(:,is),fo)
343 rfmt(lm,1:nrcmt(is))=fo(1:nrcmt(is))
344 end do
345 rfmt(lmmax+1:lmmaxo,1:nrcmt(is))=0.d0
346 call rfmtpack(.true.,nrcmt(is),nrcmti(is),rfmt,rvfcmt(:,ias,idm))
347 end do
348end do
349end subroutine
350
351subroutine rgvir(rvfir)
352implicit none
353! arguments
354real(8), intent(out) :: rvfir(ngtot,ndmag)
355do idm=1,ndmag
356 jdm=mapidm(idm)
357 if (jdm /= 0) then
358 rvfir(1:ngtot,idm)=rvfir_(mapir(1:ngtot),jdm)
359 else
360 rvfir(1:ngtot,idm)=0.d0
361 end if
362end do
363end subroutine
364
365end subroutine
366!EOC
367
integer dftu
Definition moddftu.f90:32
integer, parameter lmmaxdm
Definition moddftu.f90:14
integer ftmtype
Definition moddftu.f90:70
complex(8), dimension(:,:,:,:,:), allocatable vmatmt
Definition moddftu.f90:20
complex(8), dimension(:,:,:,:,:), allocatable vmftm
Definition moddftu.f90:82
integer, dimension(maxspecies) nrmti
Definition modmain.f90:211
real(8), dimension(:,:,:), allocatable bxcmt
Definition modmain.f90:636
integer ngtot
Definition modmain.f90:390
integer, dimension(3) ngridg
Definition modmain.f90:386
logical ncmag
Definition modmain.f90:240
real(8) efermi
Definition modmain.f90:904
integer nspinor
Definition modmain.f90:267
real(8), dimension(:,:,:), pointer, contiguous magmt
Definition modmain.f90:616
integer, dimension(maxspecies) nrmt
Definition modmain.f90:150
integer, dimension(maxspecies) natoms
Definition modmain.f90:36
real(8), dimension(:), pointer, contiguous rhoir
Definition modmain.f90:614
character(256) filext
Definition modmain.f90:1300
real(8), dimension(:,:), allocatable rcmt
Definition modmain.f90:177
real(8), dimension(3) momfix
Definition modmain.f90:253
integer, dimension(maxatoms, maxspecies) idxas
Definition modmain.f90:42
integer fsmtype
Definition modmain.f90:251
real(8), dimension(:,:), allocatable bfsmcmt
Definition modmain.f90:263
integer, dimension(maxspecies) nrcmt
Definition modmain.f90:173
real(8), dimension(:,:), allocatable bxcir
Definition modmain.f90:636
real(8), dimension(:,:), allocatable rsp
Definition modmain.f90:135
real(8), dimension(:), allocatable vxcir
Definition modmain.f90:634
integer, dimension(maxatoms *maxspecies) idxis
Definition modmain.f90:44
real(8), dimension(3) bfsmc
Definition modmain.f90:257
integer natmtot
Definition modmain.f90:40
real(8), dimension(:), allocatable vclir
Definition modmain.f90:624
real(8), dimension(3, maxatoms, maxspecies) mommtfix
Definition modmain.f90:259
integer, dimension(3), parameter version
Definition modmain.f90:1288
real(8), dimension(:,:), pointer, contiguous magir
Definition modmain.f90:616
real(8), dimension(:,:), pointer, contiguous vsmt
Definition modmain.f90:649
real(8), dimension(:,:), allocatable bsir
Definition modmain.f90:658
real(8), dimension(:,:), allocatable vclmt
Definition modmain.f90:624
real(8), dimension(:,:), pointer, contiguous bsirc
Definition modmain.f90:660
real(8), dimension(:,:), allocatable vxcmt
Definition modmain.f90:634
real(8), dimension(:), pointer, contiguous vsirc
Definition modmain.f90:653
integer nrmtmax
Definition modmain.f90:152
integer xcgrad
Definition modmain.f90:602
real(8), dimension(:), allocatable vsir
Definition modmain.f90:651
integer lmmaxo
Definition modmain.f90:203
real(8), dimension(:,:,:), pointer, contiguous bsmt
Definition modmain.f90:656
real(8), dimension(:,:), pointer, contiguous rhomt
Definition modmain.f90:614
integer, dimension(maxspecies) nrcmti
Definition modmain.f90:211
integer nspecies
Definition modmain.f90:34
real(8), dimension(:), allocatable wxcir
Definition modmain.f90:676
integer ndmag
Definition modmain.f90:238
real(8), dimension(:,:), allocatable wxcmt
Definition modmain.f90:676
pure subroutine r3vo(x, y)
Definition r3vo.f90:7
subroutine readfermi
Definition readfermi.f90:10
subroutine rgvfmt(rvfmt)
subroutine rgvir(rvfir)
subroutine readstate
Definition readstate.f90:10
subroutine rgfmt(rfmtp)
subroutine rgvfcmt(rvfcmt)
subroutine rfinterp(ni, xi, wci, fi, no, xo, fo)
Definition rfinterp.f90:10
subroutine rfirftoc(rfir, rfirc)
Definition rfirftoc.f90:7
pure subroutine rfmtpack(tpack, nr, nri, rfmt1, rfmt2)
Definition rfmtpack.f90:7
subroutine wspline(n, x, wc)
Definition wspline.f90:7