The Elk Code
writetddft.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2014 K. Krieger, 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 writetddft
7 use modmain
8 use modtddft
9 use moddftu
10 use moddelf
11 implicit none
12 ! local variables
13 integer is,ia,ias
14 character(32) fext
15 ! allocatable arrays
16 real(8), allocatable :: rvfmt(:,:,:),rvfir(:,:)
17 ! file extension
18 write(fext,'("_TS",I8.8,".OUT")') itimes
19 ! delete files at first time step
20 if (itimes <= 1) then
21  call delfile('TOTENERGY_TD.OUT')
22  call delfile('CHARGEMT_TD.OUT')
23  call delfile('CHARGEIR_TD.OUT')
24  if (spinpol) then
25  call delfile('MOMENT_TD.OUT')
26  call delfile('MOMENTM_TD.OUT')
27  call delfile('MOMENTMT_TD.OUT')
28  call delfile('MOMENTIR_TD.OUT')
29  end if
30  call delfile('JTOT_TD.OUT')
31  call delfile('JTOTM_TD.OUT')
32  if (tddos) call delfile('TDTEMP.OUT')
33  if (tdlsj) call delfile('TDLSJ.OUT')
34  if (tforce) then
35  call delfile('FORCETOT_TD.OUT')
36  call delfile('FORCEMAX_TD.OUT')
37  end if
38  if (tatdisp) then
39  call delfile('ATDISPL_TD.OUT')
40  call delfile('ATDISPC_TD.OUT')
41  end if
42  if (tafindt) call delfile('AFIND_TD.OUT')
43 end if
44 ! total energy
45 call writetdengy
46 ! muffin-tin charges
47 open(50,file='CHARGEMT_TD.OUT',form='FORMATTED',position='APPEND')
48 write(50,'(G18.10)') times(itimes)
49 do is=1,nspecies
50  do ia=1,natoms(is)
51  ias=idxas(ia,is)
52  write(50,'(2I4,G18.10)') is,ia,chgmt(ias)
53  end do
54 end do
55 write(50,*)
56 close(50)
57 ! interstitial charge
58 open(50,file='CHARGEIR_TD.OUT',form='FORMATTED',position='APPEND')
59 write(50,'(2G18.10)') times(itimes),chgir
60 close(50)
61 ! write spin moments to file if required
62 if (spinpol) call writemomtd
63 ! total current
64 open(50,file='JTOT_TD.OUT',form='FORMATTED',position='APPEND')
65 write(50,'(4G18.10)') times(itimes),jtot(:)
66 close(50)
67 ! total current magnitude
68 open(50,file='JTOTM_TD.OUT',form='FORMATTED',position='APPEND')
69 write(50,'(4G18.10)') times(itimes),jtotm
70 close(50)
71 ! write the time-dependent atomic forces
72 if (tforce.and.ttsforce) then
73  call writetdforces
74  open(50,file='FORCES'//trim(fext),form='FORMATTED',action='WRITE')
75  call writeforces(50)
76  close(50)
77 end if
78 ! write the time-dependent atomic displacements
79 if (tatdisp.and.ttsforce) call writeatdisp
80 ! write the time-dependent induced A-field
81 if (tafindt) then
82  open(50,file='AFIND_TD.OUT',form='FORMATTED',position='APPEND')
83  write(50,'(4G18.10)') times(itimes),afindt(:,0)
84  close(50)
85 end if
86 ! write optional quantities
87 if (.not.ttswrite) return
88 ! charge density in 1D
89 if (tdrho1d) then
90  open(50,file='RHO1D'//trim(fext),form='FORMATTED',action='WRITE')
91  open(51,file='RHOLINES.OUT',form='FORMATTED',action='WRITE')
92  call plot1d(50,51,1,rhomt,rhoir)
93  close(50)
94  close(51)
95 end if
96 ! charge density in 2D
97 if (tdrho2d) then
98  open(50,file='RHO2D'//trim(fext),form='FORMATTED',action='WRITE')
99  call plot2d(.false.,50,1,rhomt,rhoir)
100  close(50)
101 end if
102 ! charge density in 3D
103 if (tdrho3d) then
104  open(50,file='RHO3D'//trim(fext),form='FORMATTED',action='WRITE')
105  call plot3d(50,1,rhomt,rhoir)
106  close(50)
107 end if
108 ! magnetisation in 1D, 2D or 3D
109 if ((tdmag1d.or.tdmag2d.or.tdmag3d).and.spinpol) then
110  allocate(rvfmt(npmtmax,natmtot,3),rvfir(ngtot,3))
111  if (ncmag) then
112 ! non-collinear
113  rvfmt(:,:,:)=magmt(:,:,:)
114  rvfir(:,:)=magir(:,:)
115  else
116 ! collinear
117  rvfmt(:,:,1:2)=0.d0
118  rvfir(:,1:2)=0.d0
119  rvfmt(:,:,3)=magmt(:,:,1)
120  rvfir(:,3)=magir(:,1)
121  end if
122  if (tdmag1d) then
123  open(50,file='MAG1D'//trim(fext),form='FORMATTED',action='WRITE')
124  open(51,file='MAGLINES.OUT',form='FORMATTED',action='WRITE')
125  call plot1d(50,51,3,rvfmt,rvfir)
126  close(50)
127  close(51)
128  end if
129  if (tdmag2d) then
130  open(50,file='MAG2D'//trim(fext),form='FORMATTED',action='WRITE')
131  call plot2d(.true.,50,3,rvfmt,rvfir)
132  close(50)
133  end if
134  if (tdmag3d) then
135  open(50,file='MAG3D'//trim(fext),form='FORMATTED',action='WRITE')
136  call plot3d(50,3,rvfmt,rvfir)
137  close(50)
138  end if
139  deallocate(rvfmt,rvfir)
140 end if
141 ! gauge-invariant current density in 1D
142 if (tdjr1d) then
143  open(50,file='JR1D'//trim(fext),form='FORMATTED',action='WRITE')
144  open(51,file='JRLINES.OUT',form='FORMATTED',action='WRITE')
145  call plot1d(50,51,3,jrmt,jrir)
146  close(50)
147  close(51)
148 end if
149 ! gauge-invariant current density in 2D
150 if (tdjr2d) then
151  open(50,file='JR2D'//trim(fext),form='FORMATTED',action='WRITE')
152  call plot2d(.true.,50,3,jrmt,jrir)
153  close(50)
154 end if
155 ! gauge-invariant current density in 3D
156 if (tdjr3d) then
157  open(50,file='JR3D'//trim(fext),form='FORMATTED',action='WRITE')
158  call plot3d(50,3,jrmt,jrir)
159  close(50)
160 end if
161 ! calculate and write tensor moments
162 if (dftu /= 0) then
163  if (tmwrite) call writetdtm3
164 end if
165 end subroutine
166 
logical ttsforce
Definition: modtddft.f90:100
logical tatdisp
Definition: modmain.f90:59
subroutine writetdengy
Definition: writetdengy.f90:7
integer ngtot
Definition: modmain.f90:390
subroutine writetdforces
real(8), dimension(3) jtot
Definition: modmain.f90:748
logical spinpol
Definition: modmain.f90:228
real(8), dimension(:), pointer, contiguous rhoir
Definition: modmain.f90:614
integer, dimension(maxatoms, maxspecies) idxas
Definition: modmain.f90:42
logical tdlsj
Definition: modtddft.f90:94
real(8), dimension(:,:), pointer, contiguous rhomt
Definition: modmain.f90:614
logical tdmag1d
Definition: modtddft.f90:92
real(8), dimension(:), allocatable chgmt
Definition: modmain.f90:732
logical tafindt
Definition: modtddft.f90:72
logical tmwrite
Definition: moddftu.f90:74
subroutine plot3d(fnum, nf, rfmt, rfir)
Definition: plot3d.f90:10
subroutine writemomtd
Definition: writemomtd.f90:7
logical tdrho3d
Definition: modtddft.f90:91
logical tdmag3d
Definition: modtddft.f90:92
logical tdmag2d
Definition: modtddft.f90:92
subroutine plot1d(fnum1, fnum2, nf, rfmt, rfir)
Definition: plot1d.f90:10
logical tdrho1d
Definition: modtddft.f90:91
logical tforce
Definition: modmain.f90:983
real(8) jtotm
Definition: modmain.f90:748
real(8) chgir
Definition: modmain.f90:730
real(8), dimension(:,:,:), pointer, contiguous magmt
Definition: modmain.f90:616
subroutine plot2d(tproj, fnum, nf, rfmt, rfir)
Definition: plot2d.f90:10
real(8), dimension(3, 0:1) afindt
Definition: modtddft.f90:67
logical tdjr2d
Definition: modtddft.f90:93
logical tdrho2d
Definition: modtddft.f90:91
integer, dimension(maxspecies) natoms
Definition: modmain.f90:36
subroutine delfile(fname)
Definition: moddelf.f90:15
integer dftu
Definition: moddftu.f90:35
real(8), dimension(:), allocatable times
Definition: modtddft.f90:48
integer itimes
Definition: modtddft.f90:46
subroutine writeforces(fnum)
Definition: writeforces.f90:7
integer nspecies
Definition: modmain.f90:34
logical tdjr3d
Definition: modtddft.f90:93
subroutine writetddft
Definition: writetddft.f90:7
integer npmtmax
Definition: modmain.f90:216
real(8), dimension(:,:), pointer, contiguous magir
Definition: modmain.f90:616
real(8), dimension(:,:,:), allocatable jrmt
Definition: modmain.f90:622
integer natmtot
Definition: modmain.f90:40
logical ttswrite
Definition: modtddft.f90:80
logical tdjr1d
Definition: modtddft.f90:93
subroutine writetdtm3
Definition: writetdtm3.f90:7
logical ncmag
Definition: modmain.f90:240
logical tddos
Definition: modtddft.f90:94
real(8), dimension(:,:), allocatable jrir
Definition: modmain.f90:622
subroutine writeatdisp
Definition: writeatdisp.f90:7