pwdft  0.1
PW-DFT code for education
griddata Module Reference

Functions/Subroutines

subroutine read_griddata (filename, gdata)
 Read unit-cell grid data such as Vks. More...
 
subroutine write_griddata (filename, gdata)
 Write unit-cell grid data such as Vks. More...
 

Function/Subroutine Documentation

◆ read_griddata()

subroutine griddata::read_griddata ( character(*), intent(in)  filename,
real(8), dimension(g_rh%nft(1),g_rh%nft(2),g_rh%nft(3)), intent(out)  gdata 
)

Read unit-cell grid data such as Vks.

Definition at line 32 of file griddata.F90.

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  !

References atm_spec::atm, atm_spec::avec, atm_spec::bvec, gvec::g_rh, atm_spec::nat, and constant::pi.

Referenced by pwdft().

Here is the caller graph for this function:

◆ write_griddata()

subroutine griddata::write_griddata ( character(*), intent(in)  filename,
real(8), dimension(g_rh%nft(1),g_rh%nft(2),g_rh%nft(3)), intent(in)  gdata 
)

Write unit-cell grid data such as Vks.

Definition at line 96 of file griddata.F90.

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  !

References atm_spec::atm, atm_spec::avec, constant::bohr2ang, gvec::g_rh, and atm_spec::nat.

Referenced by pwdft().

Here is the caller graph for this function:
atm_spec::avec
real(8), dimension(3, 3), save avec
Unit lattice vector [Bohr].
Definition: atm_spec.F90:50
constant
Definition: constant.F90:23
atm_spec::atm
type(atm_t), dimension(:), allocatable, save atm
(nat) Atom
Definition: atm_spec.F90:55
gvec
Definition: gvec.F90:23
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
atm_spec
Definition: atm_spec.F90:23