(git:58e3e09)
kpoint_types.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief Types and basic routines needed for a kpoint calculation
10 !> \par History
11 !> 2014.07 created [JGH]
12 !> 2014.11 unified k-point and gamma-point code [Ole Schuett]
13 !> \author JGH
14 ! **************************************************************************************************
17  cp_blacs_env_type
18  USE cp_fm_types, ONLY: cp_fm_release,&
19  cp_fm_type
21  cp_logger_type
27  section_vals_type,&
29  USE kinds, ONLY: default_string_length,&
30  dp
31  USE mathconstants, ONLY: twopi
33  mp_para_env_type
34  USE physcon, ONLY: angstrom
36  qs_diis_buffer_type_kp
37  USE qs_matrix_pools, ONLY: mpools_release,&
38  qs_matrix_pools_type
39  USE qs_mo_types, ONLY: deallocate_mo_set,&
40  mo_set_type
41  USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
42  USE string_utilities, ONLY: uppercase
43 #include "./base/base_uses.f90"
44 
45  IMPLICIT NONE
46 
47  PRIVATE
48 
49  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'kpoint_types'
50 
51  PUBLIC :: kpoint_type
54  PUBLIC :: kpoint_env_type, kpoint_env_p_type
56  PUBLIC :: kpoint_sym_type
57  PUBLIC :: kpoint_sym_create
58 
59 ! **************************************************************************************************
60 !> \brief Keeps information about a specific k-point
61 !> \param nkpoint the kpoint index
62 !> \param wkp weight of this kpoint
63 !> \param xkp kpoint coordinates in units of b-vector
64 !> \param is_local if this kpoint is calculated on a single thread
65 !> \param mos associated MOs (r/i,spin)
66 !> \param pmat associated density matrix (r/i,spin)
67 !> \param wmat associated energy weighted density matrix (r/i,spin)
68 !> \param smat associated overlap matrix (for ADMM) (r/i,spin)
69 !> \param amat associated ADMM basis projection matrix (r/i,spin)
70 !> \author JGH
71 ! **************************************************************************************************
72  TYPE kpoint_env_type
73  INTEGER :: nkpoint
74  REAL(KIND=dp) :: wkp
75  REAL(KIND=dp), DIMENSION(3) :: xkp
76  LOGICAL :: is_local
77  TYPE(mo_set_type), DIMENSION(:, :), POINTER :: mos
78  TYPE(cp_fm_type), DIMENSION(:, :), POINTER :: pmat
79  TYPE(cp_fm_type), DIMENSION(:, :), POINTER :: wmat
80  TYPE(cp_fm_type), DIMENSION(:, :), POINTER :: smat
81  TYPE(cp_fm_type), DIMENSION(:, :), POINTER :: amat
82  END TYPE kpoint_env_type
83 
84  TYPE kpoint_env_p_type
85  TYPE(kpoint_env_type), POINTER :: kpoint_env
86  END TYPE kpoint_env_p_type
87 
88 ! **************************************************************************************************
89 !> \brief Keeps symmetry information about a specific k-point
90 !> \param apply_symmetry ...
91 !> \param nwght kpoint multiplicity
92 !> \param xkp kpoint coordinates
93 !> \param rot rotation matrices
94 !> \param f0 atom permutation
95 !> \author JGH
96 ! **************************************************************************************************
97  TYPE kpoint_sym_type
98  LOGICAL :: apply_symmetry
99  INTEGER :: nwght
100  REAL(KIND=dp), DIMENSION(:, :), POINTER :: xkp
101  REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: rot
102  INTEGER, DIMENSION(:, :), POINTER :: f0
103  END TYPE kpoint_sym_type
104 
105  TYPE kpoint_sym_p_type
106  TYPE(kpoint_sym_type), POINTER :: kpoint_sym
107  END TYPE kpoint_sym_p_type
108 
109 ! **************************************************************************************************
110 !> \brief Contains information about kpoints
111 !> \par History
112 !> 2014.07 created [JGH]
113 !> \param kp_scheme [input] Type of kpoint grid
114 !> \param nkp_grid [input] Grid points
115 !> \param kp_shift [input] Shift of the grid
116 !> \param use_real_wfn [input] real/complex wfn
117 !> \param symmetry [input] use symmetry (atoms) to reduce kpoints
118 !> \param full_grid [input] don't reduce kpoints at all
119 !> \param verbose [input] more output information
120 !> \param eps_geo [input] accuracy of atom symmetry detection
121 !> \param parallel_group_size [input] kpoint group size
122 !> \param nkp number of kpoints
123 !> \param xkp kpoint coordinates
124 !> \param wkp kpoint weights
125 !> \param para_env 'global' parallel environment
126 !> \param para_env_kp parallel environment of the kpoint calculation
127 !> \param para_env_inter_kp parallel environment between kpoints
128 !> \param iogrp this kpoint group has the IO processor
129 !> \param nkp_groups number of kpoint groups
130 !> \param kp_dist kpoints distribution on groups
131 !> \param kp_range kpoints distribution for local processor
132 !> \param blacs_env BLACS env for the kpoint group
133 !> \param opmats Operator matrices
134 !> \param kp_env Information for each kpoint
135 !> \param mpools FM matrix pools for kpoint groups
136 !> \author JGH
137 ! **************************************************************************************************
138  TYPE kpoint_type
139  CHARACTER(LEN=default_string_length) :: kp_scheme
140  INTEGER, DIMENSION(3) :: nkp_grid
141  REAL(KIND=dp), DIMENSION(3) :: kp_shift
142  LOGICAL :: use_real_wfn
143  LOGICAL :: symmetry
144  LOGICAL :: full_grid
145  LOGICAL :: verbose
146  REAL(KIND=dp) :: eps_geo
147  INTEGER :: parallel_group_size
148  INTEGER :: nkp
149  REAL(KIND=dp), DIMENSION(:, :), POINTER :: xkp => null()
150  REAL(KIND=dp), DIMENSION(:), POINTER :: wkp => null()
151  ! parallel environment
152  TYPE(mp_para_env_type), POINTER :: para_env => null()
153  TYPE(cp_blacs_env_type), POINTER :: blacs_env_all => null()
154  TYPE(mp_para_env_type), POINTER :: para_env_kp => null(), &
155  para_env_inter_kp => null()
156  LOGICAL :: iogrp
157  INTEGER :: nkp_groups
158  INTEGER, DIMENSION(:, :), POINTER :: kp_dist => null()
159  INTEGER, DIMENSION(2) :: kp_range
160  TYPE(cp_blacs_env_type), POINTER :: blacs_env => null()
161  INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index => null()
162  INTEGER, DIMENSION(:, :), POINTER :: index_to_cell => null()
163  TYPE(neighbor_list_set_p_type), &
164  DIMENSION(:), POINTER :: sab_nl => null(), &
165  sab_nl_nosym => null()
166  ! environment
167  TYPE(kpoint_env_p_type), DIMENSION(:), &
168  POINTER :: kp_env => null()
169  TYPE(kpoint_env_p_type), DIMENSION(:), &
170  POINTER :: kp_aux_env => null()
171  TYPE(kpoint_sym_p_type), DIMENSION(:), &
172  POINTER :: kp_sym => null()
173  TYPE(qs_matrix_pools_type), POINTER :: mpools => null()
174  TYPE(qs_diis_buffer_type_kp), POINTER :: scf_diis_buffer => null()
175  TYPE(qs_matrix_pools_type), POINTER :: mpools_aux_fit => null()
176  END TYPE kpoint_type
177 
178 ! **************************************************************************************************
179 
180 CONTAINS
181 
182 ! **************************************************************************************************
183 !> \brief Create a kpoint environment
184 !> \param kpoint All the kpoint information
185 !> \author JGH
186 ! **************************************************************************************************
187  SUBROUTINE kpoint_create(kpoint)
188  TYPE(kpoint_type), POINTER :: kpoint
189 
190  cpassert(.NOT. ASSOCIATED(kpoint))
191 
192  ALLOCATE (kpoint)
193 
194  kpoint%kp_scheme = ""
195  kpoint%nkp_grid = 0
196  kpoint%kp_shift = 0.0_dp
197  kpoint%symmetry = .false.
198  kpoint%verbose = .false.
199  kpoint%full_grid = .false.
200  kpoint%use_real_wfn = .false.
201  kpoint%eps_geo = 1.0e-6_dp
202  kpoint%parallel_group_size = -1
203 
204  kpoint%nkp = 0
205 
206  NULLIFY (kpoint%xkp, kpoint%wkp)
207  NULLIFY (kpoint%kp_dist)
208 
209  NULLIFY (kpoint%para_env)
210  NULLIFY (kpoint%blacs_env_all)
211  NULLIFY (kpoint%para_env_kp, kpoint%para_env_inter_kp)
212  NULLIFY (kpoint%blacs_env)
213  kpoint%nkp_groups = 0
214  kpoint%iogrp = .false.
215  kpoint%kp_range = 0
216 
217  NULLIFY (kpoint%kp_env)
218  NULLIFY (kpoint%mpools)
219 
220  ALLOCATE (kpoint%cell_to_index(0:0, 0:0, 0:0))
221  kpoint%cell_to_index(:, :, :) = 1
222 
223  ALLOCATE (kpoint%index_to_cell(0:0, 0:0))
224  kpoint%index_to_cell(:, :) = 0
225 
226  END SUBROUTINE kpoint_create
227 
228 ! **************************************************************************************************
229 !> \brief Release a kpoint environment, deallocate all data
230 !> \param kpoint The kpoint environment
231 !> \author JGH
232 ! **************************************************************************************************
233  SUBROUTINE kpoint_release(kpoint)
234  TYPE(kpoint_type), POINTER :: kpoint
235 
236  INTEGER :: ik
237 
238  IF (ASSOCIATED(kpoint)) THEN
239 
240  IF (ASSOCIATED(kpoint%xkp)) THEN
241  DEALLOCATE (kpoint%xkp)
242  END IF
243  IF (ASSOCIATED(kpoint%wkp)) THEN
244  DEALLOCATE (kpoint%wkp)
245  END IF
246  IF (ASSOCIATED(kpoint%kp_dist)) THEN
247  DEALLOCATE (kpoint%kp_dist)
248  END IF
249 
250  CALL mpools_release(kpoint%mpools)
251  CALL mpools_release(kpoint%mpools_aux_fit)
252 
253  CALL cp_blacs_env_release(kpoint%blacs_env)
254  CALL cp_blacs_env_release(kpoint%blacs_env_all)
255 
256  CALL mp_para_env_release(kpoint%para_env)
257  CALL mp_para_env_release(kpoint%para_env_kp)
258  CALL mp_para_env_release(kpoint%para_env_inter_kp)
259 
260  IF (ASSOCIATED(kpoint%cell_to_index)) DEALLOCATE (kpoint%cell_to_index)
261  IF (ASSOCIATED(kpoint%index_to_cell)) DEALLOCATE (kpoint%index_to_cell)
262 
263  IF (ASSOCIATED(kpoint%kp_env)) THEN
264  DO ik = 1, SIZE(kpoint%kp_env)
265  CALL kpoint_env_release(kpoint%kp_env(ik)%kpoint_env)
266  END DO
267  DEALLOCATE (kpoint%kp_env)
268  END IF
269 
270  IF (ASSOCIATED(kpoint%kp_aux_env)) THEN
271  DO ik = 1, SIZE(kpoint%kp_aux_env)
272  CALL kpoint_env_release(kpoint%kp_aux_env(ik)%kpoint_env)
273  END DO
274  DEALLOCATE (kpoint%kp_aux_env)
275  END IF
276 
277  IF (ASSOCIATED(kpoint%kp_sym)) THEN
278  DO ik = 1, SIZE(kpoint%kp_sym)
279  CALL kpoint_sym_release(kpoint%kp_sym(ik)%kpoint_sym)
280  END DO
281  DEALLOCATE (kpoint%kp_sym)
282  END IF
283 
284  IF (ASSOCIATED(kpoint%scf_diis_buffer)) THEN
285  CALL qs_diis_b_release_kp(kpoint%scf_diis_buffer)
286  DEALLOCATE (kpoint%scf_diis_buffer)
287  END IF
288 
289  DEALLOCATE (kpoint)
290 
291  END IF
292 
293  END SUBROUTINE kpoint_release
294 
295 ! **************************************************************************************************
296 !> \brief Retrieve information from a kpoint environment
297 !> \param kpoint The kpoint environment
298 !> \param kp_scheme Type of kpoint grid
299 !> \param nkp_grid Grid points
300 !> \param kp_shift Shift of the grid
301 !> \param symmetry use symmetry (atoms) to reduce kpoints
302 !> \param verbose more output information
303 !> \param full_grid don't reduce kpoints at all
304 !> \param use_real_wfn real/complex wfn
305 !> \param eps_geo accuracy of atom symmetry detection
306 !> \param parallel_group_size kpoint group size
307 !> \param kp_range kpoints distribution for local processor
308 !> \param nkp number of kpoints
309 !> \param xkp kpoint coordinates in units of b-vector
310 !> \param wkp kpoint weights
311 !> \param para_env 'global' parallel environment
312 !> \param blacs_env_all BLACS env for the total environment
313 !> \param para_env_kp parallel environment of the kpoint calculation
314 !> \param para_env_inter_kp parallel environment between kpoints
315 !> \param blacs_env BLACS env for the kpoint group
316 !> \param kp_env Information for each kpoint
317 !> \param kp_aux_env ...
318 !> \param mpools FM matrix pools for kpoint groups
319 !> \param iogrp this kpoint group has the IO processor
320 !> \param nkp_groups number of kpoint groups
321 !> \param kp_dist kpoints distribution on groups
322 !> \param cell_to_index given a cell triple, returns the real space index
323 !> \param index_to_cell ...
324 !> \param sab_nl neighbourlist that defines real space matrices
325 !> \param sab_nl_nosym neighbourlist that defines real space matrices, non-symmetric
326 !> \author JGH
327 ! **************************************************************************************************
328  SUBROUTINE get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, &
329  full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, &
330  para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, &
331  kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, &
332  sab_nl, sab_nl_nosym)
333  TYPE(kpoint_type), INTENT(IN) :: kpoint
334  CHARACTER(LEN=*), OPTIONAL :: kp_scheme
335  INTEGER, DIMENSION(3), OPTIONAL :: nkp_grid
336  REAL(kind=dp), DIMENSION(3), OPTIONAL :: kp_shift
337  LOGICAL, OPTIONAL :: symmetry, verbose, full_grid, &
339  REAL(kind=dp), OPTIONAL :: eps_geo
340  INTEGER, OPTIONAL :: parallel_group_size
341  INTEGER, DIMENSION(2), OPTIONAL :: kp_range
342  INTEGER, OPTIONAL :: nkp
343  REAL(kind=dp), DIMENSION(:, :), OPTIONAL, POINTER :: xkp
344  REAL(kind=dp), DIMENSION(:), OPTIONAL, POINTER :: wkp
345  TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
346  TYPE(cp_blacs_env_type), OPTIONAL, POINTER :: blacs_env_all
347  TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env_kp, para_env_inter_kp
348  TYPE(cp_blacs_env_type), OPTIONAL, POINTER :: blacs_env
349  TYPE(kpoint_env_p_type), DIMENSION(:), OPTIONAL, &
350  POINTER :: kp_env, kp_aux_env
351  TYPE(qs_matrix_pools_type), OPTIONAL, POINTER :: mpools
352  LOGICAL, OPTIONAL :: iogrp
353  INTEGER, OPTIONAL :: nkp_groups
354  INTEGER, DIMENSION(:, :), OPTIONAL, POINTER :: kp_dist
355  INTEGER, DIMENSION(:, :, :), OPTIONAL, POINTER :: cell_to_index
356  INTEGER, DIMENSION(:, :), OPTIONAL, POINTER :: index_to_cell
357  TYPE(neighbor_list_set_p_type), DIMENSION(:), &
358  OPTIONAL, POINTER :: sab_nl, sab_nl_nosym
359 
360  IF (PRESENT(kp_scheme)) kp_scheme = kpoint%kp_scheme
361  IF (PRESENT(nkp_grid)) nkp_grid = kpoint%nkp_grid
362  IF (PRESENT(kp_shift)) kp_shift = kpoint%kp_shift
363  IF (PRESENT(symmetry)) symmetry = kpoint%symmetry
364  IF (PRESENT(verbose)) verbose = kpoint%verbose
365  IF (PRESENT(full_grid)) full_grid = kpoint%full_grid
366  IF (PRESENT(use_real_wfn)) use_real_wfn = kpoint%use_real_wfn
367  IF (PRESENT(eps_geo)) eps_geo = kpoint%eps_geo
368  IF (PRESENT(parallel_group_size)) parallel_group_size = kpoint%parallel_group_size
369 
370  IF (PRESENT(nkp)) nkp = kpoint%nkp
371  IF (PRESENT(wkp)) wkp => kpoint%wkp
372  IF (PRESENT(xkp)) xkp => kpoint%xkp
373 
374  IF (PRESENT(para_env)) para_env => kpoint%para_env
375  IF (PRESENT(para_env_kp)) para_env_kp => kpoint%para_env_kp
376  IF (PRESENT(para_env_inter_kp)) para_env_inter_kp => kpoint%para_env_inter_kp
377  IF (PRESENT(blacs_env_all)) blacs_env_all => kpoint%blacs_env_all
378  IF (PRESENT(blacs_env)) blacs_env => kpoint%blacs_env
379 
380  IF (PRESENT(iogrp)) iogrp = kpoint%iogrp
381  IF (PRESENT(kp_range)) kp_range = kpoint%kp_range
382  IF (PRESENT(nkp_groups)) nkp_groups = kpoint%nkp_groups
383  IF (PRESENT(kp_dist)) kp_dist => kpoint%kp_dist
384 
385  IF (PRESENT(kp_env)) kp_env => kpoint%kp_env
386  IF (PRESENT(kp_aux_env)) kp_aux_env => kpoint%kp_aux_env
387  IF (PRESENT(mpools)) mpools => kpoint%mpools
388 
389  IF (PRESENT(cell_to_index)) cell_to_index => kpoint%cell_to_index
390  IF (PRESENT(index_to_cell)) index_to_cell => kpoint%index_to_cell
391  IF (PRESENT(sab_nl)) sab_nl => kpoint%sab_nl
392  IF (PRESENT(sab_nl_nosym)) sab_nl_nosym => kpoint%sab_nl_nosym
393 
394  END SUBROUTINE get_kpoint_info
395 
396 ! **************************************************************************************************
397 !> \brief Set information in a kpoint environment
398 !> \param kpoint The kpoint environment
399 !> \param kp_scheme Type of kpoint grid
400 !> \param nkp_grid Grid points
401 !> \param kp_shift Shift of the grid
402 !> \param symmetry use symmetry (atoms) to reduce kpoints
403 !> \param verbose more output information
404 !> \param full_grid don't reduce kpoints at all
405 !> \param use_real_wfn real/complex wfn
406 !> \param eps_geo accuracy of atom symmetry detection
407 !> \param parallel_group_size kpoint group size
408 !> \param kp_range kpoints distribution for local processor
409 !> \param nkp number of kpoints
410 !> \param xkp kpoint coordinates
411 !> \param wkp kpoint weights
412 !> \param para_env 'global' parallel environment
413 !> \param blacs_env_all BLACS env for the total environment
414 !> \param para_env_kp parallel environment of the kpoint calculation
415 !> \param para_env_inter_kp parallel environment between kpoints
416 !> \param blacs_env BLACS env for the kpoint group
417 !> \param kp_env Information for each kpoint
418 !> \param kp_aux_env ...
419 !> \param mpools FM matrix pools for kpoint groups
420 !> \param iogrp this kpoint group has the IO processor
421 !> \param nkp_groups number of kpoint groups
422 !> \param kp_dist kpoints distribution on groups
423 !> \param cell_to_index given a cell triple, returns the real space index
424 !> \param index_to_cell ...
425 !> \param sab_nl neighbourlist that defines real space matrices
426 !> \param sab_nl_nosym neighbourlist that defines real space matrices
427 !> \author JGH
428 ! **************************************************************************************************
429  SUBROUTINE set_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, &
430  full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, &
431  para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, &
432  kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, &
433  sab_nl, sab_nl_nosym)
434  TYPE(kpoint_type), INTENT(INOUT) :: kpoint
435  CHARACTER(LEN=*), OPTIONAL :: kp_scheme
436  INTEGER, DIMENSION(3), OPTIONAL :: nkp_grid
437  REAL(kind=dp), DIMENSION(3), OPTIONAL :: kp_shift
438  LOGICAL, OPTIONAL :: symmetry, verbose, full_grid, &
440  REAL(kind=dp), OPTIONAL :: eps_geo
441  INTEGER, OPTIONAL :: parallel_group_size
442  INTEGER, DIMENSION(2), OPTIONAL :: kp_range
443  INTEGER, OPTIONAL :: nkp
444  REAL(kind=dp), DIMENSION(:, :), OPTIONAL, POINTER :: xkp
445  REAL(kind=dp), DIMENSION(:), OPTIONAL, POINTER :: wkp
446  TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
447  TYPE(cp_blacs_env_type), OPTIONAL, POINTER :: blacs_env_all
448  TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env_kp, para_env_inter_kp
449  TYPE(cp_blacs_env_type), OPTIONAL, POINTER :: blacs_env
450  TYPE(kpoint_env_p_type), DIMENSION(:), OPTIONAL, &
451  POINTER :: kp_env, kp_aux_env
452  TYPE(qs_matrix_pools_type), OPTIONAL, POINTER :: mpools
453  LOGICAL, OPTIONAL :: iogrp
454  INTEGER, OPTIONAL :: nkp_groups
455  INTEGER, DIMENSION(:, :), OPTIONAL, POINTER :: kp_dist
456  INTEGER, DIMENSION(:, :, :), OPTIONAL, POINTER :: cell_to_index
457  INTEGER, DIMENSION(:, :), OPTIONAL, POINTER :: index_to_cell
458  TYPE(neighbor_list_set_p_type), DIMENSION(:), &
459  OPTIONAL, POINTER :: sab_nl, sab_nl_nosym
460 
461  IF (PRESENT(kp_scheme)) kpoint%kp_scheme = kp_scheme
462  IF (PRESENT(nkp_grid)) kpoint%nkp_grid = nkp_grid
463  IF (PRESENT(kp_shift)) kpoint%kp_shift = kp_shift
464  IF (PRESENT(symmetry)) kpoint%symmetry = symmetry
465  IF (PRESENT(verbose)) kpoint%verbose = verbose
466  IF (PRESENT(full_grid)) kpoint%full_grid = full_grid
467  IF (PRESENT(use_real_wfn)) kpoint%use_real_wfn = use_real_wfn
468  IF (PRESENT(eps_geo)) kpoint%eps_geo = eps_geo
469  IF (PRESENT(parallel_group_size)) kpoint%parallel_group_size = parallel_group_size
470 
471  IF (PRESENT(nkp)) kpoint%nkp = nkp
472  IF (PRESENT(wkp)) kpoint%wkp => wkp
473  IF (PRESENT(xkp)) kpoint%xkp => xkp
474 
475  IF (PRESENT(para_env)) kpoint%para_env => para_env
476  IF (PRESENT(para_env_kp)) kpoint%para_env_kp => para_env_kp
477  IF (PRESENT(para_env_inter_kp)) kpoint%para_env_inter_kp => para_env_inter_kp
478  IF (PRESENT(blacs_env_all)) kpoint%blacs_env_all => blacs_env_all
479  IF (PRESENT(blacs_env)) kpoint%blacs_env => blacs_env
480 
481  IF (PRESENT(iogrp)) kpoint%iogrp = iogrp
482  IF (PRESENT(kp_range)) kpoint%kp_range = kp_range
483  IF (PRESENT(nkp_groups)) kpoint%nkp_groups = nkp_groups
484  IF (PRESENT(kp_dist)) kpoint%kp_dist => kp_dist
485 
486  IF (PRESENT(kp_env)) kpoint%kp_env => kp_env
487  IF (PRESENT(kp_env)) kpoint%kp_aux_env => kp_aux_env
488  IF (PRESENT(mpools)) kpoint%mpools => mpools
489  IF (PRESENT(sab_nl)) kpoint%sab_nl => sab_nl
490  IF (PRESENT(sab_nl_nosym)) kpoint%sab_nl_nosym => sab_nl_nosym
491 
492  IF (PRESENT(cell_to_index)) THEN
493  IF (ASSOCIATED(kpoint%cell_to_index)) DEALLOCATE (kpoint%cell_to_index)
494  kpoint%cell_to_index => cell_to_index
495  END IF
496 
497  IF (PRESENT(index_to_cell)) THEN
498  IF (ASSOCIATED(kpoint%index_to_cell)) DEALLOCATE (kpoint%index_to_cell)
499  kpoint%index_to_cell => index_to_cell
500  END IF
501 
502  END SUBROUTINE set_kpoint_info
503 
504 ! **************************************************************************************************
505 !> \brief Read the kpoint input section
506 !> \param kpoint The kpoint environment
507 !> \param kpoint_section The input section
508 !> \param a_vec ...
509 !> \author JGH
510 ! **************************************************************************************************
511  SUBROUTINE read_kpoint_section(kpoint, kpoint_section, a_vec)
512  TYPE(kpoint_type), INTENT(INOUT) :: kpoint
513  TYPE(section_vals_type), POINTER :: kpoint_section
514  REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: a_vec
515 
516  CHARACTER(LEN=default_string_length) :: ustr
517  CHARACTER(LEN=default_string_length), &
518  DIMENSION(:), POINTER :: tmpstringlist
519  INTEGER :: i, n_rep, nval, wfntype
520  LOGICAL :: available
521  REAL(kind=dp) :: ff
522  REAL(kind=dp), DIMENSION(:), POINTER :: reallist
523 
524  CALL section_vals_get(kpoint_section, explicit=available)
525 
526  IF (available) THEN
527  CALL section_vals_val_get(kpoint_section, "SCHEME", c_vals=tmpstringlist)
528  nval = SIZE(tmpstringlist)
529  cpassert(nval >= 1)
530  kpoint%kp_scheme = tmpstringlist(1)
531  CALL uppercase(kpoint%kp_scheme)
532 
533  ! SCHEME [None, Gamma, Monkhorst-Pack, MacDonald, General]
534  SELECT CASE (kpoint%kp_scheme)
535  CASE ("NONE")
536  ! do nothing
537  CASE ("GAMMA")
538  ! do nothing
539  CASE ("MONKHORST-PACK")
540  cpassert(nval >= 4)
541  DO i = 2, 4
542  READ (tmpstringlist(i), *) kpoint%nkp_grid(i - 1)
543  END DO
544  CASE ("MACDONALD")
545  cpassert(nval >= 7)
546  DO i = 2, 4
547  READ (tmpstringlist(i), *) kpoint%nkp_grid(i - 1)
548  END DO
549  DO i = 5, 7
550  READ (tmpstringlist(i), *) kpoint%kp_shift(i - 4)
551  END DO
552  CASE ("GENERAL")
553  CALL section_vals_val_get(kpoint_section, "UNITS", c_val=ustr)
554  CALL uppercase(ustr)
555  CALL section_vals_val_get(kpoint_section, "KPOINT", n_rep_val=n_rep)
556  kpoint%nkp = n_rep
557  ALLOCATE (kpoint%xkp(3, n_rep), kpoint%wkp(n_rep))
558  DO i = 1, n_rep
559  CALL section_vals_val_get(kpoint_section, "KPOINT", i_rep_val=i, &
560  r_vals=reallist)
561  nval = SIZE(reallist)
562  cpassert(nval >= 4)
563  SELECT CASE (ustr)
564  CASE ("B_VECTOR")
565  kpoint%xkp(1:3, i) = reallist(1:3)
566  CASE ("CART_ANGSTROM")
567  kpoint%xkp(1:3, i) = (reallist(1)*a_vec(1, 1:3) + &
568  reallist(2)*a_vec(2, 1:3) + &
569  reallist(3)*a_vec(3, 1:3))/twopi*angstrom
570  CASE ("CART_BOHR")
571  kpoint%xkp(1:3, i) = (reallist(1)*a_vec(1, 1:3) + &
572  reallist(2)*a_vec(2, 1:3) + &
573  reallist(3)*a_vec(3, 1:3))/twopi
574  CASE DEFAULT
575  cpabort("Unknown Unit for kpoint definition")
576  END SELECT
577  kpoint%wkp(i) = reallist(4)
578  END DO
579  ff = 1.0_dp/sum(kpoint%wkp(:))
580  kpoint%wkp(:) = ff*kpoint%wkp(:)
581  CASE DEFAULT
582  cpabort("")
583  END SELECT
584 
585  CALL section_vals_val_get(kpoint_section, "SYMMETRY", l_val=kpoint%symmetry)
586  CALL section_vals_val_get(kpoint_section, "WAVEFUNCTIONS", i_val=wfntype)
587  CALL section_vals_val_get(kpoint_section, "VERBOSE", l_val=kpoint%verbose)
588  CALL section_vals_val_get(kpoint_section, "FULL_GRID", l_val=kpoint%full_grid)
589  CALL section_vals_val_get(kpoint_section, "EPS_GEO", r_val=kpoint%eps_geo)
590  CALL section_vals_val_get(kpoint_section, "PARALLEL_GROUP_SIZE", &
591  i_val=kpoint%parallel_group_size)
592  SELECT CASE (wfntype)
593  CASE (use_real_wfn)
594  kpoint%use_real_wfn = .true.
595  CASE (use_complex_wfn)
596  kpoint%use_real_wfn = .false.
597  CASE DEFAULT
598  cpabort("")
599  END SELECT
600 
601  ELSE
602  kpoint%kp_scheme = "NONE"
603  END IF
604 
605  END SUBROUTINE read_kpoint_section
606 
607 ! **************************************************************************************************
608 !> \brief Write information on the kpoints to output
609 !> \param kpoint The kpoint environment
610 !> \param dft_section DFT section information
611 !> \author JGH
612 ! **************************************************************************************************
613  SUBROUTINE write_kpoint_info(kpoint, dft_section)
614  TYPE(kpoint_type), INTENT(IN) :: kpoint
615  TYPE(section_vals_type), INTENT(IN) :: dft_section
616 
617  INTEGER :: i, punit
618  TYPE(cp_logger_type), POINTER :: logger
619 
620  NULLIFY (logger)
621  logger => cp_get_default_logger()
622 
623  punit = cp_print_key_unit_nr(logger, dft_section, "PRINT%KPOINTS", extension=".Log")
624  IF (punit > 0) THEN
625 
626  IF (kpoint%kp_scheme /= "NONE") THEN
627  WRITE (punit, '(/," ",79("*"),/,T37,A,/," ",79("*"))') "Kpoints"
628  END IF
629  SELECT CASE (kpoint%kp_scheme)
630  CASE ("NONE")
631  ! be silent
632  CASE ("GAMMA")
633  WRITE (punit, '(A,T57,A)') ' BRILLOUIN|', ' Gamma-point calculation'
634  CASE ("MONKHORST-PACK")
635  WRITE (punit, '(A,T61,A20)') ' BRILLOUIN| K-point scheme ', ' Monkhorst-Pack'
636  WRITE (punit, '(A,T66,3I5)') ' BRILLOUIN| K-Point grid', kpoint%nkp_grid
637  WRITE (punit, '(A,T66,G15.6)') ' BRILLOUIN| Accuracy in Symmetry determination', kpoint%eps_geo
638  CASE ("MACDONALD")
639  WRITE (punit, '(A,T71,A10)') ' BRILLOUIN| K-point scheme ', ' MacDonald'
640  WRITE (punit, '(A,T66,3I5)') ' BRILLOUIN| K-Point grid', kpoint%nkp_grid
641  WRITE (punit, '(A,T51,3F10.4)') ' BRILLOUIN| K-Point shift', kpoint%kp_shift
642  WRITE (punit, '(A,T66,G15.6)') ' BRILLOUIN| Accuracy in Symmetry determination', kpoint%eps_geo
643  CASE ("GENERAL")
644  WRITE (punit, '(A,T71,A10)') ' BRILLOUIN| K-point scheme ', ' General'
645  CASE DEFAULT
646  cpabort("")
647  END SELECT
648  IF (kpoint%kp_scheme /= "NONE") THEN
649  IF (kpoint%symmetry) THEN
650  WRITE (punit, '(A,T76,A)') ' BRILLOUIN| K-Point point group symmetrization', ' ON'
651  ELSE
652  WRITE (punit, '(A,T76,A)') ' BRILLOUIN| K-Point point group symmetrization', ' OFF'
653  END IF
654  IF (kpoint%use_real_wfn) THEN
655  WRITE (punit, '(A,T76,A)') ' BRILLOUIN| Wavefunction type', ' REAL'
656  ELSE
657  WRITE (punit, '(A,T73,A)') ' BRILLOUIN| Wavefunction type', ' COMPLEX'
658  END IF
659  IF (kpoint%full_grid) THEN
660  WRITE (punit, '(A,T76,A)') ' BRILLOUIN| Use full k-point grid '
661  END IF
662  IF (kpoint%kp_scheme /= "GAMMA") THEN
663  WRITE (punit, '(A,T71,I10)') ' BRILLOUIN| List of Kpoints [2 Pi/Bohr]', kpoint%nkp
664  WRITE (punit, '(A,T30,A,T48,A,T63,A,T78,A)') &
665  ' BRILLOUIN| Number ', 'Weight', 'X', 'Y', 'Z'
666  DO i = 1, kpoint%nkp
667  WRITE (punit, '(A,I5,3X,4F15.5)') ' BRILLOUIN| ', i, kpoint%wkp(i), &
668  kpoint%xkp(1, i), kpoint%xkp(2, i), kpoint%xkp(3, i)
669  END DO
670  END IF
671  WRITE (punit, '(" ",79("*"))')
672  END IF
673 
674  END IF
675  CALL cp_print_key_finished_output(punit, logger, dft_section, "PRINT%KPOINTS")
676 
677  END SUBROUTINE write_kpoint_info
678 
679 ! **************************************************************************************************
680 !> \brief Create a single kpoint environment
681 !> \param kp_env Single kpoint environment
682 !> \author JGH
683 ! **************************************************************************************************
684  SUBROUTINE kpoint_env_create(kp_env)
685  TYPE(kpoint_env_type), POINTER :: kp_env
686 
687  cpassert(.NOT. ASSOCIATED(kp_env))
688 
689  ALLOCATE (kp_env)
690 
691  kp_env%nkpoint = 0
692  kp_env%wkp = 0.0_dp
693  kp_env%xkp = 0.0_dp
694  kp_env%is_local = .false.
695 
696  NULLIFY (kp_env%mos)
697  NULLIFY (kp_env%pmat)
698  NULLIFY (kp_env%wmat)
699  NULLIFY (kp_env%smat)
700  NULLIFY (kp_env%amat)
701 
702  END SUBROUTINE kpoint_env_create
703 
704 ! **************************************************************************************************
705 !> \brief Release a single kpoint environment
706 !> \param kp_env Single kpoint environment
707 !> \author JGH
708 ! **************************************************************************************************
709  SUBROUTINE kpoint_env_release(kp_env)
710  TYPE(kpoint_env_type), POINTER :: kp_env
711 
712  INTEGER :: ic, is
713 
714  IF (ASSOCIATED(kp_env)) THEN
715 
716  IF (ASSOCIATED(kp_env%mos)) THEN
717  DO is = 1, SIZE(kp_env%mos, 2)
718  DO ic = 1, SIZE(kp_env%mos, 1)
719  CALL deallocate_mo_set(kp_env%mos(ic, is))
720  END DO
721  END DO
722  DEALLOCATE (kp_env%mos)
723  END IF
724 
725  CALL cp_fm_release(kp_env%pmat)
726  CALL cp_fm_release(kp_env%wmat)
727  CALL cp_fm_release(kp_env%smat)
728  CALL cp_fm_release(kp_env%amat)
729 
730  DEALLOCATE (kp_env)
731 
732  END IF
733 
734  END SUBROUTINE kpoint_env_release
735 
736 ! **************************************************************************************************
737 !> \brief Get information from a single kpoint environment
738 !> \param kpoint_env Single kpoint environment
739 !> \param nkpoint Index of kpoint
740 !> \param wkp Weight of kpoint
741 !> \param xkp Coordinates of kpoint
742 !> \param is_local Is this kpoint local (single cpu group)
743 !> \param mos MOs of this kpoint
744 !> \author JGH
745 ! **************************************************************************************************
746  SUBROUTINE get_kpoint_env(kpoint_env, nkpoint, wkp, xkp, is_local, mos)
747  TYPE(kpoint_env_type), INTENT(IN) :: kpoint_env
748  INTEGER, OPTIONAL :: nkpoint
749  REAL(kind=dp), OPTIONAL :: wkp
750  REAL(kind=dp), DIMENSION(3), OPTIONAL :: xkp
751  LOGICAL, OPTIONAL :: is_local
752  TYPE(mo_set_type), DIMENSION(:, :), OPTIONAL, &
753  POINTER :: mos
754 
755  IF (PRESENT(nkpoint)) nkpoint = kpoint_env%nkpoint
756  IF (PRESENT(wkp)) wkp = kpoint_env%wkp
757  IF (PRESENT(xkp)) xkp = kpoint_env%xkp
758  IF (PRESENT(is_local)) is_local = kpoint_env%is_local
759  IF (PRESENT(mos)) mos => kpoint_env%mos
760 
761  END SUBROUTINE get_kpoint_env
762 
763 ! **************************************************************************************************
764 !> \brief Create a single kpoint symmetry environment
765 !> \param kp_sym ...
766 !> \author JGH
767 ! **************************************************************************************************
768  SUBROUTINE kpoint_sym_create(kp_sym)
769  TYPE(kpoint_sym_type), POINTER :: kp_sym
770 
771  cpassert(.NOT. ASSOCIATED(kp_sym))
772 
773  ALLOCATE (kp_sym)
774 
775  kp_sym%nwght = 0
776  kp_sym%apply_symmetry = .false.
777 
778  NULLIFY (kp_sym%rot)
779  NULLIFY (kp_sym%xkp)
780  NULLIFY (kp_sym%f0)
781 
782  END SUBROUTINE kpoint_sym_create
783 
784 ! **************************************************************************************************
785 !> \brief Release a single kpoint symmetry environment
786 !> \param kp_sym ...
787 !> \author JGH
788 ! **************************************************************************************************
789  SUBROUTINE kpoint_sym_release(kp_sym)
790  TYPE(kpoint_sym_type), POINTER :: kp_sym
791 
792  IF (ASSOCIATED(kp_sym)) THEN
793 
794  IF (ASSOCIATED(kp_sym%rot)) THEN
795  DEALLOCATE (kp_sym%rot)
796  END IF
797  IF (ASSOCIATED(kp_sym%xkp)) THEN
798  DEALLOCATE (kp_sym%xkp)
799  END IF
800  IF (ASSOCIATED(kp_sym%f0)) THEN
801  DEALLOCATE (kp_sym%f0)
802  END IF
803 
804  DEALLOCATE (kp_sym)
805 
806  END IF
807 
808  END SUBROUTINE kpoint_sym_release
809 
810 ! **************************************************************************************************
811 
812 END MODULE kpoint_types
methods related to the blacs parallel environment
Definition: cp_blacs_env.F:15
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
Definition: cp_blacs_env.F:282
represent a full matrix distributed on many processors
Definition: cp_fm_types.F:15
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
function that build the kpoints section of the input
integer, parameter, public use_real_wfn
integer, parameter, public use_complex_wfn
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
integer, parameter, public default_string_length
Definition: kinds.F:57
Types and basic routines needed for a kpoint calculation.
Definition: kpoint_types.F:15
subroutine, public read_kpoint_section(kpoint, kpoint_section, a_vec)
Read the kpoint input section.
Definition: kpoint_types.F:512
subroutine, public kpoint_sym_create(kp_sym)
Create a single kpoint symmetry environment.
Definition: kpoint_types.F:769
subroutine, public set_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym)
Set information in a kpoint environment.
Definition: kpoint_types.F:434
subroutine, public get_kpoint_env(kpoint_env, nkpoint, wkp, xkp, is_local, mos)
Get information from a single kpoint environment.
Definition: kpoint_types.F:747
subroutine, public write_kpoint_info(kpoint, dft_section)
Write information on the kpoints to output.
Definition: kpoint_types.F:614
subroutine, public kpoint_env_create(kp_env)
Create a single kpoint environment.
Definition: kpoint_types.F:685
subroutine, public kpoint_release(kpoint)
Release a kpoint environment, deallocate all data.
Definition: kpoint_types.F:234
subroutine, public kpoint_create(kpoint)
Create a kpoint environment.
Definition: kpoint_types.F:188
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym)
Retrieve information from a kpoint environment.
Definition: kpoint_types.F:333
Definition of mathematical constants and functions.
Definition: mathconstants.F:16
real(kind=dp), parameter, public twopi
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
Definition of physical constants:
Definition: physcon.F:68
real(kind=dp), parameter, public angstrom
Definition: physcon.F:144
buffer for the diis of the scf
Definition: qs_diis_types.F:14
subroutine, public qs_diis_b_release_kp(diis_buffer)
releases the given diis KP buffer
wrapper for the pools of matrixes
subroutine, public mpools_release(mpools)
releases the given mpools
Definition and initialisation of the mo data type.
Definition: qs_mo_types.F:22
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
Definition: qs_mo_types.F:352
Define the neighbor list data types and the corresponding functionality.
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.