(git:9a40378)
Loading...
Searching...
No Matches
gw_utils.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief
10!> \par History
11!> 01.2026 Maximilian Graml: add more bounds to exploit sparsity in 3c integrals, fixes
12!> \author Jan Wilhelm
13!> \date 07.2023
14! **************************************************************************************************
20 USE bibliography, ONLY: graml2024,&
21 cite_reference
22 USE cell_types, ONLY: cell_type,&
23 pbc,&
28 USE cp_cfm_types, ONLY: cp_cfm_create,&
34 USE cp_dbcsr_api, ONLY: &
36 dbcsr_release, dbcsr_set, dbcsr_type, dbcsr_type_no_symmetry, dbcsr_type_symmetric
42 USE cp_files, ONLY: close_file,&
48 USE cp_fm_types, ONLY: cp_fm_create,&
56 USE dbt_api, ONLY: &
57 dbt_clear, dbt_create, dbt_destroy, dbt_filter, dbt_iterator_blocks_left, &
58 dbt_iterator_next_block, dbt_iterator_start, dbt_iterator_stop, dbt_iterator_type, &
59 dbt_mp_environ_pgrid, dbt_pgrid_create, dbt_pgrid_destroy, dbt_pgrid_type, dbt_type
74 USE kinds, ONLY: default_path_length,&
76 dp,&
77 int_8
79 USE kpoint_types, ONLY: get_kpoint_info,&
85 USE machine, ONLY: m_memory,&
87 USE mathconstants, ONLY: gaussi,&
88 z_one,&
89 z_zero
90 USE mathlib, ONLY: diag_complex,&
91 gcd
92 USE message_passing, ONLY: mp_cart_type,&
98 USE mp2_gpw, ONLY: create_mat_munu
106 USE physcon, ONLY: angstrom,&
107 evolt
116 USE qs_kind_types, ONLY: get_qs_kind,&
121 USE qs_tensors, ONLY: build_2c_integrals,&
132 USE rpa_gw, ONLY: continuation_pade
133#include "base/base_uses.f90"
134
135 IMPLICIT NONE
136
137 PRIVATE
138
142
143 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_utils'
144
145CONTAINS
146
147! **************************************************************************************************
148!> \brief ...
149!> \param qs_env ...
150!> \param bs_env ...
151!> \param bs_sec ...
152! **************************************************************************************************
153 SUBROUTINE create_and_init_bs_env_for_gw(qs_env, bs_env, bs_sec)
154 TYPE(qs_environment_type), POINTER :: qs_env
155 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
156 TYPE(section_vals_type), POINTER :: bs_sec
157
158 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_and_init_bs_env_for_gw'
159
160 INTEGER :: handle
161
162 CALL timeset(routinen, handle)
163
164 CALL cite_reference(graml2024)
165
166 CALL read_gw_input_parameters(bs_env, bs_sec)
167
168 CALL print_header_and_input_parameters(bs_env)
169
170 CALL setup_ao_and_ri_basis_set(qs_env, bs_env)
171
172 CALL get_ri_basis_and_basis_function_indices(qs_env, bs_env)
173
174 CALL set_heuristic_parameters(bs_env, qs_env)
175
177
178 CALL setup_kpoints_chi_eps_w(bs_env, bs_env%kpoints_chi_eps_W)
179
180 IF (bs_env%small_cell_full_kp_or_large_cell_Gamma == small_cell_full_kp) THEN
181 CALL setup_cells_3c(qs_env, bs_env)
182 END IF
183
184 CALL set_parallelization_parameters(qs_env, bs_env)
185
186 CALL allocate_matrices(qs_env, bs_env)
187
188 CALL compute_v_xc(qs_env, bs_env)
189
190 CALL create_tensors(qs_env, bs_env)
191
192 SELECT CASE (bs_env%small_cell_full_kp_or_large_cell_Gamma)
193 CASE (large_cell_gamma)
194
195 CALL allocate_gw_eigenvalues(bs_env)
196
197 CALL check_sparsity_3c(qs_env, bs_env)
198
199 CALL set_sparsity_parallelization_parameters(bs_env)
200
201 CALL check_for_restart_files(qs_env, bs_env)
202
203 CASE (small_cell_full_kp)
204
205 CALL compute_3c_integrals(qs_env, bs_env)
206
207 CALL setup_cells_delta_r(bs_env)
208
209 CALL setup_parallelization_delta_r(bs_env)
210
211 CALL allocate_matrices_small_cell_full_kp(qs_env, bs_env)
212
213 CALL trafo_v_xc_r_to_kp(qs_env, bs_env)
214
215 CALL heuristic_ri_regularization(qs_env, bs_env)
216
217 END SELECT
218
219 CALL setup_time_and_frequency_minimax_grid(bs_env)
220
221 ! free memory in qs_env; only if one is not calculating the LDOS because
222 ! we need real-space grid operations in pw_env, task_list for the LDOS
223 ! Recommendation in case of memory issues: first perform GW calculation without calculating
224 ! LDOS (to safe memor). Then, use GW restart files
225 ! in a subsequent calculation to calculate the LDOS
226 ! Marek : TODO - boolean that does not interfere with RTP init but sets this to correct value
227 IF (.NOT. bs_env%do_ldos .AND. .false.) THEN
228 CALL qs_env_part_release(qs_env)
229 END IF
230
231 CALL timestop(handle)
232
233 END SUBROUTINE create_and_init_bs_env_for_gw
234
235! **************************************************************************************************
236!> \brief ...
237!> \param bs_env ...
238! **************************************************************************************************
239 SUBROUTINE de_init_bs_env(bs_env)
240 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
241
242 CHARACTER(LEN=*), PARAMETER :: routinen = 'de_init_bs_env'
243
244 INTEGER :: handle
245
246 CALL timeset(routinen, handle)
247 ! deallocate quantities here which:
248 ! 1. cannot be deallocated in bs_env_release due to circular dependencies
249 ! 2. consume a lot of memory and should not be kept until the quantity is
250 ! deallocated in bs_env_release
251
252 IF (ASSOCIATED(bs_env%nl_3c%ij_list) .AND. (bs_env%rtp_method == rtp_method_bse)) THEN
253 IF (bs_env%unit_nr > 0) WRITE (bs_env%unit_nr, *) "Retaining nl_3c for RTBSE"
254 ELSE
255 CALL neighbor_list_3c_destroy(bs_env%nl_3c)
256 END IF
257
259
260 CALL timestop(handle)
261
262 END SUBROUTINE de_init_bs_env
263
264! **************************************************************************************************
265!> \brief ...
266!> \param bs_env ...
267!> \param bs_sec ...
268! **************************************************************************************************
269 SUBROUTINE read_gw_input_parameters(bs_env, bs_sec)
270 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
271 TYPE(section_vals_type), POINTER :: bs_sec
272
273 CHARACTER(LEN=*), PARAMETER :: routinen = 'read_gw_input_parameters'
274
275 INTEGER :: handle
276 TYPE(section_vals_type), POINTER :: gw_sec
277
278 CALL timeset(routinen, handle)
279
280 NULLIFY (gw_sec)
281 gw_sec => section_vals_get_subs_vals(bs_sec, "GW")
282
283 CALL section_vals_val_get(gw_sec, "NUM_TIME_FREQ_POINTS", i_val=bs_env%num_time_freq_points)
284 CALL section_vals_val_get(gw_sec, "EPS_FILTER", r_val=bs_env%eps_filter)
285 CALL section_vals_val_get(gw_sec, "REGULARIZATION_RI", r_val=bs_env%input_regularization_RI)
286 CALL section_vals_val_get(gw_sec, "REGULARIZATION_MINIMAX", r_val=bs_env%input_regularization_minimax)
287 CALL section_vals_val_get(gw_sec, "CUTOFF_RADIUS_RI", r_val=bs_env%ri_metric%cutoff_radius)
288 CALL section_vals_val_get(gw_sec, "MEMORY_PER_PROC", r_val=bs_env%input_memory_per_proc_GB)
289 CALL section_vals_val_get(gw_sec, "APPROX_KP_EXTRAPOL", l_val=bs_env%approx_kp_extrapol)
290 CALL section_vals_val_get(gw_sec, "SIZE_LATTICE_SUM", i_val=bs_env%size_lattice_sum_V)
291 CALL section_vals_val_get(gw_sec, "KPOINTS_W", i_vals=bs_env%nkp_grid_chi_eps_W_input)
292 CALL section_vals_val_get(gw_sec, "HEDIN_SHIFT", l_val=bs_env%do_hedin_shift)
293 CALL section_vals_val_get(gw_sec, "FREQ_MAX_FIT", r_val=bs_env%freq_max_fit)
294 CALL section_vals_val_get(gw_sec, "PRINT%PRINT_DBT_CONTRACT", l_val=bs_env%print_contract)
295 CALL section_vals_val_get(gw_sec, "PRINT%PRINT_DBT_CONTRACT_VERBOSE", l_val=bs_env%print_contract_verbose)
296
297 IF (bs_env%print_contract) THEN
298 bs_env%unit_nr_contract = bs_env%unit_nr
299 ELSE
300 bs_env%unit_nr_contract = 0
301 END IF
302 CALL timestop(handle)
303
304 END SUBROUTINE read_gw_input_parameters
305
306! **************************************************************************************************
307!> \brief ...
308!> \param qs_env ...
309!> \param bs_env ...
310! **************************************************************************************************
311 SUBROUTINE setup_ao_and_ri_basis_set(qs_env, bs_env)
312 TYPE(qs_environment_type), POINTER :: qs_env
313 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
314
315 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_AO_and_RI_basis_set'
316
317 INTEGER :: handle, natom, nkind
318 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
319 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
320
321 CALL timeset(routinen, handle)
322
323 CALL get_qs_env(qs_env, &
324 qs_kind_set=qs_kind_set, &
325 particle_set=particle_set, &
326 natom=natom, nkind=nkind)
327
328 ! set up basis
329 ALLOCATE (bs_env%sizes_RI(natom), bs_env%sizes_AO(natom))
330 ALLOCATE (bs_env%basis_set_RI(nkind), bs_env%basis_set_AO(nkind))
331
332 CALL basis_set_list_setup(bs_env%basis_set_RI, "RI_AUX", qs_kind_set)
333 CALL basis_set_list_setup(bs_env%basis_set_AO, "ORB", qs_kind_set)
334
335 CALL get_particle_set(particle_set, qs_kind_set, nsgf=bs_env%sizes_RI, &
336 basis=bs_env%basis_set_RI)
337 CALL get_particle_set(particle_set, qs_kind_set, nsgf=bs_env%sizes_AO, &
338 basis=bs_env%basis_set_AO)
339
340 CALL timestop(handle)
341
342 END SUBROUTINE setup_ao_and_ri_basis_set
343
344! **************************************************************************************************
345!> \brief ...
346!> \param qs_env ...
347!> \param bs_env ...
348! **************************************************************************************************
349 SUBROUTINE get_ri_basis_and_basis_function_indices(qs_env, bs_env)
350 TYPE(qs_environment_type), POINTER :: qs_env
351 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
352
353 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_RI_basis_and_basis_function_indices'
354
355 INTEGER :: handle, i_ri, iatom, ikind, iset, &
356 max_ao_bf_per_atom, n_ao_test, n_atom, &
357 n_kind, n_ri, nset, nsgf, u
358 INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of
359 INTEGER, DIMENSION(:), POINTER :: l_max, l_min, nsgf_set
360 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
361 TYPE(gto_basis_set_type), POINTER :: basis_set_a
362 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
363
364 CALL timeset(routinen, handle)
365
366 ! determine RI basis set size
367 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set)
368
369 n_kind = SIZE(qs_kind_set)
370 n_atom = bs_env%n_atom
371
372 CALL get_atomic_kind_set(atomic_kind_set, kind_of=kind_of)
373
374 DO ikind = 1, n_kind
375 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), basis_set=basis_set_a, &
376 basis_type="RI_AUX")
377 IF (.NOT. ASSOCIATED(basis_set_a)) THEN
378 CALL cp_abort(__location__, &
379 "At least one RI_AUX basis set was not explicitly invoked in &KIND-section.")
380 END IF
381 END DO
382
383 ALLOCATE (bs_env%i_RI_start_from_atom(n_atom))
384 ALLOCATE (bs_env%i_RI_end_from_atom(n_atom))
385 ALLOCATE (bs_env%i_ao_start_from_atom(n_atom))
386 ALLOCATE (bs_env%i_ao_end_from_atom(n_atom))
387
388 n_ri = 0
389 DO iatom = 1, n_atom
390 bs_env%i_RI_start_from_atom(iatom) = n_ri + 1
391 ikind = kind_of(iatom)
392 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), nsgf=nsgf, basis_type="RI_AUX")
393 n_ri = n_ri + nsgf
394 bs_env%i_RI_end_from_atom(iatom) = n_ri
395 END DO
396 bs_env%n_RI = n_ri
397
398 max_ao_bf_per_atom = 0
399 n_ao_test = 0
400 DO iatom = 1, n_atom
401 bs_env%i_ao_start_from_atom(iatom) = n_ao_test + 1
402 ikind = kind_of(iatom)
403 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), nsgf=nsgf, basis_type="ORB")
404 n_ao_test = n_ao_test + nsgf
405 bs_env%i_ao_end_from_atom(iatom) = n_ao_test
406 max_ao_bf_per_atom = max(max_ao_bf_per_atom, nsgf)
407 END DO
408 cpassert(n_ao_test == bs_env%n_ao)
409 bs_env%max_AO_bf_per_atom = max_ao_bf_per_atom
410
411 ALLOCATE (bs_env%l_RI(n_ri))
412 i_ri = 0
413 DO iatom = 1, n_atom
414 ikind = kind_of(iatom)
415
416 nset = bs_env%basis_set_RI(ikind)%gto_basis_set%nset
417 l_max => bs_env%basis_set_RI(ikind)%gto_basis_set%lmax
418 l_min => bs_env%basis_set_RI(ikind)%gto_basis_set%lmin
419 nsgf_set => bs_env%basis_set_RI(ikind)%gto_basis_set%nsgf_set
420
421 DO iset = 1, nset
422 cpassert(l_max(iset) == l_min(iset))
423 bs_env%l_RI(i_ri + 1:i_ri + nsgf_set(iset)) = l_max(iset)
424 i_ri = i_ri + nsgf_set(iset)
425 END DO
426
427 END DO
428 cpassert(i_ri == n_ri)
429
430 u = bs_env%unit_nr
431
432 IF (u > 0) THEN
433 WRITE (u, fmt="(T2,A)") " "
434 WRITE (u, fmt="(T2,2A,T75,I8)") "Number of auxiliary Gaussian basis functions ", &
435 χε"for , , W", n_ri
436 END IF
437
438 CALL timestop(handle)
439
440 END SUBROUTINE get_ri_basis_and_basis_function_indices
441
442! **************************************************************************************************
443!> \brief ...
444!> \param bs_env ...
445!> \param kpoints ...
446! **************************************************************************************************
447 SUBROUTINE setup_kpoints_chi_eps_w(bs_env, kpoints)
448
449 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
450 TYPE(kpoint_type), POINTER :: kpoints
451
452 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_kpoints_chi_eps_W'
453
454 INTEGER :: handle, i_dim, n_dim, nkp, nkp_extra, &
455 nkp_orig, u
456 INTEGER, DIMENSION(3) :: nkp_grid, nkp_grid_extra, periodic
457 REAL(kind=dp) :: exp_s_p, n_dim_inv
458
459 CALL timeset(routinen, handle)
460
461 ! routine adapted from mp2_integrals.F
462 NULLIFY (kpoints)
463 CALL kpoint_create(kpoints)
464
465 kpoints%kp_scheme = "GENERAL"
466
467 periodic(1:3) = bs_env%periodic(1:3)
468
469 cpassert(SIZE(bs_env%nkp_grid_chi_eps_W_input) == 3)
470
471 IF (bs_env%nkp_grid_chi_eps_W_input(1) > 0 .AND. &
472 bs_env%nkp_grid_chi_eps_W_input(2) > 0 .AND. &
473 bs_env%nkp_grid_chi_eps_W_input(3) > 0) THEN
474 ! 1. k-point mesh for χ, ε, W from input
475 DO i_dim = 1, 3
476 SELECT CASE (periodic(i_dim))
477 CASE (0)
478 nkp_grid(i_dim) = 1
479 nkp_grid_extra(i_dim) = 1
480 CASE (1)
481 nkp_grid(i_dim) = bs_env%nkp_grid_chi_eps_W_input(i_dim)
482 nkp_grid_extra(i_dim) = nkp_grid(i_dim)*2
483 CASE DEFAULT
484 cpabort("Error in periodicity.")
485 END SELECT
486 END DO
487
488 ELSE IF (bs_env%nkp_grid_chi_eps_W_input(1) == -1 .AND. &
489 bs_env%nkp_grid_chi_eps_W_input(2) == -1 .AND. &
490 bs_env%nkp_grid_chi_eps_W_input(3) == -1) THEN
491 ! 2. automatic k-point mesh for χ, ε, W
492
493 DO i_dim = 1, 3
494
495 cpassert(periodic(i_dim) == 0 .OR. periodic(i_dim) == 1)
496
497 SELECT CASE (periodic(i_dim))
498 CASE (0)
499 nkp_grid(i_dim) = 1
500 nkp_grid_extra(i_dim) = 1
501 CASE (1)
502 SELECT CASE (bs_env%small_cell_full_kp_or_large_cell_Gamma)
503 CASE (large_cell_gamma)
504 nkp_grid(i_dim) = 4
505 nkp_grid_extra(i_dim) = 6
506 CASE (small_cell_full_kp)
507 nkp_grid(i_dim) = bs_env%kpoints_scf_desymm%nkp_grid(i_dim)*4
508 nkp_grid_extra(i_dim) = bs_env%kpoints_scf_desymm%nkp_grid(i_dim)*8
509 END SELECT
510 CASE DEFAULT
511 cpabort("Error in periodicity.")
512 END SELECT
513
514 END DO
515
516 ELSE
517
518 cpabort("An error occured when setting up the k-mesh for W.")
519
520 END IF
521
522 nkp_orig = max(nkp_grid(1)*nkp_grid(2)*nkp_grid(3)/2, 1)
523
524 nkp_extra = nkp_grid_extra(1)*nkp_grid_extra(2)*nkp_grid_extra(3)/2
525
526 nkp = nkp_orig + nkp_extra
527
528 kpoints%nkp_grid(1:3) = nkp_grid(1:3)
529 kpoints%nkp = nkp
530
531 bs_env%nkp_grid_chi_eps_W_orig(1:3) = nkp_grid(1:3)
532 bs_env%nkp_grid_chi_eps_W_extra(1:3) = nkp_grid_extra(1:3)
533 bs_env%nkp_chi_eps_W_orig = nkp_orig
534 bs_env%nkp_chi_eps_W_extra = nkp_extra
535 bs_env%nkp_chi_eps_W_orig_plus_extra = nkp
536
537 ALLOCATE (kpoints%xkp(3, nkp), kpoints%wkp(nkp))
538 ALLOCATE (bs_env%wkp_no_extra(nkp), bs_env%wkp_s_p(nkp))
539
540 CALL compute_xkp(kpoints%xkp, 1, nkp_orig, nkp_grid)
541 CALL compute_xkp(kpoints%xkp, nkp_orig + 1, nkp, nkp_grid_extra)
542
543 n_dim = sum(periodic)
544 IF (n_dim == 0) THEN
545 ! molecules
546 kpoints%wkp(1) = 1.0_dp
547 bs_env%wkp_s_p(1) = 1.0_dp
548 bs_env%wkp_no_extra(1) = 1.0_dp
549 ELSE
550
551 n_dim_inv = 1.0_dp/real(n_dim, kind=dp)
552
553 ! k-point weights are chosen to automatically extrapolate the k-point mesh
554 CALL compute_wkp(kpoints%wkp(1:nkp_orig), nkp_orig, nkp_extra, n_dim_inv)
555 CALL compute_wkp(kpoints%wkp(nkp_orig + 1:nkp), nkp_extra, nkp_orig, n_dim_inv)
556
557 bs_env%wkp_no_extra(1:nkp_orig) = 0.0_dp
558 bs_env%wkp_no_extra(nkp_orig + 1:nkp) = 1.0_dp/real(nkp_extra, kind=dp)
559
560 IF (n_dim == 3) THEN
561 ! W_PQ(k) for an s-function P and a p-function Q diverges as 1/k at k=0
562 ! (instead of 1/k^2 for P and Q both being s-functions).
563 exp_s_p = 2.0_dp*n_dim_inv
564 CALL compute_wkp(bs_env%wkp_s_p(1:nkp_orig), nkp_orig, nkp_extra, exp_s_p)
565 CALL compute_wkp(bs_env%wkp_s_p(nkp_orig + 1:nkp), nkp_extra, nkp_orig, exp_s_p)
566 ELSE
567 bs_env%wkp_s_p(1:nkp) = bs_env%wkp_no_extra(1:nkp)
568 END IF
569
570 END IF
571
572 IF (bs_env%approx_kp_extrapol) THEN
573 bs_env%wkp_orig = 1.0_dp/real(nkp_orig, kind=dp)
574 END IF
575
576 ! heuristic parameter: how many k-points for χ, ε, and W are used simultaneously
577 ! (less simultaneous k-points: less memory, but more computational effort because of
578 ! recomputation of V(k))
579 bs_env%nkp_chi_eps_W_batch = 4
580
581 bs_env%num_chi_eps_W_batches = (bs_env%nkp_chi_eps_W_orig_plus_extra - 1)/ &
582 bs_env%nkp_chi_eps_W_batch + 1
583
584 u = bs_env%unit_nr
585
586 IF (u > 0) THEN
587 WRITE (u, fmt="(T2,A)") " "
588 WRITE (u, fmt="(T2,1A,T71,3I4)") χε"K-point mesh 1 for , , W", nkp_grid(1:3)
589 WRITE (u, fmt="(T2,2A,T71,3I4)") χε"K-point mesh 2 for , , W ", &
590 "(for k-point extrapolation of W)", nkp_grid_extra(1:3)
591 WRITE (u, fmt="(T2,A,T80,L)") "Approximate the k-point extrapolation", &
592 bs_env%approx_kp_extrapol
593 END IF
594
595 CALL timestop(handle)
596
597 END SUBROUTINE setup_kpoints_chi_eps_w
598
599! **************************************************************************************************
600!> \brief ...
601!> \param xkp ...
602!> \param ikp_start ...
603!> \param ikp_end ...
604!> \param grid ...
605! **************************************************************************************************
606 SUBROUTINE compute_xkp(xkp, ikp_start, ikp_end, grid)
607
608 REAL(kind=dp), DIMENSION(:, :), POINTER :: xkp
609 INTEGER :: ikp_start, ikp_end
610 INTEGER, DIMENSION(3) :: grid
611
612 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_xkp'
613
614 INTEGER :: handle, i, ix, iy, iz
615
616 CALL timeset(routinen, handle)
617
618 i = ikp_start
619 DO ix = 1, grid(1)
620 DO iy = 1, grid(2)
621 DO iz = 1, grid(3)
622
623 IF (i > ikp_end) cycle
624
625 xkp(1, i) = real(2*ix - grid(1) - 1, kind=dp)/(2._dp*real(grid(1), kind=dp))
626 xkp(2, i) = real(2*iy - grid(2) - 1, kind=dp)/(2._dp*real(grid(2), kind=dp))
627 xkp(3, i) = real(2*iz - grid(3) - 1, kind=dp)/(2._dp*real(grid(3), kind=dp))
628 i = i + 1
629
630 END DO
631 END DO
632 END DO
633
634 CALL timestop(handle)
635
636 END SUBROUTINE compute_xkp
637
638! **************************************************************************************************
639!> \brief ...
640!> \param wkp ...
641!> \param nkp_1 ...
642!> \param nkp_2 ...
643!> \param exponent ...
644! **************************************************************************************************
645 SUBROUTINE compute_wkp(wkp, nkp_1, nkp_2, exponent)
646 REAL(kind=dp), DIMENSION(:) :: wkp
647 INTEGER :: nkp_1, nkp_2
648 REAL(kind=dp) :: exponent
649
650 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_wkp'
651
652 INTEGER :: handle
653 REAL(kind=dp) :: nkp_ratio
654
655 CALL timeset(routinen, handle)
656
657 nkp_ratio = real(nkp_2, kind=dp)/real(nkp_1, kind=dp)
658
659 wkp(:) = 1.0_dp/real(nkp_1, kind=dp)/(1.0_dp - nkp_ratio**exponent)
660
661 CALL timestop(handle)
662
663 END SUBROUTINE compute_wkp
664
665! **************************************************************************************************
666!> \brief ...
667!> \param qs_env ...
668!> \param bs_env ...
669! **************************************************************************************************
670 SUBROUTINE allocate_matrices(qs_env, bs_env)
671 TYPE(qs_environment_type), POINTER :: qs_env
672 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
673
674 CHARACTER(LEN=*), PARAMETER :: routinen = 'allocate_matrices'
675
676 INTEGER :: handle, i_t
677 TYPE(cp_blacs_env_type), POINTER :: blacs_env, blacs_env_tensor
678 TYPE(cp_fm_struct_type), POINTER :: fm_struct, fm_struct_ri_global
679 TYPE(mp_para_env_type), POINTER :: para_env
680
681 CALL timeset(routinen, handle)
682
683 CALL get_qs_env(qs_env, para_env=para_env, blacs_env=blacs_env)
684
685 fm_struct => bs_env%fm_ks_Gamma(1)%matrix_struct
686
687 CALL cp_fm_create(bs_env%fm_Gocc, fm_struct)
688 CALL cp_fm_create(bs_env%fm_Gvir, fm_struct)
689
690 NULLIFY (fm_struct_ri_global)
691 CALL cp_fm_struct_create(fm_struct_ri_global, context=blacs_env, nrow_global=bs_env%n_RI, &
692 ncol_global=bs_env%n_RI, para_env=para_env)
693 CALL cp_fm_create(bs_env%fm_RI_RI, fm_struct_ri_global)
694 CALL cp_fm_create(bs_env%fm_chi_Gamma_freq, fm_struct_ri_global)
695 CALL cp_fm_create(bs_env%fm_W_MIC_freq, fm_struct_ri_global)
696 IF (bs_env%approx_kp_extrapol) THEN
697 CALL cp_fm_create(bs_env%fm_W_MIC_freq_1_extra, fm_struct_ri_global)
698 CALL cp_fm_create(bs_env%fm_W_MIC_freq_1_no_extra, fm_struct_ri_global)
699 CALL cp_fm_set_all(bs_env%fm_W_MIC_freq_1_extra, 0.0_dp)
700 CALL cp_fm_set_all(bs_env%fm_W_MIC_freq_1_no_extra, 0.0_dp)
701 END IF
702 CALL cp_fm_struct_release(fm_struct_ri_global)
703
704 ! create blacs_env for subgroups of tensor operations
705 NULLIFY (blacs_env_tensor)
706 CALL cp_blacs_env_create(blacs_env=blacs_env_tensor, para_env=bs_env%para_env_tensor)
707
708 ! allocate dbcsr matrices in the tensor subgroup; actually, one only needs a small
709 ! subset of blocks in the tensor subgroup, however, all atomic blocks are allocated.
710 ! One might think of creating a dbcsr matrix with only the blocks that are needed
711 ! in the tensor subgroup
712 CALL create_mat_munu(bs_env%mat_ao_ao_tensor, qs_env, bs_env%eps_atom_grid_2d_mat, &
713 blacs_env_tensor, do_ri_aux_basis=.false.)
714
715 CALL create_mat_munu(bs_env%mat_RI_RI_tensor, qs_env, bs_env%eps_atom_grid_2d_mat, &
716 blacs_env_tensor, do_ri_aux_basis=.true.)
717
718 CALL create_mat_munu(bs_env%mat_RI_RI, qs_env, bs_env%eps_atom_grid_2d_mat, &
719 blacs_env, do_ri_aux_basis=.true.)
720
721 CALL cp_blacs_env_release(blacs_env_tensor)
722
723 NULLIFY (bs_env%mat_chi_Gamma_tau)
724 CALL dbcsr_allocate_matrix_set(bs_env%mat_chi_Gamma_tau, bs_env%num_time_freq_points)
725
726 DO i_t = 1, bs_env%num_time_freq_points
727 ALLOCATE (bs_env%mat_chi_Gamma_tau(i_t)%matrix)
728 CALL dbcsr_create(bs_env%mat_chi_Gamma_tau(i_t)%matrix, template=bs_env%mat_RI_RI%matrix)
729 END DO
730
731 CALL timestop(handle)
732
733 END SUBROUTINE allocate_matrices
734
735! **************************************************************************************************
736!> \brief ...
737!> \param bs_env ...
738! **************************************************************************************************
739 SUBROUTINE allocate_gw_eigenvalues(bs_env)
740 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
741
742 CHARACTER(LEN=*), PARAMETER :: routinen = 'allocate_GW_eigenvalues'
743
744 INTEGER :: handle
745
746 CALL timeset(routinen, handle)
747
748 ALLOCATE (bs_env%eigenval_G0W0(bs_env%n_ao, bs_env%nkp_bs_and_DOS, bs_env%n_spin))
749 ALLOCATE (bs_env%eigenval_HF(bs_env%n_ao, bs_env%nkp_bs_and_DOS, bs_env%n_spin))
750
751 CALL timestop(handle)
752
753 END SUBROUTINE allocate_gw_eigenvalues
754
755! **************************************************************************************************
756!> \brief ...
757!> \param qs_env ...
758!> \param bs_env ...
759! **************************************************************************************************
760 SUBROUTINE create_tensors(qs_env, bs_env)
761 TYPE(qs_environment_type), POINTER :: qs_env
762 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
763
764 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_tensors'
765
766 INTEGER :: handle
767
768 CALL timeset(routinen, handle)
769
770 CALL init_interaction_radii(bs_env)
771
772 ! split blocks does not improve load balancing/efficienfy for tensor contraction, so we go
773 ! with the standard atomic blocks
774 CALL create_3c_t(bs_env%t_RI_AO__AO, bs_env%para_env_tensor, "(RI AO | AO)", [1, 2], [3], &
775 bs_env%sizes_RI, bs_env%sizes_AO, &
776 create_nl_3c=.true., nl_3c=bs_env%nl_3c, qs_env=qs_env)
777 CALL create_3c_t(bs_env%t_RI__AO_AO, bs_env%para_env_tensor, "(RI | AO AO)", [1], [2, 3], &
778 bs_env%sizes_RI, bs_env%sizes_AO)
779
780 CALL create_2c_t(bs_env, bs_env%sizes_RI, bs_env%sizes_AO)
781
782 CALL timestop(handle)
783
784 END SUBROUTINE create_tensors
785
786! **************************************************************************************************
787!> \brief ...
788!> \param qs_env ...
789!> \param bs_env ...
790! **************************************************************************************************
791 SUBROUTINE check_sparsity_3c(qs_env, bs_env)
792 TYPE(qs_environment_type), POINTER :: qs_env
793 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
794
795 CHARACTER(LEN=*), PARAMETER :: routinen = 'check_sparsity_3c'
796
797 INTEGER :: handle, n_atom_step, ri_atom
798 INTEGER(int_8) :: non_zero_elements_sum, nze
799 REAL(dp) :: max_dist_ao_atoms, occ, occupation_sum
800 REAL(kind=dp) :: t1, t2
801 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_3c_global_array
802
803!TYPE(dbt_type) :: t_3c_global
804
805 !TYPE(neighbor_list_3c_type) :: nl_3c_global
806
807 CALL timeset(routinen, handle)
808
809 ! check the sparsity of 3c integral tensor (µν|P); calculate maximum distance between
810 ! AO atoms µ, ν where at least a single integral (µν|P) is larger than the filter threshold
811
812 ALLOCATE (t_3c_global_array(1, 1))
813 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_global_array(1, 1))
814
815 ! Allocate arrays to store min/max indices for overlap with other AO/RI functions on each atom
816 ! (Filled during loop via get_i_j_atom_ranges)
817 ALLOCATE (bs_env%min_RI_idx_from_AO_AO_atom(bs_env%n_atom, bs_env%n_atom))
818 ALLOCATE (bs_env%max_RI_idx_from_AO_AO_atom(bs_env%n_atom, bs_env%n_atom))
819 ALLOCATE (bs_env%min_AO_idx_from_RI_AO_atom(bs_env%n_atom, bs_env%n_atom))
820 ALLOCATE (bs_env%max_AO_idx_from_RI_AO_atom(bs_env%n_atom, bs_env%n_atom))
821 bs_env%min_RI_idx_from_AO_AO_atom(:, :) = bs_env%n_RI
822 bs_env%max_RI_idx_from_AO_AO_atom(:, :) = 1
823 bs_env%min_AO_idx_from_RI_AO_atom(:, :) = bs_env%n_AO
824 bs_env%max_AO_idx_from_RI_AO_atom(:, :) = 1
825
826 CALL bs_env%para_env%sync()
827 t1 = m_walltime()
828
829 occupation_sum = 0.0_dp
830 non_zero_elements_sum = 0
831 max_dist_ao_atoms = 0.0_dp
832 n_atom_step = int(sqrt(real(bs_env%n_atom, kind=dp)))
833 ! do not compute full 3c integrals at once because it may cause out of memory
834 DO ri_atom = 1, bs_env%n_atom, n_atom_step
835
836 CALL build_3c_integrals(t_3c_global_array, &
837 bs_env%eps_filter, &
838 qs_env, &
839 bs_env%nl_3c, &
840 int_eps=bs_env%eps_filter, &
841 basis_i=bs_env%basis_set_RI, &
842 basis_j=bs_env%basis_set_AO, &
843 basis_k=bs_env%basis_set_AO, &
844 bounds_i=[ri_atom, min(ri_atom + n_atom_step - 1, bs_env%n_atom)], &
845 potential_parameter=bs_env%ri_metric, &
846 desymmetrize=.false.)
847
848 CALL dbt_filter(t_3c_global_array(1, 1), bs_env%eps_filter)
849
850 CALL bs_env%para_env%sync()
851
852 CALL get_tensor_occupancy(t_3c_global_array(1, 1), nze, occ)
853 non_zero_elements_sum = non_zero_elements_sum + nze
854 occupation_sum = occupation_sum + occ
855
856 CALL get_max_dist_ao_atoms(t_3c_global_array(1, 1), max_dist_ao_atoms, qs_env)
857
858 ! Extract indices per block
859 CALL get_i_j_atom_ranges(t_3c_global_array(1, 1), bs_env)
860
861 CALL dbt_clear(t_3c_global_array(1, 1))
862
863 END DO
864
865 t2 = m_walltime()
866
867 ! Sync/max for max_dist_AO_atoms is done inside each get_max_dist_AO_atoms
868 bs_env%max_dist_AO_atoms = max_dist_ao_atoms
869 ! occupation_sum is a global quantity, also needs no sync here
870 bs_env%occupation_3c_int = occupation_sum
871
872 CALL bs_env%para_env%min(bs_env%min_RI_idx_from_AO_AO_atom)
873 CALL bs_env%para_env%max(bs_env%max_RI_idx_from_AO_AO_atom)
874 CALL bs_env%para_env%min(bs_env%min_AO_idx_from_RI_AO_atom)
875 CALL bs_env%para_env%max(bs_env%max_AO_idx_from_RI_AO_atom)
876
877 CALL dbt_destroy(t_3c_global_array(1, 1))
878 DEALLOCATE (t_3c_global_array)
879
880 IF (bs_env%unit_nr > 0) THEN
881 WRITE (bs_env%unit_nr, '(T2,A)') ''
882 WRITE (bs_env%unit_nr, '(T2,A,F27.1,A)') &
883 µν'Computed 3-center integrals (|P), execution time', t2 - t1, ' s'
884 WRITE (bs_env%unit_nr, '(T2,A,F48.3,A)') µν'Percentage of non-zero (|P)', &
885 bs_env%occupation_3c_int*100, ' %'
886 WRITE (bs_env%unit_nr, '(T2,A,F33.1,A)') µνµν'Max. distance between , in non-zero (|P)', &
887 bs_env%max_dist_AO_atoms*angstrom, ' A'
888 WRITE (bs_env%unit_nr, '(T2,2A,I20,A)') 'Required memory if storing all 3-center ', &
889 µν'integrals (|P)', int(real(non_zero_elements_sum, kind=dp)*8.0e-9_dp), ' GB'
890 END IF
891
892 CALL timestop(handle)
893
894 END SUBROUTINE check_sparsity_3c
895
896! **************************************************************************************************
897!> \brief ...
898!> \param t_3c ...
899!> \param bs_env ...
900! **************************************************************************************************
901 SUBROUTINE get_i_j_atom_ranges(t_3c, bs_env)
902 TYPE(dbt_type) :: t_3c
903 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
904
905 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_i_j_atom_ranges'
906
907 INTEGER :: handle, idx_ao_end, idx_ao_start, &
908 idx_ri_end, idx_ri_start
909 INTEGER, DIMENSION(3) :: atom_ind
910 TYPE(dbt_iterator_type) :: iter
911
912 CALL timeset(routinen, handle)
913
914 ! Loop over blocks in 3c, for given min_atom: RI_min/max index from min_atom
915!$OMP PARALLEL DEFAULT(NONE) &
916!$OMP SHARED(t_3c, bs_env) &
917!$OMP PRIVATE(iter, atom_ind, &
918!$OMP idx_RI_start, idx_RI_end, idx_AO_start, idx_AO_end)
919
920 CALL dbt_iterator_start(iter, t_3c)
921 DO WHILE (dbt_iterator_blocks_left(iter))
922 CALL dbt_iterator_next_block(iter, atom_ind)
923
924 ! Pre-fetch indices to avoid referencing 'bs_env' twice inside the ATOMIC blocks
925 idx_ri_start = bs_env%i_RI_start_from_atom(atom_ind(1))
926 idx_ri_end = bs_env%i_RI_end_from_atom(atom_ind(1))
927
928 idx_ao_start = bs_env%i_ao_start_from_atom(atom_ind(2))
929 idx_ao_end = bs_env%i_ao_end_from_atom(atom_ind(2))
930
931 ! Update values safely inside ATOMIC blocks, otherwise race conditions occur
932!$OMP ATOMIC UPDATE
933 bs_env%min_RI_idx_from_AO_AO_atom(atom_ind(2), atom_ind(3)) = &
934 min(bs_env%min_RI_idx_from_AO_AO_atom(atom_ind(2), atom_ind(3)), idx_ri_start)
935!$OMP ATOMIC UPDATE
936 bs_env%max_RI_idx_from_AO_AO_atom(atom_ind(2), atom_ind(3)) = &
937 max(bs_env%max_RI_idx_from_AO_AO_atom(atom_ind(2), atom_ind(3)), idx_ri_end)
938
939!$OMP ATOMIC UPDATE
940 bs_env%min_AO_idx_from_RI_AO_atom(atom_ind(1), atom_ind(3)) = &
941 min(bs_env%min_AO_idx_from_RI_AO_atom(atom_ind(1), atom_ind(3)), idx_ao_start)
942!$OMP ATOMIC UPDATE
943 bs_env%max_AO_idx_from_RI_AO_atom(atom_ind(1), atom_ind(3)) = &
944 max(bs_env%max_AO_idx_from_RI_AO_atom(atom_ind(1), atom_ind(3)), idx_ao_end)
945
946 END DO
947 CALL dbt_iterator_stop(iter)
948!$OMP END PARALLEL
949
950 CALL timestop(handle)
951
952 END SUBROUTINE get_i_j_atom_ranges
953
954! **************************************************************************************************
955!> \brief ...
956!> \param bs_env ...
957!> \param sizes_RI ...
958!> \param sizes_AO ...
959! **************************************************************************************************
960 SUBROUTINE create_2c_t(bs_env, sizes_RI, sizes_AO)
961 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
962 INTEGER, ALLOCATABLE, DIMENSION(:) :: sizes_ri, sizes_ao
963
964 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_2c_t'
965
966 INTEGER :: handle
967 INTEGER, ALLOCATABLE, DIMENSION(:) :: dist_1, dist_2
968 INTEGER, DIMENSION(2) :: pdims_2d
969 TYPE(dbt_pgrid_type) :: pgrid_2d
970
971 CALL timeset(routinen, handle)
972
973 ! inspired from rpa_im_time.F / hfx_types.F
974
975 pdims_2d = 0
976 CALL dbt_pgrid_create(bs_env%para_env_tensor, pdims_2d, pgrid_2d)
977
978 CALL create_2c_tensor(bs_env%t_G, dist_1, dist_2, pgrid_2d, sizes_ao, sizes_ao, &
979 name="(AO | AO)")
980 DEALLOCATE (dist_1, dist_2)
981 CALL create_2c_tensor(bs_env%t_chi, dist_1, dist_2, pgrid_2d, sizes_ri, sizes_ri, &
982 name="(RI | RI)")
983 DEALLOCATE (dist_1, dist_2)
984 CALL create_2c_tensor(bs_env%t_W, dist_1, dist_2, pgrid_2d, sizes_ri, sizes_ri, &
985 name="(RI | RI)")
986 DEALLOCATE (dist_1, dist_2)
987 CALL dbt_pgrid_destroy(pgrid_2d)
988
989 CALL timestop(handle)
990
991 END SUBROUTINE create_2c_t
992
993! **************************************************************************************************
994!> \brief ...
995!> \param tensor ...
996!> \param para_env ...
997!> \param tensor_name ...
998!> \param map1 ...
999!> \param map2 ...
1000!> \param sizes_RI ...
1001!> \param sizes_AO ...
1002!> \param create_nl_3c ...
1003!> \param nl_3c ...
1004!> \param qs_env ...
1005! **************************************************************************************************
1006 SUBROUTINE create_3c_t(tensor, para_env, tensor_name, map1, map2, sizes_RI, sizes_AO, &
1007 create_nl_3c, nl_3c, qs_env)
1008 TYPE(dbt_type) :: tensor
1009 TYPE(mp_para_env_type), POINTER :: para_env
1010 CHARACTER(LEN=12) :: tensor_name
1011 INTEGER, DIMENSION(:) :: map1, map2
1012 INTEGER, ALLOCATABLE, DIMENSION(:) :: sizes_ri, sizes_ao
1013 LOGICAL, OPTIONAL :: create_nl_3c
1014 TYPE(neighbor_list_3c_type), OPTIONAL :: nl_3c
1015 TYPE(qs_environment_type), OPTIONAL, POINTER :: qs_env
1016
1017 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_3c_t'
1018
1019 INTEGER :: handle, nkind
1020 INTEGER, ALLOCATABLE, DIMENSION(:) :: dist_ao_1, dist_ao_2, dist_ri
1021 INTEGER, DIMENSION(3) :: pcoord, pdims, pdims_3d
1022 LOGICAL :: my_create_nl_3c
1023 TYPE(dbt_pgrid_type) :: pgrid_3d
1024 TYPE(distribution_3d_type) :: dist_3d
1025 TYPE(mp_cart_type) :: mp_comm_t3c_2
1026 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1027
1028 CALL timeset(routinen, handle)
1029
1030 pdims_3d = 0
1031 CALL dbt_pgrid_create(para_env, pdims_3d, pgrid_3d)
1032 CALL create_3c_tensor(tensor, dist_ri, dist_ao_1, dist_ao_2, &
1033 pgrid_3d, sizes_ri, sizes_ao, sizes_ao, &
1034 map1=map1, map2=map2, name=tensor_name)
1035
1036 IF (PRESENT(create_nl_3c)) THEN
1037 my_create_nl_3c = create_nl_3c
1038 ELSE
1039 my_create_nl_3c = .false.
1040 END IF
1041
1042 IF (my_create_nl_3c) THEN
1043 CALL get_qs_env(qs_env, nkind=nkind, particle_set=particle_set)
1044 CALL dbt_mp_environ_pgrid(pgrid_3d, pdims, pcoord)
1045 CALL mp_comm_t3c_2%create(pgrid_3d%mp_comm_2d, 3, pdims)
1046 CALL distribution_3d_create(dist_3d, dist_ri, dist_ao_1, dist_ao_2, &
1047 nkind, particle_set, mp_comm_t3c_2, own_comm=.true.)
1048
1049 CALL build_3c_neighbor_lists(nl_3c, &
1050 qs_env%bs_env%basis_set_RI, &
1051 qs_env%bs_env%basis_set_AO, &
1052 qs_env%bs_env%basis_set_AO, &
1053 dist_3d, qs_env%bs_env%ri_metric, &
1054 "GW_3c_nl", qs_env, own_dist=.true.)
1055 END IF
1056
1057 DEALLOCATE (dist_ri, dist_ao_1, dist_ao_2)
1058 CALL dbt_pgrid_destroy(pgrid_3d)
1059
1060 CALL timestop(handle)
1061
1062 END SUBROUTINE create_3c_t
1063
1064! **************************************************************************************************
1065!> \brief ...
1066!> \param bs_env ...
1067! **************************************************************************************************
1068 SUBROUTINE init_interaction_radii(bs_env)
1069 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1070
1071 CHARACTER(LEN=*), PARAMETER :: routinen = 'init_interaction_radii'
1072
1073 INTEGER :: handle, ibasis
1074 TYPE(gto_basis_set_type), POINTER :: orb_basis, ri_basis
1075
1076 CALL timeset(routinen, handle)
1077
1078 DO ibasis = 1, SIZE(bs_env%basis_set_AO)
1079
1080 orb_basis => bs_env%basis_set_AO(ibasis)%gto_basis_set
1081 CALL init_interaction_radii_orb_basis(orb_basis, bs_env%eps_filter)
1082
1083 ri_basis => bs_env%basis_set_RI(ibasis)%gto_basis_set
1084 CALL init_interaction_radii_orb_basis(ri_basis, bs_env%eps_filter)
1085
1086 END DO
1087
1088 CALL timestop(handle)
1089
1090 END SUBROUTINE init_interaction_radii
1091
1092! **************************************************************************************************
1093!> \brief ...
1094!> \param t_3c_int ...
1095!> \param max_dist_AO_atoms ...
1096!> \param qs_env ...
1097! **************************************************************************************************
1098 SUBROUTINE get_max_dist_ao_atoms(t_3c_int, max_dist_AO_atoms, qs_env)
1099 TYPE(dbt_type) :: t_3c_int
1100 REAL(kind=dp), INTENT(INOUT) :: max_dist_ao_atoms
1101 TYPE(qs_environment_type), POINTER :: qs_env
1102
1103 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_max_dist_AO_atoms'
1104
1105 INTEGER :: atom_1, atom_2, handle, num_cells
1106 INTEGER, DIMENSION(3) :: atom_ind
1107 INTEGER, DIMENSION(:, :), POINTER :: index_to_cell
1108 REAL(kind=dp) :: abs_rab
1109 REAL(kind=dp), DIMENSION(3) :: rab
1110 TYPE(cell_type), POINTER :: cell
1111 TYPE(dbt_iterator_type) :: iter
1112 TYPE(mp_para_env_type), POINTER :: para_env
1113 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1114
1115 CALL timeset(routinen, handle)
1116
1117 NULLIFY (cell, particle_set, para_env)
1118 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set, para_env=para_env)
1119
1120 ! max_dist_AO_atoms is compared to earlier steps in the loop with step n_atom_step
1121 ! do not initialize/overwrite here
1122
1123! IMPORTANT: Use thread-local copy for max_dist_AO_atoms via REDUCTION to avoid race conditions
1124!$OMP PARALLEL DEFAULT(NONE) &
1125!$OMP SHARED(t_3c_int, num_cells, index_to_cell, particle_set, cell) &
1126!$OMP PRIVATE(iter, atom_ind, rab, abs_rab, atom_1, atom_2) &
1127!$OMP REDUCTION(MAX:max_dist_AO_atoms)
1128
1129 CALL dbt_iterator_start(iter, t_3c_int)
1130 DO WHILE (dbt_iterator_blocks_left(iter))
1131 CALL dbt_iterator_next_block(iter, atom_ind)
1132
1133 atom_1 = atom_ind(2)
1134 atom_2 = atom_ind(3)
1135 rab = pbc(particle_set(atom_1)%r(1:3), particle_set(atom_2)%r(1:3), cell)
1136 abs_rab = sqrt(rab(1)**2 + rab(2)**2 + rab(3)**2)
1137
1138 ! Reduction takes care of using a thread-local copy
1139 max_dist_ao_atoms = max(max_dist_ao_atoms, abs_rab)
1140
1141 END DO
1142 CALL dbt_iterator_stop(iter)
1143!$OMP END PARALLEL
1144
1145 CALL para_env%max(max_dist_ao_atoms)
1146
1147 CALL timestop(handle)
1148
1149 END SUBROUTINE get_max_dist_ao_atoms
1150
1151! **************************************************************************************************
1152!> \brief ...
1153!> \param bs_env ...
1154! **************************************************************************************************
1155 SUBROUTINE set_sparsity_parallelization_parameters(bs_env)
1156 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1157
1158 CHARACTER(LEN=*), PARAMETER :: routinen = 'set_sparsity_parallelization_parameters'
1159
1160 INTEGER :: handle, i_ivl, il_ivl, j_ivl, n_atom_per_il_ivl, n_atom_per_ivl, n_intervals_i, &
1161 n_intervals_inner_loop_atoms, n_intervals_j, u
1162 INTEGER(KIND=int_8) :: input_memory_per_proc
1163
1164 CALL timeset(routinen, handle)
1165
1166 ! heuristic parameter to prevent out of memory
1167 bs_env%safety_factor_memory = 0.10_dp
1168
1169 input_memory_per_proc = int(bs_env%input_memory_per_proc_GB*1.0e9_dp, kind=int_8)
1170
1171 ! choose atomic range for λ ("i_atom"), ν ("j_atom") in
1172 ! M_λνP(iτ) = sum_µ (µν|P) G^occ_µλ(i|τ|,k=0)
1173 ! N_νλQ(iτ) = sum_σ (σλ|Q) G^vir_σν(i|τ|,k=0)
1174 ! such that M and N fit into the memory
1175 n_atom_per_ivl = int(sqrt(bs_env%safety_factor_memory*input_memory_per_proc &
1176 *bs_env%group_size_tensor/24/bs_env%n_RI &
1177 /sqrt(bs_env%occupation_3c_int)))/bs_env%max_AO_bf_per_atom
1178
1179 n_intervals_i = (bs_env%n_atom_i - 1)/n_atom_per_ivl + 1
1180 n_intervals_j = (bs_env%n_atom_j - 1)/n_atom_per_ivl + 1
1181
1182 bs_env%n_atom_per_interval_ij = n_atom_per_ivl
1183 bs_env%n_intervals_i = n_intervals_i
1184 bs_env%n_intervals_j = n_intervals_j
1185
1186 ALLOCATE (bs_env%i_atom_intervals(2, n_intervals_i))
1187 ALLOCATE (bs_env%j_atom_intervals(2, n_intervals_j))
1188
1189 DO i_ivl = 1, n_intervals_i
1190 bs_env%i_atom_intervals(1, i_ivl) = (i_ivl - 1)*n_atom_per_ivl + bs_env%atoms_i(1)
1191 bs_env%i_atom_intervals(2, i_ivl) = min(i_ivl*n_atom_per_ivl + bs_env%atoms_i(1) - 1, &
1192 bs_env%atoms_i(2))
1193 END DO
1194
1195 DO j_ivl = 1, n_intervals_j
1196 bs_env%j_atom_intervals(1, j_ivl) = (j_ivl - 1)*n_atom_per_ivl + bs_env%atoms_j(1)
1197 bs_env%j_atom_intervals(2, j_ivl) = min(j_ivl*n_atom_per_ivl + bs_env%atoms_j(1) - 1, &
1198 bs_env%atoms_j(2))
1199 END DO
1200
1201 ALLOCATE (bs_env%skip_Sigma_occ(n_intervals_i, n_intervals_j))
1202 ALLOCATE (bs_env%skip_Sigma_vir(n_intervals_i, n_intervals_j))
1203 bs_env%skip_Sigma_occ(:, :) = .false.
1204 bs_env%skip_Sigma_vir(:, :) = .false.
1205 bs_env%n_skip_chi = 0
1206
1207 ALLOCATE (bs_env%skip_chi(n_intervals_i, n_intervals_j))
1208 bs_env%skip_chi(:, :) = .false.
1209 bs_env%n_skip_sigma = 0
1210
1211 ! choose atomic range for µ and σ ("inner loop (IL) atom") in
1212 ! M_λνP(iτ) = sum_µ (µν|P) G^occ_µλ(i|τ|,k=0)
1213 ! N_νλQ(iτ) = sum_σ (σλ|Q) G^vir_σν(i|τ|,k=0)
1214 n_atom_per_il_ivl = min(int(bs_env%safety_factor_memory*input_memory_per_proc &
1215 *bs_env%group_size_tensor/n_atom_per_ivl &
1216 /bs_env%max_AO_bf_per_atom &
1217 /bs_env%n_RI/8/sqrt(bs_env%occupation_3c_int) &
1218 /bs_env%max_AO_bf_per_atom), bs_env%n_atom)
1219
1220 n_intervals_inner_loop_atoms = (bs_env%n_atom - 1)/n_atom_per_il_ivl + 1
1221
1222 bs_env%n_atom_per_IL_interval = n_atom_per_il_ivl
1223 bs_env%n_intervals_inner_loop_atoms = n_intervals_inner_loop_atoms
1224
1225 ALLOCATE (bs_env%inner_loop_atom_intervals(2, n_intervals_inner_loop_atoms))
1226 DO il_ivl = 1, n_intervals_inner_loop_atoms
1227 bs_env%inner_loop_atom_intervals(1, il_ivl) = (il_ivl - 1)*n_atom_per_il_ivl + 1
1228 bs_env%inner_loop_atom_intervals(2, il_ivl) = min(il_ivl*n_atom_per_il_ivl, bs_env%n_atom)
1229 END DO
1230
1231 u = bs_env%unit_nr
1232 IF (u > 0) THEN
1233 WRITE (u, '(T2,A)') ''
1234 WRITE (u, '(T2,A,I33)') λντνλτ'Number of i and j atoms in M_P(), N_Q():', n_atom_per_ivl
1235 WRITE (u, '(T2,A,I18)') µλνµµνµλ'Number of inner loop atoms for in M_P = sum_ (|P) G_', &
1236 n_atom_per_il_ivl
1237 END IF
1238
1239 CALL timestop(handle)
1240
1241 END SUBROUTINE set_sparsity_parallelization_parameters
1242
1243! **************************************************************************************************
1244!> \brief ...
1245!> \param qs_env ...
1246!> \param bs_env ...
1247! **************************************************************************************************
1248 SUBROUTINE check_for_restart_files(qs_env, bs_env)
1249 TYPE(qs_environment_type), POINTER :: qs_env
1250 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1251
1252 CHARACTER(LEN=*), PARAMETER :: routinen = 'check_for_restart_files'
1253
1254 CHARACTER(LEN=9) :: frmt
1255 CHARACTER(len=default_path_length) :: project_name
1256 CHARACTER(len=default_string_length) :: f_chi, f_s_n, f_s_p, f_s_x, f_w_t, prefix
1257 INTEGER :: handle, i_spin, i_t_or_w, ind, n_spin, &
1258 num_time_freq_points
1259 LOGICAL :: chi_exists, sigma_neg_time_exists, &
1260 sigma_pos_time_exists, &
1261 sigma_x_spin_exists, w_time_exists
1262 TYPE(cp_logger_type), POINTER :: logger
1263 TYPE(section_vals_type), POINTER :: input, print_key
1264
1265 CALL timeset(routinen, handle)
1266
1267 num_time_freq_points = bs_env%num_time_freq_points
1268 n_spin = bs_env%n_spin
1269
1270 ALLOCATE (bs_env%read_chi(num_time_freq_points))
1271 ALLOCATE (bs_env%calc_chi(num_time_freq_points))
1272 ALLOCATE (bs_env%Sigma_c_exists(num_time_freq_points, n_spin))
1273
1274 CALL get_qs_env(qs_env, input=input)
1275
1276 logger => cp_get_default_logger()
1277 print_key => section_vals_get_subs_vals(input, 'PROPERTIES%BANDSTRUCTURE%GW%PRINT%RESTART')
1278 project_name = cp_print_key_generate_filename(logger, print_key, extension="", &
1279 my_local=.false.)
1280 WRITE (prefix, '(2A)') trim(project_name), "-RESTART_"
1281 bs_env%prefix = prefix
1282
1283 bs_env%all_W_exist = .true.
1284
1285 DO i_t_or_w = 1, num_time_freq_points
1286
1287 IF (i_t_or_w < 10) THEN
1288 WRITE (frmt, '(A)') '(3A,I1,A)'
1289 WRITE (f_chi, frmt) trim(prefix), bs_env%chi_name, "_0", i_t_or_w, ".matrix"
1290 WRITE (f_w_t, frmt) trim(prefix), bs_env%W_time_name, "_0", i_t_or_w, ".matrix"
1291 ELSE IF (i_t_or_w < 100) THEN
1292 WRITE (frmt, '(A)') '(3A,I2,A)'
1293 WRITE (f_chi, frmt) trim(prefix), bs_env%chi_name, "_", i_t_or_w, ".matrix"
1294 WRITE (f_w_t, frmt) trim(prefix), bs_env%W_time_name, "_", i_t_or_w, ".matrix"
1295 ELSE
1296 cpabort('Please implement more than 99 time/frequency points.')
1297 END IF
1298
1299 INQUIRE (file=trim(f_chi), exist=chi_exists)
1300 INQUIRE (file=trim(f_w_t), exist=w_time_exists)
1301
1302 bs_env%read_chi(i_t_or_w) = chi_exists
1303 bs_env%calc_chi(i_t_or_w) = .NOT. chi_exists
1304
1305 bs_env%all_W_exist = bs_env%all_W_exist .AND. w_time_exists
1306
1307 ! the self-energy is spin-dependent
1308 DO i_spin = 1, n_spin
1309
1310 ind = i_t_or_w + (i_spin - 1)*num_time_freq_points
1311
1312 IF (ind < 10) THEN
1313 WRITE (frmt, '(A)') '(3A,I1,A)'
1314 WRITE (f_s_p, frmt) trim(prefix), bs_env%Sigma_p_name, "_0", ind, ".matrix"
1315 WRITE (f_s_n, frmt) trim(prefix), bs_env%Sigma_n_name, "_0", ind, ".matrix"
1316 ELSE IF (i_t_or_w < 100) THEN
1317 WRITE (frmt, '(A)') '(3A,I2,A)'
1318 WRITE (f_s_p, frmt) trim(prefix), bs_env%Sigma_p_name, "_", ind, ".matrix"
1319 WRITE (f_s_n, frmt) trim(prefix), bs_env%Sigma_n_name, "_", ind, ".matrix"
1320 END IF
1321
1322 INQUIRE (file=trim(f_s_p), exist=sigma_pos_time_exists)
1323 INQUIRE (file=trim(f_s_n), exist=sigma_neg_time_exists)
1324
1325 bs_env%Sigma_c_exists(i_t_or_w, i_spin) = sigma_pos_time_exists .AND. &
1326 sigma_neg_time_exists
1327
1328 END DO
1329
1330 END DO
1331
1332 ! Marek : In the RTBSE run, check also for zero frequency W
1333 IF (bs_env%rtp_method == rtp_method_bse) THEN
1334 WRITE (f_w_t, '(3A,I1,A)') trim(prefix), "W_freq_rtp", "_0", 0, ".matrix"
1335 INQUIRE (file=trim(f_w_t), exist=w_time_exists)
1336 bs_env%all_W_exist = bs_env%all_W_exist .AND. w_time_exists
1337 END IF
1338
1339 IF (bs_env%all_W_exist) THEN
1340 bs_env%read_chi(:) = .false.
1341 bs_env%calc_chi(:) = .false.
1342 END IF
1343
1344 bs_env%Sigma_x_exists = .true.
1345 DO i_spin = 1, n_spin
1346 WRITE (f_s_x, '(3A,I1,A)') trim(prefix), bs_env%Sigma_x_name, "_0", i_spin, ".matrix"
1347 INQUIRE (file=trim(f_s_x), exist=sigma_x_spin_exists)
1348 bs_env%Sigma_x_exists = bs_env%Sigma_x_exists .AND. sigma_x_spin_exists
1349 END DO
1350
1351 ! If any restart files are read, check if the SCF converged in 1 step.
1352 ! This is important because a re-iterated SCF can lead to spurious GW results
1353 IF (any(bs_env%read_chi(:)) &
1354 .OR. any(bs_env%Sigma_c_exists) &
1355 .OR. bs_env%all_W_exist &
1356 .OR. bs_env%Sigma_x_exists &
1357 ) THEN
1358
1359 IF (qs_env%scf_env%iter_count /= 1) THEN
1360 CALL cp_warn(__location__, "SCF needed more than 1 step, "// &
1361 "which might lead to spurious GW results when using GW restart files. ")
1362 END IF
1363 END IF
1364
1365 CALL timestop(handle)
1366
1367 END SUBROUTINE check_for_restart_files
1368
1369! **************************************************************************************************
1370!> \brief ...
1371!> \param qs_env ...
1372!> \param bs_env ...
1373! **************************************************************************************************
1374 SUBROUTINE set_parallelization_parameters(qs_env, bs_env)
1375 TYPE(qs_environment_type), POINTER :: qs_env
1376 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1377
1378 CHARACTER(LEN=*), PARAMETER :: routinen = 'set_parallelization_parameters'
1379
1380 INTEGER :: color_sub, dummy_1, dummy_2, handle, &
1381 num_pe, num_t_groups, u
1382 TYPE(mp_para_env_type), POINTER :: para_env
1383
1384 CALL timeset(routinen, handle)
1385
1386 CALL get_qs_env(qs_env, para_env=para_env)
1387
1388 num_pe = para_env%num_pe
1389 ! if not already set, use all processors for the group (for large-cell GW, performance
1390 ! seems to be best for a single group with all MPI processes per group)
1391 IF (bs_env%group_size_tensor < 0 .OR. bs_env%group_size_tensor > num_pe) &
1392 bs_env%group_size_tensor = num_pe
1393
1394 ! group_size_tensor must divide num_pe without rest; otherwise everything will be complicated
1395 IF (modulo(num_pe, bs_env%group_size_tensor) /= 0) THEN
1396 CALL find_good_group_size(num_pe, bs_env%group_size_tensor)
1397 END IF
1398
1399 ! para_env_tensor for tensor subgroups
1400 color_sub = para_env%mepos/bs_env%group_size_tensor
1401 bs_env%tensor_group_color = color_sub
1402
1403 ALLOCATE (bs_env%para_env_tensor)
1404 CALL bs_env%para_env_tensor%from_split(para_env, color_sub)
1405
1406 num_t_groups = para_env%num_pe/bs_env%group_size_tensor
1407 bs_env%num_tensor_groups = num_t_groups
1408
1409 CALL get_i_j_atoms(bs_env%atoms_i, bs_env%atoms_j, bs_env%n_atom_i, bs_env%n_atom_j, &
1410 color_sub, bs_env)
1411
1412 ALLOCATE (bs_env%atoms_i_t_group(2, num_t_groups))
1413 ALLOCATE (bs_env%atoms_j_t_group(2, num_t_groups))
1414 DO color_sub = 0, num_t_groups - 1
1415 CALL get_i_j_atoms(bs_env%atoms_i_t_group(1:2, color_sub + 1), &
1416 bs_env%atoms_j_t_group(1:2, color_sub + 1), &
1417 dummy_1, dummy_2, color_sub, bs_env)
1418 END DO
1419
1420 u = bs_env%unit_nr
1421 IF (u > 0) THEN
1422 WRITE (u, '(T2,A,I47)') 'Group size for tensor operations', bs_env%group_size_tensor
1423 IF (bs_env%group_size_tensor > 1 .AND. bs_env%n_atom < 5) THEN
1424 WRITE (u, '(T2,A)') 'The requested group size is > 1 which can lead to bad performance.'
1425 WRITE (u, '(T2,A)') 'Using more memory per MPI process might improve performance.'
1426 WRITE (u, '(T2,A)') '(Also increase MEMORY_PER_PROC when using more memory per process.)'
1427 END IF
1428 END IF
1429
1430 CALL timestop(handle)
1431
1432 END SUBROUTINE set_parallelization_parameters
1433
1434! **************************************************************************************************
1435!> \brief ...
1436!> \param num_pe ...
1437!> \param group_size ...
1438! **************************************************************************************************
1439 SUBROUTINE find_good_group_size(num_pe, group_size)
1440
1441 INTEGER :: num_pe, group_size
1442
1443 CHARACTER(LEN=*), PARAMETER :: routinen = 'find_good_group_size'
1444
1445 INTEGER :: group_size_minus, group_size_orig, &
1446 group_size_plus, handle, i_diff
1447
1448 CALL timeset(routinen, handle)
1449
1450 group_size_orig = group_size
1451
1452 DO i_diff = 1, num_pe
1453
1454 group_size_minus = group_size - i_diff
1455
1456 IF (modulo(num_pe, group_size_minus) == 0 .AND. group_size_minus > 0) THEN
1457 group_size = group_size_minus
1458 EXIT
1459 END IF
1460
1461 group_size_plus = group_size + i_diff
1462
1463 IF (modulo(num_pe, group_size_plus) == 0 .AND. group_size_plus <= num_pe) THEN
1464 group_size = group_size_plus
1465 EXIT
1466 END IF
1467
1468 END DO
1469
1470 IF (group_size_orig == group_size) cpabort("Group size error")
1471
1472 CALL timestop(handle)
1473
1474 END SUBROUTINE find_good_group_size
1475
1476! **************************************************************************************************
1477!> \brief ...
1478!> \param atoms_i ...
1479!> \param atoms_j ...
1480!> \param n_atom_i ...
1481!> \param n_atom_j ...
1482!> \param color_sub ...
1483!> \param bs_env ...
1484! **************************************************************************************************
1485 SUBROUTINE get_i_j_atoms(atoms_i, atoms_j, n_atom_i, n_atom_j, color_sub, bs_env)
1486
1487 INTEGER, DIMENSION(2) :: atoms_i, atoms_j
1488 INTEGER :: n_atom_i, n_atom_j, color_sub
1489 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1490
1491 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_i_j_atoms'
1492
1493 INTEGER :: handle, i_atoms_per_group, i_group, &
1494 ipcol, ipcol_loop, iprow, iprow_loop, &
1495 j_atoms_per_group, npcol, nprow
1496
1497 CALL timeset(routinen, handle)
1498
1499 ! create a square mesh of tensor groups for iatom and jatom; code from blacs_env_create
1500 CALL square_mesh(nprow, npcol, bs_env%num_tensor_groups)
1501
1502 i_group = 0
1503 DO ipcol_loop = 0, npcol - 1
1504 DO iprow_loop = 0, nprow - 1
1505 IF (i_group == color_sub) THEN
1506 iprow = iprow_loop
1507 ipcol = ipcol_loop
1508 END IF
1509 i_group = i_group + 1
1510 END DO
1511 END DO
1512
1513 IF (modulo(bs_env%n_atom, nprow) == 0) THEN
1514 i_atoms_per_group = bs_env%n_atom/nprow
1515 ELSE
1516 i_atoms_per_group = bs_env%n_atom/nprow + 1
1517 END IF
1518
1519 IF (modulo(bs_env%n_atom, npcol) == 0) THEN
1520 j_atoms_per_group = bs_env%n_atom/npcol
1521 ELSE
1522 j_atoms_per_group = bs_env%n_atom/npcol + 1
1523 END IF
1524
1525 atoms_i(1) = iprow*i_atoms_per_group + 1
1526 atoms_i(2) = min((iprow + 1)*i_atoms_per_group, bs_env%n_atom)
1527 n_atom_i = atoms_i(2) - atoms_i(1) + 1
1528
1529 atoms_j(1) = ipcol*j_atoms_per_group + 1
1530 atoms_j(2) = min((ipcol + 1)*j_atoms_per_group, bs_env%n_atom)
1531 n_atom_j = atoms_j(2) - atoms_j(1) + 1
1532
1533 CALL timestop(handle)
1534
1535 END SUBROUTINE get_i_j_atoms
1536
1537! **************************************************************************************************
1538!> \brief ...
1539!> \param nprow ...
1540!> \param npcol ...
1541!> \param nproc ...
1542! **************************************************************************************************
1543 SUBROUTINE square_mesh(nprow, npcol, nproc)
1544 INTEGER :: nprow, npcol, nproc
1545
1546 CHARACTER(LEN=*), PARAMETER :: routinen = 'square_mesh'
1547
1548 INTEGER :: gcd_max, handle, ipe, jpe
1549
1550 CALL timeset(routinen, handle)
1551
1552 gcd_max = -1
1553 DO ipe = 1, ceiling(sqrt(real(nproc, dp)))
1554 jpe = nproc/ipe
1555 IF (ipe*jpe /= nproc) cycle
1556 IF (gcd(ipe, jpe) >= gcd_max) THEN
1557 nprow = ipe
1558 npcol = jpe
1559 gcd_max = gcd(ipe, jpe)
1560 END IF
1561 END DO
1562
1563 CALL timestop(handle)
1564
1565 END SUBROUTINE square_mesh
1566
1567! **************************************************************************************************
1568!> \brief ...
1569!> \param bs_env ...
1570!> \param qs_env ...
1571! **************************************************************************************************
1572 SUBROUTINE set_heuristic_parameters(bs_env, qs_env)
1573 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1574 TYPE(qs_environment_type), OPTIONAL, POINTER :: qs_env
1575
1576 CHARACTER(LEN=*), PARAMETER :: routinen = 'set_heuristic_parameters'
1577
1578 INTEGER :: handle, u
1579 LOGICAL :: do_bvk_cell
1580
1581 CALL timeset(routinen, handle)
1582
1583 ! for generating numerically stable minimax Fourier integration weights
1584 bs_env%num_points_per_magnitude = 200
1585
1586 IF (bs_env%input_regularization_minimax > -1.0e-12_dp) THEN
1587 bs_env%regularization_minimax = bs_env%input_regularization_minimax
1588 ELSE
1589 ! for periodic systems and for 20 minimax points, we use a regularized minimax mesh
1590 ! (from experience: regularized minimax meshes converges faster for periodic systems
1591 ! and for 20 pts)
1592 IF (sum(bs_env%periodic) /= 0 .OR. bs_env%num_time_freq_points >= 20) THEN
1593 bs_env%regularization_minimax = 1.0e-6_dp
1594 ELSE
1595 bs_env%regularization_minimax = 0.0_dp
1596 END IF
1597 END IF
1598
1599 bs_env%stabilize_exp = 70.0_dp
1600 bs_env%eps_atom_grid_2d_mat = 1.0e-50_dp
1601
1602 ! use a 16-parameter Padé fit
1603 bs_env%nparam_pade = 16
1604
1605 ! resolution of the identity with the truncated Coulomb metric, cutoff radius 3 Angström
1606 bs_env%ri_metric%potential_type = do_potential_truncated
1607 bs_env%ri_metric%omega = 0.0_dp
1608 ! cutoff radius is specified in the input
1609 bs_env%ri_metric%filename = "t_c_g.dat"
1610
1611 bs_env%eps_eigval_mat_RI = 0.0_dp
1612
1613 IF (bs_env%input_regularization_RI > -1.0e-12_dp) THEN
1614 bs_env%regularization_RI = bs_env%input_regularization_RI
1615 ELSE
1616 ! default case:
1617
1618 ! 1. for periodic systems, we use the regularized resolution of the identity per default
1619 bs_env%regularization_RI = 1.0e-2_dp
1620
1621 ! 2. for molecules, no regularization is necessary
1622 IF (sum(bs_env%periodic) == 0) bs_env%regularization_RI = 0.0_dp
1623
1624 END IF
1625
1626 ! truncated Coulomb operator for exchange self-energy
1627 ! (see details in Guidon, VandeVondele, Hutter, JCTC 5, 3010 (2009) and references therein)
1628 do_bvk_cell = bs_env%small_cell_full_kp_or_large_cell_Gamma == small_cell_full_kp
1629 CALL trunc_coulomb_for_exchange(qs_env, bs_env%trunc_coulomb, &
1630 rel_cutoff_trunc_coulomb_ri_x=0.5_dp, &
1631 cell_grid=bs_env%cell_grid_scf_desymm, &
1632 do_bvk_cell=do_bvk_cell)
1633
1634 ! for small-cell GW, we need more cells than normally used by the filter bs_env%eps_filter
1635 ! (in particular for computing the self-energy because of higher number of cells needed)
1636 bs_env%heuristic_filter_factor = 1.0e-4
1637
1638 u = bs_env%unit_nr
1639 IF (u > 0) THEN
1640 WRITE (u, fmt="(T2,2A,F21.1,A)") "Cutoff radius for the truncated Coulomb ", &
1641 Σ"operator in ^x:", bs_env%trunc_coulomb%cutoff_radius*angstrom, Å" "
1642 WRITE (u, fmt="(T2,2A,F15.1,A)") "Cutoff radius for the truncated Coulomb ", &
1643 "operator in RI metric:", bs_env%ri_metric%cutoff_radius*angstrom, Å" "
1644 WRITE (u, fmt="(T2,A,ES48.1)") "Regularization parameter of RI ", bs_env%regularization_RI
1645 WRITE (u, fmt="(T2,A,ES38.1)") "Regularization parameter of minimax grids", &
1646 bs_env%regularization_minimax
1647 WRITE (u, fmt="(T2,A,I53)") "Lattice sum size for V(k):", bs_env%size_lattice_sum_V
1648 END IF
1649
1650 CALL timestop(handle)
1651
1652 END SUBROUTINE set_heuristic_parameters
1653
1654! **************************************************************************************************
1655!> \brief ...
1656!> \param bs_env ...
1657! **************************************************************************************************
1658 SUBROUTINE print_header_and_input_parameters(bs_env)
1659
1660 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1661
1662 CHARACTER(LEN=*), PARAMETER :: routinen = 'print_header_and_input_parameters'
1663
1664 INTEGER :: handle, u
1665
1666 CALL timeset(routinen, handle)
1667
1668 u = bs_env%unit_nr
1669
1670 IF (u > 0) THEN
1671 WRITE (u, '(T2,A)') ' '
1672 WRITE (u, '(T2,A)') repeat('-', 79)
1673 WRITE (u, '(T2,A,A78)') '-', '-'
1674 WRITE (u, '(T2,A,A46,A32)') '-', 'GW CALCULATION', '-'
1675 WRITE (u, '(T2,A,A78)') '-', '-'
1676 WRITE (u, '(T2,A)') repeat('-', 79)
1677 WRITE (u, '(T2,A)') ' '
1678 WRITE (u, '(T2,A,I45)') 'Input: Number of time/freq. points', bs_env%num_time_freq_points
1679 WRITE (u, "(T2,A,F44.1,A)") ωΣω'Input: _max for fitting (i) (eV)', bs_env%freq_max_fit*evolt
1680 WRITE (u, '(T2,A,ES27.1)') 'Input: Filter threshold for sparse tensor operations', &
1681 bs_env%eps_filter
1682 WRITE (u, "(T2,A,L55)") 'Input: Apply Hedin shift', bs_env%do_hedin_shift
1683 WRITE (u, '(T2,A,F37.1,A)') 'Input: Available memory per MPI process', &
1684 bs_env%input_memory_per_proc_GB, ' GB'
1685 END IF
1686
1687 CALL timestop(handle)
1688
1689 END SUBROUTINE print_header_and_input_parameters
1690
1691! **************************************************************************************************
1692!> \brief ...
1693!> \param qs_env ...
1694!> \param bs_env ...
1695! **************************************************************************************************
1696 SUBROUTINE compute_v_xc(qs_env, bs_env)
1697 TYPE(qs_environment_type), POINTER :: qs_env
1698 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1699
1700 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_V_xc'
1701
1702 INTEGER :: handle, img, ispin, myfun, nimages
1703 LOGICAL :: hf_present
1704 REAL(kind=dp) :: energy_ex, energy_exc, energy_total, &
1705 myfraction
1706 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_ks_without_v_xc
1707 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks_kp
1708 TYPE(dft_control_type), POINTER :: dft_control
1709 TYPE(qs_energy_type), POINTER :: energy
1710 TYPE(section_vals_type), POINTER :: hf_section, input, xc_section
1711
1712 CALL timeset(routinen, handle)
1713
1714 CALL get_qs_env(qs_env, input=input, energy=energy, dft_control=dft_control)
1715
1716 ! previously, dft_control%nimages set to # neighbor cells, revert for Γ-only KS matrix
1717 nimages = dft_control%nimages
1718 dft_control%nimages = bs_env%nimages_scf
1719
1720 ! we need to reset XC functional, therefore, get XC input
1721 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
1722 CALL section_vals_val_get(xc_section, "XC_FUNCTIONAL%_SECTION_PARAMETERS_", i_val=myfun)
1723 CALL section_vals_val_set(xc_section, "XC_FUNCTIONAL%_SECTION_PARAMETERS_", i_val=xc_none)
1724 ! IF (ASSOCIATED(section_vals_get_subs_vals(xc_section, "HF", can_return_null=.TRUE.))) THEN
1725 hf_section => section_vals_get_subs_vals(input, "DFT%XC%HF", can_return_null=.true.)
1726 hf_present = .false.
1727 IF (ASSOCIATED(hf_section)) THEN
1728 CALL section_vals_get(hf_section, explicit=hf_present)
1729 END IF
1730 IF (hf_present) THEN
1731 ! Special case for handling hfx
1732 CALL section_vals_val_get(xc_section, "HF%FRACTION", r_val=myfraction)
1733 CALL section_vals_val_set(xc_section, "HF%FRACTION", r_val=0.0_dp)
1734 END IF
1735
1736 ! save the energy before the energy gets updated
1737 energy_total = energy%total
1738 energy_exc = energy%exc
1739 energy_ex = energy%ex
1740
1741 SELECT CASE (bs_env%small_cell_full_kp_or_large_cell_Gamma)
1742 CASE (large_cell_gamma)
1743
1744 NULLIFY (mat_ks_without_v_xc)
1745 CALL dbcsr_allocate_matrix_set(mat_ks_without_v_xc, bs_env%n_spin)
1746
1747 DO ispin = 1, bs_env%n_spin
1748 ALLOCATE (mat_ks_without_v_xc(ispin)%matrix)
1749 IF (hf_present) THEN
1750 CALL dbcsr_create(mat_ks_without_v_xc(ispin)%matrix, template=bs_env%mat_ao_ao%matrix, &
1751 matrix_type=dbcsr_type_symmetric)
1752 ELSE
1753 CALL dbcsr_create(mat_ks_without_v_xc(ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1754 END IF
1755 END DO
1756
1757 ! calculate KS-matrix without XC
1758 CALL qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces=.false., just_energy=.false., &
1759 ext_ks_matrix=mat_ks_without_v_xc)
1760
1761 DO ispin = 1, bs_env%n_spin
1762 ! transfer dbcsr matrix to fm
1763 CALL cp_fm_create(bs_env%fm_V_xc_Gamma(ispin), bs_env%fm_s_Gamma%matrix_struct)
1764 CALL copy_dbcsr_to_fm(mat_ks_without_v_xc(ispin)%matrix, bs_env%fm_V_xc_Gamma(ispin))
1765
1766 ! v_xc = h_ks - h_ks(v_xc = 0)
1767 CALL cp_fm_scale_and_add(alpha=-1.0_dp, matrix_a=bs_env%fm_V_xc_Gamma(ispin), &
1768 beta=1.0_dp, matrix_b=bs_env%fm_ks_Gamma(ispin))
1769 END DO
1770
1771 CALL dbcsr_deallocate_matrix_set(mat_ks_without_v_xc)
1772
1773 CASE (small_cell_full_kp)
1774
1775 ! calculate KS-matrix without XC
1776 CALL qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces=.false., just_energy=.false.)
1777 CALL get_qs_env(qs_env=qs_env, matrix_ks_kp=matrix_ks_kp)
1778
1779 ALLOCATE (bs_env%fm_V_xc_R(dft_control%nimages, bs_env%n_spin))
1780 DO ispin = 1, bs_env%n_spin
1781 DO img = 1, dft_control%nimages
1782 ! safe fm_V_xc_R in fm_matrix because saving in dbcsr matrix caused trouble...
1783 CALL copy_dbcsr_to_fm(matrix_ks_kp(ispin, img)%matrix, bs_env%fm_work_mo(1))
1784 CALL cp_fm_create(bs_env%fm_V_xc_R(img, ispin), bs_env%fm_work_mo(1)%matrix_struct, &
1785 set_zero=.true.)
1786 ! store h_ks(v_xc = 0) in fm_V_xc_R
1787 CALL cp_fm_scale_and_add(alpha=1.0_dp, matrix_a=bs_env%fm_V_xc_R(img, ispin), &
1788 beta=1.0_dp, matrix_b=bs_env%fm_work_mo(1))
1789 END DO
1790 END DO
1791
1792 END SELECT
1793
1794 ! set back the energy
1795 energy%total = energy_total
1796 energy%exc = energy_exc
1797 energy%ex = energy_ex
1798
1799 ! set back nimages
1800 dft_control%nimages = nimages
1801
1802 ! set the DFT functional and HF fraction back
1803 CALL section_vals_val_set(xc_section, "XC_FUNCTIONAL%_SECTION_PARAMETERS_", &
1804 i_val=myfun)
1805 IF (hf_present) THEN
1806 CALL section_vals_val_set(xc_section, "HF%FRACTION", &
1807 r_val=myfraction)
1808 END IF
1809
1810 IF (bs_env%small_cell_full_kp_or_large_cell_Gamma == small_cell_full_kp) THEN
1811 ! calculate KS-matrix again with XC
1812 CALL qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces=.false., just_energy=.false.)
1813 DO ispin = 1, bs_env%n_spin
1814 DO img = 1, dft_control%nimages
1815 ! store h_ks in fm_work_mo
1816 CALL copy_dbcsr_to_fm(matrix_ks_kp(ispin, img)%matrix, bs_env%fm_work_mo(1))
1817 ! v_xc = h_ks - h_ks(v_xc = 0)
1818 CALL cp_fm_scale_and_add(alpha=-1.0_dp, matrix_a=bs_env%fm_V_xc_R(img, ispin), &
1819 beta=1.0_dp, matrix_b=bs_env%fm_work_mo(1))
1820 END DO
1821 END DO
1822 END IF
1823
1824 CALL timestop(handle)
1825
1826 END SUBROUTINE compute_v_xc
1827
1828! **************************************************************************************************
1829!> \brief ...
1830!> \param bs_env ...
1831! **************************************************************************************************
1832 SUBROUTINE setup_time_and_frequency_minimax_grid(bs_env)
1833 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1834
1835 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_time_and_frequency_minimax_grid'
1836
1837 INTEGER :: handle, homo, i_w, ierr, ispin, j_w, &
1838 n_mo, num_time_freq_points, u
1839 REAL(kind=dp) :: e_max, e_max_ispin, e_min, e_min_ispin, &
1840 e_range, max_error_min
1841 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: points_and_weights
1842
1843 CALL timeset(routinen, handle)
1844
1845 n_mo = bs_env%n_ao
1846 num_time_freq_points = bs_env%num_time_freq_points
1847
1848 ALLOCATE (bs_env%imag_freq_points(num_time_freq_points))
1849 ALLOCATE (bs_env%imag_time_points(num_time_freq_points))
1850 ALLOCATE (bs_env%imag_time_weights_freq_zero(num_time_freq_points))
1851 ALLOCATE (bs_env%weights_cos_t_to_w(num_time_freq_points, num_time_freq_points))
1852 ALLOCATE (bs_env%weights_cos_w_to_t(num_time_freq_points, num_time_freq_points))
1853 ALLOCATE (bs_env%weights_sin_t_to_w(num_time_freq_points, num_time_freq_points))
1854
1855 ! minimum and maximum difference between eigenvalues of unoccupied and an occupied MOs
1856 e_min = 1000.0_dp
1857 e_max = -1000.0_dp
1858 DO ispin = 1, bs_env%n_spin
1859 homo = bs_env%n_occ(ispin)
1860 SELECT CASE (bs_env%small_cell_full_kp_or_large_cell_Gamma)
1861 CASE (large_cell_gamma)
1862 e_min_ispin = bs_env%eigenval_scf_Gamma(homo + 1, ispin) - &
1863 bs_env%eigenval_scf_Gamma(homo, ispin)
1864 e_max_ispin = bs_env%eigenval_scf_Gamma(n_mo, ispin) - &
1865 bs_env%eigenval_scf_Gamma(1, ispin)
1866 CASE (small_cell_full_kp)
1867 e_min_ispin = minval(bs_env%eigenval_scf(homo + 1, :, ispin)) - &
1868 maxval(bs_env%eigenval_scf(homo, :, ispin))
1869 e_max_ispin = maxval(bs_env%eigenval_scf(n_mo, :, ispin)) - &
1870 minval(bs_env%eigenval_scf(1, :, ispin))
1871 END SELECT
1872 e_min = min(e_min, e_min_ispin)
1873 e_max = max(e_max, e_max_ispin)
1874 END DO
1875
1876 e_range = e_max/e_min
1877
1878 ALLOCATE (points_and_weights(2*num_time_freq_points))
1879
1880 ! frequency points
1881 IF (num_time_freq_points <= 20) THEN
1882 CALL get_rpa_minimax_coeff(num_time_freq_points, e_range, points_and_weights, ierr, .false.)
1883 ELSE
1884 CALL get_rpa_minimax_coeff_larger_grid(num_time_freq_points, e_range, points_and_weights)
1885 END IF
1886
1887 ! one needs to scale the minimax grids, see Azizi, Wilhelm, Golze, Panades-Barrueta,
1888 ! Giantomassi, Rinke, Draxl, Gonze et al., 2 publications
1889 bs_env%imag_freq_points(:) = points_and_weights(1:num_time_freq_points)*e_min
1890
1891 ! determine number of fit points in the interval [0,ω_max] for virt, or [-ω_max,0] for occ
1892 bs_env%num_freq_points_fit = 0
1893 DO i_w = 1, num_time_freq_points
1894 IF (bs_env%imag_freq_points(i_w) < bs_env%freq_max_fit) THEN
1895 bs_env%num_freq_points_fit = bs_env%num_freq_points_fit + 1
1896 END IF
1897 END DO
1898
1899 ! iω values for the analytic continuation Σ^c_n(iω,k) -> Σ^c_n(ϵ,k)
1900 ALLOCATE (bs_env%imag_freq_points_fit(bs_env%num_freq_points_fit))
1901 j_w = 0
1902 DO i_w = 1, num_time_freq_points
1903 IF (bs_env%imag_freq_points(i_w) < bs_env%freq_max_fit) THEN
1904 j_w = j_w + 1
1905 bs_env%imag_freq_points_fit(j_w) = bs_env%imag_freq_points(i_w)
1906 END IF
1907 END DO
1908
1909 ! reset the number of Padé parameters if smaller than the number of
1910 ! imaginary-frequency points for the fit
1911 IF (bs_env%num_freq_points_fit < bs_env%nparam_pade) THEN
1912 bs_env%nparam_pade = bs_env%num_freq_points_fit
1913 END IF
1914
1915 ! time points
1916 IF (num_time_freq_points <= 20) THEN
1917 CALL get_exp_minimax_coeff(num_time_freq_points, e_range, points_and_weights)
1918 ELSE
1919 CALL get_exp_minimax_coeff_gw(num_time_freq_points, e_range, points_and_weights)
1920 END IF
1921
1922 bs_env%imag_time_points(:) = points_and_weights(1:num_time_freq_points)/(2.0_dp*e_min)
1923 bs_env%imag_time_weights_freq_zero(:) = points_and_weights(num_time_freq_points + 1:)/(e_min)
1924
1925 DEALLOCATE (points_and_weights)
1926
1927 u = bs_env%unit_nr
1928 IF (u > 0) THEN
1929 WRITE (u, '(T2,A)') ''
1930 WRITE (u, '(T2,A,F55.2)') 'SCF direct band gap (eV)', e_min*evolt
1931 WRITE (u, '(T2,A,F53.2)') 'Max. SCF eigval diff. (eV)', e_max*evolt
1932 WRITE (u, '(T2,A,F55.2)') 'E-Range for minimax grid', e_range
1933 WRITE (u, '(T2,A,I27)') é'Number of Pad parameters for analytic continuation:', &
1934 bs_env%nparam_pade
1935 WRITE (u, '(T2,A)') ''
1936 END IF
1937
1938 ! in minimax grids, Fourier transforms t -> w and w -> t are split using
1939 ! e^(iwt) = cos(wt) + i sin(wt); we thus calculate weights for trafos with a cos and
1940 ! sine prefactor; details in Azizi, Wilhelm, Golze, Giantomassi, Panades-Barrueta,
1941 ! Rinke, Draxl, Gonze et al., 2 publications
1942
1943 ! cosine transform weights imaginary time to imaginary frequency
1944 CALL get_l_sq_wghts_cos_tf_t_to_w(num_time_freq_points, &
1945 bs_env%imag_time_points, &
1946 bs_env%weights_cos_t_to_w, &
1947 bs_env%imag_freq_points, &
1948 e_min, e_max, max_error_min, &
1949 bs_env%num_points_per_magnitude, &
1950 bs_env%regularization_minimax)
1951
1952 ! cosine transform weights imaginary frequency to imaginary time
1953 CALL get_l_sq_wghts_cos_tf_w_to_t(num_time_freq_points, &
1954 bs_env%imag_time_points, &
1955 bs_env%weights_cos_w_to_t, &
1956 bs_env%imag_freq_points, &
1957 e_min, e_max, max_error_min, &
1958 bs_env%num_points_per_magnitude, &
1959 bs_env%regularization_minimax)
1960
1961 ! sine transform weights imaginary time to imaginary frequency
1962 CALL get_l_sq_wghts_sin_tf_t_to_w(num_time_freq_points, &
1963 bs_env%imag_time_points, &
1964 bs_env%weights_sin_t_to_w, &
1965 bs_env%imag_freq_points, &
1966 e_min, e_max, max_error_min, &
1967 bs_env%num_points_per_magnitude, &
1968 bs_env%regularization_minimax)
1969
1970 CALL timestop(handle)
1971
1972 END SUBROUTINE setup_time_and_frequency_minimax_grid
1973
1974! **************************************************************************************************
1975!> \brief ...
1976!> \param qs_env ...
1977!> \param bs_env ...
1978! **************************************************************************************************
1979 SUBROUTINE setup_cells_3c(qs_env, bs_env)
1980
1981 TYPE(qs_environment_type), POINTER :: qs_env
1982 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1983
1984 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_cells_3c'
1985
1986 INTEGER :: atom_i, atom_j, atom_k, block_count, handle, i, i_cell_x, i_cell_x_max, &
1987 i_cell_x_min, i_size, ikind, img, j, j_cell, j_cell_max, j_cell_y, j_cell_y_max, &
1988 j_cell_y_min, j_size, k_cell, k_cell_max, k_cell_z, k_cell_z_max, k_cell_z_min, k_size, &
1989 nimage_pairs_3c, nimages_3c, nimages_3c_max, nkind, u
1990 INTEGER(KIND=int_8) :: mem_occ_per_proc
1991 INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of, n_other_3c_images_max
1992 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: index_to_cell_3c_max, nblocks_3c_max
1993 INTEGER, DIMENSION(3) :: cell_index, n_max
1994 REAL(kind=dp) :: avail_mem_per_proc_gb, cell_dist, cell_radius_3c, dij, dik, djk, eps, &
1995 exp_min_ao, exp_min_ri, frobenius_norm, mem_3c_gb, mem_occ_per_proc_gb, radius_ao, &
1996 radius_ao_product, radius_ri
1997 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: exp_ao_kind, exp_ri_kind, &
1998 radius_ao_kind, &
1999 radius_ao_product_kind, radius_ri_kind
2000 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: int_3c
2001 REAL(kind=dp), DIMENSION(3) :: rij, rik, rjk, vec_cell_j, vec_cell_k
2002 REAL(kind=dp), DIMENSION(:, :), POINTER :: exp_ao, exp_ri
2003 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
2004 TYPE(cell_type), POINTER :: cell
2005 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
2006
2007 CALL timeset(routinen, handle)
2008
2009 CALL get_qs_env(qs_env, nkind=nkind, atomic_kind_set=atomic_kind_set, particle_set=particle_set, cell=cell)
2010
2011 ALLOCATE (exp_ao_kind(nkind), exp_ri_kind(nkind), radius_ao_kind(nkind), &
2012 radius_ao_product_kind(nkind), radius_ri_kind(nkind))
2013
2014 exp_min_ri = 10.0_dp
2015 exp_min_ao = 10.0_dp
2016 exp_ri_kind = 10.0_dp
2017 exp_ao_kind = 10.0_dp
2018
2019 eps = bs_env%eps_filter*bs_env%heuristic_filter_factor
2020
2021 DO ikind = 1, nkind
2022
2023 CALL get_gto_basis_set(bs_env%basis_set_RI(ikind)%gto_basis_set, zet=exp_ri)
2024 CALL get_gto_basis_set(bs_env%basis_set_ao(ikind)%gto_basis_set, zet=exp_ao)
2025
2026 ! we need to remove all exponents lower than a lower bound, e.g. 1E-3, because
2027 ! for contracted basis sets, there might be exponents = 0 in zet
2028 DO i = 1, SIZE(exp_ri, 1)
2029 DO j = 1, SIZE(exp_ri, 2)
2030 IF (exp_ri(i, j) < exp_min_ri .AND. exp_ri(i, j) > 1e-3_dp) exp_min_ri = exp_ri(i, j)
2031 IF (exp_ri(i, j) < exp_ri_kind(ikind) .AND. exp_ri(i, j) > 1e-3_dp) &
2032 exp_ri_kind(ikind) = exp_ri(i, j)
2033 END DO
2034 END DO
2035 DO i = 1, SIZE(exp_ao, 1)
2036 DO j = 1, SIZE(exp_ao, 2)
2037 IF (exp_ao(i, j) < exp_min_ao .AND. exp_ao(i, j) > 1e-3_dp) exp_min_ao = exp_ao(i, j)
2038 IF (exp_ao(i, j) < exp_ao_kind(ikind) .AND. exp_ao(i, j) > 1e-3_dp) &
2039 exp_ao_kind(ikind) = exp_ao(i, j)
2040 END DO
2041 END DO
2042 radius_ao_kind(ikind) = sqrt(-log(eps)/exp_ao_kind(ikind))
2043 radius_ao_product_kind(ikind) = sqrt(-log(eps)/(2.0_dp*exp_ao_kind(ikind)))
2044 radius_ri_kind(ikind) = sqrt(-log(eps)/exp_ri_kind(ikind))
2045 END DO
2046
2047 radius_ao = sqrt(-log(eps)/exp_min_ao)
2048 radius_ao_product = sqrt(-log(eps)/(2.0_dp*exp_min_ao))
2049 radius_ri = sqrt(-log(eps)/exp_min_ri)
2050
2051 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of)
2052
2053 ! For a 3c integral (μR υS | P0) we have that cell R and cell S need to be within radius_3c
2054 cell_radius_3c = radius_ao_product + radius_ri + bs_env%ri_metric%cutoff_radius
2055
2056 n_max(1:3) = bs_env%periodic(1:3)*30
2057
2058 nimages_3c_max = 0
2059
2060 i_cell_x_min = 0
2061 i_cell_x_max = 0
2062 j_cell_y_min = 0
2063 j_cell_y_max = 0
2064 k_cell_z_min = 0
2065 k_cell_z_max = 0
2066
2067 DO i_cell_x = -n_max(1), n_max(1)
2068 DO j_cell_y = -n_max(2), n_max(2)
2069 DO k_cell_z = -n_max(3), n_max(3)
2070
2071 cell_index(1:3) = [i_cell_x, j_cell_y, k_cell_z]
2072
2073 CALL get_cell_dist(cell_index, bs_env%hmat, cell_dist)
2074
2075 IF (cell_dist < cell_radius_3c) THEN
2076 nimages_3c_max = nimages_3c_max + 1
2077 i_cell_x_min = min(i_cell_x_min, i_cell_x)
2078 i_cell_x_max = max(i_cell_x_max, i_cell_x)
2079 j_cell_y_min = min(j_cell_y_min, j_cell_y)
2080 j_cell_y_max = max(j_cell_y_max, j_cell_y)
2081 k_cell_z_min = min(k_cell_z_min, k_cell_z)
2082 k_cell_z_max = max(k_cell_z_max, k_cell_z)
2083 END IF
2084
2085 END DO
2086 END DO
2087 END DO
2088
2089 ! get index_to_cell_3c_max for the maximum possible cell range;
2090 ! compute 3c integrals later in this routine and check really which cell is needed
2091 ALLOCATE (index_to_cell_3c_max(3, nimages_3c_max))
2092
2093 img = 0
2094 DO i_cell_x = -n_max(1), n_max(1)
2095 DO j_cell_y = -n_max(2), n_max(2)
2096 DO k_cell_z = -n_max(3), n_max(3)
2097
2098 cell_index(1:3) = [i_cell_x, j_cell_y, k_cell_z]
2099
2100 CALL get_cell_dist(cell_index, bs_env%hmat, cell_dist)
2101
2102 IF (cell_dist < cell_radius_3c) THEN
2103 img = img + 1
2104 index_to_cell_3c_max(1:3, img) = cell_index(1:3)
2105 END IF
2106
2107 END DO
2108 END DO
2109 END DO
2110
2111 ! get pairs of R and S which have non-zero 3c integral (μR υS | P0)
2112 ALLOCATE (nblocks_3c_max(nimages_3c_max, nimages_3c_max))
2113 nblocks_3c_max(:, :) = 0
2114
2115 block_count = 0
2116 DO j_cell = 1, nimages_3c_max
2117 DO k_cell = 1, nimages_3c_max
2118
2119 DO atom_j = 1, bs_env%n_atom
2120 DO atom_k = 1, bs_env%n_atom
2121 DO atom_i = 1, bs_env%n_atom
2122
2123 block_count = block_count + 1
2124 IF (modulo(block_count, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
2125
2126 CALL scaled_to_real(vec_cell_j, real(index_to_cell_3c_max(1:3, j_cell), kind=dp), cell)
2127 CALL scaled_to_real(vec_cell_k, real(index_to_cell_3c_max(1:3, k_cell), kind=dp), cell)
2128
2129 rij = pbc(particle_set(atom_j)%r(:), cell) - pbc(particle_set(atom_i)%r(:), cell) + vec_cell_j(:)
2130 rjk = pbc(particle_set(atom_k)%r(:), cell) - pbc(particle_set(atom_j)%r(:), cell) &
2131 + vec_cell_k(:) - vec_cell_j(:)
2132 rik(:) = rij(:) + rjk(:)
2133 dij = norm2(rij)
2134 dik = norm2(rik)
2135 djk = norm2(rjk)
2136 IF (djk > radius_ao_kind(kind_of(atom_j)) + radius_ao_kind(kind_of(atom_k))) cycle
2137 IF (dij > radius_ao_kind(kind_of(atom_j)) + radius_ri_kind(kind_of(atom_i)) &
2138 + bs_env%ri_metric%cutoff_radius) cycle
2139 IF (dik > radius_ri_kind(kind_of(atom_i)) + radius_ao_kind(kind_of(atom_k)) &
2140 + bs_env%ri_metric%cutoff_radius) cycle
2141
2142 j_size = bs_env%i_ao_end_from_atom(atom_j) - bs_env%i_ao_start_from_atom(atom_j) + 1
2143 k_size = bs_env%i_ao_end_from_atom(atom_k) - bs_env%i_ao_start_from_atom(atom_k) + 1
2144 i_size = bs_env%i_RI_end_from_atom(atom_i) - bs_env%i_RI_start_from_atom(atom_i) + 1
2145
2146 ALLOCATE (int_3c(j_size, k_size, i_size))
2147
2148 ! compute 3-c int. ( μ(atom j) R , ν (atom k) S | P (atom i) 0 )
2149 ! ("|": truncated Coulomb operator), inside build_3c_integrals: (j k | i)
2150 CALL build_3c_integral_block(int_3c, qs_env, bs_env%ri_metric, &
2151 basis_j=bs_env%basis_set_AO, &
2152 basis_k=bs_env%basis_set_AO, &
2153 basis_i=bs_env%basis_set_RI, &
2154 cell_j=index_to_cell_3c_max(1:3, j_cell), &
2155 cell_k=index_to_cell_3c_max(1:3, k_cell), &
2156 atom_k=atom_k, atom_j=atom_j, atom_i=atom_i)
2157
2158 frobenius_norm = sqrt(sum(int_3c(:, :, :)**2))
2159
2160 DEALLOCATE (int_3c)
2161
2162 ! we use a higher threshold here to safe memory when storing the 3c integrals
2163 ! in every tensor group
2164 IF (frobenius_norm > eps) THEN
2165 nblocks_3c_max(j_cell, k_cell) = nblocks_3c_max(j_cell, k_cell) + 1
2166 END IF
2167
2168 END DO
2169 END DO
2170 END DO
2171
2172 END DO
2173 END DO
2174
2175 CALL bs_env%para_env%sum(nblocks_3c_max)
2176
2177 ALLOCATE (n_other_3c_images_max(nimages_3c_max))
2178 n_other_3c_images_max(:) = 0
2179
2180 nimages_3c = 0
2181 nimage_pairs_3c = 0
2182
2183 DO j_cell = 1, nimages_3c_max
2184 DO k_cell = 1, nimages_3c_max
2185 IF (nblocks_3c_max(j_cell, k_cell) > 0) THEN
2186 n_other_3c_images_max(j_cell) = n_other_3c_images_max(j_cell) + 1
2187 nimage_pairs_3c = nimage_pairs_3c + 1
2188 END IF
2189 END DO
2190
2191 IF (n_other_3c_images_max(j_cell) > 0) nimages_3c = nimages_3c + 1
2192
2193 END DO
2194
2195 bs_env%nimages_3c = nimages_3c
2196 ALLOCATE (bs_env%index_to_cell_3c(3, nimages_3c))
2197 ALLOCATE (bs_env%cell_to_index_3c(i_cell_x_min:i_cell_x_max, &
2198 j_cell_y_min:j_cell_y_max, &
2199 k_cell_z_min:k_cell_z_max))
2200 bs_env%cell_to_index_3c(:, :, :) = -1
2201
2202 ALLOCATE (bs_env%nblocks_3c(nimages_3c, nimages_3c))
2203 bs_env%nblocks_3c(nimages_3c, nimages_3c) = 0
2204
2205 j_cell = 0
2206 DO j_cell_max = 1, nimages_3c_max
2207 IF (n_other_3c_images_max(j_cell_max) == 0) cycle
2208 j_cell = j_cell + 1
2209 cell_index(1:3) = index_to_cell_3c_max(1:3, j_cell_max)
2210 bs_env%index_to_cell_3c(1:3, j_cell) = cell_index(1:3)
2211 bs_env%cell_to_index_3c(cell_index(1), cell_index(2), cell_index(3)) = j_cell
2212
2213 k_cell = 0
2214 DO k_cell_max = 1, nimages_3c_max
2215 IF (n_other_3c_images_max(k_cell_max) == 0) cycle
2216 k_cell = k_cell + 1
2217
2218 bs_env%nblocks_3c(j_cell, k_cell) = nblocks_3c_max(j_cell_max, k_cell_max)
2219 END DO
2220
2221 END DO
2222
2223 ! we use: 8*10^-9 GB / double precision number
2224 mem_3c_gb = real(bs_env%n_RI, kind=dp)*real(bs_env%n_ao, kind=dp)**2 &
2225 *real(nimage_pairs_3c, kind=dp)*8e-9_dp
2226
2227 CALL m_memory(mem_occ_per_proc)
2228 CALL bs_env%para_env%max(mem_occ_per_proc)
2229
2230 mem_occ_per_proc_gb = real(mem_occ_per_proc, kind=dp)/1.0e9_dp
2231
2232 ! number of processors per group that entirely stores the 3c integrals and does tensor ops
2233 avail_mem_per_proc_gb = bs_env%input_memory_per_proc_GB - mem_occ_per_proc_gb
2234
2235 ! careful: downconvering real to integer, 1.9 -> 1; thus add 1.0 for upconversion, 1.9 -> 2
2236 bs_env%group_size_tensor = max(int(mem_3c_gb/avail_mem_per_proc_gb + 1.0_dp), 1)
2237
2238 u = bs_env%unit_nr
2239
2240 IF (u > 0) THEN
2241 WRITE (u, fmt="(T2,A,F52.1,A)") "Radius of atomic orbitals", radius_ao*angstrom, Å" "
2242 WRITE (u, fmt="(T2,A,F55.1,A)") "Radius of RI functions", radius_ri*angstrom, Å" "
2243 WRITE (u, fmt="(T2,A,I47)") "Number of cells for 3c integrals", nimages_3c
2244 WRITE (u, fmt="(T2,A,I42)") "Number of cell pairs for 3c integrals", nimage_pairs_3c
2245 WRITE (u, '(T2,A)') ''
2246 WRITE (u, '(T2,A,F37.1,A)') 'Input: Available memory per MPI process', &
2247 bs_env%input_memory_per_proc_GB, ' GB'
2248 WRITE (u, '(T2,A,F35.1,A)') 'Used memory per MPI process before GW run', &
2249 mem_occ_per_proc_gb, ' GB'
2250 WRITE (u, '(T2,A,F44.1,A)') 'Memory of three-center integrals', mem_3c_gb, ' GB'
2251 END IF
2252
2253 CALL timestop(handle)
2254
2255 END SUBROUTINE setup_cells_3c
2256
2257! **************************************************************************************************
2258!> \brief ...
2259!> \param index_to_cell_1 ...
2260!> \param index_to_cell_2 ...
2261!> \param nimages_1 ...
2262!> \param nimages_2 ...
2263!> \param index_to_cell ...
2264!> \param cell_to_index ...
2265!> \param nimages ...
2266! **************************************************************************************************
2267 SUBROUTINE sum_two_r_grids(index_to_cell_1, index_to_cell_2, nimages_1, nimages_2, &
2268 index_to_cell, cell_to_index, nimages)
2269
2270 INTEGER, DIMENSION(:, :) :: index_to_cell_1, index_to_cell_2
2271 INTEGER :: nimages_1, nimages_2
2272 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: index_to_cell
2273 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
2274 INTEGER :: nimages
2275
2276 CHARACTER(LEN=*), PARAMETER :: routinen = 'sum_two_R_grids'
2277
2278 INTEGER :: handle, i_dim, img_1, img_2, nimages_max
2279 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: index_to_cell_tmp
2280 INTEGER, DIMENSION(3) :: cell_1, cell_2, r, r_max, r_min
2281
2282 CALL timeset(routinen, handle)
2283
2284 DO i_dim = 1, 3
2285 r_min(i_dim) = minval(index_to_cell_1(i_dim, :)) + minval(index_to_cell_2(i_dim, :))
2286 r_max(i_dim) = maxval(index_to_cell_1(i_dim, :)) + maxval(index_to_cell_2(i_dim, :))
2287 END DO
2288
2289 nimages_max = (r_max(1) - r_min(1) + 1)*(r_max(2) - r_min(2) + 1)*(r_max(3) - r_min(3) + 1)
2290
2291 ALLOCATE (index_to_cell_tmp(3, nimages_max))
2292 index_to_cell_tmp(:, :) = -1
2293
2294 ALLOCATE (cell_to_index(r_min(1):r_max(1), r_min(2):r_max(2), r_min(3):r_max(3)))
2295 cell_to_index(:, :, :) = -1
2296
2297 nimages = 0
2298
2299 DO img_1 = 1, nimages_1
2300
2301 DO img_2 = 1, nimages_2
2302
2303 cell_1(1:3) = index_to_cell_1(1:3, img_1)
2304 cell_2(1:3) = index_to_cell_2(1:3, img_2)
2305
2306 r(1:3) = cell_1(1:3) + cell_2(1:3)
2307
2308 ! check whether we have found a new cell
2309 IF (cell_to_index(r(1), r(2), r(3)) == -1) THEN
2310
2311 nimages = nimages + 1
2312 cell_to_index(r(1), r(2), r(3)) = nimages
2313 index_to_cell_tmp(1:3, nimages) = r(1:3)
2314
2315 END IF
2316
2317 END DO
2318
2319 END DO
2320
2321 ALLOCATE (index_to_cell(3, nimages))
2322 index_to_cell(:, :) = index_to_cell_tmp(1:3, 1:nimages)
2323
2324 CALL timestop(handle)
2325
2326 END SUBROUTINE sum_two_r_grids
2327
2328! **************************************************************************************************
2329!> \brief ...
2330!> \param qs_env ...
2331!> \param bs_env ...
2332! **************************************************************************************************
2333 SUBROUTINE compute_3c_integrals(qs_env, bs_env)
2334
2335 TYPE(qs_environment_type), POINTER :: qs_env
2336 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2337
2338 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_3c_integrals'
2339
2340 INTEGER :: handle, j_cell, k_cell, nimages_3c
2341
2342 CALL timeset(routinen, handle)
2343
2344 nimages_3c = bs_env%nimages_3c
2345 ALLOCATE (bs_env%t_3c_int(nimages_3c, nimages_3c))
2346 DO j_cell = 1, nimages_3c
2347 DO k_cell = 1, nimages_3c
2348 CALL dbt_create(bs_env%t_RI_AO__AO, bs_env%t_3c_int(j_cell, k_cell))
2349 END DO
2350 END DO
2351
2352 CALL build_3c_integrals(bs_env%t_3c_int, &
2353 bs_env%eps_filter, &
2354 qs_env, &
2355 bs_env%nl_3c, &
2356 int_eps=bs_env%eps_filter*0.05_dp, &
2357 basis_i=bs_env%basis_set_RI, &
2358 basis_j=bs_env%basis_set_AO, &
2359 basis_k=bs_env%basis_set_AO, &
2360 potential_parameter=bs_env%ri_metric, &
2361 desymmetrize=.false., do_kpoints=.true., cell_sym=.true., &
2362 cell_to_index_ext=bs_env%cell_to_index_3c)
2363
2364 CALL bs_env%para_env%sync()
2365
2366 CALL timestop(handle)
2367
2368 END SUBROUTINE compute_3c_integrals
2369
2370! **************************************************************************************************
2371!> \brief ...
2372!> \param cell_index ...
2373!> \param hmat ...
2374!> \param cell_dist ...
2375! **************************************************************************************************
2376 SUBROUTINE get_cell_dist(cell_index, hmat, cell_dist)
2377
2378 INTEGER, DIMENSION(3) :: cell_index
2379 REAL(kind=dp) :: hmat(3, 3), cell_dist
2380
2381 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_cell_dist'
2382
2383 INTEGER :: handle, i_dim
2384 INTEGER, DIMENSION(3) :: cell_index_adj
2385 REAL(kind=dp) :: cell_dist_3(3)
2386
2387 CALL timeset(routinen, handle)
2388
2389 ! the distance of cells needs to be taken to adjacent neighbors, not
2390 ! between the center of the cells. We thus need to rescale the cell index
2391 DO i_dim = 1, 3
2392 IF (cell_index(i_dim) > 0) cell_index_adj(i_dim) = cell_index(i_dim) - 1
2393 IF (cell_index(i_dim) < 0) cell_index_adj(i_dim) = cell_index(i_dim) + 1
2394 IF (cell_index(i_dim) == 0) cell_index_adj(i_dim) = cell_index(i_dim)
2395 END DO
2396
2397 cell_dist_3(1:3) = matmul(hmat, real(cell_index_adj, kind=dp))
2398
2399 cell_dist = sqrt(abs(sum(cell_dist_3(1:3)**2)))
2400
2401 CALL timestop(handle)
2402
2403 END SUBROUTINE get_cell_dist
2404
2405! **************************************************************************************************
2406!> \brief ...
2407!> \param qs_env ...
2408!> \param bs_env ...
2409!> \param kpoints ...
2410!> \param do_print ...
2411! **************************************************************************************************
2412 SUBROUTINE setup_kpoints_scf_desymm(qs_env, bs_env, kpoints, do_print)
2413 TYPE(qs_environment_type), POINTER :: qs_env
2414 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2415 TYPE(kpoint_type), POINTER :: kpoints
2416
2417 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_kpoints_scf_desymm'
2418
2419 INTEGER :: handle, i_cell_x, i_dim, img, j_cell_y, &
2420 k_cell_z, nimages, nkp, u
2421 INTEGER, DIMENSION(3) :: cell_grid, cixd, nkp_grid
2422 TYPE(kpoint_type), POINTER :: kpoints_scf
2423
2424 LOGICAL:: do_print
2425
2426 CALL timeset(routinen, handle)
2427
2428 NULLIFY (kpoints)
2429 CALL kpoint_create(kpoints)
2430
2431 CALL get_qs_env(qs_env=qs_env, kpoints=kpoints_scf)
2432
2433 nkp_grid(1:3) = kpoints_scf%nkp_grid(1:3)
2434 nkp = nkp_grid(1)*nkp_grid(2)*nkp_grid(3)
2435
2436 ! we need in periodic directions at least 2 k-points in the SCF
2437 DO i_dim = 1, 3
2438 IF (bs_env%periodic(i_dim) == 1) THEN
2439 cpassert(nkp_grid(i_dim) > 1)
2440 END IF
2441 END DO
2442
2443 kpoints%kp_scheme = "GENERAL"
2444 kpoints%nkp_grid(1:3) = nkp_grid(1:3)
2445 kpoints%nkp = nkp
2446 bs_env%nkp_scf_desymm = nkp
2447
2448 ALLOCATE (kpoints%xkp(1:3, nkp))
2449 CALL compute_xkp(kpoints%xkp, 1, nkp, nkp_grid)
2450
2451 ALLOCATE (kpoints%wkp(nkp))
2452 kpoints%wkp(:) = 1.0_dp/real(nkp, kind=dp)
2453
2454 ! for example 4x3x6 kpoint grid -> 3x3x5 cell grid because we need the same number of
2455 ! neighbor cells on both sides of the unit cell
2456 cell_grid(1:3) = nkp_grid(1:3) - modulo(nkp_grid(1:3) + 1, 2)
2457 ! cell index: for example for x: from -n_x/2 to +n_x/2, n_x: number of cells in x direction
2458 cixd(1:3) = cell_grid(1:3)/2
2459
2460 nimages = cell_grid(1)*cell_grid(2)*cell_grid(3)
2461
2462 bs_env%nimages_scf_desymm = nimages
2463
2464 ALLOCATE (kpoints%cell_to_index(-cixd(1):cixd(1), -cixd(2):cixd(2), -cixd(3):cixd(3)))
2465 ALLOCATE (kpoints%index_to_cell(3, nimages))
2466
2467 img = 0
2468 DO i_cell_x = -cixd(1), cixd(1)
2469 DO j_cell_y = -cixd(2), cixd(2)
2470 DO k_cell_z = -cixd(3), cixd(3)
2471 img = img + 1
2472 kpoints%cell_to_index(i_cell_x, j_cell_y, k_cell_z) = img
2473 kpoints%index_to_cell(1:3, img) = [i_cell_x, j_cell_y, k_cell_z]
2474 END DO
2475 END DO
2476 END DO
2477
2478 u = bs_env%unit_nr
2479 IF (u > 0 .AND. do_print) THEN
2480 WRITE (u, fmt="(T2,A,I49)") χΣ"Number of cells for G, , W, ", nimages
2481 END IF
2482
2483 CALL timestop(handle)
2484
2485 END SUBROUTINE setup_kpoints_scf_desymm
2486
2487! **************************************************************************************************
2488!> \brief ...
2489!> \param bs_env ...
2490! **************************************************************************************************
2491 SUBROUTINE setup_cells_delta_r(bs_env)
2492
2493 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2494
2495 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_cells_Delta_R'
2496
2497 INTEGER :: handle
2498
2499 CALL timeset(routinen, handle)
2500
2501 ! cell sums batch wise for fixed ΔR = S_1 - R_1; for example:
2502 ! Σ_λσ^R = sum_PR1νS1 M^G_λ0,νS1,PR1 M^W_σR,νS1,PR1
2503
2504 CALL sum_two_r_grids(bs_env%index_to_cell_3c, &
2505 bs_env%index_to_cell_3c, &
2506 bs_env%nimages_3c, bs_env%nimages_3c, &
2507 bs_env%index_to_cell_Delta_R, &
2508 bs_env%cell_to_index_Delta_R, &
2509 bs_env%nimages_Delta_R)
2510
2511 IF (bs_env%unit_nr > 0) THEN
2512 WRITE (bs_env%unit_nr, fmt="(T2,A,I61)") Δ"Number of cells R", bs_env%nimages_Delta_R
2513 END IF
2514
2515 CALL timestop(handle)
2516
2517 END SUBROUTINE setup_cells_delta_r
2518
2519! **************************************************************************************************
2520!> \brief ...
2521!> \param bs_env ...
2522! **************************************************************************************************
2523 SUBROUTINE setup_parallelization_delta_r(bs_env)
2524
2525 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2526
2527 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_parallelization_Delta_R'
2528
2529 INTEGER :: handle, i_cell_delta_r, i_task_local, &
2530 n_tasks_local
2531 INTEGER, ALLOCATABLE, DIMENSION(:) :: i_cell_delta_r_group, &
2532 n_tensor_ops_delta_r
2533
2534 CALL timeset(routinen, handle)
2535
2536 CALL compute_n_tensor_ops_delta_r(bs_env, n_tensor_ops_delta_r)
2537
2538 CALL compute_delta_r_dist(bs_env, n_tensor_ops_delta_r, i_cell_delta_r_group, n_tasks_local)
2539
2540 bs_env%n_tasks_Delta_R_local = n_tasks_local
2541
2542 ALLOCATE (bs_env%task_Delta_R(n_tasks_local))
2543
2544 i_task_local = 0
2545 DO i_cell_delta_r = 1, bs_env%nimages_Delta_R
2546
2547 IF (i_cell_delta_r_group(i_cell_delta_r) /= bs_env%tensor_group_color) cycle
2548
2549 i_task_local = i_task_local + 1
2550
2551 bs_env%task_Delta_R(i_task_local) = i_cell_delta_r
2552
2553 END DO
2554
2555 ALLOCATE (bs_env%skip_DR_chi(n_tasks_local))
2556 bs_env%skip_DR_chi(:) = .false.
2557 ALLOCATE (bs_env%skip_DR_Sigma(n_tasks_local))
2558 bs_env%skip_DR_Sigma(:) = .false.
2559
2560 CALL allocate_skip_3xr(bs_env%skip_DR_R12_S_Goccx3c_chi, bs_env)
2561 CALL allocate_skip_3xr(bs_env%skip_DR_R12_S_Gvirx3c_chi, bs_env)
2562 CALL allocate_skip_3xr(bs_env%skip_DR_R_R2_MxM_chi, bs_env)
2563
2564 CALL allocate_skip_3xr(bs_env%skip_DR_R1_S2_Gx3c_Sigma, bs_env)
2565 CALL allocate_skip_3xr(bs_env%skip_DR_R1_R_MxM_Sigma, bs_env)
2566
2567 CALL timestop(handle)
2568
2569 END SUBROUTINE setup_parallelization_delta_r
2570
2571! **************************************************************************************************
2572!> \brief ...
2573!> \param skip ...
2574!> \param bs_env ...
2575! **************************************************************************************************
2576 SUBROUTINE allocate_skip_3xr(skip, bs_env)
2577 LOGICAL, ALLOCATABLE, DIMENSION(:, :, :) :: skip
2578 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2579
2580 CHARACTER(LEN=*), PARAMETER :: routinen = 'allocate_skip_3xR'
2581
2582 INTEGER :: handle
2583
2584 CALL timeset(routinen, handle)
2585
2586 ALLOCATE (skip(bs_env%n_tasks_Delta_R_local, bs_env%nimages_3c, bs_env%nimages_scf_desymm))
2587 skip(:, :, :) = .false.
2588
2589 CALL timestop(handle)
2590
2591 END SUBROUTINE allocate_skip_3xr
2592
2593! **************************************************************************************************
2594!> \brief ...
2595!> \param bs_env ...
2596!> \param n_tensor_ops_Delta_R ...
2597!> \param i_cell_Delta_R_group ...
2598!> \param n_tasks_local ...
2599! **************************************************************************************************
2600 SUBROUTINE compute_delta_r_dist(bs_env, n_tensor_ops_Delta_R, i_cell_Delta_R_group, n_tasks_local)
2601 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2602 INTEGER, ALLOCATABLE, DIMENSION(:) :: n_tensor_ops_delta_r, &
2603 i_cell_delta_r_group
2604 INTEGER :: n_tasks_local
2605
2606 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_Delta_R_dist'
2607
2608 INTEGER :: handle, i_delta_r_max_op, i_group_min, &
2609 nimages_delta_r, u
2610 INTEGER, ALLOCATABLE, DIMENSION(:) :: n_tensor_ops_delta_r_in_group
2611
2612 CALL timeset(routinen, handle)
2613
2614 nimages_delta_r = bs_env%nimages_Delta_R
2615
2616 u = bs_env%unit_nr
2617
2618 IF (u > 0 .AND. nimages_delta_r < bs_env%num_tensor_groups) THEN
2619 WRITE (u, fmt="(T2,A,I5,A,I5,A)") "There are only ", nimages_delta_r, &
2620 " tasks to work on but there are ", bs_env%num_tensor_groups, " groups."
2621 WRITE (u, fmt="(T2,A)") "Please reduce the number of MPI processes."
2622 WRITE (u, '(T2,A)') ''
2623 END IF
2624
2625 ALLOCATE (n_tensor_ops_delta_r_in_group(bs_env%num_tensor_groups))
2626 n_tensor_ops_delta_r_in_group(:) = 0
2627 ALLOCATE (i_cell_delta_r_group(nimages_delta_r))
2628 i_cell_delta_r_group(:) = -1
2629
2630 n_tasks_local = 0
2631
2632 DO WHILE (any(n_tensor_ops_delta_r(:) /= 0))
2633
2634 ! get largest element of n_tensor_ops_Delta_R
2635 i_delta_r_max_op = maxloc(n_tensor_ops_delta_r, 1)
2636
2637 ! distribute i_Delta_R_max_op to tensor group which has currently the smallest load
2638 i_group_min = minloc(n_tensor_ops_delta_r_in_group, 1)
2639
2640 ! the tensor groups are 0-index based; but i_group_min is 1-index based
2641 i_cell_delta_r_group(i_delta_r_max_op) = i_group_min - 1
2642 n_tensor_ops_delta_r_in_group(i_group_min) = n_tensor_ops_delta_r_in_group(i_group_min) + &
2643 n_tensor_ops_delta_r(i_delta_r_max_op)
2644
2645 ! remove i_Delta_R_max_op from n_tensor_ops_Delta_R
2646 n_tensor_ops_delta_r(i_delta_r_max_op) = 0
2647
2648 IF (bs_env%tensor_group_color == i_group_min - 1) n_tasks_local = n_tasks_local + 1
2649
2650 END DO
2651
2652 CALL timestop(handle)
2653
2654 END SUBROUTINE compute_delta_r_dist
2655
2656! **************************************************************************************************
2657!> \brief ...
2658!> \param bs_env ...
2659!> \param n_tensor_ops_Delta_R ...
2660! **************************************************************************************************
2661 SUBROUTINE compute_n_tensor_ops_delta_r(bs_env, n_tensor_ops_Delta_R)
2662 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2663 INTEGER, ALLOCATABLE, DIMENSION(:) :: n_tensor_ops_delta_r
2664
2665 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_n_tensor_ops_Delta_R'
2666
2667 INTEGER :: handle, i_cell_delta_r, i_cell_r, i_cell_r1, i_cell_r1_minus_r, i_cell_r2, &
2668 i_cell_r2_m_r1, i_cell_s1, i_cell_s1_m_r1_p_r2, i_cell_s1_minus_r, i_cell_s2, &
2669 nimages_delta_r
2670 INTEGER, DIMENSION(3) :: cell_dr, cell_m_r1, cell_r, cell_r1, cell_r1_minus_r, cell_r2, &
2671 cell_r2_m_r1, cell_s1, cell_s1_m_r2_p_r1, cell_s1_minus_r, cell_s1_p_s2_m_r1, cell_s2
2672 LOGICAL :: cell_found
2673
2674 CALL timeset(routinen, handle)
2675
2676 nimages_delta_r = bs_env%nimages_Delta_R
2677
2678 ALLOCATE (n_tensor_ops_delta_r(nimages_delta_r))
2679 n_tensor_ops_delta_r(:) = 0
2680
2681 ! compute number of tensor operations for specific Delta_R
2682 DO i_cell_delta_r = 1, nimages_delta_r
2683
2684 IF (modulo(i_cell_delta_r, bs_env%num_tensor_groups) /= bs_env%tensor_group_color) cycle
2685
2686 DO i_cell_r1 = 1, bs_env%nimages_3c
2687
2688 cell_r1(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_r1)
2689 cell_dr(1:3) = bs_env%index_to_cell_Delta_R(1:3, i_cell_delta_r)
2690
2691 ! S_1 = R_1 + ΔR (from ΔR = S_1 - R_1)
2692 CALL add_r(cell_r1, cell_dr, bs_env%index_to_cell_3c, cell_s1, &
2693 cell_found, bs_env%cell_to_index_3c, i_cell_s1)
2694 IF (.NOT. cell_found) cycle
2695
2696 DO i_cell_r2 = 1, bs_env%nimages_scf_desymm
2697
2698 cell_r2(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_r2)
2699
2700 ! R_2 - R_1
2701 CALL add_r(cell_r2, -cell_r1, bs_env%index_to_cell_3c, cell_r2_m_r1, &
2702 cell_found, bs_env%cell_to_index_3c, i_cell_r2_m_r1)
2703 IF (.NOT. cell_found) cycle
2704
2705 ! S_1 - R_1 + R_2
2706 CALL add_r(cell_s1, cell_r2_m_r1, bs_env%index_to_cell_3c, cell_s1_m_r2_p_r1, &
2707 cell_found, bs_env%cell_to_index_3c, i_cell_s1_m_r1_p_r2)
2708 IF (.NOT. cell_found) cycle
2709
2710 n_tensor_ops_delta_r(i_cell_delta_r) = n_tensor_ops_delta_r(i_cell_delta_r) + 1
2711
2712 END DO ! i_cell_R2
2713
2714 DO i_cell_s2 = 1, bs_env%nimages_scf_desymm
2715
2716 cell_s2(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_s2)
2717 cell_m_r1(1:3) = -cell_r1(1:3)
2718 cell_s1_p_s2_m_r1(1:3) = cell_s1(1:3) + cell_s2(1:3) - cell_r1(1:3)
2719
2720 CALL is_cell_in_index_to_cell(cell_m_r1, bs_env%index_to_cell_3c, cell_found)
2721 IF (.NOT. cell_found) cycle
2722
2723 CALL is_cell_in_index_to_cell(cell_s1_p_s2_m_r1, bs_env%index_to_cell_3c, cell_found)
2724 IF (.NOT. cell_found) cycle
2725
2726 END DO ! i_cell_S2
2727
2728 DO i_cell_r = 1, bs_env%nimages_scf_desymm
2729
2730 cell_r = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_r)
2731
2732 ! R_1 - R
2733 CALL add_r(cell_r1, -cell_r, bs_env%index_to_cell_3c, cell_r1_minus_r, &
2734 cell_found, bs_env%cell_to_index_3c, i_cell_r1_minus_r)
2735 IF (.NOT. cell_found) cycle
2736
2737 ! S_1 - R
2738 CALL add_r(cell_s1, -cell_r, bs_env%index_to_cell_3c, cell_s1_minus_r, &
2739 cell_found, bs_env%cell_to_index_3c, i_cell_s1_minus_r)
2740 IF (.NOT. cell_found) cycle
2741
2742 END DO ! i_cell_R
2743
2744 END DO ! i_cell_R1
2745
2746 END DO ! i_cell_Delta_R
2747
2748 CALL bs_env%para_env%sum(n_tensor_ops_delta_r)
2749
2750 CALL timestop(handle)
2751
2752 END SUBROUTINE compute_n_tensor_ops_delta_r
2753
2754! **************************************************************************************************
2755!> \brief ...
2756!> \param cell_1 ...
2757!> \param cell_2 ...
2758!> \param index_to_cell ...
2759!> \param cell_1_plus_2 ...
2760!> \param cell_found ...
2761!> \param cell_to_index ...
2762!> \param i_cell_1_plus_2 ...
2763! **************************************************************************************************
2764 SUBROUTINE add_r(cell_1, cell_2, index_to_cell, cell_1_plus_2, cell_found, &
2765 cell_to_index, i_cell_1_plus_2)
2766
2767 INTEGER, DIMENSION(3) :: cell_1, cell_2
2768 INTEGER, DIMENSION(:, :) :: index_to_cell
2769 INTEGER, DIMENSION(3) :: cell_1_plus_2
2770 LOGICAL :: cell_found
2771 INTEGER, DIMENSION(:, :, :), INTENT(IN), &
2772 OPTIONAL, POINTER :: cell_to_index
2773 INTEGER, INTENT(OUT), OPTIONAL :: i_cell_1_plus_2
2774
2775 CHARACTER(LEN=*), PARAMETER :: routinen = 'add_R'
2776
2777 INTEGER :: handle
2778
2779 CALL timeset(routinen, handle)
2780
2781 cell_1_plus_2(1:3) = cell_1(1:3) + cell_2(1:3)
2782
2783 CALL is_cell_in_index_to_cell(cell_1_plus_2, index_to_cell, cell_found)
2784
2785 IF (PRESENT(i_cell_1_plus_2)) THEN
2786 IF (cell_found) THEN
2787 cpassert(PRESENT(cell_to_index))
2788 i_cell_1_plus_2 = cell_to_index(cell_1_plus_2(1), cell_1_plus_2(2), cell_1_plus_2(3))
2789 ELSE
2790 i_cell_1_plus_2 = -1000
2791 END IF
2792 END IF
2793
2794 CALL timestop(handle)
2795
2796 END SUBROUTINE add_r
2797
2798! **************************************************************************************************
2799!> \brief ...
2800!> \param cell ...
2801!> \param index_to_cell ...
2802!> \param cell_found ...
2803! **************************************************************************************************
2804 SUBROUTINE is_cell_in_index_to_cell(cell, index_to_cell, cell_found)
2805 INTEGER, DIMENSION(3) :: cell
2806 INTEGER, DIMENSION(:, :) :: index_to_cell
2807 LOGICAL :: cell_found
2808
2809 CHARACTER(LEN=*), PARAMETER :: routinen = 'is_cell_in_index_to_cell'
2810
2811 INTEGER :: handle, i_cell, nimg
2812 INTEGER, DIMENSION(3) :: cell_i
2813
2814 CALL timeset(routinen, handle)
2815
2816 nimg = SIZE(index_to_cell, 2)
2817
2818 cell_found = .false.
2819
2820 DO i_cell = 1, nimg
2821
2822 cell_i(1:3) = index_to_cell(1:3, i_cell)
2823
2824 IF (cell_i(1) == cell(1) .AND. cell_i(2) == cell(2) .AND. cell_i(3) == cell(3)) THEN
2825 cell_found = .true.
2826 END IF
2827
2828 END DO
2829
2830 CALL timestop(handle)
2831
2832 END SUBROUTINE is_cell_in_index_to_cell
2833
2834! **************************************************************************************************
2835!> \brief ...
2836!> \param qs_env ...
2837!> \param bs_env ...
2838! **************************************************************************************************
2839 SUBROUTINE allocate_matrices_small_cell_full_kp(qs_env, bs_env)
2840 TYPE(qs_environment_type), POINTER :: qs_env
2841 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2842
2843 CHARACTER(LEN=*), PARAMETER :: routinen = 'allocate_matrices_small_cell_full_kp'
2844
2845 INTEGER :: handle, i_spin, i_t, img, n_spin, &
2846 nimages_scf, num_time_freq_points
2847 TYPE(cp_blacs_env_type), POINTER :: blacs_env
2848 TYPE(mp_para_env_type), POINTER :: para_env
2849
2850 CALL timeset(routinen, handle)
2851
2852 nimages_scf = bs_env%nimages_scf_desymm
2853 num_time_freq_points = bs_env%num_time_freq_points
2854 n_spin = bs_env%n_spin
2855
2856 CALL get_qs_env(qs_env, para_env=para_env, blacs_env=blacs_env)
2857
2858 ALLOCATE (bs_env%fm_G_S(nimages_scf))
2859 ALLOCATE (bs_env%fm_Sigma_x_R(nimages_scf))
2860 ALLOCATE (bs_env%fm_chi_R_t(nimages_scf, num_time_freq_points))
2861 ALLOCATE (bs_env%fm_MWM_R_t(nimages_scf, num_time_freq_points))
2862 ALLOCATE (bs_env%fm_Sigma_c_R_neg_tau(nimages_scf, num_time_freq_points, n_spin))
2863 ALLOCATE (bs_env%fm_Sigma_c_R_pos_tau(nimages_scf, num_time_freq_points, n_spin))
2864 DO img = 1, nimages_scf
2865 CALL cp_fm_create(bs_env%fm_G_S(img), bs_env%fm_work_mo(1)%matrix_struct)
2866 CALL cp_fm_create(bs_env%fm_Sigma_x_R(img), bs_env%fm_work_mo(1)%matrix_struct)
2867 DO i_t = 1, num_time_freq_points
2868 CALL cp_fm_create(bs_env%fm_chi_R_t(img, i_t), bs_env%fm_RI_RI%matrix_struct)
2869 CALL cp_fm_create(bs_env%fm_MWM_R_t(img, i_t), bs_env%fm_RI_RI%matrix_struct)
2870 CALL cp_fm_set_all(bs_env%fm_MWM_R_t(img, i_t), 0.0_dp)
2871 DO i_spin = 1, n_spin
2872 CALL cp_fm_create(bs_env%fm_Sigma_c_R_neg_tau(img, i_t, i_spin), &
2873 bs_env%fm_work_mo(1)%matrix_struct)
2874 CALL cp_fm_create(bs_env%fm_Sigma_c_R_pos_tau(img, i_t, i_spin), &
2875 bs_env%fm_work_mo(1)%matrix_struct)
2876 CALL cp_fm_set_all(bs_env%fm_Sigma_c_R_neg_tau(img, i_t, i_spin), 0.0_dp)
2877 CALL cp_fm_set_all(bs_env%fm_Sigma_c_R_pos_tau(img, i_t, i_spin), 0.0_dp)
2878 END DO
2879 END DO
2880 END DO
2881
2882 CALL timestop(handle)
2883
2884 END SUBROUTINE allocate_matrices_small_cell_full_kp
2885
2886! **************************************************************************************************
2887!> \brief ...
2888!> \param qs_env ...
2889!> \param bs_env ...
2890! **************************************************************************************************
2891 SUBROUTINE trafo_v_xc_r_to_kp(qs_env, bs_env)
2892 TYPE(qs_environment_type), POINTER :: qs_env
2893 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2894
2895 CHARACTER(LEN=*), PARAMETER :: routinen = 'trafo_V_xc_R_to_kp'
2896
2897 INTEGER :: handle, ikp, img, ispin, n_ao
2898 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index_scf
2899 TYPE(cp_cfm_type) :: cfm_mo_coeff, cfm_tmp, cfm_v_xc
2900 TYPE(cp_fm_type) :: fm_v_xc_re
2901 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks
2902 TYPE(kpoint_type), POINTER :: kpoints_scf
2903 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2904 POINTER :: sab_nl
2905
2906 CALL timeset(routinen, handle)
2907
2908 n_ao = bs_env%n_ao
2909
2910 CALL get_qs_env(qs_env, matrix_ks_kp=matrix_ks, kpoints=kpoints_scf)
2911
2912 NULLIFY (sab_nl)
2913 CALL get_kpoint_info(kpoints_scf, sab_nl=sab_nl, cell_to_index=cell_to_index_scf)
2914
2915 CALL cp_cfm_create(cfm_v_xc, bs_env%cfm_work_mo%matrix_struct)
2916 CALL cp_cfm_create(cfm_mo_coeff, bs_env%cfm_work_mo%matrix_struct)
2917 CALL cp_cfm_create(cfm_tmp, bs_env%cfm_work_mo%matrix_struct)
2918 CALL cp_fm_create(fm_v_xc_re, bs_env%cfm_work_mo%matrix_struct)
2919
2920 DO img = 1, bs_env%nimages_scf
2921 DO ispin = 1, bs_env%n_spin
2922 ! JW kind of hack because the format of matrix_ks remains dubious...
2923 CALL dbcsr_set(matrix_ks(ispin, img)%matrix, 0.0_dp)
2924 CALL copy_fm_to_dbcsr(bs_env%fm_V_xc_R(img, ispin), matrix_ks(ispin, img)%matrix)
2925 END DO
2926 END DO
2927
2928 ALLOCATE (bs_env%v_xc_n(n_ao, bs_env%nkp_bs_and_DOS, bs_env%n_spin))
2929
2930 DO ispin = 1, bs_env%n_spin
2931 DO ikp = 1, bs_env%nkp_bs_and_DOS
2932
2933 ! v^xc^R -> v^xc(k) (matrix_ks stores v^xc^R, see SUBROUTINE compute_V_xc)
2934 CALL rsmat_to_kp(matrix_ks, ispin, bs_env%kpoints_DOS%xkp(1:3, ikp), &
2935 cell_to_index_scf, sab_nl, bs_env, cfm_v_xc)
2936
2937 ! get C_µn(k)
2938 CALL cp_cfm_to_cfm(bs_env%cfm_mo_coeff_kp(ikp, ispin), cfm_mo_coeff)
2939
2940 ! v^xc_nm(k_i) = sum_µν C^*_µn(k_i) v^xc_µν(k_i) C_νn(k_i)
2941 CALL parallel_gemm('N', 'N', n_ao, n_ao, n_ao, z_one, cfm_v_xc, cfm_mo_coeff, &
2942 z_zero, cfm_tmp)
2943 CALL parallel_gemm('C', 'N', n_ao, n_ao, n_ao, z_one, cfm_mo_coeff, cfm_tmp, &
2944 z_zero, cfm_v_xc)
2945
2946 ! get v^xc_nn(k_i) which is a real quantity as v^xc is Hermitian
2947 CALL cp_cfm_to_fm(cfm_v_xc, fm_v_xc_re)
2948 CALL cp_fm_get_diag(fm_v_xc_re, bs_env%v_xc_n(:, ikp, ispin))
2949
2950 END DO
2951
2952 END DO
2953
2954 ! just rebuild the overwritten KS matrix again
2955 CALL qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces=.false., just_energy=.false.)
2956
2957 CALL cp_cfm_release(cfm_v_xc)
2958 CALL cp_cfm_release(cfm_mo_coeff)
2959 CALL cp_cfm_release(cfm_tmp)
2960 CALL cp_fm_release(fm_v_xc_re)
2961
2962 CALL timestop(handle)
2963
2964 END SUBROUTINE trafo_v_xc_r_to_kp
2965
2966! **************************************************************************************************
2967!> \brief ...
2968!> \param qs_env ...
2969!> \param bs_env ...
2970! **************************************************************************************************
2971 SUBROUTINE heuristic_ri_regularization(qs_env, bs_env)
2972 TYPE(qs_environment_type), POINTER :: qs_env
2973 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2974
2975 CHARACTER(LEN=*), PARAMETER :: routinen = 'heuristic_RI_regularization'
2976
2977 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: m
2978 INTEGER :: handle, ikp, ikp_local, n_ri, nkp, &
2979 nkp_local, u
2980 REAL(kind=dp) :: cond_nr, cond_nr_max, max_ev, &
2981 max_ev_ikp, min_ev, min_ev_ikp
2982 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: m_r
2983
2984 CALL timeset(routinen, handle)
2985
2986 ! compute M^R_PQ = <phi_P,0|V^tr(rc)|phi_Q,R> for RI metric
2987 CALL get_v_tr_r(m_r, bs_env%ri_metric, 0.0_dp, bs_env, qs_env)
2988
2989 nkp = bs_env%nkp_chi_eps_W_orig_plus_extra
2990 n_ri = bs_env%n_RI
2991
2992 nkp_local = 0
2993 DO ikp = 1, nkp
2994 ! trivial parallelization over k-points
2995 IF (modulo(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
2996 nkp_local = nkp_local + 1
2997 END DO
2998
2999 ALLOCATE (m(n_ri, n_ri, nkp_local))
3000
3001 ikp_local = 0
3002 cond_nr_max = 0.0_dp
3003 min_ev = 1000.0_dp
3004 max_ev = -1000.0_dp
3005
3006 DO ikp = 1, nkp
3007
3008 ! trivial parallelization
3009 IF (modulo(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
3010
3011 ikp_local = ikp_local + 1
3012
3013 ! M(k) = sum_R e^ikR M^R
3014 CALL rs_to_kp(m_r, m(:, :, ikp_local), &
3015 bs_env%kpoints_scf_desymm%index_to_cell, &
3016 bs_env%kpoints_chi_eps_W%xkp(1:3, ikp))
3017
3018 ! compute condition number of M_PQ(k)
3019 CALL power(m(:, :, ikp_local), 1.0_dp, 0.0_dp, cond_nr, min_ev_ikp, max_ev_ikp)
3020
3021 IF (cond_nr > cond_nr_max) cond_nr_max = cond_nr
3022 IF (max_ev_ikp > max_ev) max_ev = max_ev_ikp
3023 IF (min_ev_ikp < min_ev) min_ev = min_ev_ikp
3024
3025 END DO ! ikp
3026
3027 CALL bs_env%para_env%max(cond_nr_max)
3028 CALL bs_env%para_env%min(min_ev)
3029 CALL bs_env%para_env%max(max_ev)
3030
3031 u = bs_env%unit_nr
3032 IF (u > 0) THEN
3033 WRITE (u, fmt="(T2,A,ES34.1)") "Min. abs. eigenvalue of RI metric matrix M(k)", min_ev
3034 WRITE (u, fmt="(T2,A,ES34.1)") "Max. abs. eigenvalue of RI metric matrix M(k)", max_ev
3035 WRITE (u, fmt="(T2,A,ES50.1)") "Max. condition number of M(k)", cond_nr_max
3036 END IF
3037
3038 CALL timestop(handle)
3039
3040 END SUBROUTINE heuristic_ri_regularization
3041
3042! **************************************************************************************************
3043!> \brief ...
3044!> \param V_tr_R ...
3045!> \param pot_type ...
3046!> \param regularization_RI ...
3047!> \param bs_env ...
3048!> \param qs_env ...
3049! **************************************************************************************************
3050 SUBROUTINE get_v_tr_r(V_tr_R, pot_type, regularization_RI, bs_env, qs_env)
3051 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: v_tr_r
3052 TYPE(libint_potential_type) :: pot_type
3053 REAL(kind=dp) :: regularization_ri
3054 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
3055 TYPE(qs_environment_type), POINTER :: qs_env
3056
3057 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_V_tr_R'
3058
3059 INTEGER :: handle, img, nimages_scf_desymm
3060 INTEGER, ALLOCATABLE, DIMENSION(:) :: sizes_ri
3061 INTEGER, DIMENSION(:), POINTER :: col_bsize, row_bsize
3062 TYPE(cp_blacs_env_type), POINTER :: blacs_env
3063 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_v_tr_r
3064 TYPE(dbcsr_distribution_type) :: dbcsr_dist
3065 TYPE(dbcsr_type), ALLOCATABLE, DIMENSION(:) :: mat_v_tr_r
3066 TYPE(distribution_2d_type), POINTER :: dist_2d
3067 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
3068 POINTER :: sab_ri
3069 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
3070 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
3071
3072 CALL timeset(routinen, handle)
3073
3074 NULLIFY (sab_ri, dist_2d)
3075
3076 CALL get_qs_env(qs_env=qs_env, &
3077 blacs_env=blacs_env, &
3078 distribution_2d=dist_2d, &
3079 qs_kind_set=qs_kind_set, &
3080 particle_set=particle_set)
3081
3082 ALLOCATE (sizes_ri(bs_env%n_atom))
3083 CALL get_particle_set(particle_set, qs_kind_set, nsgf=sizes_ri, basis=bs_env%basis_set_RI)
3084 CALL build_2c_neighbor_lists(sab_ri, bs_env%basis_set_RI, bs_env%basis_set_RI, &
3085 pot_type, "2c_nl_RI", qs_env, sym_ij=.false., &
3086 dist_2d=dist_2d)
3087 CALL cp_dbcsr_dist2d_to_dist(dist_2d, dbcsr_dist)
3088 ALLOCATE (row_bsize(SIZE(sizes_ri)))
3089 ALLOCATE (col_bsize(SIZE(sizes_ri)))
3090 row_bsize(:) = sizes_ri
3091 col_bsize(:) = sizes_ri
3092
3093 nimages_scf_desymm = bs_env%nimages_scf_desymm
3094 ALLOCATE (mat_v_tr_r(nimages_scf_desymm))
3095 CALL dbcsr_create(mat_v_tr_r(1), "(RI|RI)", dbcsr_dist, dbcsr_type_no_symmetry, &
3096 row_bsize, col_bsize)
3097 DEALLOCATE (row_bsize, col_bsize)
3098
3099 DO img = 2, nimages_scf_desymm
3100 CALL dbcsr_create(mat_v_tr_r(img), template=mat_v_tr_r(1))
3101 END DO
3102
3103 CALL build_2c_integrals(mat_v_tr_r, 0.0_dp, qs_env, sab_ri, bs_env%basis_set_RI, &
3104 bs_env%basis_set_RI, pot_type, do_kpoints=.true., &
3105 ext_kpoints=bs_env%kpoints_scf_desymm, &
3106 regularization_ri=regularization_ri)
3107
3108 ALLOCATE (fm_v_tr_r(nimages_scf_desymm))
3109 DO img = 1, nimages_scf_desymm
3110 CALL cp_fm_create(fm_v_tr_r(img), bs_env%fm_RI_RI%matrix_struct)
3111 CALL copy_dbcsr_to_fm(mat_v_tr_r(img), fm_v_tr_r(img))
3112 CALL dbcsr_release(mat_v_tr_r(img))
3113 END DO
3114
3115 IF (.NOT. ALLOCATED(v_tr_r)) THEN
3116 ALLOCATE (v_tr_r(bs_env%n_RI, bs_env%n_RI, nimages_scf_desymm))
3117 END IF
3118
3119 CALL fm_to_local_array(fm_v_tr_r, v_tr_r)
3120
3121 CALL cp_fm_release(fm_v_tr_r)
3122 CALL dbcsr_distribution_release(dbcsr_dist)
3123 CALL release_neighbor_list_sets(sab_ri)
3124
3125 CALL timestop(handle)
3126
3127 END SUBROUTINE get_v_tr_r
3128
3129! **************************************************************************************************
3130!> \brief ...
3131!> \param matrix ...
3132!> \param exponent ...
3133!> \param eps ...
3134!> \param cond_nr ...
3135!> \param min_ev ...
3136!> \param max_ev ...
3137! **************************************************************************************************
3138 SUBROUTINE power(matrix, exponent, eps, cond_nr, min_ev, max_ev)
3139 COMPLEX(KIND=dp), DIMENSION(:, :) :: matrix
3140 REAL(kind=dp) :: exponent, eps
3141 REAL(kind=dp), OPTIONAL :: cond_nr, min_ev, max_ev
3142
3143 CHARACTER(len=*), PARAMETER :: routinen = 'power'
3144
3145 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: eigenvectors
3146 INTEGER :: handle, i, n
3147 REAL(kind=dp) :: pos_eval
3148 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigenvalues
3149
3150 CALL timeset(routinen, handle)
3151
3152 ! make matrix perfectly Hermitian
3153 matrix(:, :) = 0.5_dp*(matrix(:, :) + conjg(transpose(matrix(:, :))))
3154
3155 n = SIZE(matrix, 1)
3156 ALLOCATE (eigenvalues(n), eigenvectors(n, n))
3157 CALL diag_complex(matrix, eigenvectors, eigenvalues)
3158
3159 IF (PRESENT(cond_nr)) cond_nr = maxval(abs(eigenvalues))/minval(abs(eigenvalues))
3160 IF (PRESENT(min_ev)) min_ev = minval(abs(eigenvalues))
3161 IF (PRESENT(max_ev)) max_ev = maxval(abs(eigenvalues))
3162
3163 DO i = 1, n
3164 IF (eps < eigenvalues(i)) THEN
3165 pos_eval = (eigenvalues(i))**(0.5_dp*exponent)
3166 ELSE
3167 pos_eval = 0.0_dp
3168 END IF
3169 eigenvectors(:, i) = eigenvectors(:, i)*pos_eval
3170 END DO
3171
3172 CALL zgemm("N", "C", n, n, n, z_one, eigenvectors, n, eigenvectors, n, z_zero, matrix, n)
3173
3174 DEALLOCATE (eigenvalues, eigenvectors)
3175
3176 CALL timestop(handle)
3177
3178 END SUBROUTINE power
3179
3180! **************************************************************************************************
3181!> \brief ...
3182!> \param bs_env ...
3183!> \param Sigma_c_n_time ...
3184!> \param Sigma_c_n_freq ...
3185!> \param ispin ...
3186! **************************************************************************************************
3187 SUBROUTINE time_to_freq(bs_env, Sigma_c_n_time, Sigma_c_n_freq, ispin)
3188 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
3189 REAL(kind=dp), DIMENSION(:, :, :) :: sigma_c_n_time, sigma_c_n_freq
3190 INTEGER :: ispin
3191
3192 CHARACTER(LEN=*), PARAMETER :: routinen = 'time_to_freq'
3193
3194 INTEGER :: handle, i_t, j_w, n_occ
3195 REAL(kind=dp) :: freq_j, time_i, w_cos_ij, w_sin_ij
3196 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: sigma_c_n_cos_time, sigma_c_n_sin_time
3197
3198 CALL timeset(routinen, handle)
3199
3200 ALLOCATE (sigma_c_n_cos_time(bs_env%n_ao, bs_env%num_time_freq_points))
3201 ALLOCATE (sigma_c_n_sin_time(bs_env%n_ao, bs_env%num_time_freq_points))
3202
3203 sigma_c_n_cos_time(:, :) = 0.5_dp*(sigma_c_n_time(:, :, 1) + sigma_c_n_time(:, :, 2))
3204 sigma_c_n_sin_time(:, :) = 0.5_dp*(sigma_c_n_time(:, :, 1) - sigma_c_n_time(:, :, 2))
3205
3206 sigma_c_n_freq(:, :, :) = 0.0_dp
3207
3208 DO i_t = 1, bs_env%num_time_freq_points
3209
3210 DO j_w = 1, bs_env%num_time_freq_points
3211
3212 freq_j = bs_env%imag_freq_points(j_w)
3213 time_i = bs_env%imag_time_points(i_t)
3214 ! integration weights for cosine and sine transform
3215 w_cos_ij = bs_env%weights_cos_t_to_w(j_w, i_t)*cos(freq_j*time_i)
3216 w_sin_ij = bs_env%weights_sin_t_to_w(j_w, i_t)*sin(freq_j*time_i)
3217
3218 ! 1. Re(Σ^c_nn(k_i,iω)) from cosine transform
3219 sigma_c_n_freq(:, j_w, 1) = sigma_c_n_freq(:, j_w, 1) + &
3220 w_cos_ij*sigma_c_n_cos_time(:, i_t)
3221
3222 ! 2. Im(Σ^c_nn(k_i,iω)) from sine transform
3223 sigma_c_n_freq(:, j_w, 2) = sigma_c_n_freq(:, j_w, 2) + &
3224 w_sin_ij*sigma_c_n_sin_time(:, i_t)
3225
3226 END DO
3227
3228 END DO
3229
3230 ! for occupied levels, we need the correlation self-energy for negative omega.
3231 ! Therefore, weight_sin should be computed with -omega, which results in an
3232 ! additional minus for the imaginary part:
3233 n_occ = bs_env%n_occ(ispin)
3234 sigma_c_n_freq(1:n_occ, :, 2) = -sigma_c_n_freq(1:n_occ, :, 2)
3235
3236 CALL timestop(handle)
3237
3238 END SUBROUTINE time_to_freq
3239
3240! **************************************************************************************************
3241!> \brief ...
3242!> \param bs_env ...
3243!> \param Sigma_c_ikp_n_freq ...
3244!> \param Sigma_x_ikp_n ...
3245!> \param V_xc_ikp_n ...
3246!> \param eigenval_scf ...
3247!> \param ikp ...
3248!> \param ispin ...
3249! **************************************************************************************************
3250 SUBROUTINE analyt_conti_and_print(bs_env, Sigma_c_ikp_n_freq, Sigma_x_ikp_n, V_xc_ikp_n, &
3251 eigenval_scf, ikp, ispin)
3252
3253 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
3254 REAL(kind=dp), DIMENSION(:, :, :) :: sigma_c_ikp_n_freq
3255 REAL(kind=dp), DIMENSION(:) :: sigma_x_ikp_n, v_xc_ikp_n, eigenval_scf
3256 INTEGER :: ikp, ispin
3257
3258 CHARACTER(LEN=*), PARAMETER :: routinen = 'analyt_conti_and_print'
3259
3260 CHARACTER(len=3) :: occ_vir
3261 CHARACTER(len=default_string_length) :: fname
3262 INTEGER :: handle, i_mo, ikp_for_print, iunit, &
3263 n_mo, nkp
3264 LOGICAL :: is_bandstruc_kpoint, print_dos_kpoints, &
3265 print_ikp
3266 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: dummy, sigma_c_ikp_n_qp
3267
3268 CALL timeset(routinen, handle)
3269
3270 n_mo = bs_env%n_ao
3271 ALLOCATE (dummy(n_mo), sigma_c_ikp_n_qp(n_mo))
3272 sigma_c_ikp_n_qp(:) = 0.0_dp
3273
3274 DO i_mo = 1, n_mo
3275
3276 ! parallelization
3277 IF (modulo(i_mo, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
3278
3279 CALL continuation_pade(sigma_c_ikp_n_qp, &
3280 bs_env%imag_freq_points_fit, dummy, dummy, &
3281 sigma_c_ikp_n_freq(:, 1:bs_env%num_freq_points_fit, 1)*z_one + &
3282 sigma_c_ikp_n_freq(:, 1:bs_env%num_freq_points_fit, 2)*gaussi, &
3283 sigma_x_ikp_n(:) - v_xc_ikp_n(:), &
3284 eigenval_scf(:), eigenval_scf(:), &
3285 bs_env%do_hedin_shift, &
3286 i_mo, bs_env%n_occ(ispin), bs_env%n_vir(ispin), &
3287 bs_env%nparam_pade, bs_env%num_freq_points_fit, &
3288 ri_rpa_g0w0_crossing_newton, bs_env%n_occ(ispin), &
3289 0.0_dp, .true., .false., 1, e_fermi_ext=bs_env%e_fermi(ispin))
3290 END DO
3291
3292 CALL bs_env%para_env%sum(sigma_c_ikp_n_qp)
3293
3294 CALL correct_obvious_fitting_fails(sigma_c_ikp_n_qp, ispin, bs_env)
3295
3296 bs_env%eigenval_G0W0(:, ikp, ispin) = eigenval_scf(:) + &
3297 sigma_c_ikp_n_qp(:) + &
3298 sigma_x_ikp_n(:) - &
3299 v_xc_ikp_n(:)
3300
3301 bs_env%eigenval_HF(:, ikp, ispin) = eigenval_scf(:) + sigma_x_ikp_n(:) - v_xc_ikp_n(:)
3302
3303 ! only print eigenvalues of DOS k-points in case no bandstructure path has been given
3304 print_dos_kpoints = (bs_env%nkp_only_bs <= 0)
3305 ! in kpoints_DOS, the last nkp_only_bs are bandstructure k-points
3306 is_bandstruc_kpoint = (ikp > bs_env%nkp_only_DOS)
3307 print_ikp = print_dos_kpoints .OR. is_bandstruc_kpoint
3308
3309 IF (bs_env%para_env%is_source() .AND. print_ikp) THEN
3310
3311 IF (print_dos_kpoints) THEN
3312 nkp = bs_env%nkp_only_DOS
3313 ikp_for_print = ikp
3314 ELSE
3315 nkp = bs_env%nkp_only_bs
3316 ikp_for_print = ikp - bs_env%nkp_only_DOS
3317 END IF
3318
3319 fname = "bandstructure_SCF_and_G0W0"
3320
3321 IF (ikp_for_print == 1) THEN
3322 CALL open_file(trim(fname), unit_number=iunit, file_status="REPLACE", &
3323 file_action="WRITE")
3324 ELSE
3325 CALL open_file(trim(fname), unit_number=iunit, file_status="OLD", &
3326 file_action="WRITE", file_position="APPEND")
3327 END IF
3328
3329 WRITE (iunit, "(A)") " "
3330 WRITE (iunit, "(A10,I7,A25,3F10.4)") "kpoint: ", ikp_for_print, "coordinate: ", &
3331 bs_env%kpoints_DOS%xkp(:, ikp)
3332 WRITE (iunit, "(A)") " "
3333 WRITE (iunit, "(A5,A12,3A17,A16,A18)") "n", "k", ϵ"_nk^DFT (eV)", Σ"^c_nk (eV)", &
3334 Σ"^x_nk (eV)", "v_nk^xc (eV)", ϵ"_nk^G0W0 (eV)"
3335 WRITE (iunit, "(A)") " "
3336
3337 DO i_mo = 1, n_mo
3338 IF (i_mo <= bs_env%n_occ(ispin)) occ_vir = 'occ'
3339 IF (i_mo > bs_env%n_occ(ispin)) occ_vir = 'vir'
3340 WRITE (iunit, "(I5,3A,I5,4F16.3,F17.3)") i_mo, ' (', occ_vir, ') ', ikp_for_print, &
3341 eigenval_scf(i_mo)*evolt, &
3342 sigma_c_ikp_n_qp(i_mo)*evolt, &
3343 sigma_x_ikp_n(i_mo)*evolt, &
3344 v_xc_ikp_n(i_mo)*evolt, &
3345 bs_env%eigenval_G0W0(i_mo, ikp, ispin)*evolt
3346 END DO
3347
3348 WRITE (iunit, "(A)") " "
3349
3350 CALL close_file(iunit)
3351
3352 END IF
3353
3354 CALL timestop(handle)
3355
3356 END SUBROUTINE analyt_conti_and_print
3357
3358! **************************************************************************************************
3359!> \brief ...
3360!> \param Sigma_c_ikp_n_qp ...
3361!> \param ispin ...
3362!> \param bs_env ...
3363! **************************************************************************************************
3364 SUBROUTINE correct_obvious_fitting_fails(Sigma_c_ikp_n_qp, ispin, bs_env)
3365 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: sigma_c_ikp_n_qp
3366 INTEGER :: ispin
3367 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
3368
3369 CHARACTER(LEN=*), PARAMETER :: routinen = 'correct_obvious_fitting_fails'
3370
3371 INTEGER :: handle, homo, i_mo, j_mo, &
3372 n_levels_scissor, n_mo
3373 LOGICAL :: is_occ, is_vir
3374 REAL(kind=dp) :: sum_sigma_c
3375
3376 CALL timeset(routinen, handle)
3377
3378 n_mo = bs_env%n_ao
3379 homo = bs_env%n_occ(ispin)
3380
3381 DO i_mo = 1, n_mo
3382
3383 ! if |𝚺^c| > 13 eV, we use a scissors shift
3384 IF (abs(sigma_c_ikp_n_qp(i_mo)) > 13.0_dp/evolt) THEN
3385
3386 is_occ = (i_mo <= homo)
3387 is_vir = (i_mo > homo)
3388
3389 n_levels_scissor = 0
3390 sum_sigma_c = 0.0_dp
3391
3392 ! compute scissor
3393 DO j_mo = 1, n_mo
3394
3395 ! only compute scissor from other GW levels close in energy
3396 IF (is_occ .AND. j_mo > homo) cycle
3397 IF (is_vir .AND. j_mo <= homo) cycle
3398 IF (abs(i_mo - j_mo) > 10) cycle
3399 IF (i_mo == j_mo) cycle
3400
3401 n_levels_scissor = n_levels_scissor + 1
3402 sum_sigma_c = sum_sigma_c + sigma_c_ikp_n_qp(j_mo)
3403
3404 END DO
3405
3406 ! overwrite the self-energy with scissor shift
3407 sigma_c_ikp_n_qp(i_mo) = sum_sigma_c/real(n_levels_scissor, kind=dp)
3408
3409 END IF
3410
3411 END DO ! i_mo
3412
3413 CALL timestop(handle)
3414
3415 END SUBROUTINE correct_obvious_fitting_fails
3416
3417END MODULE gw_utils
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
struct tensor_ tensor
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum)
...
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public graml2024
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public scaled_to_real(r, s, cell)
Transform scaled cell coordinates real coordinates. r=h*s.
Definition cell_types.F:521
methods related to the blacs parallel environment
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
subroutine, public cp_blacs_env_create(blacs_env, para_env, blacs_grid_layout, blacs_repeatable, row_major, grid_2d)
allocates and initializes a type that represent a blacs context
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_distribution_release(dist)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_dist2d_to_dist(dist2d, dist)
Creates a DBCSR distribution from a distribution_2d.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Utility routines to open and close files. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:311
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Definition cp_files.F:122
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_diag(matrix, diag)
returns the diagonal elements of a fm
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
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...
character(len=default_path_length) function, public cp_print_key_generate_filename(logger, print_key, middle_name, extension, my_local)
Utility function that returns a unit number to write the print key. Might open a file with a unique f...
This is the start of a dbt_api, all publically needed functions are exported here....
Definition dbt_api.F:17
stores a mapping of 2D info (e.g. matrix) on a 2D processor distribution (i.e. blacs grid) where cpus...
subroutine, public fm_to_local_array(fm_s, array_s, weight, add)
...
Utility method to build 3-center integrals for small cell GW.
subroutine, public build_3c_integral_block(int_3c, qs_env, potential_parameter, basis_j, basis_k, basis_i, cell_j, cell_k, cell_i, atom_j, atom_k, atom_i, j_bf_start_from_atom, k_bf_start_from_atom, i_bf_start_from_atom)
...
subroutine, public get_v_tr_r(v_tr_r, pot_type, regularization_ri, bs_env, qs_env)
...
Definition gw_utils.F:3051
subroutine, public time_to_freq(bs_env, sigma_c_n_time, sigma_c_n_freq, ispin)
...
Definition gw_utils.F:3188
subroutine, public de_init_bs_env(bs_env)
...
Definition gw_utils.F:240
subroutine, public compute_xkp(xkp, ikp_start, ikp_end, grid)
...
Definition gw_utils.F:607
subroutine, public analyt_conti_and_print(bs_env, sigma_c_ikp_n_freq, sigma_x_ikp_n, v_xc_ikp_n, eigenval_scf, ikp, ispin)
...
Definition gw_utils.F:3252
subroutine, public create_and_init_bs_env_for_gw(qs_env, bs_env, bs_sec)
...
Definition gw_utils.F:154
subroutine, public add_r(cell_1, cell_2, index_to_cell, cell_1_plus_2, cell_found, cell_to_index, i_cell_1_plus_2)
...
Definition gw_utils.F:2766
subroutine, public get_i_j_atoms(atoms_i, atoms_j, n_atom_i, n_atom_j, color_sub, bs_env)
...
Definition gw_utils.F:1486
subroutine, public power(matrix, exponent, eps, cond_nr, min_ev, max_ev)
...
Definition gw_utils.F:3139
subroutine, public is_cell_in_index_to_cell(cell, index_to_cell, cell_found)
...
Definition gw_utils.F:2805
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_potential_truncated
integer, parameter, public rtp_method_bse
integer, parameter, public small_cell_full_kp
integer, parameter, public large_cell_gamma
integer, parameter, public xc_none
integer, parameter, public ri_rpa_g0w0_crossing_newton
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_set(section_vals, keyword_name, i_rep_section, i_rep_val, val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
sets the requested value
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
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 int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Implements transformations from k-space to R-space for Fortran array matrices.
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.
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_create(kpoint)
Create a kpoint environment.
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.
2- and 3-center electron repulsion integral routines based on libint2 Currently available operators: ...
Interface to the Libint-Library or a c++ wrapper.
subroutine, public cp_libint_static_cleanup()
subroutine, public cp_libint_static_init()
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
subroutine, public m_memory(mem)
Returns the total amount of memory [bytes] in use, if known, zero otherwise.
Definition machine.F:452
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:153
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public gaussi
complex(kind=dp), parameter, public z_zero
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
subroutine, public diag_complex(matrix, eigenvectors, eigenvalues)
Diagonalizes a local complex Hermitian matrix using LAPACK. Based on cp_cfm_heevd.
Definition mathlib.F:1751
elemental integer function, public gcd(a, b)
computes the greatest common divisor of two number
Definition mathlib.F:1288
Interface to the message passing library MPI.
Routines to calculate the minimax coefficients in order to approximate 1/x as a sum over exponential ...
subroutine, public get_exp_minimax_coeff_gw(k, e_range, aw)
...
Routines to calculate the minimax coefficients in order to approximate 1/x as a sum over exponential ...
Definition minimax_exp.F:29
subroutine, public get_exp_minimax_coeff(k, rc, aw, mm_error, which_coeffs)
Get best minimax approximation for given input parameters. Automatically chooses the most exact set o...
Routines to calculate the minimax coefficients for approximating 1/x as 1/x ~ 1/pi SUM_{i}^{K} w_i x^...
Definition minimax_rpa.F:14
subroutine, public get_rpa_minimax_coeff_larger_grid(k, e_range, aw)
...
subroutine, public get_rpa_minimax_coeff(k, e_range, aw, ierr, print_warning)
The a_i and w_i coefficient are stored in aw such that the first 1:K elements correspond to a_i and t...
Definition minimax_rpa.F:41
Calls routines to get RI integrals and calculate total energies.
Definition mp2_gpw.F:14
subroutine, public create_mat_munu(mat_munu, qs_env, eps_grid, blacs_env_sub, do_ri_aux_basis, do_mixed_basis, group_size_prim, do_alloc_blocks_from_nbl, do_kpoints, sab_orb_sub, dbcsr_sym_type)
Encapsulate the building of dbcsr_matrix mat_munu.
Definition mp2_gpw.F:989
Routines to calculate frequency and time grids (integration points and weights) for correlation metho...
Definition mp2_grids.F:14
subroutine, public get_l_sq_wghts_cos_tf_w_to_t(num_integ_points, tau_tj, weights_cos_tf_w_to_t, omega_tj, e_min, e_max, max_error, num_points_per_magnitude, regularization)
...
Definition mp2_grids.F:1225
subroutine, public get_l_sq_wghts_cos_tf_t_to_w(num_integ_points, tau_tj, weights_cos_tf_t_to_w, omega_tj, e_min, e_max, max_error, num_points_per_magnitude, regularization)
Calculate integration weights for the tau grid (in dependency of the omega node)
Definition mp2_grids.F:726
subroutine, public get_l_sq_wghts_sin_tf_t_to_w(num_integ_points, tau_tj, weights_sin_tf_t_to_w, omega_tj, e_min, e_max, max_error, num_points_per_magnitude, regularization)
Calculate integration weights for the tau grid (in dependency of the omega node)
Definition mp2_grids.F:862
Framework for 2c-integrals for RI.
Definition mp2_ri_2c.F:14
subroutine, public trunc_coulomb_for_exchange(qs_env, trunc_coulomb, rel_cutoff_trunc_coulomb_ri_x, cell_grid, do_bvk_cell)
...
Definition mp2_ri_2c.F:1601
basic linear algebra operations for full matrixes
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis)
Get the components of a particle set.
Define the data structure for the particle information.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public evolt
Definition physcon.F:183
real(kind=dp), parameter, public angstrom
Definition physcon.F:144
subroutine, public rsmat_to_kp(mat_rs, ispin, xkp, cell_to_index_scf, sab_nl, bs_env, cfm_kp, imag_rs_mat)
...
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public qs_env_part_release(qs_env)
releases part of the given qs_env in order to save memory
Some utility functions for the calculation of integrals.
subroutine, public basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
Set up an easy accessible list of the basis sets for all kinds.
Calculate the interaction radii for the operator matrix calculation.
subroutine, public init_interaction_radii_orb_basis(orb_basis_set, eps_pgf_orb, eps_pgf_short)
...
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces, just_energy, print_active, ext_ks_matrix, ext_xc_section)
routine where the real calculations are made: the KS matrix is calculated
Define the neighbor list data types and the corresponding functionality.
subroutine, public release_neighbor_list_sets(nlists)
releases an array of neighbor_list_sets
Utility methods to build 3-center integral tensors of various types.
subroutine, public distribution_3d_create(dist_3d, dist1, dist2, dist3, nkind, particle_set, mp_comm_3d, own_comm)
Create a 3d distribution.
subroutine, public create_2c_tensor(t2c, dist_1, dist_2, pgrid, sizes_1, sizes_2, order, name)
...
subroutine, public create_3c_tensor(t3c, dist_1, dist_2, dist_3, pgrid, sizes_1, sizes_2, sizes_3, map1, map2, name)
...
Utility methods to build 3-center integral tensors of various types.
Definition qs_tensors.F:11
subroutine, public build_2c_integrals(t2c, filter_eps, qs_env, nl_2c, basis_i, basis_j, potential_parameter, do_kpoints, do_hfx_kpoints, ext_kpoints, regularization_ri)
...
subroutine, public build_2c_neighbor_lists(ij_list, basis_i, basis_j, potential_parameter, name, qs_env, sym_ij, molecular, dist_2d, pot_to_rad)
Build 2-center neighborlists adapted to different operators This mainly wraps build_neighbor_lists fo...
Definition qs_tensors.F:144
subroutine, public build_3c_integrals(t3c, filter_eps, qs_env, nl_3c, basis_i, basis_j, basis_k, potential_parameter, int_eps, op_pos, do_kpoints, do_hfx_kpoints, desymmetrize, cell_sym, bounds_i, bounds_j, bounds_k, ri_range, img_to_ri_cell, cell_to_index_ext)
Build 3-center integral tensor.
subroutine, public neighbor_list_3c_destroy(ijk_list)
Destroy 3c neighborlist.
Definition qs_tensors.F:381
subroutine, public get_tensor_occupancy(tensor, nze, occ)
...
subroutine, public build_3c_neighbor_lists(ijk_list, basis_i, basis_j, basis_k, dist_3d, potential_parameter, name, qs_env, sym_ij, sym_jk, sym_ik, molecular, op_pos, own_dist)
Build a 3-center neighbor list.
Definition qs_tensors.F:280
Routines for GW, continuous development [Jan Wilhelm].
Definition rpa_gw.F:14
subroutine, public continuation_pade(vec_gw_energ, vec_omega_fit_gw, z_value, m_value, vec_sigma_c_gw, vec_sigma_x_minus_vxc_gw, eigenval, eigenval_scf, do_hedin_shift, n_level_gw, gw_corr_lev_occ, gw_corr_lev_vir, nparam_pade, num_fit_points, crossing_search, homo, fermi_level_offset, do_gw_im_time, print_self_energy, count_ev_sc_gw, vec_gw_dos, dos_lower_bound, dos_precision, ndos, min_level_self_energy, max_level_self_energy, dos_eta, dos_min, dos_max, e_fermi_ext)
perform analytic continuation with pade approximation
Definition rpa_gw.F:4314
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
Represent a complex full matrix.
keeps the information about the structure of a full matrix
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
distributes pairs on a 2d grid of processors
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.