write_wfc_1d_r.f90 3.94 KB
Newer Older
Marco Govoni's avatar
Marco Govoni committed
1
!
2
! Copyright (C) 2015-2017 M. Govoni 
Marco Govoni's avatar
Marco Govoni committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
! This file is part of WEST.
!
! Contributors to this file: 
! Marco Govoni
!
! -------------------------------------------------------------------
SUBROUTINE write_wfc_1D_r ( dfft, iu, fname, wfc_distr, ipol)
  ! -------------------------------------------------------------------
  !
  USE kinds,                 ONLY : DP
  USE cell_base,             ONLY : celldm, at, bg, omega
  USE ions_base,             ONLY : nat, tau, atm, ityp
  USE scatter_mod,           ONLY : gather_grid
  USE fft_types,             ONLY : fft_type_descriptor
  !
  IMPLICIT NONE
  !
  ! I/O
  !
  TYPE(fft_type_descriptor), INTENT(IN) :: dfft
  INTEGER,INTENT(IN) :: iu
  CHARACTER(LEN=*),INTENT(IN) :: fname
  REAL(DP),INTENT(IN) :: wfc_distr(dfft%nnr)
  INTEGER,INTENT(IN) :: ipol
  !
  ! Workspace
  ! 
  REAL(DP)         :: alat
  INTEGER          :: nr1, nr2, nr3, nr1x, nr2x, nr3x
  INTEGER :: ir,ntot
  REAL(DP) :: wfc_gat(dfft%nr1x*dfft%nr2x*dfft%nr3x)
  REAL(DP),ALLOCATABLE :: integral(:)
  REAL(DP) :: conversion_1, conversion_2
  !
  wfc_gat=0.0_DP
  CALL gather_grid(dfft,wfc_distr,wfc_gat)
  !
  alat = celldm(1)
  nr1 = dfft%nr1
  nr2 = dfft%nr2
  nr3 = dfft%nr3
  nr1x= dfft%nr1x
  nr2x= dfft%nr2x
  nr3x= dfft%nr3x
  !
  ! ipol
  !
  SELECT CASE(ipol)
  CASE(1)
     !
     ! X
     !
     ntot=nr1
     ALLOCATE(integral(ntot))
     CALL calc_int_x(wfc_gat,nr1,nr2,nr3,integral)
     IF( dfft%mype == dfft%root ) THEN 
        OPEN(UNIT=iu,FILE=TRIM(fname))
     ENDIF
     !
  CASE(2)
     !
     ! Y
     ! 
     ntot=nr2
     ALLOCATE(integral(ntot))
     CALL calc_int_y(wfc_gat,nr1,nr2,nr3,integral)
     IF( dfft%mype == dfft%root ) THEN 
        OPEN(UNIT=iu,FILE=TRIM(fname))
     ENDIF
     !
  CASE(3)
     !
     ! Z
     !
     ntot=nr3
     ALLOCATE(integral(ntot))
     CALL calc_int_z(wfc_gat,nr1,nr2,nr3,integral)
     IF( dfft%mype == dfft%root ) THEN 
        OPEN(UNIT=iu,FILE=TRIM(fname))
     ENDIF
     !
  CASE DEFAULT 
     !
     CALL errore('write_1D_r','ipol must be 1,2,3',ipol)
     !
  END SELECT
  !
  ! Write
  !
  conversion_1 = alat*at(ipol,ipol)/REAL(ntot,KIND=DP) 
  conversion_2 = 1._DP/REAL(nr1*nr2*nr3,KIND=DP) 
  !
  IF( dfft%mype == dfft%root ) THEN 
     WRITE(iu,'("#",a12,a13)') 'r[au]', 'f(r)'
     DO ir=1,ntot
        WRITE(iu,'(2es14.6)') REAL(ir-1,KIND=DP)*conversion_1, integral(ir)*conversion_2
     ENDDO
     WRITE(iu,'(2es14.6)') REAL(ntot,KIND=DP)*conversion_1, integral(1)*conversion_2
     CLOSE(iu)
  ENDIF
  !
  DEALLOCATE(integral)
  !
END SUBROUTINE
!
!
SUBROUTINE calc_int_x(func,nr1,nr2,nr3,integral) 
  !
  USE kinds,  ONLY : DP
  !
  IMPLICIT NONE
  !
  REAL(DP) :: func(nr1,nr2,nr3)
  INTEGER :: nr1,nr2,nr3
  REAL(DP) :: integral(nr1)
  !
  INTEGER :: i1,i2,i3
  !
  integral = 0._DP
  DO i1=1,nr1
     DO i2=1,nr2
        DO i3=1,nr3
           !
           integral(i1) = integral(i1) + func(i1,i2,i3) 
           !
        ENDDO
     ENDDO
  ENDDO
  !
END SUBROUTINE
!
!
SUBROUTINE calc_int_y(func,nr1,nr2,nr3,integral) 
  !
  USE kinds,  ONLY : DP
  !
  IMPLICIT NONE
  !
  REAL(DP) :: func(nr1,nr2,nr3)
  INTEGER :: nr1,nr2,nr3
  REAL(DP) :: integral(nr2)
  !
  INTEGER :: i1,i2,i3
  !
  integral = 0._DP
  DO i1=1,nr1
     DO i2=1,nr2
        DO i3=1,nr3
           !
           integral(i2) = integral(i2) + func(i1,i2,i3) 
           !
        ENDDO
     ENDDO
  ENDDO
  !
END SUBROUTINE
!
!
SUBROUTINE calc_int_z(func,nr1,nr2,nr3,integral) 
  !
  USE kinds,  ONLY : DP
  !
  IMPLICIT NONE
  !
  REAL(DP) :: func(nr1,nr2,nr3)
  INTEGER :: nr1,nr2,nr3
  REAL(DP) :: integral(nr3)
  !
  INTEGER :: i1,i2,i3
  !
  integral = 0._DP
  DO i1=1,nr1
     DO i2=1,nr2
        DO i3=1,nr3
           !
           integral(i3) = integral(i3) + func(i1,i2,i3) 
           !
        ENDDO
     ENDDO
  ENDDO
  !
END SUBROUTINE