-
Notifications
You must be signed in to change notification settings - Fork 1
/
gw_kp_to_real_space_and_back.F
292 lines (210 loc) · 10.9 KB
/
gw_kp_to_real_space_and_back.F
1
2
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief
!> \author Jan Wilhelm
!> \date 05.2024
! **************************************************************************************************
MODULE gw_kp_to_real_space_and_back
USE cp_cfm_types, ONLY: cp_cfm_type
USE cp_fm_types, ONLY: cp_fm_set_all,&
cp_fm_type
USE kinds, ONLY: dp
USE kpoint_types, ONLY: kpoint_type
USE mathconstants, ONLY: gaussi,&
twopi,&
z_one,&
z_zero
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_kp_to_real_space_and_back'
PUBLIC :: fm_trafo_rs_to_ikp, trafo_rs_to_ikp, trafo_ikp_to_rs, fm_add_ikp_to_rs, &
add_ikp_to_all_rs
CONTAINS
! **************************************************************************************************
!> \brief ...
!> \param cfm_ikp ...
!> \param fm_rs ...
!> \param kpoints ...
!> \param ikp ...
! **************************************************************************************************
SUBROUTINE fm_trafo_rs_to_ikp(cfm_ikp, fm_rs, kpoints, ikp)
TYPE(cp_cfm_type) :: cfm_ikp
TYPE(cp_fm_type), DIMENSION(:) :: fm_rs
TYPE(kpoint_type), POINTER :: kpoints
INTEGER :: ikp
CHARACTER(LEN=*), PARAMETER :: routineN = 'fm_trafo_rs_to_ikp'
INTEGER :: handle, img, nimages, nimages_fm_rs
CALL timeset(routineN, handle)
nimages = SIZE(kpoints%index_to_cell, 1)
nimages_fm_rs = SIZE(fm_rs)
CPASSERT(nimages == nimages_fm_rs)
cfm_ikp%local_data(:, :) = z_zero
DO img = 1, nimages
CALL add_rs_to_ikp(fm_rs(img)%local_data, cfm_ikp%local_data, kpoints%index_to_cell, &
kpoints%xkp(1:3, ikp), img)
END DO
CALL timestop(handle)
END SUBROUTINE fm_trafo_rs_to_ikp
! **************************************************************************************************
!> \brief ...
!> \param array_rs ...
!> \param array_kp ...
!> \param index_to_cell ...
!> \param xkp ...
! **************************************************************************************************
SUBROUTINE trafo_rs_to_ikp(array_rs, array_kp, index_to_cell, xkp)
REAL(KIND=dp), DIMENSION(:, :, :) :: array_rs
COMPLEX(KIND=dp), DIMENSION(:, :) :: array_kp
INTEGER, DIMENSION(:, :) :: index_to_cell
REAL(KIND=dp) :: xkp(3)
CHARACTER(LEN=*), PARAMETER :: routineN = 'trafo_rs_to_ikp'
INTEGER :: handle, i_cell, nimages
CALL timeset(routineN, handle)
nimages = SIZE(index_to_cell, 1)
CPASSERT(nimages == SIZE(array_rs, 3))
array_kp(:, :) = 0.0_dp
DO i_cell = 1, nimages
CALL add_rs_to_ikp(array_rs(:, :, i_cell), array_kp, index_to_cell, xkp, i_cell)
END DO
CALL timestop(handle)
END SUBROUTINE trafo_rs_to_ikp
! **************************************************************************************************
!> \brief ...
!> \param array_rs ...
!> \param array_kp ...
!> \param index_to_cell ...
!> \param xkp ...
!> \param i_cell ...
! **************************************************************************************************
SUBROUTINE add_rs_to_ikp(array_rs, array_kp, index_to_cell, xkp, i_cell)
REAL(KIND=dp), DIMENSION(:, :) :: array_rs
COMPLEX(KIND=dp), DIMENSION(:, :) :: array_kp
INTEGER, DIMENSION(:, :) :: index_to_cell
REAL(KIND=dp) :: xkp(3)
INTEGER :: i_cell
CHARACTER(LEN=*), PARAMETER :: routineN = 'add_rs_to_ikp'
COMPLEX(KIND=dp) :: expikR
INTEGER :: handle
REAL(KIND=dp) :: arg
CALL timeset(routineN, handle)
arg = REAL(index_to_cell(i_cell, 1), dp)*xkp(1) + &
REAL(index_to_cell(i_cell, 2), dp)*xkp(2) + &
REAL(index_to_cell(i_cell, 3), dp)*xkp(3)
expikR = z_one*COS(twopi*arg) + gaussi*SIN(twopi*arg)
array_kp(:, :) = array_kp(:, :) + expikR*array_rs(:, :)
CALL timestop(handle)
END SUBROUTINE add_rs_to_ikp
! **************************************************************************************************
!> \brief ...
!> \param array_kp ...
!> \param array_rs ...
!> \param cell ...
!> \param kpoints ...
! **************************************************************************************************
SUBROUTINE trafo_ikp_to_rs(array_kp, array_rs, cell, kpoints)
COMPLEX(KIND=dp), DIMENSION(:, :, :) :: array_kp
REAL(KIND=dp), DIMENSION(:, :) :: array_rs
INTEGER :: cell(3)
TYPE(kpoint_type), POINTER :: kpoints
CHARACTER(LEN=*), PARAMETER :: routineN = 'trafo_ikp_to_rs'
INTEGER :: handle, ikp
CALL timeset(routineN, handle)
CPASSERT(kpoints%nkp == SIZE(array_kp, 3))
array_rs(:, :) = 0.0_dp
DO ikp = 1, kpoints%nkp
CALL add_ikp_to_rs(array_kp(:, :, ikp), array_rs, cell, kpoints, ikp)
END DO
CALL timestop(handle)
END SUBROUTINE trafo_ikp_to_rs
! **************************************************************************************************
!> \brief ...
!> \param cfm_ikp ...
!> \param fm_rs ...
!> \param kpoints ...
!> \param ikp ...
! **************************************************************************************************
SUBROUTINE fm_add_ikp_to_rs(cfm_ikp, fm_rs, kpoints, ikp)
TYPE(cp_cfm_type) :: cfm_ikp
TYPE(cp_fm_type), DIMENSION(:) :: fm_rs
TYPE(kpoint_type), POINTER :: kpoints
INTEGER :: ikp
CHARACTER(LEN=*), PARAMETER :: routineN = 'fm_add_ikp_to_rs'
INTEGER :: handle, img, nimages, nimages_fm_rs
INTEGER, ALLOCATABLE, DIMENSION(:, :) :: index_to_cell
CALL timeset(routineN, handle)
nimages = SIZE(kpoints%index_to_cell, 1)
nimages_fm_rs = SIZE(fm_rs)
CPASSERT(nimages == nimages_fm_rs)
ALLOCATE (index_to_cell(nimages, 3))
index_to_cell(1:nimages, 1:3) = kpoints%index_to_cell(1:nimages, 1:3)
DO img = 1, nimages
IF (ikp == 1) CALL cp_fm_set_all(fm_rs(img), 0.0_dp)
CALL add_ikp_to_rs(cfm_ikp%local_data(:, :), fm_rs(img)%local_data, &
index_to_cell(img, 1:3), kpoints, ikp)
END DO
CALL timestop(handle)
END SUBROUTINE fm_add_ikp_to_rs
! **************************************************************************************************
!> \brief ...
!> \param array_kp ...
!> \param array_rs ...
!> \param kpoints ...
!> \param ikp ...
!> \param index_to_cell_ext ...
! **************************************************************************************************
SUBROUTINE add_ikp_to_all_rs(array_kp, array_rs, kpoints, ikp, index_to_cell_ext)
COMPLEX(KIND=dp), DIMENSION(:, :) :: array_kp
REAL(KIND=dp), DIMENSION(:, :, :) :: array_rs
TYPE(kpoint_type), POINTER :: kpoints
INTEGER :: ikp
INTEGER, DIMENSION(:, :), OPTIONAL, POINTER :: index_to_cell_ext
CHARACTER(LEN=*), PARAMETER :: routineN = 'add_ikp_to_all_rs'
INTEGER :: cell(3), handle, img, nimages
INTEGER, DIMENSION(:, :), POINTER :: index_to_cell
CALL timeset(routineN, handle)
IF (PRESENT(index_to_cell_ext)) THEN
index_to_cell => index_to_cell_ext
ELSE
index_to_cell => kpoints%index_to_cell
END IF
nimages = SIZE(index_to_cell, 1)
CPASSERT(SIZE(array_rs, 3) == nimages)
DO img = 1, nimages
cell(1:3) = index_to_cell(img, 1:3)
CALL add_ikp_to_rs(array_kp, array_rs(:, :, img), cell, kpoints, ikp)
END DO
CALL timestop(handle)
END SUBROUTINE add_ikp_to_all_rs
! **************************************************************************************************
!> \brief ...
!> \param array_kp ...
!> \param array_rs ...
!> \param cell ...
!> \param kpoints ...
!> \param ikp ...
! **************************************************************************************************
SUBROUTINE add_ikp_to_rs(array_kp, array_rs, cell, kpoints, ikp)
COMPLEX(KIND=dp), DIMENSION(:, :) :: array_kp
REAL(KIND=dp), DIMENSION(:, :) :: array_rs
INTEGER :: cell(3)
TYPE(kpoint_type), POINTER :: kpoints
INTEGER :: ikp
CHARACTER(LEN=*), PARAMETER :: routineN = 'add_ikp_to_rs'
INTEGER :: handle
REAL(KIND=dp) :: arg, im, re
CALL timeset(routineN, handle)
arg = REAL(cell(1), dp)*kpoints%xkp(1, ikp) + &
REAL(cell(2), dp)*kpoints%xkp(2, ikp) + &
REAL(cell(3), dp)*kpoints%xkp(3, ikp)
re = COS(twopi*arg)*kpoints%wkp(ikp)
im = SIN(twopi*arg)*kpoints%wkp(ikp)
array_rs(:, :) = array_rs(:, :) + re*REAL(array_kp(:, :)) + im*AIMAG(array_kp(:, :))
CALL timestop(handle)
END SUBROUTINE add_ikp_to_rs
END MODULE gw_kp_to_real_space_and_back