25 dbcsr_type_antisymmetric,&
26 dbcsr_type_no_symmetry
42#include "./base/base_uses.f90"
48 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'kpoint_k_r_trafo_simple'
71 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rs_dbcsr_in
73 REAL(kind=
dp),
DIMENSION(:, :, :, :) :: rs_array_out
74 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index_out
76 CHARACTER(len=*),
PARAMETER :: routinen =
'replicate_rs_matrices'
78 CHARACTER :: matrix_sym
79 INTEGER :: handle, iatom, ispin, jatom, n_spin, &
81 INTEGER,
DIMENSION(3) :: cell
84 DIMENSION(:),
POINTER :: iterator
88 CALL timeset(routinen, handle)
90 IF (
SIZE(rs_dbcsr_in, 2) < 1)
THEN
91 CALL cp_abort(__location__,
"No source image cells provided!")
94 sab_kp_src => kpoint_in%sab_nl
97 n_spin =
SIZE(rs_dbcsr_in, 1)
98 CALL dbcsr_get_info(rs_dbcsr_in(1, 1)%matrix, group=group, matrix_type=matrix_sym)
103 src_index = kpoint_in%cell_to_index(cell(1), cell(2), cell(3))
104 IF (src_index == 0)
THEN
105 CALL cp_abort(__location__,
"Image not found in the source array.")
108 IF (matrix_sym == dbcsr_type_no_symmetry)
THEN
109 CALL write_block_no_sym(iatom, jatom, cell, rs_dbcsr_in(ispin, src_index)%matrix, &
110 rs_array_out(ispin, :, :, :), cell_to_index_out)
112 CALL write_block_symmetric(iatom, jatom, cell, rs_dbcsr_in(ispin, src_index)%matrix, &
113 rs_array_out(ispin, :, :, :), cell_to_index_out, &
114 merge(-1.0_dp, 1.0_dp, matrix_sym == dbcsr_type_antisymmetric))
119 CALL group%sum(rs_array_out(:, :, :, :))
120 CALL timestop(handle)
134 SUBROUTINE write_block_symmetric(iatom, jatom, cell, matrix_in, array_out, cell_to_index_out, transpose_sign)
135 INTEGER,
INTENT(IN) :: iatom, jatom
136 INTEGER,
DIMENSION(3),
INTENT(IN) :: cell
138 REAL(kind=
dp),
DIMENSION(:, :, :),
INTENT(INOUT) :: array_out
139 INTEGER,
DIMENSION(:, :, :),
INTENT(IN),
POINTER :: cell_to_index_out
140 REAL(
dp),
INTENT(IN) :: transpose_sign
142 INTEGER :: col_offset, col_size, dest_index, &
143 dest_index_t, i, i_g, j, j_g, &
145 INTEGER,
DIMENSION(:),
POINTER :: col_offsets, row_offsets
147 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
149 CALL dbcsr_get_info(matrix_in, row_blk_offset=row_offsets, col_blk_offset=col_offsets)
150 IF (iatom > jatom)
THEN
152 row_size=row_size, col_size=col_size, found=found)
153 IF (.NOT. found)
RETURN
155 dest_index = cell_to_index_out(-cell(1), -cell(2), -cell(3))
156 IF (dest_index == 0) cpabort(
"Mirror image index not present.")
157 dest_index_t = cell_to_index_out(cell(1), cell(2), cell(3))
158 IF (dest_index_t == 0) cpabort(
"Image index not present.")
159 row_offset = row_offsets(jatom)
160 col_offset = col_offsets(iatom)
163 row_size=row_size, col_size=col_size, found=found)
164 IF (.NOT. found)
RETURN
166 dest_index = cell_to_index_out(cell(1), cell(2), cell(3))
167 IF (dest_index == 0) cpabort(
"Image index not present.")
168 dest_index_t = cell_to_index_out(-cell(1), -cell(2), -cell(3))
169 IF (dest_index_t == 0) cpabort(
"Mirror image index not present.")
170 row_offset = row_offsets(iatom)
171 col_offset = col_offsets(jatom)
178 i_g = i + row_offset - 1
180 j_g = j + col_offset - 1
181 array_out(i_g, j_g, dest_index) = block(i, j)
182 IF (iatom /= jatom) array_out(j_g, i_g, dest_index_t) = transpose_sign*block(i, j)
186 END SUBROUTINE write_block_symmetric
198 SUBROUTINE write_block_no_sym(iatom, jatom, cell, matrix_in, array_out, cell_to_index_out)
199 INTEGER,
INTENT(IN) :: iatom, jatom
200 INTEGER,
DIMENSION(3),
INTENT(IN) :: cell
202 REAL(kind=
dp),
DIMENSION(:, :, :),
INTENT(INOUT) :: array_out
203 INTEGER,
DIMENSION(:, :, :),
INTENT(IN),
POINTER :: cell_to_index_out
205 INTEGER :: col_offset, col_size, dest_index, i, &
206 i_g, j, j_g, row_offset, row_size
207 INTEGER,
DIMENSION(:),
POINTER :: col_offsets, row_offsets
209 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
211 dest_index = cell_to_index_out(cell(1), cell(2), cell(3))
212 IF (dest_index == 0) cpabort(
"Image index not present.")
213 CALL dbcsr_get_info(matrix_in, row_blk_offset=row_offsets, col_blk_offset=col_offsets)
214 row_offset = row_offsets(iatom)
215 col_offset = col_offsets(jatom)
217 row_size=row_size, col_size=col_size)
221 i_g = i + row_offset - 1
223 j_g = j + col_offset - 1
224 array_out(i_g, j_g, dest_index) = block(i, j)
228 END SUBROUTINE write_block_no_sym
240 SUBROUTINE rs_to_kp(rs_real, ks_complex, index_to_cell, xkp, deriv_direction, hmat)
241 REAL(kind=
dp),
DIMENSION(:, :, :),
INTENT(IN) :: rs_real
242 COMPLEX(kind=dp),
DIMENSION(:, :),
INTENT(OUT) :: ks_complex
243 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell
244 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
245 INTEGER,
INTENT(IN),
OPTIONAL :: deriv_direction
246 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(IN), &
249 CHARACTER(len=*),
PARAMETER :: routinen =
'rs_to_kp'
251 INTEGER :: handle, i, n_images
253 CALL timeset(routinen, handle)
255 n_images =
SIZE(rs_real, 3)
257 IF (
PRESENT(deriv_direction))
THEN
258 IF (.NOT.
PRESENT(hmat) .AND. deriv_direction /= 0)
THEN
259 CALL cp_abort(__location__,
"Derivative requested but h matrix not provided!")
263 ks_complex(:, :) = cmplx(0.0, 0.0, kind=
dp)
265 CALL add_rs_to_kp(ks_complex, rs_real(:, :, i), xkp, i, index_to_cell, deriv_direction, hmat)
267 CALL timestop(handle)
282 SUBROUTINE fm_gamma_to_kp(cfm_kp, fm_gamma, cell, particle_set, atom_from_bf, index_to_cell, xkp)
285 TYPE(
cell_type),
INTENT(IN),
POINTER :: cell
286 TYPE(
particle_type),
DIMENSION(:),
INTENT(IN) :: particle_set
287 INTEGER,
DIMENSION(:),
INTENT(IN) :: atom_from_bf
288 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: index_to_cell
289 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
291 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_gamma_to_kp'
293 COMPLEX(KIND=dp) :: phase
294 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: phases, row_phases
295 INTEGER :: handle, i_atom, i_atom_old, i_cell, &
296 i_mic_cell, i_row, j_atom, j_atom_old, &
297 j_col, ncol_local, nrow_local, &
299 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
300 LOGICAL :: same_layout
302 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: weights
304 CALL timeset(routinen, handle)
306 cpassert(
ASSOCIATED(fm_gamma%matrix_struct))
307 cpassert(fm_gamma%matrix_struct%nrow_global == fm_gamma%matrix_struct%ncol_global)
308 cpassert(
SIZE(atom_from_bf) == fm_gamma%matrix_struct%nrow_global)
309 cpassert(all(atom_from_bf >= 1) .AND. all(atom_from_bf <=
SIZE(particle_set)))
310 cpassert(
SIZE(index_to_cell, 1) == 3 .AND.
SIZE(index_to_cell, 2) > 0)
311 IF (.NOT.
ASSOCIATED(cfm_kp%local_data))
CALL cp_cfm_create(cfm_kp, fm_gamma%matrix_struct)
313 same_layout = same_layout .AND. all(cfm_kp%matrix_struct%descriptor == fm_gamma%matrix_struct%descriptor)
314 cpassert(same_layout)
315 CALL cp_fm_get_info(fm_gamma, nrow_local=nrow_local, ncol_local=ncol_local, &
316 row_indices=row_indices, col_indices=col_indices)
318 num_cells =
SIZE(index_to_cell, 2)
319 ALLOCATE (weights(num_cells), phases(num_cells), row_phases(nrow_local))
320 DO i_cell = 1, num_cells
321 arg = dot_product(real(index_to_cell(:, i_cell), kind=
dp), xkp)
322 phases(i_cell) = cmplx(cos(
twopi*arg), sin(
twopi*arg), kind=
dp)
326 phase = cmplx(1.0_dp, 0.0_dp,
dp)
327 DO j_col = 1, ncol_local
328 j_atom = atom_from_bf(col_indices(j_col))
329 IF (j_atom /= j_atom_old)
THEN
332 DO i_row = 1, nrow_local
333 i_atom = atom_from_bf(row_indices(i_row))
334 IF (i_atom /= i_atom_old)
THEN
336 cell, index_to_cell, weights)
338 i_mic_cell = findloc(weights > 0.0_dp .AND. &
339 all(abs(index_to_cell) <= 1, dim=1), .true., dim=1, back=.true.)
340 cpassert(i_mic_cell > 0)
341 phase = phases(i_mic_cell)
343 row_phases(i_row) = phase
348 cfm_kp%local_data(1:nrow_local, j_col) = row_phases*fm_gamma%local_data(1:nrow_local, j_col)
351 CALL timestop(handle)
371 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_rs_to_kp'
373 INTEGER :: handle, img, nimages, nimages_fm_rs
375 CALL timeset(routinen, handle)
377 nimages =
SIZE(kpoints%index_to_cell, 2)
378 nimages_fm_rs =
SIZE(fm_rs)
380 IF (nimages /= nimages_fm_rs)
CALL cp_abort(__location__,
"Index to cell and provided fm "// &
381 "array are inconsistent.")
383 cfm_kp%local_data(:, :) =
z_zero
386 CALL add_rs_to_kp(cfm_kp%local_data, fm_rs(img)%local_data, kpoints%xkp(1:3, ikp), &
387 img, kpoints%index_to_cell)
391 CALL timestop(handle)
408 SUBROUTINE add_rs_to_kp(ks_array_out, rs_array_in, xkp, imindex, index_to_cell, deriv_direction, hmat)
409 COMPLEX(kind=dp),
DIMENSION(:, :),
INTENT(INOUT) :: ks_array_out
410 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: rs_array_in
411 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xkp
412 INTEGER,
INTENT(IN) :: imindex
413 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: index_to_cell
414 INTEGER,
INTENT(IN),
OPTIONAL :: deriv_direction
415 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(IN), &
418 COMPLEX(kind=dp) :: deriv_factor, phase_factor
420 REAL(kind=
dp),
DIMENSION(3) :: cell_vector
422 IF (
PRESENT(deriv_direction) .AND. (.NOT.
PRESENT(hmat)))
THEN
423 CALL cp_abort(__location__,
"Deriv. direction given but no hmat provided")
426 deriv_factor = cmplx(1.0, 0.0, kind=
dp)
427 IF (
PRESENT(deriv_direction))
THEN
428 cell_vector = matmul(hmat, index_to_cell(1:3, imindex))
430 deriv_factor = cmplx(0.0, cell_vector(deriv_direction), kind=
dp)
433 phase_factor = cmplx(cos(
twopi*sum(xkp(:)*index_to_cell(:, imindex))), &
434 sin(
twopi*sum(xkp(:)*index_to_cell(:, imindex))), kind=
dp)
436 DO i = 1,
SIZE(ks_array_out, 1)
437 DO j = 1,
SIZE(ks_array_out, 2)
438 ks_array_out(i, j) = ks_array_out(i, j) + &
439 deriv_factor*phase_factor*rs_array_in(i, j)
442 END SUBROUTINE add_rs_to_kp
456 COMPLEX(kind=dp),
DIMENSION(:, :) :: array_kp
457 REAL(kind=
dp),
DIMENSION(:, :, :) :: array_rs
460 INTEGER,
DIMENSION(:, :),
OPTIONAL,
POINTER :: index_to_cell_ext
462 CHARACTER(len=*),
PARAMETER :: routinen =
'add_kp_to_all_rs'
464 INTEGER :: handle, img
465 INTEGER,
DIMENSION(3) :: cell
466 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell
468 index_to_cell => kpoints%index_to_cell
469 IF (
PRESENT(index_to_cell_ext)) index_to_cell => index_to_cell_ext
471 CALL timeset(routinen, handle)
473 IF (
SIZE(array_rs, 3) /=
SIZE(index_to_cell, 2))
CALL cp_abort(__location__, &
474 "The provided RS array and cell_to_index array are inconsistent.")
476 DO img = 1,
SIZE(array_rs, 3)
477 cell(:) = index_to_cell(:, img)
478 CALL add_kp_to_rs(array_kp, array_rs(:, :, img), cell, kpoints, ikp)
481 CALL timestop(handle)
500 CHARACTER(len=*),
PARAMETER :: routinen =
'fm_add_kp_to_all_rs'
502 INTEGER :: handle, img
503 INTEGER,
DIMENSION(3) :: cell
505 CALL timeset(routinen, handle)
507 IF (
SIZE(fm_rs, 1) /=
SIZE(kpoints%index_to_cell, 2))
CALL cp_abort(__location__, &
508 "The provided RS array and cell_to_index array are inconsistent.")
510 DO img = 1,
SIZE(fm_rs, 1)
511 cell(:) = kpoints%index_to_cell(:, img)
512 CALL add_kp_to_rs(cfm_kp%local_data, fm_rs(img)%local_data, cell, kpoints, ikp)
514 CALL timestop(handle)
529 COMPLEX(kind=dp),
DIMENSION(:, :) :: array_kp
530 REAL(kind=
dp),
DIMENSION(:, :) :: array_rs
531 INTEGER,
DIMENSION(3) :: cell
535 REAL(kind=
dp) :: phase
538 phase =
twopi*sum(kpoints%xkp(:, ikp)*cell(:))
542 array_rs(:, :) = array_rs(:, :) + (real(array_kp(:, :))*cos(phase) + &
543 aimag(array_kp(:, :))*sin(phase))*kpoints%wkp(ikp)
556 SUBROUTINE kp_to_rs(array_kp, array_rs, cell, kpoints)
557 COMPLEX(kind=dp),
DIMENSION(:, :, :) :: array_kp
558 REAL(kind=
dp),
DIMENSION(:, :) :: array_rs
559 INTEGER,
DIMENSION(3) :: cell
562 CHARACTER(len=*),
PARAMETER :: routinen =
'kp_to_rs'
564 INTEGER :: handle, ikp
566 IF (kpoints%nkp /=
SIZE(array_kp, 3))
CALL cp_abort(__location__, &
567 "Provided kpoints and array_kp are inconsistent.")
569 CALL timeset(routinen, handle)
571 array_rs(:, :) = 0.0_dp
572 DO ikp = 1, kpoints%nkp
573 CALL add_kp_to_rs(array_kp(:, :, ikp), array_rs, cell, kpoints, ikp)
576 CALL timestop(handle)
577 END SUBROUTINE kp_to_rs
Handles all functions related to the CELL.
subroutine, public minimum_image_weights(ra, rb, cell, index_to_cell, weights)
Distribute an atom-pair contribution equally among its nearest candidate images. Images within 1....
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
subroutine, public dbcsr_get_readonly_block_p(matrix, row, col, block, found, row_size, col_size)
Like dbcsr_get_block_p() but with matrix being INTENT(IN). When invoking this routine,...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
represent the structure of a full matrix
logical function, public cp_fm_struct_equivalent(fmstruct1, fmstruct2)
returns true if the two matrix structures are equivalent, false otherwise.
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
Defines the basic variable types.
integer, parameter, public dp
Implements simple k-space/R-space transformations and Gamma-point MIC reconstruction.
subroutine, public rs_to_kp(rs_real, ks_complex, index_to_cell, xkp, deriv_direction, hmat)
Integrate RS matrices (stored as Fortran array) into a kpoint matrix at given kp.
subroutine, public fm_add_kp_to_all_rs(cfm_kp, fm_rs, kpoints, ikp)
Adds given kpoint matrix to a single rs matrix.
subroutine, public add_kp_to_rs(array_kp, array_rs, cell, kpoints, ikp)
Adds given kpoint matrix to a single rs matrix.
subroutine, public add_kp_to_all_rs(array_kp, array_rs, kpoints, ikp, index_to_cell_ext)
Adds given kpoint matrix to all rs matrices.
subroutine, public fm_gamma_to_kp(cfm_kp, fm_gamma, cell, particle_set, atom_from_bf, index_to_cell, xkp)
Reconstruct a complex k-point matrix from a real Gamma matrix using one MIC phase....
subroutine, public replicate_rs_matrices(rs_dbcsr_in, kpoint_in, rs_array_out, cell_to_index_out)
Convert dbcsr matrices representing operators in real-space image cells to arrays.
subroutine, public fm_rs_to_kp(cfm_kp, fm_rs, kpoints, ikp)
Transforms array of fm RS matrices into cfm k-space matrix, at given kpoint index.
Types and basic routines needed for a kpoint calculation.
Definition of mathematical constants and functions.
real(kind=dp), parameter, public twopi
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
Define the data structure for the particle information.
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
Type defining parameters related to the simulation cell.
Represent a complex full matrix.
Contains information about kpoints.