pwdft  0.1
PW-DFT code for education
griddata.F90
Go to the documentation of this file.
1 !
2 ! Copyright (c) 2018 Mitsuaki Kawamura
3 !
4 ! Permission is hereby granted, free of charge, to any person obtaining a
5 ! copy of this software and associated documentation files (the
6 ! "Software"), to deal in the Software without restriction, including
7 ! without limitation the rights to use, copy, modify, merge, publish,
8 ! distribute, sublicense, and/or sell copies of the Software, and to
9 ! permit persons to whom the Software is furnished to do so, subject to
10 ! the following conditions:
11 !
12 ! The above copyright notice and this permission notice shall be included
13 ! in all copies or substantial portions of the Software.
14 !
15 ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 ! OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 ! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 ! IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 ! CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 ! TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 ! SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 !
23 module griddata
24  !
25  implicit none
26  !
27 contains
31  subroutine read_griddata(filename, gdata)
32  !
33  use constant, only : pi
34  use atm_spec, only : nat, atm, bvec, avec
35  use gvec, only : g_rh
36  !
37  character(*),intent(in) :: filename
38  real(8),intent(out) :: gdata(g_rh%nft(1),g_rh%nft(2),g_rh%nft(3))
39  !
40  integer :: itemp(3), fi = 10, iat
41  character(256) :: ctemp
42  real(8) :: avec0(3,3), &
43  & gdata0(g_rh%nft(1)+1,g_rh%nft(2)+1,g_rh%nft(3)+1)
44  !
45  open(fi, file = trim(filename))
46  !
47  read(fi,*) ctemp
48  read(fi,*) ctemp
49  read(fi,*) avec0(1:3,1:3)
50  avec0(1:3,1:3) = avec0(1:3,1:3) / 0.529177249d0
51  if(any(abs(avec0(1:3,1:3)-avec(1:3,1:3)) > 1.0d-3)) then
52  write(*,*) "Error in read_griddata"
53  write(*,*) "Direct lattice vector is different."
54  stop 'error in read_griddata'
55  end if
56  read(fi,*) ctemp
57  read(fi,*) itemp(1:2)
58  if(nat /= itemp(1)) then
59  write(*,*) "Error in read_griddata"
60  write(*,*) "Number of atoms is different."
61  stop 'error in read_griddata'
62  end if
63  do iat = 1, nat
64  read(fi,*) ctemp, avec0(1:3,1)
65  avec0(1:3,1) = avec0(1:3,1) / 0.529177249d0
66  avec0(1:3,1) = matmul(avec0(1:3,1), bvec(1:3,1:3)) / (2.0d0*pi)
67  if(any(abs(avec0(1:3,1)-atm(iat)%pos(1:3)) > 1.0d-3)) then
68  write(*,*) "Error in read_griddata"
69  write(*,*) "Position of atom ", iat, " is different."
70  stop 'error in read_griddata'
71  end if
72  end do
73  read(fi,*) ctemp
74  read(fi,*) ctemp
75  read(fi,*) ctemp
76  read(fi,*) itemp(1:3)
77  if(any(itemp(1:3) /= g_rh%nft(1:3)+1)) then
78  write(*,*) "Error in read_griddata"
79  write(*,*) "FFT grid is different."
80  stop 'error in read_griddata'
81  end if
82  read(fi,*) avec0(1:3,1)
83  read(fi,*) avec0(1:3,1:3)
84  read(fi,*) gdata0(1:itemp(1),1:itemp(2),1:itemp(3))
85  !
86  close(fi)
87  !
88  gdata( 1:g_rh%nft(1),1:g_rh%nft(2),1:g_rh%nft(3)) &
89  & = gdata0(1:g_rh%nft(1),1:g_rh%nft(2),1:g_rh%nft(3))
90  !
91  end subroutine read_griddata
95  subroutine write_griddata(filename, gdata)
96  !
97  use constant, only : bohr2ang
98  use atm_spec, only : nat, atm, avec
99  use gvec, only : g_rh
100  !
101  character(*),intent(in) :: filename
102  real(8),intent(in) :: gdata(g_rh%nft(1),g_rh%nft(2),g_rh%nft(3))
103  !
104  integer :: fo = 20, iat, i1, i2, i3, ii1, ii2, ii3
105  real(8) :: gdata0(g_rh%nft(1)+1,g_rh%nft(2)+1,g_rh%nft(3)+1)
106  !
107  do i3 = 1, g_rh%nft(3)+1
108  ii3 = modulo(i3 - 1, g_rh%nft(3)) + 1
109  do i2 = 1, g_rh%nft(2)+1
110  ii2 = modulo(i2 - 1, g_rh%nft(2)) + 1
111  do i1 = 1, g_rh%nft(1)+1
112  ii1 = modulo(i1 - 1, g_rh%nft(1)) + 1
113  gdata0(i1, i2, i3) = gdata(ii1, ii2, ii3)
114  end do
115  end do
116  end do
117  !
118  write(*,*) " Output ", trim(filename)
119  open(fo, file = trim(filename))
120  !
121  write(fo,'(a)') "CRYSTAL"
122  write(fo,'(a)') "PRIMVEC"
123  write(fo,'(3e20.10)') avec(1:3,1:3) * bohr2ang
124  write(fo,'(a)') "PRIMCOORD"
125  write(fo,'(2(2x,i0))') nat, 1
126  do iat = 1, nat
127  write(fo,'(a,2x,3e20.10)') trim(atm(iat)%elem), &
128  & matmul(avec(1:3,1:3), atm(iat)%pos(1:3)) * bohr2ang
129  end do
130  write(fo,'(a)') "BEGIN_BLOCK_DATAGRID_3D"
131  write(fo,'(a)') "3D_PWSCF"
132  write(fo,'(a)') "DATAGRID_3D_UNKNOWN"
133  write(fo,'(3(2x,i0))') g_rh%nft(1:3)+1
134  write(fo,'(3e20.10)') (/0.0d0, 0.0d0, 0.0d0/), avec(1:3,1:3) * bohr2ang
135  write(fo,'(6e20.10)') gdata0(1:g_rh%nft(1)+1,1:g_rh%nft(2)+1,1:g_rh%nft(3)+1)
136  write(fo,'(a)') "END_DATAGRID_3D"
137  write(fo,'(a)') "END_BLOCK_DATAGRID_3D"
138  !
139  close(fo)
140  !
141  end subroutine write_griddata
142  !
143 end module griddata
atm_spec::avec
real(8), dimension(3, 3), save avec
Unit lattice vector [Bohr].
Definition: atm_spec.F90:50
constant
Definition: constant.F90:23
griddata::read_griddata
subroutine read_griddata(filename, gdata)
Read unit-cell grid data such as Vks.
Definition: griddata.F90:32
constant::pi
real(8), parameter pi
Definition: constant.F90:25
atm_spec::atm
type(atm_t), dimension(:), allocatable, save atm
(nat) Atom
Definition: atm_spec.F90:55
griddata
Definition: griddata.F90:23
gvec
Definition: gvec.F90:23
gvec::g_rh
type(fft), save g_rh
Definition: gvec.F90:37
atm_spec::nat
integer, save nat
Number of atoms.
Definition: atm_spec.F90:47
atm_spec::bvec
real(8), dimension(3, 3), save bvec
Unit reciplocal lattice vector [Bohr^-1].
Definition: atm_spec.F90:50
griddata::write_griddata
subroutine write_griddata(filename, gdata)
Write unit-cell grid data such as Vks.
Definition: griddata.F90:96
atm_spec
Definition: atm_spec.F90:23
constant::bohr2ang
real(8), parameter bohr2ang
Definition: constant.F90:26