(git:4f857eb)
Loading...
Searching...
No Matches
qs_tensors.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 Utility methods to build 3-center integral tensors of various types.
10! **************************************************************************************************
12 USE omp_lib, ONLY: omp_get_max_threads,&
13 omp_get_num_threads,&
14 omp_get_thread_num
15 USE ai_contraction, ONLY: block_add
23 USE cell_types, ONLY: cell_type,&
25 USE coulomb_integral_interface, ONLY: compute_coulomb_2c,&
26 compute_coulomb_2c_derivs,&
27 compute_coulomb_3c,&
28 compute_coulomb_3c_derivs,&
29 coulomb_integral_cleanup,&
30 coulomb_integral_context_type,&
31 coulomb_integral_init
34 USE cp_dbcsr_api, ONLY: dbcsr_filter,&
40 dbcsr_type_antisymmetric,&
41 dbcsr_type_no_symmetry
43 USE dbt_api, ONLY: &
44 dbt_blk_sizes, dbt_clear, dbt_copy, dbt_create, dbt_destroy, dbt_filter, dbt_get_block, &
45 dbt_get_info, dbt_get_num_blocks, dbt_get_nze_total, dbt_iterator_next_block, &
46 dbt_iterator_num_blocks, dbt_iterator_start, dbt_iterator_stop, dbt_iterator_type, &
47 dbt_ndims, dbt_put_block, dbt_reserve_blocks, dbt_type
55 USE hfx_types, ONLY: dealloc_containers,&
69 USE kinds, ONLY: dp,&
70 int_8
71 USE kpoint_types, ONLY: get_kpoint_info,&
75 USE orbital_pointers, ONLY: ncoset
80 USE qs_neighbor_list_types, ONLY: &
90 USE qs_tensors_types, ONLY: &
95 USE util, ONLY: get_limit
96
97!$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num
98#include "./base/base_uses.f90"
99
100 IMPLICIT NONE
101
102 PRIVATE
103
104 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_tensors'
105
106 PUBLIC :: build_3c_neighbor_lists, &
112
113 TYPE one_dim_int_array
114 INTEGER, DIMENSION(:), ALLOCATABLE :: array
115 END TYPE one_dim_int_array
116
117 ! cache size for integral compression
118 INTEGER, PARAMETER, PRIVATE :: cache_size = 1024
119
120CONTAINS
121
122! **************************************************************************************************
123!> \brief Build 2-center neighborlists adapted to different operators
124!> This mainly wraps build_neighbor_lists for consistency with build_3c_neighbor_lists
125!> \param ij_list 2c neighbor list for atom pairs i, j
126!> \param basis_i basis object for atoms i
127!> \param basis_j basis object for atoms j
128!> \param potential_parameter ...
129!> \param name name of 2c neighbor list
130!> \param qs_env ...
131!> \param sym_ij Symmetry in i, j (default .TRUE.)
132!> \param molecular ...
133!> \param dist_2d optionally a custom 2d distribution
134!> \param pot_to_rad which radius (1 for i, 2 for j) should be adapted to incorporate potential
135! **************************************************************************************************
136 SUBROUTINE build_2c_neighbor_lists(ij_list, basis_i, basis_j, potential_parameter, name, qs_env, &
137 sym_ij, molecular, dist_2d, pot_to_rad)
138 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
139 POINTER :: ij_list
140 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_i, basis_j
141 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
142 CHARACTER(LEN=*), INTENT(IN) :: name
143 TYPE(qs_environment_type), POINTER :: qs_env
144 LOGICAL, INTENT(IN), OPTIONAL :: sym_ij, molecular
145 TYPE(distribution_2d_type), OPTIONAL, POINTER :: dist_2d
146 INTEGER, INTENT(IN), OPTIONAL :: pot_to_rad
147
148 INTEGER :: ikind, nkind, pot_to_rad_prv
149 LOGICAL, ALLOCATABLE, DIMENSION(:) :: i_present, j_present
150 REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: pair_radius
151 REAL(kind=dp) :: subcells
152 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: i_radius, j_radius
153 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
154 TYPE(cell_type), POINTER :: cell
155 TYPE(distribution_1d_type), POINTER :: local_particles
156 TYPE(distribution_2d_type), POINTER :: dist_2d_prv
157 TYPE(local_atoms_type), ALLOCATABLE, DIMENSION(:) :: atom2d
158 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
159 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
160
161 NULLIFY (atomic_kind_set, cell, local_particles, molecule_set, &
162 particle_set, dist_2d_prv)
163
164 IF (PRESENT(pot_to_rad)) THEN
165 pot_to_rad_prv = pot_to_rad
166 ELSE
167 pot_to_rad_prv = 1
168 END IF
169
170 CALL get_qs_env(qs_env, &
171 nkind=nkind, &
172 cell=cell, &
173 particle_set=particle_set, &
174 atomic_kind_set=atomic_kind_set, &
175 local_particles=local_particles, &
176 distribution_2d=dist_2d_prv, &
177 molecule_set=molecule_set)
178
179 CALL section_vals_val_get(qs_env%input, "DFT%SUBCELLS", r_val=subcells)
180
181 ALLOCATE (i_present(nkind), source=.false.)
182 ALLOCATE (j_present(nkind), source=.false.)
183 ALLOCATE (i_radius(nkind), source=0.0_dp)
184 ALLOCATE (j_radius(nkind), source=0.0_dp)
185
186 IF (PRESENT(dist_2d)) dist_2d_prv => dist_2d
187
188 ! Set up the radii, depending on the operator type
189 IF (potential_parameter%potential_type == do_potential_id) THEN
190
191 !overlap => use the kind radius for both i and j
192 DO ikind = 1, nkind
193 IF (ASSOCIATED(basis_i(ikind)%gto_basis_set)) THEN
194 i_present(ikind) = .true.
195 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, kind_radius=i_radius(ikind))
196 END IF
197 IF (ASSOCIATED(basis_j(ikind)%gto_basis_set)) THEN
198 j_present(ikind) = .true.
199 CALL get_gto_basis_set(basis_j(ikind)%gto_basis_set, kind_radius=j_radius(ikind))
200 END IF
201 END DO
202
203 ELSE IF (potential_parameter%potential_type == do_potential_coulomb) THEN
204
205 !Coulomb operator, virtually infinite range => set j_radius to arbitrarily large number
206 DO ikind = 1, nkind
207 IF (ASSOCIATED(basis_i(ikind)%gto_basis_set)) THEN
208 i_present(ikind) = .true.
209 IF (pot_to_rad_prv == 1) i_radius(ikind) = 1000000.0_dp
210 END IF
211 IF (ASSOCIATED(basis_j(ikind)%gto_basis_set)) THEN
212 j_present(ikind) = .true.
213 IF (pot_to_rad_prv == 2) j_radius(ikind) = 1000000.0_dp
214 END IF
215 END DO !ikind
216
217 ELSE IF (potential_parameter%potential_type == do_potential_truncated .OR. &
218 potential_parameter%potential_type == do_potential_short .OR. &
219 potential_parameter%potential_type == do_potential_mix_cl_trunc) THEN
220
221 !Truncated coulomb/short range: set j_radius to r_cutoff + the kind_radii
222 DO ikind = 1, nkind
223 IF (ASSOCIATED(basis_i(ikind)%gto_basis_set)) THEN
224 i_present(ikind) = .true.
225 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, kind_radius=i_radius(ikind))
226 IF (pot_to_rad_prv == 1) i_radius(ikind) = i_radius(ikind) + cutoff_screen_factor*potential_parameter%cutoff_radius
227 END IF
228 IF (ASSOCIATED(basis_j(ikind)%gto_basis_set)) THEN
229 j_present(ikind) = .true.
230 CALL get_gto_basis_set(basis_j(ikind)%gto_basis_set, kind_radius=j_radius(ikind))
231 IF (pot_to_rad_prv == 2) j_radius(ikind) = j_radius(ikind) + cutoff_screen_factor*potential_parameter%cutoff_radius
232 END IF
233 END DO
234
235 ELSE
236 cpabort("Operator not implemented.")
237 END IF
238
239 ALLOCATE (pair_radius(nkind, nkind), source=0.0_dp)
240 CALL pair_radius_setup(i_present, j_present, i_radius, j_radius, pair_radius)
241
242 ALLOCATE (atom2d(nkind))
243
244 CALL atom2d_build(atom2d, local_particles, dist_2d_prv, atomic_kind_set, &
245 molecule_set, molecule_only=.false., particle_set=particle_set)
246 CALL build_neighbor_lists(ij_list, particle_set, atom2d, cell, pair_radius, subcells, &
247 symmetric=sym_ij, molecular=molecular, nlname=trim(name))
248
249 CALL atom2d_cleanup(atom2d)
250
251 END SUBROUTINE build_2c_neighbor_lists
252
253! **************************************************************************************************
254!> \brief Build a 3-center neighbor list
255!> \param ijk_list 3c neighbor list for atom triples i, j, k
256!> \param basis_i basis object for atoms i
257!> \param basis_j basis object for atoms j
258!> \param basis_k basis object for atoms k
259!> \param dist_3d 3d distribution object
260!> \param potential_parameter ...
261!> \param name name of 3c neighbor list
262!> \param qs_env ...
263!> \param sym_ij Symmetry in i, j (default .FALSE.)
264!> \param sym_jk Symmetry in j, k (default .FALSE.)
265!> \param sym_ik Symmetry in i, k (default .FALSE.)
266!> \param molecular ??? not tested
267!> \param op_pos ...
268!> \param own_dist ...
269! **************************************************************************************************
270 SUBROUTINE build_3c_neighbor_lists(ijk_list, basis_i, basis_j, basis_k, &
271 dist_3d, potential_parameter, name, qs_env, &
272 sym_ij, sym_jk, sym_ik, molecular, op_pos, &
273 own_dist)
274 TYPE(neighbor_list_3c_type), INTENT(OUT) :: ijk_list
275 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_i, basis_j, basis_k
276 TYPE(distribution_3d_type), INTENT(IN) :: dist_3d
277 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
278 CHARACTER(LEN=*), INTENT(IN) :: name
279 TYPE(qs_environment_type), POINTER :: qs_env
280 LOGICAL, INTENT(IN), OPTIONAL :: sym_ij, sym_jk, sym_ik, molecular
281 INTEGER, INTENT(IN), OPTIONAL :: op_pos
282 LOGICAL, INTENT(IN), OPTIONAL :: own_dist
283
284 CHARACTER(len=*), PARAMETER :: routinen = 'build_3c_neighbor_lists'
285
286 INTEGER :: handle, op_pos_prv, sym_level
287 TYPE(coulomb_operator_type) :: pot_par_1, pot_par_2
288
289 CALL timeset(routinen, handle)
290
291 IF (PRESENT(op_pos)) THEN
292 op_pos_prv = op_pos
293 ELSE
294 op_pos_prv = 1
295 END IF
296
297 SELECT CASE (op_pos_prv)
298 CASE (1)
299 pot_par_1 = potential_parameter
300 pot_par_2%potential_type = do_potential_id
301 CASE (2)
302 pot_par_2 = potential_parameter
303 pot_par_1%potential_type = do_potential_id
304 END SELECT
305
306 CALL build_2c_neighbor_lists(ijk_list%ij_list, basis_i, basis_j, pot_par_1, trim(name)//"_sub_1", &
307 qs_env, sym_ij=.false., molecular=molecular, &
308 dist_2d=dist_3d%dist_2d_1, pot_to_rad=1)
309
310 CALL build_2c_neighbor_lists(ijk_list%jk_list, basis_j, basis_k, pot_par_2, trim(name)//"_sub_2", &
311 qs_env, sym_ij=.false., molecular=molecular, &
312 dist_2d=dist_3d%dist_2d_2, pot_to_rad=2)
313
314 ijk_list%sym = symmetric_none
315
316 sym_level = 0
317 IF (PRESENT(sym_ij)) THEN
318 IF (sym_ij) THEN
319 ijk_list%sym = symmetric_ij
320 sym_level = sym_level + 1
321 END IF
322 END IF
323
324 IF (PRESENT(sym_jk)) THEN
325 IF (sym_jk) THEN
326 ijk_list%sym = symmetric_jk
327 sym_level = sym_level + 1
328 END IF
329 END IF
330
331 IF (PRESENT(sym_ik)) THEN
332 IF (sym_ik) THEN
333 ijk_list%sym = symmetrik_ik
334 sym_level = sym_level + 1
335 END IF
336 END IF
337
338 IF (sym_level >= 2) THEN
339 ijk_list%sym = symmetric_ijk
340 END IF
341
342 ijk_list%dist_3d = dist_3d
343 IF (PRESENT(own_dist)) THEN
344 ijk_list%owns_dist = own_dist
345 ELSE
346 ijk_list%owns_dist = .false.
347 END IF
348
349 CALL timestop(handle)
350 END SUBROUTINE build_3c_neighbor_lists
351
352! **************************************************************************************************
353!> \brief Symmetry criterion
354!> \param a ...
355!> \param b ...
356!> \return ...
357! **************************************************************************************************
358 PURE FUNCTION include_symmetric(a, b)
359 INTEGER, INTENT(IN) :: a, b
360 LOGICAL :: include_symmetric
361
362 IF (a > b) THEN
363 include_symmetric = (modulo(a + b, 2) /= 0)
364 ELSE
365 include_symmetric = (modulo(a + b, 2) == 0)
366 END IF
367
368 END FUNCTION include_symmetric
369
370! **************************************************************************************************
371!> \brief Destroy 3c neighborlist
372!> \param ijk_list ...
373! **************************************************************************************************
374 SUBROUTINE neighbor_list_3c_destroy(ijk_list)
375 TYPE(neighbor_list_3c_type), INTENT(INOUT) :: ijk_list
376
377 CALL release_neighbor_list_sets(ijk_list%ij_list)
378 CALL release_neighbor_list_sets(ijk_list%jk_list)
379
380 IF (ijk_list%owns_dist) THEN
381 CALL distribution_3d_destroy(ijk_list%dist_3d)
382 END IF
383
384 END SUBROUTINE neighbor_list_3c_destroy
385
386! **************************************************************************************************
387!> \brief Create a 3-center neighborlist iterator
388!> \param iterator ...
389!> \param ijk_nl ...
390! **************************************************************************************************
391 SUBROUTINE neighbor_list_3c_iterator_create(iterator, ijk_nl)
392 TYPE(neighbor_list_3c_iterator_type), INTENT(OUT) :: iterator
393 TYPE(neighbor_list_3c_type), INTENT(IN) :: ijk_nl
394
395 CHARACTER(len=*), PARAMETER :: routinen = 'neighbor_list_3c_iterator_create'
396
397 INTEGER :: handle
398
399 CALL timeset(routinen, handle)
400
401 CALL neighbor_list_iterator_create(iterator%iter_ij, ijk_nl%ij_list)
402 CALL neighbor_list_iterator_create(iterator%iter_jk, ijk_nl%jk_list, search=.true.)
403
404 iterator%iter_level = 0
405 iterator%ijk_nl = ijk_nl
406
407 iterator%bounds_i = 0
408 iterator%bounds_j = 0
409 iterator%bounds_k = 0
410
411 iterator%ipair = -1
412 iterator%my_pair = -1
413
414 CALL timestop(handle)
416
417! **************************************************************************************************
418!> \brief impose atomic upper and lower bounds
419!> \param iterator ...
420!> \param bounds_i ...
421!> \param bounds_j ...
422!> \param bounds_k ...
423! **************************************************************************************************
424 SUBROUTINE nl_3c_iter_set_bounds(iterator, bounds_i, bounds_j, bounds_k)
426 INTENT(INOUT) :: iterator
427 INTEGER, DIMENSION(2), INTENT(IN), OPTIONAL :: bounds_i, bounds_j, bounds_k
428
429 IF (PRESENT(bounds_i)) iterator%bounds_i = bounds_i
430 IF (PRESENT(bounds_j)) iterator%bounds_j = bounds_j
431 IF (PRESENT(bounds_k)) iterator%bounds_k = bounds_k
432
433 END SUBROUTINE nl_3c_iter_set_bounds
434
435! **************************************************************************************************
436!> \brief Destroy 3c-nl iterator
437!> \param iterator ...
438! **************************************************************************************************
441 INTENT(INOUT) :: iterator
442
443 CHARACTER(len=*), PARAMETER :: routinen = 'neighbor_list_3c_iterator_destroy'
444
445 INTEGER :: handle
446
447 CALL timeset(routinen, handle)
448 CALL neighbor_list_iterator_release(iterator%iter_ij)
449 CALL neighbor_list_iterator_release(iterator%iter_jk)
450 NULLIFY (iterator%iter_ij)
451 NULLIFY (iterator%iter_jk)
452
453 CALL timestop(handle)
455
456! **************************************************************************************************
457!> \brief Iterate 3c-nl iterator
458!> \param iterator ...
459!> \param next_pair counter shared by the threads that iterate the same list: each takes the next
460!> untaken (i,j) pair (within the bounds) and only then iterates its k
461!> \return 0 if successful; 1 if end was reached
462! **************************************************************************************************
463 FUNCTION neighbor_list_3c_iterate(iterator, next_pair) RESULT(iter_stat)
465 INTENT(INOUT) :: iterator
466 INTEGER, INTENT(INOUT), OPTIONAL :: next_pair
467 INTEGER :: iter_stat
468
469 INTEGER :: iatom, jatom, jatom_1, jatom_2, katom
470 LOGICAL :: found, skip_this
471
472 ! skipped entries are a loop (not a recursion): the stack does not grow with their number
473 found = .false.
474 iter_stat = 0
475 DO WHILE (.NOT. found .AND. iter_stat == 0)
476 skip_this = .false.
477
478 IF (iterator%iter_level == 0) THEN
479 iter_stat = neighbor_list_iterate(iterator%iter_ij)
480
481 IF (iter_stat == 0) THEN
482 CALL get_iterator_info(iterator%iter_ij, iatom=iatom, jatom=jatom)
483 IF ((iterator%bounds_i(1) > 0 .AND. iatom < iterator%bounds_i(1)) &
484 .OR. (iterator%bounds_i(2) > 0 .AND. iatom > iterator%bounds_i(2))) skip_this = .true.
485 IF ((iterator%bounds_j(1) > 0 .AND. jatom < iterator%bounds_j(1)) &
486 .OR. (iterator%bounds_j(2) > 0 .AND. jatom > iterator%bounds_j(2))) skip_this = .true.
487
488 IF (PRESENT(next_pair) .AND. .NOT. skip_this) THEN
489 IF (iterator%my_pair < 0) THEN ! first ticket
490!$OMP ATOMIC CAPTURE
491 iterator%my_pair = next_pair
492 next_pair = next_pair + 1
493!$OMP END ATOMIC
494 END IF
495 iterator%ipair = iterator%ipair + 1
496 IF (iterator%ipair == iterator%my_pair) THEN ! take this pair, and a ticket for later
497!$OMP ATOMIC CAPTURE
498 iterator%my_pair = next_pair
499 next_pair = next_pair + 1
500!$OMP END ATOMIC
501 ELSE
502 skip_this = .true.
503 END IF
504 END IF
505 END IF
506 END IF
507
508 IF (iter_stat == 0 .AND. .NOT. skip_this) THEN
509 iter_stat = nl_sub_iterate(iterator%iter_jk, iterator%iter_ij)
510 IF (iter_stat /= 0) THEN ! no further k for this pair: next pair
511 iterator%iter_level = 0
512 iter_stat = 0
513 ELSE
514 iterator%iter_level = 1
515
516 CALL get_iterator_info(iterator%iter_ij, iatom=iatom, jatom=jatom_1)
517 CALL get_iterator_info(iterator%iter_jk, iatom=jatom_2, jatom=katom)
518
519 cpassert(jatom_1 == jatom_2)
520 jatom = jatom_1
521
522 IF ((iterator%bounds_k(1) > 0 .AND. katom < iterator%bounds_k(1)) &
523 .OR. (iterator%bounds_k(2) > 0 .AND. katom > iterator%bounds_k(2))) skip_this = .true.
524
525 IF (.NOT. skip_this) THEN
526 SELECT CASE (iterator%ijk_nl%sym)
527 CASE (symmetric_none)
528 skip_this = .false.
529 CASE (symmetric_ij)
530 skip_this = .NOT. include_symmetric(iatom, jatom)
531 CASE (symmetric_jk)
532 skip_this = .NOT. include_symmetric(jatom, katom)
533 CASE (symmetrik_ik)
534 skip_this = .NOT. include_symmetric(iatom, katom)
535 CASE (symmetric_ijk)
536 skip_this = .NOT. include_symmetric(iatom, jatom) .OR. .NOT. include_symmetric(jatom, katom)
537 CASE DEFAULT
538 cpabort("should not happen")
539 END SELECT
540 END IF
541
542 found = .NOT. skip_this
543 END IF
544 END IF
545 END DO
546
547 END FUNCTION neighbor_list_3c_iterate
548
549! **************************************************************************************************
550!> \brief Get info of current iteration
551!> \param iterator ...
552!> \param ikind ...
553!> \param jkind ...
554!> \param kkind ...
555!> \param nkind ...
556!> \param iatom ...
557!> \param jatom ...
558!> \param katom ...
559!> \param rij ...
560!> \param rjk ...
561!> \param rik ...
562!> \param cell_j ...
563!> \param cell_k ...
564!> \return ...
565! **************************************************************************************************
566 SUBROUTINE get_3c_iterator_info(iterator, ikind, jkind, kkind, nkind, iatom, jatom, katom, &
567 rij, rjk, rik, cell_j, cell_k)
569 INTENT(INOUT) :: iterator
570 INTEGER, INTENT(OUT), OPTIONAL :: ikind, jkind, kkind, nkind, iatom, &
571 jatom, katom
572 REAL(kind=dp), DIMENSION(3), INTENT(OUT), OPTIONAL :: rij, rjk, rik
573 INTEGER, DIMENSION(3), INTENT(OUT), OPTIONAL :: cell_j, cell_k
574
575 INTEGER, DIMENSION(2) :: atoms_1, atoms_2, kinds_1, kinds_2
576 INTEGER, DIMENSION(3) :: cell_1, cell_2
577 REAL(kind=dp), DIMENSION(3) :: r_1, r_2
578
579 cpassert(iterator%iter_level == 1)
580
581 CALL get_iterator_info(iterator%iter_ij, &
582 ikind=kinds_1(1), jkind=kinds_1(2), nkind=nkind, &
583 iatom=atoms_1(1), jatom=atoms_1(2), r=r_1, &
584 cell=cell_1)
585
586 CALL get_iterator_info(iterator%iter_jk, &
587 ikind=kinds_2(1), jkind=kinds_2(2), &
588 iatom=atoms_2(1), jatom=atoms_2(2), r=r_2, &
589 cell=cell_2)
590
591 IF (PRESENT(ikind)) ikind = kinds_1(1)
592 IF (PRESENT(jkind)) jkind = kinds_1(2)
593 IF (PRESENT(kkind)) kkind = kinds_2(2)
594 IF (PRESENT(iatom)) iatom = atoms_1(1)
595 IF (PRESENT(jatom)) jatom = atoms_1(2)
596 IF (PRESENT(katom)) katom = atoms_2(2)
597
598 IF (PRESENT(rij)) rij = r_1
599 IF (PRESENT(rjk)) rjk = r_2
600 IF (PRESENT(rik)) rik = r_1 + r_2
601
602 IF (PRESENT(cell_j)) cell_j = cell_1
603 IF (PRESENT(cell_k)) cell_k = cell_1 + cell_2
604
605 END SUBROUTINE get_3c_iterator_info
606
607! **************************************************************************************************
608!> \brief Allocate blocks of a 3-center tensor based on neighborlist
609!> \param t3c empty DBCSR tensor
610!> Should be of shape (1,1) if no kpoints are used and of shape (nimages, nimages)
611!> if k-points are used
612!> \param nl_3c 3-center neighborlist
613!> \param basis_i ...
614!> \param basis_j ...
615!> \param basis_k ...
616!> \param qs_env ...
617!> \param potential_parameter ...
618!> \param op_pos ...
619!> \param do_kpoints ...
620!> \param do_hfx_kpoints ...
621!> \param bounds_i ...
622!> \param bounds_j ...
623!> \param bounds_k ...
624!> \param RI_range ...
625!> \param img_to_RI_cell ...
626!> \param cell_to_index ...
627!> \param cell_sym ...
628! **************************************************************************************************
629 SUBROUTINE alloc_block_3c(t3c, nl_3c, basis_i, basis_j, basis_k, qs_env, potential_parameter, op_pos, &
630 do_kpoints, do_hfx_kpoints, bounds_i, bounds_j, bounds_k, RI_range, &
631 img_to_RI_cell, cell_to_index, cell_sym)
632 TYPE(dbt_type), DIMENSION(:, :), INTENT(INOUT) :: t3c
633 TYPE(neighbor_list_3c_type), INTENT(INOUT) :: nl_3c
634 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_i, basis_j, basis_k
635 TYPE(qs_environment_type), POINTER :: qs_env
636 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
637 INTEGER, INTENT(IN), OPTIONAL :: op_pos
638 LOGICAL, INTENT(IN), OPTIONAL :: do_kpoints, do_hfx_kpoints
639 INTEGER, DIMENSION(2), INTENT(IN), OPTIONAL :: bounds_i, bounds_j, bounds_k
640 REAL(dp), INTENT(IN), OPTIONAL :: ri_range
641 INTEGER, DIMENSION(:), INTENT(IN), OPTIONAL :: img_to_ri_cell
642 INTEGER, DIMENSION(:, :, :), OPTIONAL, POINTER :: cell_to_index
643 LOGICAL, INTENT(IN), OPTIONAL :: cell_sym
644
645 CHARACTER(LEN=*), PARAMETER :: routinen = 'alloc_block_3c'
646
647 INTEGER :: handle, iatom, ikind, j_img, jatom, &
648 jcell, jkind, k_img, katom, kcell, &
649 kkind, natom, ncell_ri, nimg, op_ij, &
650 op_jk, op_pos_prv
651 INTEGER(int_8) :: a, b, nblk_per_thread
652 INTEGER(int_8), ALLOCATABLE, DIMENSION(:, :) :: nblk
653 INTEGER, ALLOCATABLE, DIMENSION(:) :: img_to_ri_cell_prv
654 INTEGER, DIMENSION(3) :: blk_idx, cell_j, cell_k, &
655 kp_index_lbounds, kp_index_ubounds
656 LOGICAL :: cell_sym_prv, do_hfx_kpoints_prv, &
657 do_kpoints_prv
658 REAL(kind=dp) :: dij, dik, djk, dr_ij, dr_ik, dr_jk, &
659 kind_radius_i, kind_radius_j, &
660 kind_radius_k
661 REAL(kind=dp), DIMENSION(3) :: rij, rik, rjk
662 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
663 TYPE(cell_type), POINTER :: cell
664 TYPE(dft_control_type), POINTER :: dft_control
665 TYPE(mp_para_env_type), POINTER :: para_env
666 TYPE(neighbor_list_3c_iterator_type) :: nl_3c_iter
667 TYPE(one_dim_int_array), ALLOCATABLE, &
668 DIMENSION(:, :) :: alloc_i, alloc_j, alloc_k
669 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
670
671 CALL timeset(routinen, handle)
672 NULLIFY (qs_kind_set, atomic_kind_set, cell)
673
674 IF (PRESENT(do_kpoints)) THEN
675 do_kpoints_prv = do_kpoints
676 ELSE
677 do_kpoints_prv = .false.
678 END IF
679 IF (PRESENT(do_hfx_kpoints)) THEN
680 do_hfx_kpoints_prv = do_hfx_kpoints
681 ELSE
682 do_hfx_kpoints_prv = .false.
683 END IF
684 IF (do_hfx_kpoints_prv) THEN
685 cpassert(do_kpoints_prv)
686 cpassert(PRESENT(ri_range))
687 cpassert(PRESENT(img_to_ri_cell))
688 END IF
689
690 IF (PRESENT(img_to_ri_cell)) THEN
691 ALLOCATE (img_to_ri_cell_prv(SIZE(img_to_ri_cell)))
692 img_to_ri_cell_prv(:) = img_to_ri_cell
693 END IF
694
695 IF (PRESENT(cell_sym)) THEN
696 cell_sym_prv = cell_sym
697 ELSE
698 cell_sym_prv = .false.
699 END IF
700
701 dr_ij = 0.0_dp; dr_jk = 0.0_dp; dr_ik = 0.0_dp
702
703 op_ij = do_potential_id; op_jk = do_potential_id
704
705 IF (PRESENT(op_pos)) THEN
706 op_pos_prv = op_pos
707 ELSE
708 op_pos_prv = 1
709 END IF
710
711 SELECT CASE (op_pos_prv)
712 CASE (1)
713 op_ij = potential_parameter%potential_type
714 CASE (2)
715 op_jk = potential_parameter%potential_type
716 END SELECT
717
718 IF (op_ij == do_potential_truncated .OR. op_ij == do_potential_short &
719 .OR. op_ij == do_potential_mix_cl_trunc) THEN
720 dr_ij = potential_parameter%cutoff_radius*cutoff_screen_factor
721 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
722 ELSE IF (op_ij == do_potential_coulomb) THEN
723 dr_ij = 1000000.0_dp
724 dr_ik = 1000000.0_dp
725 END IF
726
727 IF (op_jk == do_potential_truncated .OR. op_jk == do_potential_short &
728 .OR. op_jk == do_potential_mix_cl_trunc) THEN
729 dr_jk = potential_parameter%cutoff_radius*cutoff_screen_factor
730 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
731 ELSE IF (op_jk == do_potential_coulomb) THEN
732 dr_jk = 1000000.0_dp
733 dr_ik = 1000000.0_dp
734 END IF
735
736 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, natom=natom, &
737 dft_control=dft_control, para_env=para_env, cell=cell)
738
739 IF (do_kpoints_prv) THEN
740 cpassert(PRESENT(cell_to_index))
741 cpassert(ASSOCIATED(cell_to_index))
742! nimg = dft_control%nimages
743 nimg = maxval(cell_to_index)
744 ncell_ri = nimg
745 IF (do_hfx_kpoints_prv) THEN
746 nimg = SIZE(t3c, 1)
747 ncell_ri = SIZE(t3c, 2)
748 END IF
749 ELSE
750 nimg = 1
751 ncell_ri = 1
752 END IF
753
754 IF (do_kpoints_prv) THEN
755 kp_index_lbounds = lbound(cell_to_index)
756 kp_index_ubounds = ubound(cell_to_index)
757 END IF
758
759 !Do a first loop over the nl and count the blocks present
760 ALLOCATE (nblk(nimg, ncell_ri))
761 nblk(:, :) = 0
762
763 CALL neighbor_list_3c_iterator_create(nl_3c_iter, nl_3c)
764
765 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bounds_j, bounds_k)
766
767 DO WHILE (neighbor_list_3c_iterate(nl_3c_iter) == 0)
768 CALL get_3c_iterator_info(nl_3c_iter, iatom=iatom, ikind=ikind, jkind=jkind, kkind=kkind, &
769 rij=rij, rjk=rjk, rik=rik, cell_j=cell_j, cell_k=cell_k)
770
771 djk = norm2(rjk)
772 dij = norm2(rij)
773 dik = norm2(rik)
774
775 IF (do_kpoints_prv) THEN
776
777 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
778 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
779
780 jcell = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
781 IF (jcell > nimg .OR. jcell < 1) cycle
782
783 IF (any([cell_k(1), cell_k(2), cell_k(3)] < kp_index_lbounds) .OR. &
784 any([cell_k(1), cell_k(2), cell_k(3)] > kp_index_ubounds)) cycle
785
786 kcell = cell_to_index(cell_k(1), cell_k(2), cell_k(3))
787 IF (kcell > nimg .OR. kcell < 1) cycle
788 IF (do_hfx_kpoints_prv) THEN
789 IF (dik > ri_range) cycle
790 kcell = 1
791 END IF
792 ELSE
793 jcell = 1; kcell = 1
794 END IF
795
796 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, kind_radius=kind_radius_i)
797 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, kind_radius=kind_radius_j)
798 CALL get_gto_basis_set(basis_k(kkind)%gto_basis_set, kind_radius=kind_radius_k)
799
800 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
801 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
802 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
803
804 nblk(jcell, kcell) = nblk(jcell, kcell) + 1
805 END DO
806 CALL neighbor_list_3c_iterator_destroy(nl_3c_iter)
807
808 !Do a second loop over the nl to give block indices
809 ALLOCATE (alloc_i(nimg, ncell_ri))
810 ALLOCATE (alloc_j(nimg, ncell_ri))
811 ALLOCATE (alloc_k(nimg, ncell_ri))
812 DO k_img = 1, ncell_ri
813 DO j_img = 1, nimg
814 ALLOCATE (alloc_i(j_img, k_img)%array(nblk(j_img, k_img)))
815 ALLOCATE (alloc_j(j_img, k_img)%array(nblk(j_img, k_img)))
816 ALLOCATE (alloc_k(j_img, k_img)%array(nblk(j_img, k_img)))
817 END DO
818 END DO
819 nblk(:, :) = 0
820
821 CALL neighbor_list_3c_iterator_create(nl_3c_iter, nl_3c)
822
823 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bounds_j, bounds_k)
824
825 DO WHILE (neighbor_list_3c_iterate(nl_3c_iter) == 0)
826 CALL get_3c_iterator_info(nl_3c_iter, ikind=ikind, jkind=jkind, kkind=kkind, &
827 iatom=iatom, jatom=jatom, katom=katom, &
828 rij=rij, rjk=rjk, rik=rik, cell_j=cell_j, cell_k=cell_k)
829
830 djk = norm2(rjk)
831 dij = norm2(rij)
832 dik = norm2(rik)
833
834 IF (do_kpoints_prv) THEN
835
836 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
837 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
838
839 jcell = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
840 IF (jcell > nimg .OR. jcell < 1) cycle
841
842 IF (any([cell_k(1), cell_k(2), cell_k(3)] < kp_index_lbounds) .OR. &
843 any([cell_k(1), cell_k(2), cell_k(3)] > kp_index_ubounds)) cycle
844
845 kcell = cell_to_index(cell_k(1), cell_k(2), cell_k(3))
846 IF (kcell > nimg .OR. kcell < 1) cycle
847 IF (do_hfx_kpoints_prv) THEN
848 IF (dik > ri_range) cycle
849 kcell = img_to_ri_cell_prv(kcell)
850 END IF
851 ELSE
852 jcell = 1; kcell = 1
853 END IF
854
855 blk_idx = [iatom, jatom, katom]
856 IF (do_hfx_kpoints_prv) THEN
857 blk_idx(3) = (kcell - 1)*natom + katom
858 kcell = 1
859 END IF
860
861 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, kind_radius=kind_radius_i)
862 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, kind_radius=kind_radius_j)
863 CALL get_gto_basis_set(basis_k(kkind)%gto_basis_set, kind_radius=kind_radius_k)
864
865 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
866 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
867 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
868
869 nblk(jcell, kcell) = nblk(jcell, kcell) + 1
870
871 !Note: there may be repeated indices due to periodic images => dbt_reserve_blocks takes care of it
872 alloc_i(jcell, kcell)%array(nblk(jcell, kcell)) = blk_idx(1)
873 alloc_j(jcell, kcell)%array(nblk(jcell, kcell)) = blk_idx(2)
874 alloc_k(jcell, kcell)%array(nblk(jcell, kcell)) = blk_idx(3)
875
876 END DO
877 CALL neighbor_list_3c_iterator_destroy(nl_3c_iter)
878
879!TODO: Parallelize creation of block list.
880!$OMP PARALLEL DEFAULT(NONE) SHARED(t3c,nimg,nblk,alloc_i,alloc_j,alloc_k,ncell_RI,cell_sym_prv) &
881!$OMP PRIVATE(k_img,j_img,nblk_per_thread,A,b)
882 DO k_img = 1, ncell_ri
883 DO j_img = 1, nimg
884 IF (cell_sym_prv .AND. j_img < k_img) cycle
885 IF (ALLOCATED(alloc_i(j_img, k_img)%array)) THEN
886 nblk_per_thread = nblk(j_img, k_img)/omp_get_num_threads() + 1
887 a = omp_get_thread_num()*nblk_per_thread + 1
888 b = min(a + nblk_per_thread, nblk(j_img, k_img))
889 CALL dbt_reserve_blocks(t3c(j_img, k_img), &
890 alloc_i(j_img, k_img)%array(a:b), &
891 alloc_j(j_img, k_img)%array(a:b), &
892 alloc_k(j_img, k_img)%array(a:b))
893 END IF
894 END DO
895 END DO
896!$OMP END PARALLEL
897
898 CALL timestop(handle)
899
900 END SUBROUTINE alloc_block_3c
901
902! **************************************************************************************************
903!> \brief Build 3-center derivative tensors
904!> \param t3c_der_i empty DBCSR tensor which will contain the 1st center derivatives
905!> \param t3c_der_k empty DBCSR tensor which will contain the 3rd center derivatives
906!> \param filter_eps Filter threshold for tensor blocks
907!> \param qs_env ...
908!> \param nl_3c 3-center neighborlist
909!> \param basis_i ...
910!> \param basis_j ...
911!> \param basis_k ...
912!> \param potential_parameter ...
913!> \param der_eps neglect integrals smaller than der_eps
914!> \param op_pos operator position.
915!> 1: calculate (i|jk) integrals,
916!> 2: calculate (ij|k) integrals
917!> \param do_kpoints ...
918!> this routine requires that libint has been static initialised somewhere else
919!> \param do_hfx_kpoints ...
920!> \param bounds_i ...
921!> \param bounds_j ...
922!> \param bounds_k ...
923!> \param RI_range ...
924!> \param img_to_RI_cell ...
925! **************************************************************************************************
926 SUBROUTINE build_3c_derivatives(t3c_der_i, t3c_der_k, filter_eps, qs_env, &
927 nl_3c, basis_i, basis_j, basis_k, &
928 potential_parameter, der_eps, &
929 op_pos, do_kpoints, do_hfx_kpoints, &
930 bounds_i, bounds_j, bounds_k, &
931 RI_range, img_to_RI_cell)
932
933 TYPE(dbt_type), DIMENSION(:, :, :), INTENT(INOUT) :: t3c_der_i, t3c_der_k
934 REAL(kind=dp), INTENT(IN) :: filter_eps
935 TYPE(qs_environment_type), POINTER :: qs_env
936 TYPE(neighbor_list_3c_type), INTENT(INOUT) :: nl_3c
937 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_i, basis_j, basis_k
938 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
939 REAL(kind=dp), INTENT(IN), OPTIONAL :: der_eps
940 INTEGER, INTENT(IN), OPTIONAL :: op_pos
941 LOGICAL, INTENT(IN), OPTIONAL :: do_kpoints, do_hfx_kpoints
942 INTEGER, DIMENSION(2), INTENT(IN), OPTIONAL :: bounds_i, bounds_j, bounds_k
943 REAL(dp), INTENT(IN), OPTIONAL :: ri_range
944 INTEGER, DIMENSION(:), INTENT(IN), OPTIONAL :: img_to_ri_cell
945
946 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_3c_derivatives'
947
948 INTEGER :: block_end_i, block_end_j, block_end_k, block_start_i, block_start_j, &
949 block_start_k, egfi, handle, handle2, i, i_img, i_xyz, iatom, ibasis, ikind, ilist, imax, &
950 iset, j_img, jatom, jcell, jkind, jset, katom, kcell, kkind, kset, m_max, max_ncoj, &
951 max_nset, max_nsgfi, maxli, maxlj, maxlk, mepos, natom, nbasis, ncell_ri, ncoi, ncoj, &
952 ncok, nimg, nseti, nsetj, nsetk, nthread, op_ij, op_jk, op_pos_prv, sgfi, sgfj, sgfk
953 INTEGER, ALLOCATABLE, DIMENSION(:) :: img_to_ri_cell_prv
954 INTEGER, DIMENSION(2) :: bo
955 INTEGER, DIMENSION(3) :: blk_idx, blk_size, cell_j, cell_k, &
956 kp_index_lbounds, kp_index_ubounds, sp
957 INTEGER, DIMENSION(:), POINTER :: lmax_i, lmax_j, lmax_k, lmin_i, lmin_j, &
958 lmin_k, npgfi, npgfj, npgfk, nsgfi, &
959 nsgfj, nsgfk
960 INTEGER, DIMENSION(:, :), POINTER :: first_sgf_i, first_sgf_j, first_sgf_k
961 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
962 LOGICAL :: do_hfx_kpoints_prv, do_kpoints_prv, &
963 found, skip
964 LOGICAL, DIMENSION(3) :: block_j_not_zero, block_k_not_zero, &
965 der_j_zero, der_k_zero
966 REAL(dp), DIMENSION(3) :: der_ext_i, der_ext_j, der_ext_k
967 REAL(kind=dp) :: dij, dik, djk, dr_ij, dr_ik, dr_jk, &
968 kind_radius_i, kind_radius_j, &
969 kind_radius_k, prefac
970 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: ccp_buffer, cpp_buffer, &
971 max_contraction_i, max_contraction_j, &
972 max_contraction_k
973 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: dijk_contr, dummy_block_t
974 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :, :) :: block_t_i, block_t_j, block_t_k, dijk_j, &
975 dijk_k, tmp_ijk_i, tmp_ijk_j
976 REAL(kind=dp), DIMENSION(3) :: ri, rij, rik, rj, rjk, rk
977 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_i, set_radius_j, set_radius_k
978 REAL(kind=dp), DIMENSION(:, :), POINTER :: rpgf_i, rpgf_j, rpgf_k, sphi_i, sphi_j, &
979 sphi_k, zeti, zetj, zetk
980 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
981 TYPE(coulomb_integral_context_type) :: integral_context
982 TYPE(cp_2d_r_p_type), DIMENSION(:, :), POINTER :: spi, spk, tspj
983 TYPE(dbt_type) :: t3c_tmp
984 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t3c_template
985 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :, :) :: t3c_der_j
986 TYPE(dft_control_type), POINTER :: dft_control
987 TYPE(gto_basis_set_type), POINTER :: basis_set
988 TYPE(kpoint_type), POINTER :: kpoints
989 TYPE(mp_para_env_type), POINTER :: para_env
990 TYPE(neighbor_list_3c_iterator_type) :: nl_3c_iter
991 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
992
993 CALL timeset(routinen, handle)
994
995 IF (PRESENT(do_kpoints)) THEN
996 do_kpoints_prv = do_kpoints
997 ELSE
998 do_kpoints_prv = .false.
999 END IF
1000
1001 IF (PRESENT(do_hfx_kpoints)) THEN
1002 do_hfx_kpoints_prv = do_hfx_kpoints
1003 ELSE
1004 do_hfx_kpoints_prv = .false.
1005 END IF
1006 IF (do_hfx_kpoints_prv) THEN
1007 cpassert(do_kpoints_prv)
1008 cpassert(PRESENT(ri_range))
1009 cpassert(PRESENT(img_to_ri_cell))
1010 END IF
1011
1012 IF (PRESENT(img_to_ri_cell)) THEN
1013 ALLOCATE (img_to_ri_cell_prv(SIZE(img_to_ri_cell)))
1014 img_to_ri_cell_prv(:) = img_to_ri_cell
1015 END IF
1016
1017 op_ij = do_potential_id; op_jk = do_potential_id
1018
1019 IF (PRESENT(op_pos)) THEN
1020 op_pos_prv = op_pos
1021 ELSE
1022 op_pos_prv = 1
1023 END IF
1024
1025 SELECT CASE (op_pos_prv)
1026 CASE (1)
1027 op_ij = potential_parameter%potential_type
1028 CASE (2)
1029 op_jk = potential_parameter%potential_type
1030 END SELECT
1031
1032 dr_ij = 0.0_dp; dr_jk = 0.0_dp; dr_ik = 0.0_dp
1033
1034 IF (op_ij == do_potential_truncated .OR. op_ij == do_potential_short &
1035 .OR. op_ij == do_potential_mix_cl_trunc) THEN
1036 dr_ij = potential_parameter%cutoff_radius*cutoff_screen_factor
1037 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
1038 ELSE IF (op_ij == do_potential_coulomb) THEN
1039 dr_ij = 1000000.0_dp
1040 dr_ik = 1000000.0_dp
1041 END IF
1042
1043 IF (op_jk == do_potential_truncated .OR. op_jk == do_potential_short &
1044 .OR. op_jk == do_potential_mix_cl_trunc) THEN
1045 dr_jk = potential_parameter%cutoff_radius*cutoff_screen_factor
1046 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
1047 ELSE IF (op_jk == do_potential_coulomb) THEN
1048 dr_jk = 1000000.0_dp
1049 dr_ik = 1000000.0_dp
1050 END IF
1051
1052 NULLIFY (qs_kind_set, atomic_kind_set)
1053
1054 ! get stuff
1055 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
1056 natom=natom, kpoints=kpoints, dft_control=dft_control, para_env=para_env)
1057
1058 IF (do_kpoints_prv) THEN
1059 nimg = dft_control%nimages
1060 ncell_ri = nimg
1061 IF (do_hfx_kpoints_prv) THEN
1062 nimg = SIZE(t3c_der_k, 1)
1063 ncell_ri = SIZE(t3c_der_k, 2)
1064 END IF
1065 CALL get_kpoint_info(kpoints, cell_to_index=cell_to_index)
1066 ELSE
1067 nimg = 1
1068 ncell_ri = 1
1069 END IF
1070
1071 IF (do_hfx_kpoints_prv) THEN
1072 cpassert(op_pos_prv == 2)
1073 ELSE
1074 cpassert(all(shape(t3c_der_k) == [nimg, ncell_ri, 3]))
1075 END IF
1076
1077 ALLOCATE (t3c_template(nimg, ncell_ri))
1078 DO j_img = 1, ncell_ri
1079 DO i_img = 1, nimg
1080 CALL dbt_create(t3c_der_i(i_img, j_img, 1), t3c_template(i_img, j_img))
1081 END DO
1082 END DO
1083
1084 CALL alloc_block_3c(t3c_template, nl_3c, basis_i, basis_j, basis_k, qs_env, potential_parameter, &
1085 op_pos=op_pos_prv, do_kpoints=do_kpoints, do_hfx_kpoints=do_hfx_kpoints, &
1086 bounds_i=bounds_i, bounds_j=bounds_j, bounds_k=bounds_k, &
1087 ri_range=ri_range, img_to_ri_cell=img_to_ri_cell, cell_to_index=cell_to_index)
1088 DO i_xyz = 1, 3
1089 DO j_img = 1, ncell_ri
1090 DO i_img = 1, nimg
1091 CALL dbt_copy(t3c_template(i_img, j_img), t3c_der_i(i_img, j_img, i_xyz))
1092 CALL dbt_copy(t3c_template(i_img, j_img), t3c_der_k(i_img, j_img, i_xyz))
1093 END DO
1094 END DO
1095 END DO
1096
1097 DO j_img = 1, ncell_ri
1098 DO i_img = 1, nimg
1099 CALL dbt_destroy(t3c_template(i_img, j_img))
1100 END DO
1101 END DO
1102 DEALLOCATE (t3c_template)
1103
1104 IF (nl_3c%sym == symmetric_jk) THEN
1105 ALLOCATE (t3c_der_j(nimg, ncell_ri, 3))
1106 DO i_xyz = 1, 3
1107 DO j_img = 1, ncell_ri
1108 DO i_img = 1, nimg
1109 CALL dbt_create(t3c_der_k(i_img, j_img, i_xyz), t3c_der_j(i_img, j_img, i_xyz))
1110 CALL dbt_copy(t3c_der_k(i_img, j_img, i_xyz), t3c_der_j(i_img, j_img, i_xyz))
1111 END DO
1112 END DO
1113 END DO
1114 END IF
1115
1116 !Need the max l for each basis for libint and max nset, nco and nsgf for LIBXSMM contraction
1117 nbasis = SIZE(basis_i)
1118 max_nsgfi = 0
1119 max_nset = 0
1120 maxli = 0
1121 DO ibasis = 1, nbasis
1122 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=imax, &
1123 nset=iset, nsgf_set=nsgfi, npgf=npgfi)
1124 maxli = max(maxli, imax)
1125 max_nset = max(max_nset, iset)
1126 max_nsgfi = max(max_nsgfi, maxval(nsgfi))
1127 END DO
1128 max_ncoj = 0
1129 maxlj = 0
1130 DO ibasis = 1, nbasis
1131 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=imax, &
1132 nset=jset, nsgf_set=nsgfj, npgf=npgfj)
1133 maxlj = max(maxlj, imax)
1134 max_nset = max(max_nset, jset)
1135 max_ncoj = max(max_ncoj, maxval(npgfj)*ncoset(maxlj))
1136 END DO
1137 maxlk = 0
1138 DO ibasis = 1, nbasis
1139 CALL get_gto_basis_set(gto_basis_set=basis_k(ibasis)%gto_basis_set, maxl=imax, &
1140 nset=kset, nsgf_set=nsgfk, npgf=npgfk)
1141 maxlk = max(maxlk, imax)
1142 max_nset = max(max_nset, kset)
1143 END DO
1144 m_max = maxli + maxlj + maxlk + 1
1145
1146 !To minimize expensive memory ops and generally optimize contraction, pre-allocate
1147 !contiguous sphi arrays (and transposed in the case of sphi_i)
1148
1149 NULLIFY (tspj, spi, spk)
1150 ALLOCATE (spi(max_nset, nbasis), tspj(max_nset, nbasis), spk(max_nset, nbasis))
1151
1152 DO ibasis = 1, nbasis
1153 DO iset = 1, max_nset
1154 NULLIFY (spi(iset, ibasis)%array)
1155 NULLIFY (tspj(iset, ibasis)%array)
1156 NULLIFY (spk(iset, ibasis)%array)
1157 END DO
1158 END DO
1159
1160 DO ilist = 1, 3
1161 DO ibasis = 1, nbasis
1162 IF (ilist == 1) basis_set => basis_i(ibasis)%gto_basis_set
1163 IF (ilist == 2) basis_set => basis_j(ibasis)%gto_basis_set
1164 IF (ilist == 3) basis_set => basis_k(ibasis)%gto_basis_set
1165
1166 DO iset = 1, basis_set%nset
1167
1168 ncoi = basis_set%npgf(iset)*ncoset(basis_set%lmax(iset))
1169 sgfi = basis_set%first_sgf(1, iset)
1170 egfi = sgfi + basis_set%nsgf_set(iset) - 1
1171
1172 IF (ilist == 1) THEN
1173 ALLOCATE (spi(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
1174 spi(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
1175
1176 ELSE IF (ilist == 2) THEN
1177 ALLOCATE (tspj(iset, ibasis)%array(basis_set%nsgf_set(iset), ncoi))
1178 tspj(iset, ibasis)%array(:, :) = transpose(basis_set%sphi(1:ncoi, sgfi:egfi))
1179
1180 ELSE
1181 ALLOCATE (spk(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
1182 spk(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
1183 END IF
1184
1185 END DO !iset
1186 END DO !ibasis
1187 END DO !ilist
1188
1189 CALL r12_fundamentals_init(m_max, potential_parameter, para_env)
1190
1191 IF (do_kpoints_prv) THEN
1192 kp_index_lbounds = lbound(cell_to_index)
1193 kp_index_ubounds = ubound(cell_to_index)
1194 END IF
1195
1196 nthread = 1
1197!$ nthread = omp_get_max_threads()
1198
1199!$OMP PARALLEL DEFAULT(NONE) &
1200!$OMP SHARED (nthread,do_kpoints_prv,kp_index_lbounds,kp_index_ubounds,maxli,maxlk,maxlj,bounds_i,&
1201!$OMP bounds_j,bounds_k,nimg,basis_i,basis_j,basis_k,dr_ij,dr_jk,dr_ik,ncoset,op_pos_prv,&
1202!$OMP potential_parameter,der_eps,tspj,spi,spk,cell_to_index,RI_range,natom,nl_3c,&
1203!$OMP t3c_der_i,t3c_der_k,t3c_der_j,ncell_RI,img_to_RI_cell_prv,do_hfx_kpoints_prv) &
1204!$OMP PRIVATE (integral_context,nl_3c_iter,ikind,jkind,kkind,iatom,jatom,katom,rij,rjk,rik,cell_j,cell_k,&
1205!$OMP prefac,jcell,kcell,first_sgf_i,lmax_i,lmin_i,npgfi,nseti,nsgfi,rpgf_i,set_radius_i,&
1206!$OMP sphi_i,zeti,kind_radius_i,first_sgf_j,lmax_j,lmin_j,npgfj,nsetj,nsgfj,rpgf_j,&
1207!$OMP set_radius_j,sphi_j,zetj,kind_radius_j,first_sgf_k,lmax_k,lmin_k,npgfk,nsetk,nsgfk,&
1208!$OMP rpgf_k,set_radius_k,sphi_k,zetk,kind_radius_k,djk,dij,dik,ncoi,ncoj,ncok,sgfi,sgfj,&
1209!$OMP sgfk,dijk_j,dijk_k,ri,rj,rk,max_contraction_i,max_contraction_j,blk_idx,&
1210!$OMP max_contraction_k,iset,jset,kset,block_t_i,blk_size,dijk_contr,cpp_buffer,ccp_buffer,&
1211!$OMP block_start_j,block_end_j,block_start_k,block_end_k,block_start_i,block_end_i,found,&
1212!$OMP dummy_block_t,sp,handle2,mepos,bo,block_t_k,der_ext_i,der_ext_j,der_ext_k,tmp_ijk_i,&
1213!$OMP block_k_not_zero,der_k_zero,skip,der_j_zero,block_t_j,block_j_not_zero,tmp_ijk_j,i)
1214
1215 mepos = 0
1216!$ mepos = omp_get_thread_num()
1217
1218 integral_context = coulomb_integral_context_type()
1219 CALL coulomb_integral_init(integral_context, max_am_3c=max(maxli, maxlj, maxlk), &
1220 derivative_order=1, library=library_libint)
1221 CALL neighbor_list_3c_iterator_create(nl_3c_iter, nl_3c)
1222
1223 !We split the provided bounds among the threads such that each threads works on a different set of atoms
1224 IF (PRESENT(bounds_i)) THEN
1225 bo = get_limit(bounds_i(2) - bounds_i(1) + 1, nthread, mepos)
1226 bo(:) = bo(:) + bounds_i(1) - 1
1227 CALL nl_3c_iter_set_bounds(nl_3c_iter, bo, bounds_j, bounds_k)
1228 ELSE IF (PRESENT(bounds_j)) THEN
1229 bo = get_limit(bounds_j(2) - bounds_j(1) + 1, nthread, mepos)
1230 bo(:) = bo(:) + bounds_j(1) - 1
1231 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bo, bounds_k)
1232 ELSE IF (PRESENT(bounds_k)) THEN
1233 bo = get_limit(bounds_k(2) - bounds_k(1) + 1, nthread, mepos)
1234 bo(:) = bo(:) + bounds_k(1) - 1
1235 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bounds_j, bo)
1236 ELSE
1237 bo = get_limit(natom, nthread, mepos)
1238 CALL nl_3c_iter_set_bounds(nl_3c_iter, bo, bounds_j, bounds_k)
1239 END IF
1240
1241 skip = .false.
1242 IF (bo(1) > bo(2)) skip = .true.
1243
1244 DO WHILE (neighbor_list_3c_iterate(nl_3c_iter) == 0)
1245 CALL get_3c_iterator_info(nl_3c_iter, ikind=ikind, jkind=jkind, kkind=kkind, &
1246 iatom=iatom, jatom=jatom, katom=katom, &
1247 rij=rij, rjk=rjk, rik=rik, cell_j=cell_j, cell_k=cell_k)
1248 IF (skip) EXIT
1249
1250 djk = norm2(rjk)
1251 dij = norm2(rij)
1252 dik = norm2(rik)
1253
1254 IF (do_kpoints_prv) THEN
1255 prefac = 0.5_dp
1256 ELSE IF (nl_3c%sym == symmetric_jk) THEN
1257 IF (jatom == katom) THEN
1258 prefac = 0.5_dp
1259 ELSE
1260 prefac = 1.0_dp
1261 END IF
1262 ELSE
1263 prefac = 1.0_dp
1264 END IF
1265 IF (do_hfx_kpoints_prv) prefac = 1.0_dp
1266
1267 IF (do_kpoints_prv) THEN
1268
1269 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
1270 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
1271
1272 jcell = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
1273 IF (jcell > nimg .OR. jcell < 1) cycle
1274
1275 IF (any([cell_k(1), cell_k(2), cell_k(3)] < kp_index_lbounds) .OR. &
1276 any([cell_k(1), cell_k(2), cell_k(3)] > kp_index_ubounds)) cycle
1277
1278 kcell = cell_to_index(cell_k(1), cell_k(2), cell_k(3))
1279 IF (kcell > nimg .OR. kcell < 1) cycle
1280 !In case of HFX k-points, we only consider P^k if d_ik <= RI_range
1281 IF (do_hfx_kpoints_prv) THEN
1282 IF (dik > ri_range) cycle
1283 kcell = img_to_ri_cell_prv(kcell)
1284 END IF
1285 ELSE
1286 jcell = 1; kcell = 1
1287 END IF
1288
1289 blk_idx = [iatom, jatom, katom]
1290 IF (do_hfx_kpoints_prv) THEN
1291 blk_idx(3) = (kcell - 1)*natom + katom
1292 kcell = 1
1293 END IF
1294
1295 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
1296 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
1297 sphi=sphi_i, zet=zeti, kind_radius=kind_radius_i)
1298
1299 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
1300 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
1301 sphi=sphi_j, zet=zetj, kind_radius=kind_radius_j)
1302
1303 CALL get_gto_basis_set(basis_k(kkind)%gto_basis_set, first_sgf=first_sgf_k, lmax=lmax_k, lmin=lmin_k, &
1304 npgf=npgfk, nset=nsetk, nsgf_set=nsgfk, pgf_radius=rpgf_k, set_radius=set_radius_k, &
1305 sphi=sphi_k, zet=zetk, kind_radius=kind_radius_k)
1306
1307 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
1308 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
1309 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
1310
1311 IF (PRESENT(der_eps)) THEN
1312 ALLOCATE (max_contraction_i(nseti))
1313 DO iset = 1, nseti
1314 sgfi = first_sgf_i(1, iset)
1315 max_contraction_i(iset) = maxval([(sum(abs(sphi_i(:, i))), i=sgfi, sgfi + nsgfi(iset) - 1)])
1316 END DO
1317
1318 ALLOCATE (max_contraction_j(nsetj))
1319 DO jset = 1, nsetj
1320 sgfj = first_sgf_j(1, jset)
1321 max_contraction_j(jset) = maxval([(sum(abs(sphi_j(:, i))), i=sgfj, sgfj + nsgfj(jset) - 1)])
1322 END DO
1323
1324 ALLOCATE (max_contraction_k(nsetk))
1325 DO kset = 1, nsetk
1326 sgfk = first_sgf_k(1, kset)
1327 max_contraction_k(kset) = maxval([(sum(abs(sphi_k(:, i))), i=sgfk, sgfk + nsgfk(kset) - 1)])
1328 END DO
1329 END IF
1330
1331 CALL dbt_blk_sizes(t3c_der_i(jcell, kcell, 1), blk_idx, blk_size)
1332
1333 ALLOCATE (block_t_i(blk_size(2), blk_size(3), blk_size(1), 3), source=0.0_dp)
1334 ALLOCATE (block_t_j(blk_size(2), blk_size(3), blk_size(1), 3), source=0.0_dp)
1335 ALLOCATE (block_t_k(blk_size(2), blk_size(3), blk_size(1), 3), source=0.0_dp)
1336
1337 block_j_not_zero = .false.
1338 block_k_not_zero = .false.
1339
1340 DO iset = 1, nseti
1341
1342 DO jset = 1, nsetj
1343
1344 IF (set_radius_j(jset) + set_radius_i(iset) + dr_ij < dij) cycle
1345
1346 DO kset = 1, nsetk
1347
1348 IF (set_radius_j(jset) + set_radius_k(kset) + dr_jk < djk) cycle
1349 IF (set_radius_k(kset) + set_radius_i(iset) + dr_ik < dik) cycle
1350
1351 ncoi = npgfi(iset)*ncoset(lmax_i(iset))
1352 ncoj = npgfj(jset)*ncoset(lmax_j(jset))
1353 ncok = npgfk(kset)*ncoset(lmax_k(kset))
1354
1355 sgfi = first_sgf_i(1, iset)
1356 sgfj = first_sgf_j(1, jset)
1357 sgfk = first_sgf_k(1, kset)
1358
1359 IF (ncoj*ncok*ncoi > 0) THEN
1360 ALLOCATE (dijk_j(ncoj, ncok, ncoi, 3), source=0.0_dp)
1361 ALLOCATE (dijk_k(ncoj, ncok, ncoi, 3), source=0.0_dp)
1362
1363 der_j_zero = .false.
1364 der_k_zero = .false.
1365
1366 !need positions for libint. Only relative positions are needed => set ri to 0.0
1367 ri = 0.0_dp
1368 rj = rij ! ri + rij
1369 rk = rik ! ri + rik
1370
1371 IF (op_pos_prv == 1) THEN
1372 CALL compute_coulomb_3c_derivs(dijk_j, dijk_k, &
1373 lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), rpgf_j(:, jset), rj, &
1374 lmin_k(kset), lmax_k(kset), npgfk(kset), zetk(:, kset), rpgf_k(:, kset), rk, &
1375 lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), rpgf_i(:, iset), ri, &
1376 djk, dij, dik, integral_context, potential_parameter, &
1377 der_abc_1_ext=der_ext_j, der_abc_2_ext=der_ext_k)
1378 ELSE
1379 ALLOCATE (tmp_ijk_i(ncoi, ncoj, ncok, 3), source=0.0_dp)
1380 ALLOCATE (tmp_ijk_j(ncoi, ncoj, ncok, 3), source=0.0_dp)
1381
1382 CALL compute_coulomb_3c_derivs(tmp_ijk_i, tmp_ijk_j, &
1383 lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), rpgf_i(:, iset), ri, &
1384 lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), rpgf_j(:, jset), rj, &
1385 lmin_k(kset), lmax_k(kset), npgfk(kset), zetk(:, kset), rpgf_k(:, kset), rk, &
1386 dij, dik, djk, integral_context, potential_parameter, &
1387 der_abc_1_ext=der_ext_i, der_abc_2_ext=der_ext_j)
1388
1389 !TODO: is that inefficient?
1390 der_ext_k = 0
1391 DO i_xyz = 1, 3
1392 DO i = 1, ncoi
1393 dijk_j(:, :, i, i_xyz) = tmp_ijk_j(i, :, :, i_xyz)
1394 dijk_k(:, :, i, i_xyz) = -(dijk_j(:, :, i, i_xyz) + tmp_ijk_i(i, :, :, i_xyz))
1395 der_ext_k(i_xyz) = max(der_ext_k(i_xyz), maxval(abs(dijk_k(:, :, i, i_xyz))))
1396 END DO
1397 END DO
1398 DEALLOCATE (tmp_ijk_i, tmp_ijk_j)
1399
1400 END IF
1401
1402 IF (PRESENT(der_eps)) THEN
1403 DO i_xyz = 1, 3
1404 IF (der_eps > der_ext_j(i_xyz)*(max_contraction_i(iset)* &
1405 max_contraction_j(jset)* &
1406 max_contraction_k(kset))) THEN
1407 der_j_zero(i_xyz) = .true.
1408 END IF
1409 END DO
1410
1411 DO i_xyz = 1, 3
1412 IF (der_eps > der_ext_k(i_xyz)*(max_contraction_i(iset)* &
1413 max_contraction_j(jset)* &
1414 max_contraction_k(kset))) THEN
1415 der_k_zero(i_xyz) = .true.
1416 END IF
1417 END DO
1418 IF (all(der_j_zero) .AND. all(der_k_zero)) THEN
1419 DEALLOCATE (dijk_j, dijk_k)
1420 cycle
1421 END IF
1422 END IF
1423
1424 ALLOCATE (dijk_contr(nsgfj(jset), nsgfk(kset), nsgfi(iset)))
1425
1426 block_start_j = sgfj
1427 block_end_j = sgfj + nsgfj(jset) - 1
1428 block_start_k = sgfk
1429 block_end_k = sgfk + nsgfk(kset) - 1
1430 block_start_i = sgfi
1431 block_end_i = sgfi + nsgfi(iset) - 1
1432
1433 DO i_xyz = 1, 3
1434 IF (der_j_zero(i_xyz)) cycle
1435
1436 block_j_not_zero(i_xyz) = .true.
1437 CALL abc_contract_xsmm(dijk_contr, dijk_j(:, :, :, i_xyz), tspj(jset, jkind)%array, &
1438 spk(kset, kkind)%array, spi(iset, ikind)%array, &
1439 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
1440 nsgfi(iset), cpp_buffer, ccp_buffer, prefac)
1441
1442 block_t_j(block_start_j:block_end_j, &
1443 block_start_k:block_end_k, &
1444 block_start_i:block_end_i, i_xyz) = &
1445 block_t_j(block_start_j:block_end_j, &
1446 block_start_k:block_end_k, &
1447 block_start_i:block_end_i, i_xyz) + &
1448 dijk_contr(:, :, :)
1449
1450 END DO
1451
1452 DO i_xyz = 1, 3
1453 IF (der_k_zero(i_xyz)) cycle
1454
1455 block_k_not_zero(i_xyz) = .true.
1456 CALL abc_contract_xsmm(dijk_contr, dijk_k(:, :, :, i_xyz), tspj(jset, jkind)%array, &
1457 spk(kset, kkind)%array, spi(iset, ikind)%array, &
1458 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
1459 nsgfi(iset), cpp_buffer, ccp_buffer, prefac)
1460
1461 block_t_k(block_start_j:block_end_j, &
1462 block_start_k:block_end_k, &
1463 block_start_i:block_end_i, i_xyz) = &
1464 block_t_k(block_start_j:block_end_j, &
1465 block_start_k:block_end_k, &
1466 block_start_i:block_end_i, i_xyz) + &
1467 dijk_contr(:, :, :)
1468
1469 END DO
1470
1471 DEALLOCATE (dijk_j, dijk_k, dijk_contr)
1472 END IF ! number of triples > 0
1473 END DO
1474 END DO
1475 END DO
1476
1477 CALL timeset(routinen//"_put_dbcsr", handle2)
1478!$OMP CRITICAL(qs_tensors_t3c_der_i)
1479 sp = shape(block_t_i(:, :, :, 1))
1480 sp([2, 3, 1]) = sp
1481
1482 DO i_xyz = 1, 3
1483 !Derivatives wrt to center i can be obtained by translational invariance
1484 IF ((.NOT. block_j_not_zero(i_xyz)) .AND. (.NOT. block_k_not_zero(i_xyz))) cycle
1485 block_t_i(:, :, :, i_xyz) = -(block_t_j(:, :, :, i_xyz) + block_t_k(:, :, :, i_xyz))
1486
1487 CALL dbt_put_block(t3c_der_i(jcell, kcell, i_xyz), blk_idx, sp, &
1488 reshape(block_t_i(:, :, :, i_xyz), shape=sp, order=[2, 3, 1]), &
1489 summation=.true.)
1490 END DO
1491
1492 sp = shape(block_t_k(:, :, :, 1))
1493 sp([2, 3, 1]) = sp
1494
1495 DO i_xyz = 1, 3
1496 IF (.NOT. block_k_not_zero(i_xyz)) cycle
1497 CALL dbt_put_block(t3c_der_k(jcell, kcell, i_xyz), blk_idx, sp, &
1498 reshape(block_t_k(:, :, :, i_xyz), shape=sp, order=[2, 3, 1]), &
1499 summation=.true.)
1500 END DO
1501!$OMP END CRITICAL(qs_tensors_t3c_der_i)
1502
1503 IF (nl_3c%sym == symmetric_jk) THEN
1504 sp = shape(block_t_j(:, :, :, 1))
1505 sp([2, 3, 1]) = sp
1506!$OMP CRITICAL(qs_tensors_t3c_der_j)
1507 DO i_xyz = 1, 3
1508 IF (.NOT. block_j_not_zero(i_xyz)) cycle
1509 CALL dbt_put_block(t3c_der_j(jcell, kcell, i_xyz), blk_idx, sp, &
1510 reshape(block_t_j(:, :, :, i_xyz), shape=sp, order=[2, 3, 1]), &
1511 summation=.true.)
1512 END DO
1513!$OMP END CRITICAL(qs_tensors_t3c_der_j)
1514 END IF
1515
1516 CALL timestop(handle2)
1517
1518 DEALLOCATE (block_t_i, block_t_j, block_t_k)
1519 IF (PRESENT(der_eps)) THEN
1520 DEALLOCATE (max_contraction_i, max_contraction_j, max_contraction_k)
1521 END IF
1522 END DO
1523
1524 IF (ALLOCATED(ccp_buffer)) DEALLOCATE (ccp_buffer)
1525 IF (ALLOCATED(cpp_buffer)) DEALLOCATE (cpp_buffer)
1526
1527 CALL coulomb_integral_cleanup(integral_context)
1528 CALL neighbor_list_3c_iterator_destroy(nl_3c_iter)
1529!$OMP END PARALLEL
1530
1531 IF (do_kpoints_prv .AND. .NOT. do_hfx_kpoints_prv) THEN
1532 DO i_xyz = 1, 3
1533 DO kcell = 1, nimg
1534 DO jcell = 1, nimg
1535 ! need half of filter eps because afterwards we add transposed tensor
1536 CALL dbt_filter(t3c_der_i(jcell, kcell, i_xyz), filter_eps/2)
1537 CALL dbt_filter(t3c_der_k(jcell, kcell, i_xyz), filter_eps/2)
1538 END DO
1539 END DO
1540 END DO
1541
1542 ELSE IF (nl_3c%sym == symmetric_jk) THEN
1543 !Add the transpose of t3c_der_j to t3c_der_k to get the fully populated tensor
1544 CALL dbt_create(t3c_der_k(1, 1, 1), t3c_tmp)
1545 DO i_xyz = 1, 3
1546 DO kcell = 1, nimg
1547 DO jcell = 1, nimg
1548 CALL dbt_copy(t3c_der_j(jcell, kcell, i_xyz), t3c_der_k(jcell, kcell, i_xyz), &
1549 order=[1, 3, 2], move_data=.true., summation=.true.)
1550 CALL dbt_filter(t3c_der_k(jcell, kcell, i_xyz), filter_eps)
1551
1552 CALL dbt_copy(t3c_der_i(jcell, kcell, i_xyz), t3c_tmp)
1553 CALL dbt_copy(t3c_tmp, t3c_der_i(jcell, kcell, i_xyz), &
1554 order=[1, 3, 2], move_data=.true., summation=.true.)
1555 CALL dbt_filter(t3c_der_i(jcell, kcell, i_xyz), filter_eps)
1556 END DO
1557 END DO
1558 END DO
1559 CALL dbt_destroy(t3c_tmp)
1560
1561 ELSE IF (nl_3c%sym == symmetric_none) THEN
1562 DO i_xyz = 1, 3
1563 DO kcell = 1, ncell_ri
1564 DO jcell = 1, nimg
1565 CALL dbt_filter(t3c_der_i(jcell, kcell, i_xyz), filter_eps)
1566 CALL dbt_filter(t3c_der_k(jcell, kcell, i_xyz), filter_eps)
1567 END DO
1568 END DO
1569 END DO
1570 ELSE
1571 cpabort("requested symmetric case not implemented")
1572 END IF
1573
1574 IF (nl_3c%sym == symmetric_jk) THEN
1575 DO i_xyz = 1, 3
1576 DO j_img = 1, nimg
1577 DO i_img = 1, nimg
1578 CALL dbt_destroy(t3c_der_j(i_img, j_img, i_xyz))
1579 END DO
1580 END DO
1581 END DO
1582 END IF
1583
1584 DO iset = 1, max_nset
1585 DO ibasis = 1, nbasis
1586 IF (ASSOCIATED(spi(iset, ibasis)%array)) DEALLOCATE (spi(iset, ibasis)%array)
1587 IF (ASSOCIATED(tspj(iset, ibasis)%array)) DEALLOCATE (tspj(iset, ibasis)%array)
1588 IF (ASSOCIATED(spk(iset, ibasis)%array)) DEALLOCATE (spk(iset, ibasis)%array)
1589 END DO
1590 END DO
1591
1592 DEALLOCATE (spi, tspj, spk)
1593
1594 CALL timestop(handle)
1595 END SUBROUTINE build_3c_derivatives
1596
1597! **************************************************************************************************
1598!> \brief Calculates the 3c virial contributions on the fly
1599!> \param work_virial ...
1600!> \param t3c_trace the tensor with which the trace should be taken
1601!> \param pref ...
1602!> \param qs_env ...
1603!> \param nl_3c 3-center neighborlist, with a distribution matching that of t3c_trace
1604!> \param basis_i ...
1605!> \param basis_j ...
1606!> \param basis_k ...
1607!> \param potential_parameter ...
1608!> \param der_eps neglect integrals smaller than der_eps
1609!> \param op_pos operator position.
1610!> 1: calculate (i|jk) integrals,
1611!> 2: calculate (ij|k) integrals
1612!> this routine requires that libint has been static initialised somewhere else
1613! **************************************************************************************************
1614 SUBROUTINE calc_3c_virial(work_virial, t3c_trace, pref, qs_env, &
1615 nl_3c, basis_i, basis_j, basis_k, &
1616 potential_parameter, der_eps, op_pos)
1617
1618 REAL(dp), DIMENSION(3, 3), INTENT(INOUT) :: work_virial
1619 TYPE(dbt_type), INTENT(INOUT) :: t3c_trace
1620 REAL(kind=dp), INTENT(IN) :: pref
1621 TYPE(qs_environment_type), POINTER :: qs_env
1622 TYPE(neighbor_list_3c_type), INTENT(INOUT) :: nl_3c
1623 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_i, basis_j, basis_k
1624 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
1625 REAL(kind=dp), INTENT(IN), OPTIONAL :: der_eps
1626 INTEGER, INTENT(IN), OPTIONAL :: op_pos
1627
1628 CHARACTER(LEN=*), PARAMETER :: routinen = 'calc_3c_virial'
1629
1630 INTEGER :: block_end_i, block_end_j, block_end_k, block_start_i, block_start_j, &
1631 block_start_k, egfi, handle, i, i_xyz, iatom, ibasis, ikind, ilist, imax, iset, j_xyz, &
1632 jatom, jkind, jset, katom, kkind, kset, m_max, max_ncoj, max_nset, max_nsgfi, maxli, &
1633 maxlj, maxlk, mepos, natom, nbasis, ncoi, ncoj, ncok, nseti, nsetj, nsetk, nthread, &
1634 op_ij, op_jk, op_pos_prv, sgfi, sgfj, sgfk
1635 INTEGER, DIMENSION(2) :: bo
1636 INTEGER, DIMENSION(3) :: blk_size, sp
1637 INTEGER, DIMENSION(:), POINTER :: lmax_i, lmax_j, lmax_k, lmin_i, lmin_j, &
1638 lmin_k, npgfi, npgfj, npgfk, nsgfi, &
1639 nsgfj, nsgfk
1640 INTEGER, DIMENSION(:, :), POINTER :: first_sgf_i, first_sgf_j, first_sgf_k
1641 LOGICAL :: found, skip
1642 LOGICAL, DIMENSION(3) :: block_j_not_zero, block_k_not_zero, &
1643 der_j_zero, der_k_zero
1644 REAL(dp) :: force
1645 REAL(dp), DIMENSION(3) :: der_ext_i, der_ext_j, der_ext_k
1646 REAL(kind=dp) :: dij, dik, djk, dr_ij, dr_ik, dr_jk, &
1647 kind_radius_i, kind_radius_j, &
1648 kind_radius_k
1649 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: ccp_buffer, cpp_buffer, &
1650 max_contraction_i, max_contraction_j, &
1651 max_contraction_k
1652 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: ablock, dijk_contr, tmp_block
1653 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :, :) :: block_t_i, block_t_j, block_t_k, dijk_j, &
1654 dijk_k
1655 REAL(kind=dp), DIMENSION(3) :: ri, rij, rik, rj, rjk, rk, scoord
1656 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_i, set_radius_j, set_radius_k
1657 REAL(kind=dp), DIMENSION(:, :), POINTER :: rpgf_i, rpgf_j, rpgf_k, sphi_i, sphi_j, &
1658 sphi_k, zeti, zetj, zetk
1659 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1660 TYPE(cell_type), POINTER :: cell
1661 TYPE(coulomb_integral_context_type) :: integral_context
1662 TYPE(cp_2d_r_p_type), DIMENSION(:, :), POINTER :: spi, spk, tspj
1663 TYPE(dft_control_type), POINTER :: dft_control
1664 TYPE(gto_basis_set_type), POINTER :: basis_set
1665 TYPE(mp_para_env_type), POINTER :: para_env
1666 TYPE(neighbor_list_3c_iterator_type) :: nl_3c_iter
1667 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1668 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1669
1670 CALL timeset(routinen, handle)
1671
1672 op_ij = do_potential_id; op_jk = do_potential_id
1673
1674 IF (PRESENT(op_pos)) THEN
1675 op_pos_prv = op_pos
1676 ELSE
1677 op_pos_prv = 1
1678 END IF
1679 cpassert(op_pos == 1)
1680 cpassert(.NOT. nl_3c%sym == symmetric_jk)
1681
1682 SELECT CASE (op_pos_prv)
1683 CASE (1)
1684 op_ij = potential_parameter%potential_type
1685 CASE (2)
1686 op_jk = potential_parameter%potential_type
1687 END SELECT
1688
1689 dr_ij = 0.0_dp; dr_jk = 0.0_dp; dr_ik = 0.0_dp
1690
1691 IF (op_ij == do_potential_truncated .OR. op_ij == do_potential_short &
1692 .OR. op_ij == do_potential_mix_cl_trunc) THEN
1693 dr_ij = potential_parameter%cutoff_radius*cutoff_screen_factor
1694 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
1695 ELSE IF (op_ij == do_potential_coulomb) THEN
1696 dr_ij = 1000000.0_dp
1697 dr_ik = 1000000.0_dp
1698 END IF
1699
1700 IF (op_jk == do_potential_truncated .OR. op_jk == do_potential_short &
1701 .OR. op_jk == do_potential_mix_cl_trunc) THEN
1702 dr_jk = potential_parameter%cutoff_radius*cutoff_screen_factor
1703 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
1704 ELSE IF (op_jk == do_potential_coulomb) THEN
1705 dr_jk = 1000000.0_dp
1706 dr_ik = 1000000.0_dp
1707 END IF
1708
1709 NULLIFY (qs_kind_set, atomic_kind_set)
1710
1711 ! get stuff
1712 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
1713 natom=natom, dft_control=dft_control, para_env=para_env, &
1714 particle_set=particle_set, cell=cell)
1715
1716 !Need the max l for each basis for libint and max nset, nco and nsgf for LIBXSMM contraction
1717 nbasis = SIZE(basis_i)
1718 max_nsgfi = 0
1719 max_nset = 0
1720 maxli = 0
1721 DO ibasis = 1, nbasis
1722 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=imax, &
1723 nset=iset, nsgf_set=nsgfi, npgf=npgfi)
1724 maxli = max(maxli, imax)
1725 max_nset = max(max_nset, iset)
1726 max_nsgfi = max(max_nsgfi, maxval(nsgfi))
1727 END DO
1728 max_ncoj = 0
1729 maxlj = 0
1730 DO ibasis = 1, nbasis
1731 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=imax, &
1732 nset=jset, nsgf_set=nsgfj, npgf=npgfj)
1733 maxlj = max(maxlj, imax)
1734 max_nset = max(max_nset, jset)
1735 max_ncoj = max(max_ncoj, maxval(npgfj)*ncoset(maxlj))
1736 END DO
1737 maxlk = 0
1738 DO ibasis = 1, nbasis
1739 CALL get_gto_basis_set(gto_basis_set=basis_k(ibasis)%gto_basis_set, maxl=imax, &
1740 nset=kset, nsgf_set=nsgfk, npgf=npgfk)
1741 maxlk = max(maxlk, imax)
1742 max_nset = max(max_nset, kset)
1743 END DO
1744 m_max = maxli + maxlj + maxlk + 1
1745
1746 !To minimize expensive memory ops and generally optimize contraction, pre-allocate
1747 !contiguous sphi arrays (and transposed in the case of sphi_i)
1748
1749 NULLIFY (tspj, spi, spk)
1750 ALLOCATE (spi(max_nset, nbasis), tspj(max_nset, nbasis), spk(max_nset, nbasis))
1751
1752 DO ibasis = 1, nbasis
1753 DO iset = 1, max_nset
1754 NULLIFY (spi(iset, ibasis)%array)
1755 NULLIFY (tspj(iset, ibasis)%array)
1756
1757 NULLIFY (spk(iset, ibasis)%array)
1758 END DO
1759 END DO
1760
1761 DO ilist = 1, 3
1762 DO ibasis = 1, nbasis
1763 IF (ilist == 1) basis_set => basis_i(ibasis)%gto_basis_set
1764 IF (ilist == 2) basis_set => basis_j(ibasis)%gto_basis_set
1765 IF (ilist == 3) basis_set => basis_k(ibasis)%gto_basis_set
1766
1767 DO iset = 1, basis_set%nset
1768
1769 ncoi = basis_set%npgf(iset)*ncoset(basis_set%lmax(iset))
1770 sgfi = basis_set%first_sgf(1, iset)
1771 egfi = sgfi + basis_set%nsgf_set(iset) - 1
1772
1773 IF (ilist == 1) THEN
1774 ALLOCATE (spi(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
1775 spi(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
1776
1777 ELSE IF (ilist == 2) THEN
1778 ALLOCATE (tspj(iset, ibasis)%array(basis_set%nsgf_set(iset), ncoi))
1779 tspj(iset, ibasis)%array(:, :) = transpose(basis_set%sphi(1:ncoi, sgfi:egfi))
1780
1781 ELSE
1782 ALLOCATE (spk(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
1783 spk(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
1784 END IF
1785
1786 END DO !iset
1787 END DO !ibasis
1788 END DO !ilist
1789
1790 CALL r12_fundamentals_init(m_max, potential_parameter, para_env)
1791
1792 nthread = 1
1793!$ nthread = omp_get_max_threads()
1794
1795!$OMP PARALLEL DEFAULT(NONE) &
1796!$OMP SHARED (nthread,maxli,maxlk,maxlj,work_virial,pref,basis_i,basis_j,basis_k,dr_ij,dr_jk,dr_ik,&
1797!$OMP ncoset,potential_parameter,der_eps,tspj,spi,spk,natom,nl_3c,t3c_trace,cell,particle_set) &
1798!$OMP PRIVATE (integral_context,nl_3c_iter,ikind,jkind,kkind,iatom,jatom,katom,rij,rjk,rik,i_xyz,j_xyz,first_sgf_i,&
1799!$OMP lmax_i,lmin_i,npgfi,nseti,nsgfi,rpgf_i,set_radius_i,sphi_i,zeti,kind_radius_i,first_sgf_j,&
1800!$OMP lmax_j,lmin_j,npgfj,nsetj,nsgfj,rpgf_j,set_radius_j,sphi_j,zetj,kind_radius_j,first_sgf_k,&
1801!$OMP lmax_k,lmin_k,npgfk,nsetk,nsgfk,rpgf_k,set_radius_k,sphi_k,zetk,kind_radius_k,djk,dij,dik,&
1802!$OMP ncoi,ncoj,ncok,sgfi,sgfj,sgfk,dijk_j,dijk_k,ri,rj,rk,max_contraction_i,max_contraction_j,&
1803!$OMP tmp_block,max_contraction_k,iset,jset,kset,block_t_i,blk_size,dijk_contr,found,sp,mepos,&
1804!$OMP block_start_j,block_end_j,block_start_k,block_end_k,block_start_i,block_end_i,block_t_k,&
1805!$OMP bo,der_ext_i,der_ext_j,der_ext_k,ablock,force,scoord,skip,cpp_buffer,ccp_buffer,&
1806!$OMP block_k_not_zero,der_k_zero,der_j_zero,block_t_j,block_j_not_zero,i)
1807
1808 mepos = 0
1809!$ mepos = omp_get_thread_num()
1810
1811 integral_context = coulomb_integral_context_type()
1812 CALL coulomb_integral_init(integral_context, max_am_3c=max(maxli, maxlj, maxlk), &
1813 derivative_order=1, library=library_libint)
1814 CALL neighbor_list_3c_iterator_create(nl_3c_iter, nl_3c)
1815
1816 !We split the provided bounds among the threads such that each threads works on a different set of atoms
1817
1818 bo = get_limit(natom, nthread, mepos)
1819 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i=bo)
1820
1821 skip = .false.
1822 IF (bo(1) > bo(2)) skip = .true.
1823
1824 DO WHILE (neighbor_list_3c_iterate(nl_3c_iter) == 0)
1825 CALL get_3c_iterator_info(nl_3c_iter, ikind=ikind, jkind=jkind, kkind=kkind, &
1826 iatom=iatom, jatom=jatom, katom=katom, &
1827 rij=rij, rjk=rjk, rik=rik)
1828 IF (skip) EXIT
1829
1830 CALL dbt_get_block(t3c_trace, [iatom, jatom, katom], tmp_block, found)
1831 IF (.NOT. found) cycle
1832
1833 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
1834 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
1835 sphi=sphi_i, zet=zeti, kind_radius=kind_radius_i)
1836
1837 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
1838 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
1839 sphi=sphi_j, zet=zetj, kind_radius=kind_radius_j)
1840
1841 CALL get_gto_basis_set(basis_k(kkind)%gto_basis_set, first_sgf=first_sgf_k, lmax=lmax_k, lmin=lmin_k, &
1842 npgf=npgfk, nset=nsetk, nsgf_set=nsgfk, pgf_radius=rpgf_k, set_radius=set_radius_k, &
1843 sphi=sphi_k, zet=zetk, kind_radius=kind_radius_k)
1844
1845 djk = norm2(rjk)
1846 dij = norm2(rij)
1847 dik = norm2(rik)
1848
1849 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
1850 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
1851 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
1852
1853 IF (PRESENT(der_eps)) THEN
1854 ALLOCATE (max_contraction_i(nseti))
1855 DO iset = 1, nseti
1856 sgfi = first_sgf_i(1, iset)
1857 max_contraction_i(iset) = maxval([(sum(abs(sphi_i(:, i))), i=sgfi, sgfi + nsgfi(iset) - 1)])
1858 END DO
1859
1860 ALLOCATE (max_contraction_j(nsetj))
1861 DO jset = 1, nsetj
1862 sgfj = first_sgf_j(1, jset)
1863 max_contraction_j(jset) = maxval([(sum(abs(sphi_j(:, i))), i=sgfj, sgfj + nsgfj(jset) - 1)])
1864 END DO
1865
1866 ALLOCATE (max_contraction_k(nsetk))
1867 DO kset = 1, nsetk
1868 sgfk = first_sgf_k(1, kset)
1869 max_contraction_k(kset) = maxval([(sum(abs(sphi_k(:, i))), i=sgfk, sgfk + nsgfk(kset) - 1)])
1870 END DO
1871 END IF
1872
1873 CALL dbt_blk_sizes(t3c_trace, [iatom, jatom, katom], blk_size)
1874
1875 ALLOCATE (block_t_i(blk_size(2), blk_size(3), blk_size(1), 3))
1876 ALLOCATE (block_t_j(blk_size(2), blk_size(3), blk_size(1), 3))
1877 ALLOCATE (block_t_k(blk_size(2), blk_size(3), blk_size(1), 3))
1878
1879 ALLOCATE (ablock(blk_size(2), blk_size(3), blk_size(1)))
1880 DO i = 1, blk_size(1)
1881 ablock(:, :, i) = tmp_block(i, :, :)
1882 END DO
1883 DEALLOCATE (tmp_block)
1884
1885 block_t_i = 0.0_dp
1886 block_t_j = 0.0_dp
1887 block_t_k = 0.0_dp
1888 block_j_not_zero = .false.
1889 block_k_not_zero = .false.
1890
1891 DO iset = 1, nseti
1892
1893 DO jset = 1, nsetj
1894
1895 IF (set_radius_j(jset) + set_radius_i(iset) + dr_ij < dij) cycle
1896
1897 DO kset = 1, nsetk
1898
1899 IF (set_radius_j(jset) + set_radius_k(kset) + dr_jk < djk) cycle
1900 IF (set_radius_k(kset) + set_radius_i(iset) + dr_ik < dik) cycle
1901
1902 ncoi = npgfi(iset)*ncoset(lmax_i(iset))
1903 ncoj = npgfj(jset)*ncoset(lmax_j(jset))
1904 ncok = npgfk(kset)*ncoset(lmax_k(kset))
1905
1906 sgfi = first_sgf_i(1, iset)
1907 sgfj = first_sgf_j(1, jset)
1908 sgfk = first_sgf_k(1, kset)
1909
1910 IF (ncoj*ncok*ncoi > 0) THEN
1911 ALLOCATE (dijk_j(ncoj, ncok, ncoi, 3), source=0.0_dp)
1912 ALLOCATE (dijk_k(ncoj, ncok, ncoi, 3), source=0.0_dp)
1913
1914 der_j_zero = .false.
1915 der_k_zero = .false.
1916
1917 !need positions for libint. Only relative positions are needed => set ri to 0.0
1918 ri = 0.0_dp
1919 rj = rij ! ri + rij
1920 rk = rik ! ri + rik
1921
1922 CALL compute_coulomb_3c_derivs(dijk_j, dijk_k, &
1923 lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), rpgf_j(:, jset), rj, &
1924 lmin_k(kset), lmax_k(kset), npgfk(kset), zetk(:, kset), rpgf_k(:, kset), rk, &
1925 lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), rpgf_i(:, iset), ri, &
1926 djk, dij, dik, integral_context, potential_parameter, &
1927 der_abc_1_ext=der_ext_j, der_abc_2_ext=der_ext_k)
1928
1929 IF (PRESENT(der_eps)) THEN
1930 DO i_xyz = 1, 3
1931 IF (der_eps > der_ext_j(i_xyz)*(max_contraction_i(iset)* &
1932 max_contraction_j(jset)* &
1933 max_contraction_k(kset))) THEN
1934 der_j_zero(i_xyz) = .true.
1935 END IF
1936 END DO
1937
1938 DO i_xyz = 1, 3
1939 IF (der_eps > der_ext_k(i_xyz)*(max_contraction_i(iset)* &
1940 max_contraction_j(jset)* &
1941 max_contraction_k(kset))) THEN
1942 der_k_zero(i_xyz) = .true.
1943 END IF
1944 END DO
1945 IF (all(der_j_zero) .AND. all(der_k_zero)) THEN
1946 DEALLOCATE (dijk_j, dijk_k)
1947 cycle
1948 END IF
1949 END IF
1950
1951 ALLOCATE (dijk_contr(nsgfj(jset), nsgfk(kset), nsgfi(iset)))
1952
1953 block_start_j = sgfj
1954 block_end_j = sgfj + nsgfj(jset) - 1
1955 block_start_k = sgfk
1956 block_end_k = sgfk + nsgfk(kset) - 1
1957 block_start_i = sgfi
1958 block_end_i = sgfi + nsgfi(iset) - 1
1959
1960 DO i_xyz = 1, 3
1961 IF (der_j_zero(i_xyz)) cycle
1962
1963 block_j_not_zero(i_xyz) = .true.
1964 CALL abc_contract_xsmm(dijk_contr, dijk_j(:, :, :, i_xyz), tspj(jset, jkind)%array, &
1965 spk(kset, kkind)%array, spi(iset, ikind)%array, &
1966 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
1967 nsgfi(iset), cpp_buffer, ccp_buffer)
1968
1969 block_t_j(block_start_j:block_end_j, &
1970 block_start_k:block_end_k, &
1971 block_start_i:block_end_i, i_xyz) = &
1972 block_t_j(block_start_j:block_end_j, &
1973 block_start_k:block_end_k, &
1974 block_start_i:block_end_i, i_xyz) + &
1975 dijk_contr(:, :, :)
1976
1977 END DO
1978
1979 DO i_xyz = 1, 3
1980 IF (der_k_zero(i_xyz)) cycle
1981
1982 block_k_not_zero(i_xyz) = .true.
1983 CALL abc_contract_xsmm(dijk_contr, dijk_k(:, :, :, i_xyz), tspj(jset, jkind)%array, &
1984 spk(kset, kkind)%array, spi(iset, ikind)%array, &
1985 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
1986 nsgfi(iset), cpp_buffer, ccp_buffer)
1987
1988 block_t_k(block_start_j:block_end_j, &
1989 block_start_k:block_end_k, &
1990 block_start_i:block_end_i, i_xyz) = &
1991 block_t_k(block_start_j:block_end_j, &
1992 block_start_k:block_end_k, &
1993 block_start_i:block_end_i, i_xyz) + &
1994 dijk_contr(:, :, :)
1995
1996 END DO
1997
1998 DEALLOCATE (dijk_j, dijk_k, dijk_contr)
1999 END IF ! number of triples > 0
2000 END DO
2001 END DO
2002 END DO
2003
2004 !We obtain the derivative wrt to first center using translational invariance
2005 DO i_xyz = 1, 3
2006 block_t_i(:, :, :, i_xyz) = -block_t_j(:, :, :, i_xyz) - block_t_k(:, :, :, i_xyz)
2007 END DO
2008
2009 !virial contribution coming from deriv wrt to first center
2010 DO i_xyz = 1, 3
2011 force = pref*sum(ablock(:, :, :)*block_t_i(:, :, :, i_xyz))
2012 CALL real_to_scaled(scoord, particle_set(iatom)%r, cell)
2013 DO j_xyz = 1, 3
2014!$OMP ATOMIC
2015 work_virial(i_xyz, j_xyz) = work_virial(i_xyz, j_xyz) + force*scoord(j_xyz)
2016 END DO
2017 END DO
2018
2019 !second center
2020 DO i_xyz = 1, 3
2021 force = pref*sum(ablock(:, :, :)*block_t_j(:, :, :, i_xyz))
2022 CALL real_to_scaled(scoord, particle_set(iatom)%r + rij, cell)
2023 DO j_xyz = 1, 3
2024!$OMP ATOMIC
2025 work_virial(i_xyz, j_xyz) = work_virial(i_xyz, j_xyz) + force*scoord(j_xyz)
2026 END DO
2027 END DO
2028
2029 !third center
2030 DO i_xyz = 1, 3
2031 force = pref*sum(ablock(:, :, :)*block_t_k(:, :, :, i_xyz))
2032 CALL real_to_scaled(scoord, particle_set(iatom)%r + rik, cell)
2033 DO j_xyz = 1, 3
2034!$OMP ATOMIC
2035 work_virial(i_xyz, j_xyz) = work_virial(i_xyz, j_xyz) + force*scoord(j_xyz)
2036 END DO
2037 END DO
2038
2039 DEALLOCATE (block_t_i, block_t_j, block_t_k)
2040 IF (PRESENT(der_eps)) THEN
2041 DEALLOCATE (max_contraction_i, max_contraction_j, max_contraction_k, ablock)
2042 END IF
2043 END DO
2044
2045 IF (ALLOCATED(ccp_buffer)) DEALLOCATE (ccp_buffer)
2046 IF (ALLOCATED(cpp_buffer)) DEALLOCATE (cpp_buffer)
2047
2048 CALL coulomb_integral_cleanup(integral_context)
2049 CALL neighbor_list_3c_iterator_destroy(nl_3c_iter)
2050!$OMP END PARALLEL
2051
2052 DO iset = 1, max_nset
2053 DO ibasis = 1, nbasis
2054 IF (ASSOCIATED(spi(iset, ibasis)%array)) DEALLOCATE (spi(iset, ibasis)%array)
2055 IF (ASSOCIATED(tspj(iset, ibasis)%array)) DEALLOCATE (tspj(iset, ibasis)%array)
2056 IF (ASSOCIATED(spk(iset, ibasis)%array)) DEALLOCATE (spk(iset, ibasis)%array)
2057 END DO
2058 END DO
2059
2060 DEALLOCATE (spi, tspj, spk)
2061
2062 CALL timestop(handle)
2063 END SUBROUTINE calc_3c_virial
2064
2065! **************************************************************************************************
2066!> \brief Build 3-center integral tensor
2067!> \param t3c empty DBCSR tensor
2068!> Should be of shape (1,1) if no kpoints are used and of shape (nimages, nimages)
2069!> if k-points are used
2070!> \param filter_eps Filter threshold for tensor blocks
2071!> \param qs_env ...
2072!> \param nl_3c 3-center neighborlist
2073!> \param basis_i ...
2074!> \param basis_j ...
2075!> \param basis_k ...
2076!> \param potential_parameter ...
2077!> \param int_eps neglect integrals smaller than int_eps
2078!> \param op_pos operator position.
2079!> 1: calculate (i|jk) integrals,
2080!> 2: calculate (ij|k) integrals
2081!> \param do_kpoints ...
2082!> this routine requires that libint has been static initialised somewhere else
2083!> \param do_hfx_kpoints ...
2084!> \param desymmetrize ...
2085!> \param cell_sym ...
2086!> \param bounds_i ...
2087!> \param bounds_j ...
2088!> \param bounds_k ...
2089!> \param RI_range ...
2090!> \param img_to_RI_cell ...
2091!> \param cell_to_index_ext ...
2092! **************************************************************************************************
2093 SUBROUTINE build_3c_integrals(t3c, filter_eps, qs_env, &
2094 nl_3c, basis_i, basis_j, basis_k, &
2095 potential_parameter, int_eps, &
2096 op_pos, do_kpoints, do_hfx_kpoints, desymmetrize, cell_sym, &
2097 bounds_i, bounds_j, bounds_k, &
2098 RI_range, img_to_RI_cell, cell_to_index_ext)
2099
2100 TYPE(dbt_type), DIMENSION(:, :), INTENT(INOUT) :: t3c
2101 REAL(kind=dp), INTENT(IN) :: filter_eps
2102 TYPE(qs_environment_type), POINTER :: qs_env
2103 TYPE(neighbor_list_3c_type), INTENT(INOUT) :: nl_3c
2104 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_i, basis_j, basis_k
2105 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
2106 REAL(kind=dp), INTENT(IN), OPTIONAL :: int_eps
2107 INTEGER, INTENT(IN), OPTIONAL :: op_pos
2108 LOGICAL, INTENT(IN), OPTIONAL :: do_kpoints, do_hfx_kpoints, &
2109 desymmetrize, cell_sym
2110 INTEGER, DIMENSION(2), INTENT(IN), OPTIONAL :: bounds_i, bounds_j, bounds_k
2111 REAL(dp), INTENT(IN), OPTIONAL :: ri_range
2112 INTEGER, DIMENSION(:), INTENT(IN), OPTIONAL :: img_to_ri_cell
2113 INTEGER, DIMENSION(:, :, :), OPTIONAL, POINTER :: cell_to_index_ext
2114
2115 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_3c_integrals'
2116
2117 INTEGER :: block_end_i, block_end_j, block_end_k, block_start_i, block_start_j, &
2118 block_start_k, eg_local, handle, handle2, i, iatom, ibasis, ikind, ilist, imax, iset, &
2119 jatom, jcell, jkind, jset, katom, kcell, kkind, kset, m_max, max_ncoj, max_nset, &
2120 max_nsgfi, maxli, maxlj, maxlk, natom, nbasis, ncell_ri, ncoi, ncoj, ncok, next_pair, &
2121 nimg, nseti, nsetj, nsetk, nsgf, op_ij, op_jk, op_pos_prv, sg_local, sgfi, sgfj, sgfk
2122 INTEGER, ALLOCATABLE, DIMENSION(:) :: img_to_ri_cell_prv
2123 INTEGER, DIMENSION(3) :: blk_idx, blk_size, cell_j, cell_k, &
2124 kp_index_lbounds, kp_index_ubounds, sp
2125 INTEGER, DIMENSION(:), POINTER :: lmax_i, lmax_j, lmax_k, lmin_i, lmin_j, &
2126 lmin_k, npgfi, npgfj, npgfk, nsgfi, &
2127 nsgfj, nsgfk
2128 INTEGER, DIMENSION(:, :), POINTER :: first_sgf_i, first_sgf_j, first_sgf_k
2129 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
2130 LOGICAL :: block_not_zero, cell_sym_prv, debug, &
2131 desymmetrize_prv, do_hfx_kpoints_prv, &
2132 do_kpoints_prv, found
2133 REAL(kind=dp) :: dij, dik, djk, dr_ij, dr_ik, dr_jk, kind_radius_i, kind_radius_j, &
2134 kind_radius_k, max_contraction_i, max_contraction_j, max_contraction_k, prefac, sijk_ext
2135 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: ccp_buffer, cpp_buffer
2136 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :), &
2137 TARGET :: max_sphi_norm_i, max_sphi_norm_j, &
2138 max_sphi_norm_k
2139 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: block_t, dummy_block_t, sijk, &
2140 sijk_contr, tmp_ijk
2141 REAL(kind=dp), DIMENSION(1, 1, 1) :: counter
2142 REAL(kind=dp), DIMENSION(3) :: ri, rij, rik, rj, rjk, rk
2143 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_i, set_radius_j, set_radius_k
2144 REAL(kind=dp), DIMENSION(:, :), POINTER :: rpgf_i, rpgf_j, rpgf_k, sphi_i, sphi_j, &
2145 sphi_k, zeti, zetj, zetk
2146 REAL(kind=dp), POINTER :: max_contr_i_ptr(:), max_contr_j_ptr(:), &
2147 max_contr_k_ptr(:)
2148 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
2149 TYPE(cell_type), POINTER :: cell
2150 TYPE(coulomb_integral_context_type) :: integral_context
2151 TYPE(cp_2d_r_p_type), DIMENSION(:, :), POINTER :: spi, spk, tspj
2152 TYPE(dbt_type) :: t_3c_tmp
2153 TYPE(dft_control_type), POINTER :: dft_control
2154 TYPE(gto_basis_set_type), POINTER :: basis_set
2155 TYPE(kpoint_type), POINTER :: kpoints
2156 TYPE(mp_para_env_type), POINTER :: para_env
2157 TYPE(neighbor_list_3c_iterator_type) :: nl_3c_iter
2158 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2159
2160 CALL timeset(routinen, handle)
2161
2162 debug = .false.
2163
2164 IF (PRESENT(do_kpoints)) THEN
2165 do_kpoints_prv = do_kpoints
2166 ELSE
2167 do_kpoints_prv = .false.
2168 END IF
2169
2170 IF (PRESENT(do_hfx_kpoints)) THEN
2171 do_hfx_kpoints_prv = do_hfx_kpoints
2172 ELSE
2173 do_hfx_kpoints_prv = .false.
2174 END IF
2175 IF (do_hfx_kpoints_prv) THEN
2176 cpassert(do_kpoints_prv)
2177 cpassert(PRESENT(ri_range))
2178 cpassert(PRESENT(img_to_ri_cell))
2179 END IF
2180
2181 IF (PRESENT(img_to_ri_cell)) THEN
2182 ALLOCATE (img_to_ri_cell_prv(SIZE(img_to_ri_cell)))
2183 img_to_ri_cell_prv(:) = img_to_ri_cell
2184 END IF
2185
2186 IF (PRESENT(desymmetrize)) THEN
2187 desymmetrize_prv = desymmetrize
2188 ELSE
2189 desymmetrize_prv = .true.
2190 END IF
2191
2192 IF (PRESENT(cell_sym)) THEN
2193 cell_sym_prv = cell_sym
2194 ELSE
2195 cell_sym_prv = .false.
2196 END IF
2197
2198 op_ij = do_potential_id; op_jk = do_potential_id
2199
2200 IF (PRESENT(op_pos)) THEN
2201 op_pos_prv = op_pos
2202 ELSE
2203 op_pos_prv = 1
2204 END IF
2205
2206 SELECT CASE (op_pos_prv)
2207 CASE (1)
2208 op_ij = potential_parameter%potential_type
2209 CASE (2)
2210 op_jk = potential_parameter%potential_type
2211 END SELECT
2212
2213 dr_ij = 0.0_dp; dr_jk = 0.0_dp; dr_ik = 0.0_dp
2214
2215 IF (op_ij == do_potential_truncated .OR. op_ij == do_potential_short &
2216 .OR. op_ij == do_potential_mix_cl_trunc) THEN
2217 dr_ij = potential_parameter%cutoff_radius*cutoff_screen_factor
2218 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
2219 ELSE IF (op_ij == do_potential_coulomb) THEN
2220 dr_ij = 1000000.0_dp
2221 dr_ik = 1000000.0_dp
2222 END IF
2223
2224 IF (op_jk == do_potential_truncated .OR. op_jk == do_potential_short &
2225 .OR. op_jk == do_potential_mix_cl_trunc) THEN
2226 dr_jk = potential_parameter%cutoff_radius*cutoff_screen_factor
2227 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
2228 ELSE IF (op_jk == do_potential_coulomb) THEN
2229 dr_jk = 1000000.0_dp
2230 dr_ik = 1000000.0_dp
2231 END IF
2232
2233 NULLIFY (qs_kind_set, atomic_kind_set)
2234
2235 ! get stuff
2236 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, cell=cell, &
2237 natom=natom, dft_control=dft_control, para_env=para_env)
2238
2239 IF (do_kpoints_prv) THEN
2240 IF (PRESENT(cell_to_index_ext)) THEN
2241 cell_to_index => cell_to_index_ext
2242 nimg = maxval(cell_to_index)
2243 ELSE
2244 CALL get_qs_env(qs_env, kpoints=kpoints)
2245 CALL get_kpoint_info(kpoints, cell_to_index=cell_to_index)
2246 nimg = dft_control%nimages
2247 END IF
2248 ncell_ri = nimg
2249 IF (do_hfx_kpoints_prv) THEN
2250 nimg = SIZE(t3c, 1)
2251 ncell_ri = SIZE(t3c, 2)
2252 END IF
2253 ELSE
2254 nimg = 1
2255 ncell_ri = 1
2256 END IF
2257
2258 CALL alloc_block_3c(t3c, nl_3c, basis_i, basis_j, basis_k, qs_env, potential_parameter, &
2259 op_pos=op_pos_prv, do_kpoints=do_kpoints, do_hfx_kpoints=do_hfx_kpoints, &
2260 bounds_i=bounds_i, bounds_j=bounds_j, bounds_k=bounds_k, &
2261 ri_range=ri_range, img_to_ri_cell=img_to_ri_cell, cell_sym=cell_sym_prv, &
2262 cell_to_index=cell_to_index)
2263
2264 IF (do_hfx_kpoints_prv) THEN
2265 cpassert(op_pos_prv == 2)
2266 cpassert(.NOT. desymmetrize_prv)
2267 ELSE IF (do_kpoints_prv) THEN
2268 cpassert(all(shape(t3c) == [nimg, ncell_ri]))
2269 END IF
2270
2271 !Need the max l for each basis for libint and max nset, nco and nsgf for LIBXSMM contraction
2272 nbasis = SIZE(basis_i)
2273 max_nsgfi = 0
2274 max_nset = 0
2275 maxli = 0
2276 DO ibasis = 1, nbasis
2277 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=imax, &
2278 nset=iset, nsgf_set=nsgfi, npgf=npgfi)
2279 maxli = max(maxli, imax)
2280 max_nset = max(max_nset, iset)
2281 max_nsgfi = max(max_nsgfi, maxval(nsgfi))
2282 END DO
2283 max_ncoj = 0
2284 maxlj = 0
2285 DO ibasis = 1, nbasis
2286 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=imax, &
2287 nset=jset, nsgf_set=nsgfj, npgf=npgfj)
2288 maxlj = max(maxlj, imax)
2289 max_nset = max(max_nset, jset)
2290 max_ncoj = max(max_ncoj, maxval(npgfj)*ncoset(maxlj))
2291 END DO
2292 maxlk = 0
2293 DO ibasis = 1, nbasis
2294 CALL get_gto_basis_set(gto_basis_set=basis_k(ibasis)%gto_basis_set, maxl=imax, &
2295 nset=kset, nsgf_set=nsgfk, npgf=npgfk)
2296 maxlk = max(maxlk, imax)
2297 max_nset = max(max_nset, kset)
2298 END DO
2299 m_max = maxli + maxlj + maxlk
2300
2301 !To minimize expensive memory ops and generally optimize contraction, pre-allocate
2302 !contiguous sphi arrays (and transposed in the case of sphi_i)
2303
2304 NULLIFY (tspj, spi, spk)
2305 NULLIFY (max_contr_i_ptr, max_contr_j_ptr, max_contr_k_ptr)
2306 ALLOCATE (spi(max_nset, nbasis), tspj(max_nset, nbasis), spk(max_nset, nbasis))
2307
2308 DO ibasis = 1, nbasis
2309 DO iset = 1, max_nset
2310 NULLIFY (spi(iset, ibasis)%array)
2311 NULLIFY (tspj(iset, ibasis)%array)
2312
2313 NULLIFY (spk(iset, ibasis)%array)
2314 END DO
2315 END DO
2316
2317 IF (PRESENT(int_eps)) THEN
2318 ALLOCATE (max_sphi_norm_i(max_nset, nbasis), source=0.0_dp)
2319 ALLOCATE (max_sphi_norm_j(max_nset, nbasis), source=0.0_dp)
2320 ALLOCATE (max_sphi_norm_k(max_nset, nbasis), source=0.0_dp)
2321 END IF
2322
2323 DO ilist = 1, 3
2324 DO ibasis = 1, nbasis
2325 SELECT CASE (ilist)
2326 CASE (1)
2327 basis_set => basis_i(ibasis)%gto_basis_set
2328 CASE (2)
2329 basis_set => basis_j(ibasis)%gto_basis_set
2330 CASE (3)
2331 basis_set => basis_k(ibasis)%gto_basis_set
2332 END SELECT
2333
2334 DO iset = 1, basis_set%nset
2335 nsgf = basis_set%nsgf_set(iset)
2336 ncoi = basis_set%npgf(iset)*ncoset(basis_set%lmax(iset))
2337 sg_local = basis_set%first_sgf(1, iset)
2338 eg_local = sg_local + nsgf - 1
2339
2340 SELECT CASE (ilist)
2341 CASE (1)
2342 ALLOCATE (spi(iset, ibasis)%array(ncoi, nsgf))
2343 IF (ncoi > 0 .AND. nsgf > 0) THEN
2344 spi(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sg_local:eg_local)
2345 ELSE
2346 spi(iset, ibasis)%array(:, :) = 0.0_dp
2347 END IF
2348 IF (PRESENT(int_eps)) THEN
2349 IF (ncoi > 0 .AND. nsgf > 0) THEN
2350 max_sphi_norm_i(iset, ibasis) = maxval(sum(abs(basis_set%sphi(1:ncoi, sg_local:eg_local)), &
2351 dim=1))
2352 ELSE
2353 max_sphi_norm_i(iset, ibasis) = 0.0_dp
2354 END IF
2355 END IF
2356 CASE (2)
2357 ALLOCATE (tspj(iset, ibasis)%array(nsgf, ncoi))
2358 IF (ncoi > 0 .AND. nsgf > 0) THEN
2359 tspj(iset, ibasis)%array(:, :) = transpose(basis_set%sphi(1:ncoi, sg_local:eg_local))
2360 ELSE
2361 tspj(iset, ibasis)%array(:, :) = 0.0_dp
2362 END IF
2363 IF (PRESENT(int_eps)) THEN
2364 IF (ncoi > 0 .AND. nsgf > 0) THEN
2365 max_sphi_norm_j(iset, ibasis) = maxval(sum(abs(basis_set%sphi(1:ncoi, sg_local:eg_local)), &
2366 dim=1))
2367 ELSE
2368 max_sphi_norm_j(iset, ibasis) = 0.0_dp
2369 END IF
2370 END IF
2371 CASE (3)
2372 ALLOCATE (spk(iset, ibasis)%array(ncoi, nsgf))
2373 IF (ncoi > 0 .AND. nsgf > 0) THEN
2374 spk(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sg_local:eg_local)
2375 ELSE
2376 spk(iset, ibasis)%array(:, :) = 0.0_dp
2377 END IF
2378 IF (PRESENT(int_eps)) THEN
2379 IF (ncoi > 0 .AND. nsgf > 0) THEN
2380 max_sphi_norm_k(iset, ibasis) = maxval(sum(abs(basis_set%sphi(1:ncoi, sg_local:eg_local)), &
2381 dim=1))
2382 ELSE
2383 max_sphi_norm_k(iset, ibasis) = 0.0_dp
2384 END IF
2385 END IF
2386 END SELECT
2387
2388 END DO !iset
2389 END DO !ibasis
2390 END DO !ilist
2391
2392 CALL r12_fundamentals_init(m_max, potential_parameter, para_env)
2393
2394 IF (do_kpoints_prv) THEN
2395 kp_index_lbounds = lbound(cell_to_index)
2396 kp_index_ubounds = ubound(cell_to_index)
2397 END IF
2398
2399 counter = 1.0_dp
2400 next_pair = 0
2401
2402!$OMP PARALLEL DEFAULT(NONE) &
2403!$OMP SHARED (next_pair,do_kpoints_prv,kp_index_lbounds,kp_index_ubounds,maxli,maxlk,maxlj,bounds_i,&
2404!$OMP bounds_j,bounds_k,nimg,basis_i,basis_j,basis_k,dr_ij,dr_jk,dr_ik,ncoset,&
2405!$OMP potential_parameter,int_eps,t3c,tspj,spi,spk,debug,cell_to_index,&
2406!$OMP natom,nl_3c,cell,op_pos_prv,do_hfx_kpoints_prv,RI_range,ncell_RI, &
2407!$OMP img_to_RI_cell_prv, cell_sym_prv, max_sphi_norm_i, max_sphi_norm_j, max_sphi_norm_k) &
2408!$OMP PRIVATE (integral_context,nl_3c_iter,ikind,jkind,kkind,iatom,jatom,katom,rij,rjk,rik,cell_j,cell_k,&
2409!$OMP prefac,jcell,kcell,first_sgf_i,lmax_i,lmin_i,npgfi,nseti,nsgfi,rpgf_i,set_radius_i,&
2410!$OMP sphi_i,zeti,kind_radius_i,first_sgf_j,lmax_j,lmin_j,npgfj,nsetj,nsgfj,rpgf_j,&
2411!$OMP set_radius_j,sphi_j,zetj,kind_radius_j,first_sgf_k,lmax_k,lmin_k,npgfk,nsetk,nsgfk,&
2412!$OMP rpgf_k,set_radius_k,sphi_k,zetk,kind_radius_k,djk,dij,dik,ncoi,ncoj,ncok,sgfi,sgfj,&
2413!$OMP sgfk,sijk,ri,rj,rk,sijk_ext,block_not_zero,max_contraction_i,max_contraction_j,&
2414!$OMP max_contraction_k,iset,jset,kset,block_t,blk_size,sijk_contr,cpp_buffer,ccp_buffer,&
2415!$OMP block_start_j,block_end_j,block_start_k,block_end_k,block_start_i,block_end_i,found,&
2416!$OMP dummy_block_t,sp,handle2,tmp_ijk,i,blk_idx,&
2417!$OMP max_contr_i_ptr, max_contr_j_ptr, max_contr_k_ptr)
2418
2419 integral_context = coulomb_integral_context_type()
2420 CALL coulomb_integral_init(integral_context, max_am_3c=max(maxli, maxlj, maxlk), &
2421 derivative_order=0, library=library_libint)
2422 CALL neighbor_list_3c_iterator_create(nl_3c_iter, nl_3c)
2423
2424 ! the threads take the (i,j) pairs in turn (dynamic): a static split of the atoms leaves
2425 ! threads idle when the triples per atom vary or are not local
2426 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bounds_j, bounds_k)
2427
2428 DO WHILE (neighbor_list_3c_iterate(nl_3c_iter, next_pair) == 0)
2429 CALL get_3c_iterator_info(nl_3c_iter, ikind=ikind, jkind=jkind, kkind=kkind, &
2430 iatom=iatom, jatom=jatom, katom=katom, &
2431 rij=rij, rjk=rjk, rik=rik, cell_j=cell_j, cell_k=cell_k)
2432
2433 djk = norm2(rjk)
2434 dij = norm2(rij)
2435 dik = norm2(rik)
2436
2437 IF (nl_3c%sym == symmetric_jk) THEN
2438 IF (jatom == katom) THEN
2439 ! factor 0.5 due to double-counting of diagonal blocks
2440 ! (we desymmetrize by adding transpose)
2441 prefac = 0.5_dp
2442 ELSE
2443 prefac = 1.0_dp
2444 END IF
2445 ELSE IF (nl_3c%sym == symmetric_ij) THEN
2446 IF (iatom == jatom) THEN
2447 ! factor 0.5 due to double-counting of diagonal blocks
2448 ! (we desymmetrize by adding transpose)
2449 prefac = 0.5_dp
2450 ELSE
2451 prefac = 1.0_dp
2452 END IF
2453 ELSE
2454 prefac = 1.0_dp
2455 END IF
2456 IF (do_kpoints_prv) prefac = 1.0_dp
2457
2458 IF (do_kpoints_prv) THEN
2459 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
2460 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
2461
2462 jcell = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
2463 IF (jcell > nimg .OR. jcell < 1) cycle
2464
2465 IF (any([cell_k(1), cell_k(2), cell_k(3)] < kp_index_lbounds) .OR. &
2466 any([cell_k(1), cell_k(2), cell_k(3)] > kp_index_ubounds)) cycle
2467
2468 kcell = cell_to_index(cell_k(1), cell_k(2), cell_k(3))
2469 IF (kcell > nimg .OR. kcell < 1) cycle
2470 !In case of HFX k-points, we only consider P^k if d_ik <= RI_range
2471 IF (do_hfx_kpoints_prv) THEN
2472 IF (dik > ri_range) cycle
2473 kcell = img_to_ri_cell_prv(kcell)
2474 END IF
2475 ELSE
2476 jcell = 1; kcell = 1
2477 END IF
2478
2479 IF (cell_sym_prv .AND. jcell < kcell) cycle
2480
2481 blk_idx = [iatom, jatom, katom]
2482 IF (do_hfx_kpoints_prv) THEN
2483 blk_idx(3) = (kcell - 1)*natom + katom
2484 kcell = 1
2485 END IF
2486
2487 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
2488 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
2489 sphi=sphi_i, zet=zeti, kind_radius=kind_radius_i)
2490 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
2491 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
2492 sphi=sphi_j, zet=zetj, kind_radius=kind_radius_j)
2493 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
2494
2495 CALL get_gto_basis_set(basis_k(kkind)%gto_basis_set, first_sgf=first_sgf_k, lmax=lmax_k, lmin=lmin_k, &
2496 npgf=npgfk, nset=nsetk, nsgf_set=nsgfk, pgf_radius=rpgf_k, set_radius=set_radius_k, &
2497 sphi=sphi_k, zet=zetk, kind_radius=kind_radius_k)
2498 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
2499 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
2500
2501 IF (PRESENT(int_eps)) THEN
2502 NULLIFY (max_contr_i_ptr, max_contr_j_ptr, max_contr_k_ptr)
2503 IF (nseti > 0) max_contr_i_ptr => max_sphi_norm_i(1:nseti, ikind)
2504 IF (nsetj > 0) max_contr_j_ptr => max_sphi_norm_j(1:nsetj, jkind)
2505 IF (nsetk > 0) max_contr_k_ptr => max_sphi_norm_k(1:nsetk, kkind)
2506 END IF
2507
2508 CALL dbt_blk_sizes(t3c(jcell, kcell), blk_idx, blk_size)
2509
2510 ALLOCATE (block_t(blk_size(2), blk_size(3), blk_size(1)), source=0.0_dp)
2511
2512 block_not_zero = .false.
2513 DO iset = 1, nseti
2514
2515 sgfi = first_sgf_i(1, iset)
2516 IF (PRESENT(int_eps)) max_contraction_i = max_contr_i_ptr(iset)
2517
2518 DO jset = 1, nsetj
2519 IF (set_radius_j(jset) + set_radius_i(iset) + dr_ij < dij) cycle
2520
2521 DO kset = 1, nsetk
2522 IF (set_radius_j(jset) + set_radius_k(kset) + dr_jk < djk) cycle
2523 IF (set_radius_k(kset) + set_radius_i(iset) + dr_ik < dik) cycle
2524
2525 ncoi = npgfi(iset)*ncoset(lmax_i(iset))
2526 ncoj = npgfj(jset)*ncoset(lmax_j(jset))
2527 ncok = npgfk(kset)*ncoset(lmax_k(kset))
2528
2529 !ensure non-zero number of triples below
2530 IF (ncoj*ncok*ncoi == 0) cycle
2531
2532 !need positions for libint. Only relative positions are needed => set ri to 0.0
2533 ri = 0.0_dp
2534 rj = rij ! ri + rij
2535 rk = rik ! ri + rik
2536
2537 ALLOCATE (sijk(ncoj, ncok, ncoi))
2538 IF (op_pos_prv == 1) THEN
2539 sijk(:, :, :) = 0.0_dp
2540 CALL compute_coulomb_3c(integral_context, lmin_j(jset), lmax_j(jset), lmin_k(kset), &
2541 lmax_k(kset), lmin_i(iset), lmax_i(iset), npgfj(jset), npgfk(kset), npgfi(iset), &
2542 zetj(:, jset), zetk(:, kset), zeti(:, iset), rpgf_j(:, jset), rpgf_k(:, kset), &
2543 rpgf_i(:, iset), rj, rk, ri, sijk, potential_parameter, dab=djk, dac=dij, dbc=dik, &
2544 int_abc_ext=sijk_ext)
2545 ELSE
2546 ALLOCATE (tmp_ijk(ncoi, ncoj, ncok), source=0.0_dp)
2547 CALL compute_coulomb_3c(integral_context, lmin_i(iset), lmax_i(iset), lmin_j(jset), &
2548 lmax_j(jset), lmin_k(kset), lmax_k(kset), npgfi(iset), npgfj(jset), npgfk(kset), &
2549 zeti(:, iset), zetj(:, jset), zetk(:, kset), rpgf_i(:, iset), rpgf_j(:, jset), &
2550 rpgf_k(:, kset), ri, rj, rk, tmp_ijk, potential_parameter, dab=dij, dac=dik, dbc=djk, &
2551 int_abc_ext=sijk_ext)
2552
2553 !F08: sijk = RESHAPE(tmp_ijk, [ncoj, ncok, ncoi], ORDER=[2, 3, 1]) with sijk not allocated
2554 DO i = 1, ncoi !TODO: revise/check for efficiency
2555 sijk(:, :, i) = tmp_ijk(i, :, :)
2556 END DO
2557 DEALLOCATE (tmp_ijk)
2558 END IF
2559
2560 IF (PRESENT(int_eps)) THEN
2561 max_contraction_j = max_contr_j_ptr(jset)
2562 max_contraction_k = max_contr_k_ptr(kset)
2563 IF (int_eps > sijk_ext*(max_contraction_i* &
2564 max_contraction_j* &
2565 max_contraction_k)) THEN
2566 DEALLOCATE (sijk)
2567 cycle
2568 END IF
2569 END IF
2570
2571 block_not_zero = .true.
2572 ALLOCATE (sijk_contr(nsgfj(jset), nsgfk(kset), nsgfi(iset)))
2573 CALL abc_contract_xsmm(sijk_contr, sijk, tspj(jset, jkind)%array, &
2574 spk(kset, kkind)%array, spi(iset, ikind)%array, &
2575 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
2576 nsgfi(iset), cpp_buffer, ccp_buffer, prefac)
2577 DEALLOCATE (sijk)
2578
2579 sgfj = first_sgf_j(1, jset)
2580 sgfk = first_sgf_k(1, kset)
2581
2582 block_start_j = sgfj
2583 block_end_j = sgfj + nsgfj(jset) - 1
2584 block_start_k = sgfk
2585 block_end_k = sgfk + nsgfk(kset) - 1
2586 block_start_i = sgfi
2587 block_end_i = sgfi + nsgfi(iset) - 1
2588
2589 block_t(block_start_j:block_end_j, &
2590 block_start_k:block_end_k, &
2591 block_start_i:block_end_i) = &
2592 block_t(block_start_j:block_end_j, &
2593 block_start_k:block_end_k, &
2594 block_start_i:block_end_i) + &
2595 sijk_contr(:, :, :)
2596 DEALLOCATE (sijk_contr)
2597
2598 END DO
2599
2600 END DO
2601
2602 END DO
2603
2604 IF (block_not_zero) THEN
2605!$OMP CRITICAL(qs_tensors_t3c)
2606 CALL timeset(routinen//"_put_dbcsr", handle2)
2607 IF (debug) THEN
2608 CALL dbt_get_block(t3c(jcell, kcell), blk_idx, dummy_block_t, found=found)
2609 cpassert(found)
2610 END IF
2611
2612 sp = shape(block_t)
2613 sp([2, 3, 1]) = sp ! sp = sp([2, 3, 1]) performs worse
2614
2615 CALL dbt_put_block(t3c(jcell, kcell), blk_idx, sp, &
2616 reshape(block_t, shape=sp, order=[2, 3, 1]), summation=.true.)
2617
2618 CALL timestop(handle2)
2619!$OMP END CRITICAL(qs_tensors_t3c)
2620 END IF
2621
2622 DEALLOCATE (block_t)
2623 END DO
2624
2625 IF (ALLOCATED(ccp_buffer)) DEALLOCATE (ccp_buffer)
2626 IF (ALLOCATED(cpp_buffer)) DEALLOCATE (cpp_buffer)
2627
2628 CALL coulomb_integral_cleanup(integral_context)
2629 CALL neighbor_list_3c_iterator_destroy(nl_3c_iter)
2630!$OMP END PARALLEL
2631
2632 !TODO: deal with hfx_kpoints, because should not filter by 1/2
2633 IF (nl_3c%sym == symmetric_jk .OR. do_kpoints_prv) THEN
2634
2635 IF (.NOT. do_hfx_kpoints_prv) THEN
2636 DO kcell = 1, nimg
2637 DO jcell = 1, nimg
2638 ! need half of filter eps because afterwards we add transposed tensor
2639 CALL dbt_filter(t3c(jcell, kcell), filter_eps/2)
2640 END DO
2641 END DO
2642 ELSE
2643 DO kcell = 1, ncell_ri
2644 DO jcell = 1, nimg
2645 CALL dbt_filter(t3c(jcell, kcell), filter_eps)
2646 END DO
2647 END DO
2648 END IF
2649
2650 IF (desymmetrize_prv) THEN
2651 ! add transposed of overlap integrals
2652 CALL dbt_create(t3c(1, 1), t_3c_tmp)
2653 DO kcell = 1, jcell
2654 DO jcell = 1, nimg
2655 CALL dbt_copy(t3c(jcell, kcell), t_3c_tmp)
2656 CALL dbt_copy(t_3c_tmp, t3c(kcell, jcell), order=[1, 3, 2], summation=.true., move_data=.true.)
2657 CALL dbt_filter(t3c(kcell, jcell), filter_eps)
2658 END DO
2659 END DO
2660 DO kcell = jcell + 1, nimg
2661 DO jcell = 1, nimg
2662 CALL dbt_copy(t3c(jcell, kcell), t_3c_tmp)
2663 CALL dbt_copy(t_3c_tmp, t3c(kcell, jcell), order=[1, 3, 2], summation=.false., move_data=.true.)
2664 CALL dbt_filter(t3c(kcell, jcell), filter_eps)
2665 END DO
2666 END DO
2667 CALL dbt_destroy(t_3c_tmp)
2668 END IF
2669 ELSE IF (nl_3c%sym == symmetric_ij) THEN
2670 DO kcell = 1, nimg
2671 DO jcell = 1, nimg
2672 CALL dbt_filter(t3c(jcell, kcell), filter_eps/2)
2673 END DO
2674 END DO
2675 ELSE IF (nl_3c%sym == symmetric_none) THEN
2676 DO kcell = 1, nimg
2677 DO jcell = 1, nimg
2678 CALL dbt_filter(t3c(jcell, kcell), filter_eps)
2679 END DO
2680 END DO
2681 ELSE
2682 cpabort("requested symmetric case not implemented")
2683 END IF
2684
2685 IF (ALLOCATED(max_sphi_norm_i)) DEALLOCATE (max_sphi_norm_i)
2686 IF (ALLOCATED(max_sphi_norm_j)) DEALLOCATE (max_sphi_norm_j)
2687 IF (ALLOCATED(max_sphi_norm_k)) DEALLOCATE (max_sphi_norm_k)
2688
2689 DO ibasis = 1, nbasis
2690 DO iset = 1, max_nset
2691 IF (ASSOCIATED(spi(iset, ibasis)%array)) DEALLOCATE (spi(iset, ibasis)%array)
2692 IF (ASSOCIATED(tspj(iset, ibasis)%array)) DEALLOCATE (tspj(iset, ibasis)%array)
2693 IF (ASSOCIATED(spk(iset, ibasis)%array)) DEALLOCATE (spk(iset, ibasis)%array)
2694 END DO
2695 END DO
2696 DEALLOCATE (spi, tspj, spk)
2697
2698 CALL timestop(handle)
2699 END SUBROUTINE build_3c_integrals
2700
2701! **************************************************************************************************
2702!> \brief Calculates the derivatives of 2-center integrals, wrt to the first center
2703!> \param t2c_der ...
2704!> this routine requires that libint has been static initialised somewhere else
2705!> \param filter_eps Filter threshold for matrix blocks
2706!> \param qs_env ...
2707!> \param nl_2c 2-center neighborlist
2708!> \param basis_i ...
2709!> \param basis_j ...
2710!> \param potential_parameter ...
2711!> \param do_kpoints ...
2712! **************************************************************************************************
2713 SUBROUTINE build_2c_derivatives(t2c_der, filter_eps, qs_env, &
2714 nl_2c, basis_i, basis_j, &
2715 potential_parameter, do_kpoints)
2716
2717 TYPE(dbcsr_type), DIMENSION(:, :), INTENT(INOUT) :: t2c_der
2718 REAL(kind=dp), INTENT(IN) :: filter_eps
2719 TYPE(qs_environment_type), POINTER :: qs_env
2720 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2721 POINTER :: nl_2c
2722 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_i, basis_j
2723 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
2724 LOGICAL, INTENT(IN), OPTIONAL :: do_kpoints
2725
2726 CHARACTER(len=*), PARAMETER :: routinen = 'build_2c_derivatives'
2727
2728 INTEGER :: handle, i_xyz, iatom, ibasis, icol, ikind, imax, img, irow, iset, jatom, jkind, &
2729 jset, m_max, maxli, maxlj, natom, ncoi, ncoj, nimg, nseti, nsetj, op_prv, sgfi, sgfj
2730 INTEGER, DIMENSION(3) :: cell_j, kp_index_lbounds, &
2731 kp_index_ubounds
2732 INTEGER, DIMENSION(:), POINTER :: lmax_i, lmax_j, lmin_i, lmin_j, npgfi, &
2733 npgfj, nsgfi, nsgfj
2734 INTEGER, DIMENSION(:, :), POINTER :: first_sgf_i, first_sgf_j
2735 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
2736 LOGICAL :: do_kpoints_prv, do_symmetric, found, &
2737 trans
2738 REAL(kind=dp) :: dab
2739 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: dij_contr, dij_rs
2740 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: dij
2741 REAL(kind=dp), DIMENSION(3) :: ri, rij, rj
2742 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_i, set_radius_j
2743 REAL(kind=dp), DIMENSION(:, :), POINTER :: rpgf_i, rpgf_j, sphi_i, sphi_j, zeti, &
2744 zetj
2745 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
2746 TYPE(block_p_type), DIMENSION(3) :: block_t
2747 TYPE(coulomb_integral_context_type) :: integral_context
2748 TYPE(dft_control_type), POINTER :: dft_control
2749 TYPE(kpoint_type), POINTER :: kpoints
2750 TYPE(mp_para_env_type), POINTER :: para_env
2752 DIMENSION(:), POINTER :: nl_iterator
2753 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2754
2755 CALL timeset(routinen, handle)
2756
2757 IF (PRESENT(do_kpoints)) THEN
2758 do_kpoints_prv = do_kpoints
2759 ELSE
2760 do_kpoints_prv = .false.
2761 END IF
2762
2763 op_prv = potential_parameter%potential_type
2764
2765 NULLIFY (qs_kind_set, atomic_kind_set, block_t(1)%block, block_t(2)%block, block_t(3)%block, cell_to_index)
2766
2767 ! get stuff
2768 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
2769 natom=natom, kpoints=kpoints, dft_control=dft_control, para_env=para_env)
2770
2771 IF (do_kpoints_prv) THEN
2772 nimg = SIZE(t2c_der, 1)
2773 CALL get_kpoint_info(kpoints, cell_to_index=cell_to_index)
2774 kp_index_lbounds = lbound(cell_to_index)
2775 kp_index_ubounds = ubound(cell_to_index)
2776 ELSE
2777 nimg = 1
2778 END IF
2779
2780 ! check for symmetry
2781 cpassert(SIZE(nl_2c) > 0)
2782 CALL get_neighbor_list_set_p(neighbor_list_sets=nl_2c, symmetric=do_symmetric)
2783
2784 IF (do_symmetric) THEN
2785 DO img = 1, nimg
2786 !Derivtive matrix is assymetric
2787 DO i_xyz = 1, 3
2788 cpassert(dbcsr_get_matrix_type(t2c_der(img, i_xyz)) == dbcsr_type_antisymmetric)
2789 END DO
2790 END DO
2791 ELSE
2792 DO img = 1, nimg
2793 DO i_xyz = 1, 3
2794 cpassert(dbcsr_get_matrix_type(t2c_der(img, i_xyz)) == dbcsr_type_no_symmetry)
2795 END DO
2796 END DO
2797 END IF
2798
2799 DO img = 1, nimg
2800 DO i_xyz = 1, 3
2801 CALL cp_dbcsr_alloc_block_from_nbl(t2c_der(img, i_xyz), nl_2c)
2802 END DO
2803 END DO
2804
2805 maxli = 0
2806 DO ibasis = 1, SIZE(basis_i)
2807 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=imax)
2808 maxli = max(maxli, imax)
2809 END DO
2810 maxlj = 0
2811 DO ibasis = 1, SIZE(basis_j)
2812 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=imax)
2813 maxlj = max(maxlj, imax)
2814 END DO
2815
2816 m_max = maxli + maxlj + 1
2817
2818 CALL r12_fundamentals_init(m_max, potential_parameter, para_env)
2819
2820 CALL coulomb_integral_init(integral_context, max_am_2c=max(maxli, maxlj), &
2821 derivative_order=1, library=library_libint)
2822
2823 CALL neighbor_list_iterator_create(nl_iterator, nl_2c)
2824 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
2825
2826 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
2827 iatom=iatom, jatom=jatom, r=rij, cell=cell_j)
2828 IF (do_kpoints_prv) THEN
2829 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
2830 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
2831 img = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
2832 IF (img > nimg .OR. img < 1) cycle
2833 ELSE
2834 img = 1
2835 END IF
2836
2837 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
2838 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
2839 sphi=sphi_i, zet=zeti)
2840
2841 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
2842 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
2843 sphi=sphi_j, zet=zetj)
2844
2845 IF (do_symmetric) THEN
2846 IF (iatom <= jatom) THEN
2847 irow = iatom
2848 icol = jatom
2849 ELSE
2850 irow = jatom
2851 icol = iatom
2852 END IF
2853 ELSE
2854 irow = iatom
2855 icol = jatom
2856 END IF
2857
2858 dab = norm2(rij)
2859 trans = do_symmetric .AND. (iatom > jatom)
2860
2861 DO i_xyz = 1, 3
2862 CALL dbcsr_get_block_p(matrix=t2c_der(img, i_xyz), &
2863 row=irow, col=icol, block=block_t(i_xyz)%block, found=found)
2864 cpassert(found)
2865 END DO
2866
2867 DO iset = 1, nseti
2868
2869 ncoi = npgfi(iset)*ncoset(lmax_i(iset))
2870 sgfi = first_sgf_i(1, iset)
2871
2872 DO jset = 1, nsetj
2873
2874 ncoj = npgfj(jset)*ncoset(lmax_j(jset))
2875 sgfj = first_sgf_j(1, jset)
2876
2877 IF (ncoi*ncoj > 0) THEN
2878 ALLOCATE (dij_contr(nsgfi(iset), nsgfj(jset)))
2879 ALLOCATE (dij(ncoi, ncoj, 3), source=0.0_dp)
2880
2881 ri = 0.0_dp
2882 rj = rij
2883
2884 CALL compute_coulomb_2c_derivs(dij, lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), &
2885 rpgf_i(:, iset), ri, lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), &
2886 rpgf_j(:, jset), rj, dab, integral_context, potential_parameter)
2887
2888 DO i_xyz = 1, 3
2889
2890 dij_contr(:, :) = 0.0_dp
2891 CALL ab_contract(dij_contr, dij(:, :, i_xyz), &
2892 sphi_i(:, sgfi:), sphi_j(:, sgfj:), &
2893 ncoi, ncoj, nsgfi(iset), nsgfj(jset))
2894
2895 IF (trans) THEN
2896 !if transpose, then -1 factor for antisymmetry
2897 ALLOCATE (dij_rs(nsgfj(jset), nsgfi(iset)))
2898 dij_rs(:, :) = -1.0_dp*transpose(dij_contr)
2899 ELSE
2900 ALLOCATE (dij_rs(nsgfi(iset), nsgfj(jset)))
2901 dij_rs(:, :) = dij_contr
2902 END IF
2903
2904 CALL block_add("IN", dij_rs, &
2905 nsgfi(iset), nsgfj(jset), block_t(i_xyz)%block, &
2906 sgfi, sgfj, trans=trans)
2907 DEALLOCATE (dij_rs)
2908 END DO
2909
2910 DEALLOCATE (dij, dij_contr)
2911 END IF
2912 END DO
2913 END DO
2914 END DO
2915
2916 CALL coulomb_integral_cleanup(integral_context)
2917 CALL neighbor_list_iterator_release(nl_iterator)
2918
2919 DO img = 1, nimg
2920 DO i_xyz = 1, 3
2921 CALL dbcsr_finalize(t2c_der(img, i_xyz))
2922 CALL dbcsr_filter(t2c_der(img, i_xyz), filter_eps)
2923 END DO
2924 END DO
2925
2926 CALL timestop(handle)
2927
2928 END SUBROUTINE build_2c_derivatives
2929
2930! **************************************************************************************************
2931!> \brief Calculates the virial coming from 2c derivatives on the fly
2932!> \param work_virial ...
2933!> \param t2c_trace the 2c tensor that we should trace with the derivatives
2934!> \param pref ...
2935!> \param qs_env ...
2936!> \param nl_2c 2-center neighborlist. Assumed to have compatible distribution with t2c_trace,
2937!> and to be non-symmetric
2938!> \param basis_i ...
2939!> \param basis_j ...
2940!> \param potential_parameter ...
2941! **************************************************************************************************
2942 SUBROUTINE calc_2c_virial(work_virial, t2c_trace, pref, qs_env, nl_2c, basis_i, basis_j, potential_parameter)
2943 REAL(dp), DIMENSION(3, 3), INTENT(INOUT) :: work_virial
2944 TYPE(dbcsr_type), INTENT(INOUT) :: t2c_trace
2945 REAL(kind=dp), INTENT(IN) :: pref
2946 TYPE(qs_environment_type), POINTER :: qs_env
2947 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2948 POINTER :: nl_2c
2949 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_i, basis_j
2950 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
2951
2952 CHARACTER(len=*), PARAMETER :: routinen = 'calc_2c_virial'
2953
2954 INTEGER :: handle, i_xyz, iatom, ibasis, ikind, imax, iset, j_xyz, jatom, jkind, jset, &
2955 m_max, maxli, maxlj, natom, ncoi, ncoj, nseti, nsetj, op_prv, sgfi, sgfj
2956 INTEGER, DIMENSION(:), POINTER :: lmax_i, lmax_j, lmin_i, lmin_j, npgfi, &
2957 npgfj, nsgfi, nsgfj
2958 INTEGER, DIMENSION(:, :), POINTER :: first_sgf_i, first_sgf_j
2959 LOGICAL :: do_symmetric, found
2960 REAL(dp) :: force
2961 REAL(dp), DIMENSION(:, :), POINTER :: pblock
2962 REAL(kind=dp) :: dab
2963 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: dij_contr
2964 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: dij
2965 REAL(kind=dp), DIMENSION(3) :: ri, rij, rj, scoord
2966 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_i, set_radius_j
2967 REAL(kind=dp), DIMENSION(:, :), POINTER :: rpgf_i, rpgf_j, sphi_i, sphi_j, zeti, &
2968 zetj
2969 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
2970 TYPE(cell_type), POINTER :: cell
2971 TYPE(coulomb_integral_context_type) :: integral_context
2972 TYPE(dft_control_type), POINTER :: dft_control
2973 TYPE(mp_para_env_type), POINTER :: para_env
2975 DIMENSION(:), POINTER :: nl_iterator
2976 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
2977 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2978
2979 CALL timeset(routinen, handle)
2980
2981 op_prv = potential_parameter%potential_type
2982
2983 NULLIFY (qs_kind_set, atomic_kind_set, pblock, particle_set, cell)
2984
2985 ! get stuff
2986 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
2987 natom=natom, dft_control=dft_control, para_env=para_env, &
2988 particle_set=particle_set, cell=cell)
2989
2990 ! check for symmetry
2991 cpassert(SIZE(nl_2c) > 0)
2992 CALL get_neighbor_list_set_p(neighbor_list_sets=nl_2c, symmetric=do_symmetric)
2993 cpassert(.NOT. do_symmetric)
2994
2995 maxli = 0
2996 DO ibasis = 1, SIZE(basis_i)
2997 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=imax)
2998 maxli = max(maxli, imax)
2999 END DO
3000 maxlj = 0
3001 DO ibasis = 1, SIZE(basis_j)
3002 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=imax)
3003 maxlj = max(maxlj, imax)
3004 END DO
3005
3006 m_max = maxli + maxlj + 1
3007
3008 CALL r12_fundamentals_init(m_max, potential_parameter, para_env)
3009
3010 CALL coulomb_integral_init(integral_context, max_am_2c=max(maxli, maxlj), &
3011 derivative_order=1, library=library_libint)
3012
3013 CALL neighbor_list_iterator_create(nl_iterator, nl_2c)
3014 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
3015
3016 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
3017 iatom=iatom, jatom=jatom, r=rij)
3018
3019 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
3020 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
3021 sphi=sphi_i, zet=zeti)
3022
3023 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
3024 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
3025 sphi=sphi_j, zet=zetj)
3026
3027 dab = norm2(rij)
3028
3029 CALL dbcsr_get_block_p(t2c_trace, iatom, jatom, pblock, found)
3030 IF (.NOT. found) cycle
3031
3032 DO iset = 1, nseti
3033
3034 ncoi = npgfi(iset)*ncoset(lmax_i(iset))
3035 sgfi = first_sgf_i(1, iset)
3036
3037 DO jset = 1, nsetj
3038
3039 ncoj = npgfj(jset)*ncoset(lmax_j(jset))
3040 sgfj = first_sgf_j(1, jset)
3041
3042 IF (ncoi*ncoj > 0) THEN
3043 ALLOCATE (dij_contr(nsgfi(iset), nsgfj(jset)))
3044 ALLOCATE (dij(ncoi, ncoj, 3), source=0.0_dp)
3045
3046 ri = 0.0_dp
3047 rj = rij
3048
3049 CALL compute_coulomb_2c_derivs(dij, lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), &
3050 rpgf_i(:, iset), ri, lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), &
3051 rpgf_j(:, jset), rj, dab, integral_context, potential_parameter)
3052
3053 DO i_xyz = 1, 3
3054
3055 dij_contr(:, :) = 0.0_dp
3056 CALL ab_contract(dij_contr, dij(:, :, i_xyz), &
3057 sphi_i(:, sgfi:), sphi_j(:, sgfj:), &
3058 ncoi, ncoj, nsgfi(iset), nsgfj(jset))
3059
3060 force = sum(pblock(sgfi:sgfi + nsgfi(iset) - 1, sgfj:sgfj + nsgfj(jset) - 1)*dij_contr(:, :))
3061 force = pref*force
3062
3063 !iatom virial
3064 CALL real_to_scaled(scoord, particle_set(iatom)%r, cell)
3065 DO j_xyz = 1, 3
3066 work_virial(i_xyz, j_xyz) = work_virial(i_xyz, j_xyz) + force*scoord(j_xyz)
3067 END DO
3068
3069 !jatom virial
3070 CALL real_to_scaled(scoord, particle_set(iatom)%r + rij, cell)
3071 DO j_xyz = 1, 3
3072 work_virial(i_xyz, j_xyz) = work_virial(i_xyz, j_xyz) - force*scoord(j_xyz)
3073 END DO
3074 END DO
3075
3076 DEALLOCATE (dij, dij_contr)
3077 END IF
3078 END DO
3079 END DO
3080 END DO
3081
3082 CALL neighbor_list_iterator_release(nl_iterator)
3083 CALL coulomb_integral_cleanup(integral_context)
3084
3085 CALL timestop(handle)
3086
3087 END SUBROUTINE calc_2c_virial
3088
3089! **************************************************************************************************
3090!> \brief ...
3091!> \param t2c empty DBCSR matrix
3092!> \param filter_eps Filter threshold for matrix blocks
3093!> \param qs_env ...
3094!> \param nl_2c 2-center neighborlist
3095!> \param basis_i ...
3096!> \param basis_j ...
3097!> \param potential_parameter ...
3098!> \param do_kpoints ...
3099!> \param do_hfx_kpoints ...
3100!> this routine requires that libint has been static initialised somewhere else
3101!> \param ext_kpoints ...
3102!> \param regularization_RI ...
3103! **************************************************************************************************
3104 SUBROUTINE build_2c_integrals(t2c, filter_eps, qs_env, &
3105 nl_2c, basis_i, basis_j, &
3106 potential_parameter, do_kpoints, &
3107 do_hfx_kpoints, ext_kpoints, regularization_RI)
3108
3109 TYPE(dbcsr_type), DIMENSION(:), INTENT(INOUT) :: t2c
3110 REAL(kind=dp), INTENT(IN) :: filter_eps
3111 TYPE(qs_environment_type), POINTER :: qs_env
3112 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
3113 POINTER :: nl_2c
3114 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_i, basis_j
3115 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
3116 LOGICAL, INTENT(IN), OPTIONAL :: do_kpoints, do_hfx_kpoints
3117 TYPE(kpoint_type), OPTIONAL, POINTER :: ext_kpoints
3118 REAL(kind=dp), OPTIONAL :: regularization_ri
3119
3120 CHARACTER(len=*), PARAMETER :: routinen = 'build_2c_integrals'
3121
3122 INTEGER :: handle, i_diag, iatom, ibasis, icol, ikind, imax, img, irow, iset, jatom, jkind, &
3123 jset, m_max, maxli, maxlj, natom, ncoi, ncoj, nimg, nseti, nsetj, op_prv, sgfi, sgfj
3124 INTEGER, DIMENSION(3) :: cell_j, kp_index_lbounds, &
3125 kp_index_ubounds
3126 INTEGER, DIMENSION(:), POINTER :: lmax_i, lmax_j, lmin_i, lmin_j, npgfi, &
3127 npgfj, nsgfi, nsgfj
3128 INTEGER, DIMENSION(:, :), POINTER :: first_sgf_i, first_sgf_j
3129 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
3130 LOGICAL :: do_hfx_kpoints_prv, do_kpoints_prv, &
3131 do_symmetric, found, trans
3132 REAL(kind=dp) :: dab, min_zet
3133 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: sij, sij_contr, sij_rs
3134 REAL(kind=dp), DIMENSION(3) :: ri, rij, rj
3135 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_i, set_radius_j
3136 REAL(kind=dp), DIMENSION(:, :), POINTER :: rpgf_i, rpgf_j, sphi_i, sphi_j, zeti, &
3137 zetj
3138 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
3139 TYPE(block_p_type) :: block_t
3140 TYPE(cell_type), POINTER :: cell
3141 TYPE(coulomb_integral_context_type) :: integral_context
3142 TYPE(dft_control_type), POINTER :: dft_control
3143 TYPE(kpoint_type), POINTER :: kpoints
3144 TYPE(mp_para_env_type), POINTER :: para_env
3146 DIMENSION(:), POINTER :: nl_iterator
3147 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
3148
3149 CALL timeset(routinen, handle)
3150
3151 IF (PRESENT(do_kpoints)) THEN
3152 do_kpoints_prv = do_kpoints
3153 ELSE
3154 do_kpoints_prv = .false.
3155 END IF
3156
3157 IF (PRESENT(do_hfx_kpoints)) THEN
3158 do_hfx_kpoints_prv = do_hfx_kpoints
3159 ELSE
3160 do_hfx_kpoints_prv = .false.
3161 END IF
3162 IF (do_hfx_kpoints_prv) THEN
3163 cpassert(do_kpoints_prv)
3164 END IF
3165
3166 op_prv = potential_parameter%potential_type
3167
3168 NULLIFY (qs_kind_set, atomic_kind_set, block_t%block, cell_to_index)
3169
3170 ! get stuff
3171 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, cell=cell, &
3172 natom=natom, dft_control=dft_control, para_env=para_env, kpoints=kpoints)
3173
3174 IF (PRESENT(ext_kpoints)) kpoints => ext_kpoints
3175
3176 IF (do_kpoints_prv) THEN
3177 nimg = SIZE(t2c)
3178 CALL get_kpoint_info(kpoints, cell_to_index=cell_to_index)
3179 kp_index_lbounds = lbound(cell_to_index)
3180 kp_index_ubounds = ubound(cell_to_index)
3181 ELSE
3182 nimg = 1
3183 END IF
3184
3185 ! check for symmetry
3186 cpassert(SIZE(nl_2c) > 0)
3187 CALL get_neighbor_list_set_p(neighbor_list_sets=nl_2c, symmetric=do_symmetric)
3188
3189 IF (do_symmetric) THEN
3190 DO img = 1, nimg
3191 cpassert(dbcsr_has_symmetry(t2c(img)))
3192 END DO
3193 ELSE
3194 DO img = 1, nimg
3195 cpassert(.NOT. dbcsr_has_symmetry(t2c(img)))
3196 END DO
3197 END IF
3198
3199 DO img = 1, nimg
3200 CALL cp_dbcsr_alloc_block_from_nbl(t2c(img), nl_2c)
3201 END DO
3202
3203 maxli = 0
3204 DO ibasis = 1, SIZE(basis_i)
3205 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=imax)
3206 maxli = max(maxli, imax)
3207 END DO
3208 maxlj = 0
3209 DO ibasis = 1, SIZE(basis_j)
3210 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=imax)
3211 maxlj = max(maxlj, imax)
3212 END DO
3213
3214 m_max = maxli + maxlj
3215
3216 CALL r12_fundamentals_init(m_max, potential_parameter, para_env)
3217
3218 CALL coulomb_integral_init(integral_context, max_am_2c=max(maxli, maxlj), &
3219 derivative_order=0, library=library_libint)
3220
3221 CALL neighbor_list_iterator_create(nl_iterator, nl_2c)
3222 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
3223
3224 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
3225 iatom=iatom, jatom=jatom, r=rij, cell=cell_j)
3226 IF (do_kpoints_prv) THEN
3227 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
3228 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
3229 img = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
3230 IF (img > nimg .OR. img < 1) cycle
3231 ELSE
3232 img = 1
3233 END IF
3234
3235 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
3236 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
3237 sphi=sphi_i, zet=zeti)
3238
3239 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
3240 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
3241 sphi=sphi_j, zet=zetj)
3242
3243 IF (do_symmetric) THEN
3244 IF (iatom <= jatom) THEN
3245 irow = iatom
3246 icol = jatom
3247 ELSE
3248 irow = jatom
3249 icol = iatom
3250 END IF
3251 ELSE
3252 irow = iatom
3253 icol = jatom
3254 END IF
3255
3256 dab = norm2(rij)
3257
3258 CALL dbcsr_get_block_p(matrix=t2c(img), &
3259 row=irow, col=icol, block=block_t%block, found=found)
3260 cpassert(found)
3261 trans = do_symmetric .AND. (iatom > jatom)
3262
3263 DO iset = 1, nseti
3264
3265 ncoi = npgfi(iset)*ncoset(lmax_i(iset))
3266 sgfi = first_sgf_i(1, iset)
3267
3268 DO jset = 1, nsetj
3269
3270 ncoj = npgfj(jset)*ncoset(lmax_j(jset))
3271 sgfj = first_sgf_j(1, jset)
3272
3273 IF (ncoi*ncoj > 0) THEN
3274 ALLOCATE (sij_contr(nsgfi(iset), nsgfj(jset)), source=0.0_dp)
3275 ALLOCATE (sij(ncoi, ncoj), source=0.0_dp)
3276
3277 ri = 0.0_dp
3278 rj = rij
3279
3280 CALL compute_coulomb_2c(integral_context, lmin_i(iset), lmax_i(iset), lmin_j(jset), lmax_j(jset), &
3281 npgfi(iset), npgfj(jset), zeti(:, iset), zetj(:, jset), rpgf_i(:, iset), rpgf_j(:, jset), &
3282 ri, rj, sij, potential_parameter, dab=dab)
3283
3284 CALL ab_contract(sij_contr, sij, &
3285 sphi_i(:, sgfi:), sphi_j(:, sgfj:), &
3286 ncoi, ncoj, nsgfi(iset), nsgfj(jset))
3287
3288 DEALLOCATE (sij)
3289 IF (trans) THEN
3290 ALLOCATE (sij_rs(nsgfj(jset), nsgfi(iset)))
3291 sij_rs(:, :) = transpose(sij_contr)
3292 ELSE
3293 ALLOCATE (sij_rs(nsgfi(iset), nsgfj(jset)))
3294 sij_rs(:, :) = sij_contr
3295 END IF
3296
3297 DEALLOCATE (sij_contr)
3298
3299 ! RI regularization
3300 IF (.NOT. do_hfx_kpoints_prv .AND. PRESENT(regularization_ri) .AND. &
3301 iatom == jatom .AND. iset == jset .AND. &
3302 cell_j(1) == 0 .AND. cell_j(2) == 0 .AND. cell_j(3) == 0) THEN
3303 DO i_diag = 1, nsgfi(iset)
3304 min_zet = minval(zeti(1:npgfi(iset), iset))
3305 cpassert(min_zet > 1.0e-10_dp)
3306 sij_rs(i_diag, i_diag) = sij_rs(i_diag, i_diag) + &
3307 regularization_ri*max(1.0_dp, 1.0_dp/min_zet)
3308 END DO
3309 END IF
3310
3311 CALL block_add("IN", sij_rs, &
3312 nsgfi(iset), nsgfj(jset), block_t%block, &
3313 sgfi, sgfj, trans=trans)
3314 DEALLOCATE (sij_rs)
3315
3316 END IF
3317 END DO
3318 END DO
3319 END DO
3320
3321 CALL coulomb_integral_cleanup(integral_context)
3322
3323 CALL neighbor_list_iterator_release(nl_iterator)
3324 DO img = 1, nimg
3325 CALL dbcsr_finalize(t2c(img))
3326 CALL dbcsr_filter(t2c(img), filter_eps)
3327 END DO
3328
3329 CALL timestop(handle)
3330
3331 END SUBROUTINE build_2c_integrals
3332
3333! **************************************************************************************************
3334!> \brief ...
3335!> \param tensor tensor with data. Data is cleared after compression.
3336!> \param blk_indices ...
3337!> \param compressed compressed tensor data
3338!> \param eps all entries < eps are discarded
3339!> \param memory ...
3340! **************************************************************************************************
3341 SUBROUTINE compress_tensor(tensor, blk_indices, compressed, eps, memory)
3342 TYPE(dbt_type), INTENT(INOUT) :: tensor
3343 INTEGER, ALLOCATABLE, DIMENSION(:, :), &
3344 INTENT(INOUT) :: blk_indices
3345 TYPE(hfx_compression_type), INTENT(INOUT) :: compressed
3346 REAL(dp), INTENT(IN) :: eps
3347 REAL(dp), INTENT(INOUT) :: memory
3348
3349 CHARACTER(LEN=*), PARAMETER :: routinen = 'compress_tensor'
3350
3351 INTEGER :: buffer_left, buffer_size, buffer_start, &
3352 handle, i, ibin, iblk, memory_usage, &
3353 nbins, nblk, nints, offset, &
3354 shared_offset
3355 INTEGER(int_8) :: storage_counter_integrals
3356 INTEGER, DIMENSION(3) :: ind
3357 LOGICAL :: found
3358 REAL(dp), ALLOCATABLE, DIMENSION(:, :, :), TARGET :: blk_data
3359 REAL(dp), DIMENSION(:), POINTER :: blk_data_1d
3360 TYPE(dbt_iterator_type) :: iter
3361 TYPE(hfx_container_type), POINTER :: integral_container
3362 TYPE(hfx_real_cache_type) :: real_cache
3363
3364 CALL timeset(routinen, handle)
3365
3366 CALL dealloc_containers(compressed, memory_usage)
3367 ! one bin (independent stream) per thread lets decompress_tensor run in parallel
3368 nbins = omp_get_max_threads()
3369 ! Only containers (in the shape dealloc_containers expects): a bin uses its first container,
3370 ! and its cache exists while a (de)compression runs, which keeps the fixed cost per bin low.
3371 ALLOCATE (compressed%maxval_container(nbins), compressed%integral_containers(64, nbins))
3372
3373 IF (ALLOCATED(blk_indices)) DEALLOCATE (blk_indices)
3374 ALLOCATE (blk_indices(dbt_get_num_blocks(tensor), 3))
3375 shared_offset = 0
3376!$OMP PARALLEL DEFAULT(NONE) SHARED(tensor,blk_indices,shared_offset) &
3377!$OMP PRIVATE(iter,ind,offset,nblk,iblk)
3378 CALL dbt_iterator_start(iter, tensor)
3379 nblk = dbt_iterator_num_blocks(iter)
3380!$OMP CRITICAL(qs_tensors_offset)
3381 offset = shared_offset
3382 shared_offset = shared_offset + nblk
3383!$OMP END CRITICAL(qs_tensors_offset)
3384 DO iblk = 1, nblk
3385 CALL dbt_iterator_next_block(iter, ind)
3386 blk_indices(offset + iblk, :) = ind(:)
3387 END DO
3388 CALL dbt_iterator_stop(iter)
3389!$OMP END PARALLEL
3390
3391 ! Can not use the tensor iterator here because the order of the blocks is not guaranteed.
3392 nblk = SIZE(blk_indices, 1)
3393 storage_counter_integrals = 0
3394 ! values as they are, quantized and packed within eps (one stream per bin)
3395!$OMP PARALLEL DO DEFAULT(NONE) SHARED(tensor,blk_indices,compressed,eps,nbins,nblk) &
3396!$OMP PRIVATE(ibin,i,ind,blk_data,blk_data_1d,found,nints,buffer_left,buffer_size,buffer_start) &
3397!$OMP PRIVATE(memory_usage,integral_container,real_cache) &
3398!$OMP REDUCTION(+:storage_counter_integrals) SCHEDULE(STATIC,1)
3399 DO ibin = 1, nbins
3400 integral_container => compressed%integral_containers(1, ibin)
3401 CALL hfx_init_container(integral_container, memory_usage, .false.)
3402 real_cache%element_counter = 1
3403
3404 DO i = (ibin - 1)*nblk/nbins + 1, ibin*nblk/nbins
3405 ind = blk_indices(i, :)
3406 CALL dbt_get_block(tensor, ind, blk_data, found)
3407 cpassert(found)
3408 nints = SIZE(blk_data)
3409 blk_data_1d(1:nints) => blk_data
3410
3411 buffer_left = nints
3412 buffer_start = 1
3413
3414 DO WHILE (buffer_left > 0)
3415 buffer_size = min(buffer_left, cache_size)
3416 CALL hfx_add_mult_real_elements(blk_data_1d(buffer_start:), buffer_size, real_cache, &
3417 integral_container, eps, memory_usage, .false.)
3418 buffer_left = buffer_left - buffer_size
3419 buffer_start = buffer_start + buffer_size
3420 END DO
3421
3422 NULLIFY (blk_data_1d); DEALLOCATE (blk_data)
3423 END DO
3424
3425 CALL hfx_flush_last_real_cache(real_cache, integral_container, eps, memory_usage, .false.)
3426
3427 ! all of the bin (before the reset restarts memory_usage): the first node and the nodes added since
3428 storage_counter_integrals = storage_counter_integrals + int(memory_usage, int_8)*cache_size
3429
3430 CALL hfx_reset_real_cache_and_container(real_cache, integral_container, memory_usage, .false.)
3431 END DO
3432!$OMP END PARALLEL DO
3433
3434 CALL dbt_clear(tensor)
3435
3436 memory = memory + real(storage_counter_integrals, dp)/1024/128
3437 !WRITE (UNIT=iw, FMT="((T3,A,T60,I21))") &
3438 ! "HFX_MEM_INFO| Total memory consumption ERI's RAM [MiB]: ", memory
3439
3440 CALL timestop(handle)
3441
3442 END SUBROUTINE compress_tensor
3443
3444! **************************************************************************************************
3445!> \brief ...
3446!> \param tensor empty tensor which is filled by decompressed data
3447!> \param blk_indices indices of blocks to be reserved
3448!> \param compressed compressed data
3449!> \param eps all entries < eps are discarded
3450! **************************************************************************************************
3451 SUBROUTINE decompress_tensor(tensor, blk_indices, compressed, eps)
3452
3453 TYPE(dbt_type), INTENT(INOUT) :: tensor
3454 INTEGER, DIMENSION(:, :) :: blk_indices
3455 TYPE(hfx_compression_type), INTENT(INOUT) :: compressed
3456 REAL(dp), INTENT(IN) :: eps
3457
3458 CHARACTER(LEN=*), PARAMETER :: routinen = 'decompress_tensor'
3459
3460 INTEGER :: a, b, buffer_left, buffer_size, &
3461 buffer_start, handle, i, ibin, &
3462 memory_usage, nbins, nblk, &
3463 nblk_per_thread, nints
3464 INTEGER, DIMENSION(3) :: blk_size, ind
3465 REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET :: blk_data
3466 REAL(dp), DIMENSION(:, :, :), POINTER :: blk_data_3d
3467 TYPE(hfx_container_type), POINTER :: integral_container
3468 TYPE(hfx_real_cache_type) :: real_cache
3469
3470 CALL timeset(routinen, handle)
3471
3472!TODO: Parallelize creation of block list.
3473!$OMP PARALLEL DEFAULT(NONE) SHARED(tensor,blk_indices) PRIVATE(nblk_per_thread,A,b)
3474 nblk_per_thread = SIZE(blk_indices, 1)/omp_get_num_threads() + 1
3475 a = omp_get_thread_num()*nblk_per_thread + 1
3476 b = min(a + nblk_per_thread, SIZE(blk_indices, 1))
3477 CALL dbt_reserve_blocks(tensor, blk_indices(a:b, :))
3478!$OMP END PARALLEL
3479
3480 ! bins are independent streams, each holding a contiguous range of blk_indices
3481 nbins = SIZE(compressed%integral_containers, 2)
3482 nblk = SIZE(blk_indices, 1)
3483!$OMP PARALLEL DO DEFAULT(NONE) SHARED(tensor,blk_indices,compressed,eps,nbins,nblk) &
3484!$OMP PRIVATE(ibin,i,ind,blk_size,nints,buffer_left,buffer_size,buffer_start,blk_data,blk_data_3d) &
3485!$OMP PRIVATE(memory_usage,integral_container,real_cache) SCHEDULE(STATIC,1)
3486 DO ibin = 1, nbins
3487 integral_container => compressed%integral_containers(1, ibin)
3488 memory_usage = 0
3489 CALL hfx_decompress_first_real_cache(real_cache, integral_container, eps, memory_usage, .false.)
3490
3491 DO i = (ibin - 1)*nblk/nbins + 1, ibin*nblk/nbins
3492 ind = blk_indices(i, :)
3493 CALL dbt_blk_sizes(tensor, ind, blk_size)
3494 nints = product(blk_size)
3495
3496 buffer_left = nints
3497 buffer_start = 1
3498
3499 ALLOCATE (blk_data(nints))
3500 DO WHILE (buffer_left > 0)
3501 buffer_size = min(buffer_left, cache_size)
3502 CALL hfx_get_mult_real_elements(blk_data(buffer_start), buffer_size, real_cache, &
3503 integral_container, eps, memory_usage, .false.)
3504 buffer_left = buffer_left - buffer_size
3505 buffer_start = buffer_start + buffer_size
3506 END DO
3507
3508 blk_data_3d(1:blk_size(1), 1:blk_size(2), 1:blk_size(3)) => blk_data
3509 CALL dbt_put_block(tensor, ind, blk_size, blk_data_3d)
3510 NULLIFY (blk_data_3d); DEALLOCATE (blk_data)
3511 END DO
3512
3513 CALL hfx_reset_real_cache_and_container(real_cache, integral_container, memory_usage, .false.)
3514 END DO
3515!$OMP END PARALLEL DO
3516
3517 CALL timestop(handle)
3518 END SUBROUTINE decompress_tensor
3519
3520! **************************************************************************************************
3521!> \brief ...
3522!> \param tensor ...
3523!> \param nze ...
3524!> \param occ ...
3525! **************************************************************************************************
3526 SUBROUTINE get_tensor_occupancy(tensor, nze, occ)
3527 TYPE(dbt_type), INTENT(IN) :: tensor
3528 INTEGER(int_8), INTENT(OUT) :: nze
3529 REAL(dp), INTENT(OUT) :: occ
3530
3531 INTEGER, DIMENSION(dbt_ndims(tensor)) :: dims
3532
3533 nze = dbt_get_nze_total(tensor)
3534 CALL dbt_get_info(tensor, nfull_total=dims)
3535 occ = real(nze, dp)/product(real(dims, dp))
3536
3537 END SUBROUTINE get_tensor_occupancy
3538
3539END MODULE qs_tensors
static int imax(int x, int y)
Returns the larger of two given integers (missing from the C standard).
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
Contraction of integrals over primitive Cartesian Gaussians based on the contraction matrix sphi whic...
subroutine, public abc_contract_xsmm(abcint, sabc, sphi_a, sphi_b, sphi_c, ncoa, ncob, ncoc, nsgfa, nsgfb, nsgfc, cpp_buffer, ccp_buffer, prefac, pstfac)
3-center contraction routine from primitive cartesian Gaussians to spherical Gaussian functions using...
subroutine, public ab_contract(abint, sab, sphi_a, sphi_b, ncoa, ncob, nsgfa, nsgfb)
contract overlap integrals (a,b) and transfer to spherical Gaussians
Set of routines to: Contract integrals over primitive Gaussians Decontract (density) matrices Trace m...
Define the atomic kind types and their sub types.
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, ccon)
...
collect pointers to a block of reals
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
Definition cell_types.F:631
Common interface for two- and three-center Coulomb integrals.
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
logical function, public dbcsr_has_symmetry(matrix)
...
character function, public dbcsr_get_matrix_type(matrix)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_finalize(matrix)
...
This is the start of a dbt_api, all publically needed functions are exported here....
Definition dbt_api.F:17
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
stores a mapping of 2D info (e.g. matrix) on a 2D processor distribution (i.e. blacs grid) where cpus...
routines and types for Hartree-Fock-Exchange
subroutine, public hfx_flush_last_real_cache(cache, container, eps, memory_usage, use_disk_storage)
Packs the last cache of real values (unused values as zeros) into the container.
subroutine, public hfx_get_mult_real_elements(values, nints, cache, container, eps, memory_usage, use_disk_storage)
Gets real values from a cache (at most a cache full); an exhausted cache is refilled from the next re...
subroutine, public hfx_add_mult_real_elements(values, nints, cache, container, eps, memory_usage, use_disk_storage)
Adds real values to a cache (at most a cache full); a full cache is packed into the container,...
subroutine, public hfx_decompress_first_real_cache(cache, container, eps, memory_usage, use_disk_storage)
Fills a cache of real values with the first record of a container.
subroutine, public hfx_reset_real_cache_and_container(cache, container, memory_usage, do_disk_storage)
Moves a cache of real values and its container back to the beginning (as hfx_reset_cache_and_containe...
Types and set/get functions for HFX.
Definition hfx_types.F:16
subroutine, public hfx_init_container(container, memory_usage, do_disk_storage)
This routine deletes all list entries in a container in order to deallocate the memory.
Definition hfx_types.F:2543
subroutine, public dealloc_containers(data, memory_usage)
...
Definition hfx_types.F:2902
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_potential_truncated
integer, parameter, public do_potential_id
integer, parameter, public do_potential_coulomb
integer, parameter, public do_potential_short
integer, parameter, public do_potential_mix_cl_trunc
objects that represent the structure of input sections and the data contained in an input section
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
Library choices for electronic integral APIs.
real(dp), parameter, public cutoff_screen_factor
integer, parameter, public library_libint
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 sp
Definition kinds.F:33
Types and basic routines needed for a kpoint calculation.
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, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered, rskp_transform)
Retrieve information from a kpoint environment.
Interface to the message passing library MPI.
Define the data structure for the molecule information.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
Define the data structure for the particle information.
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, matrix_vhxc, 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.
Define the quickstep kind type and their sub types.
Define the neighbor list data types and the corresponding functionality.
subroutine, public release_neighbor_list_sets(nlists)
releases an array of neighbor_list_sets
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
subroutine, public get_neighbor_list_set_p(neighbor_list_sets, nlist, symmetric)
Return the components of the first neighbor list set.
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
Generate the atomic neighbor lists.
subroutine, public atom2d_cleanup(atom2d)
free the internals of atom2d
subroutine, public pair_radius_setup(present_a, present_b, radius_a, radius_b, pair_radius, prmin)
...
subroutine, public build_neighbor_lists(ab_list, particle_set, atom, cell, pair_radius, subcells, mic, symmetric, molecular, subset_of_mol, current_subset, operator_type, nlname, atomb_to_keep, stable_images)
Build simple pair neighbor lists.
subroutine, public atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, molecule_set, molecule_only, particle_set)
Build some distribution structure of atoms, refactored from build_qs_neighbor_lists.
Utility methods to build 3-center integral tensors of various types.
integer, parameter, public symmetrik_ik
integer, parameter, public symmetric_jk
integer, parameter, public symmetric_ijk
integer, parameter, public symmetric_ij
integer, parameter, public symmetric_none
subroutine, public distribution_3d_destroy(dist)
Destroy a 3d distribution.
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 calc_3c_virial(work_virial, t3c_trace, pref, qs_env, nl_3c, basis_i, basis_j, basis_k, potential_parameter, der_eps, op_pos)
Calculates the 3c virial contributions on the fly.
subroutine, public build_3c_derivatives(t3c_der_i, t3c_der_k, filter_eps, qs_env, nl_3c, basis_i, basis_j, basis_k, potential_parameter, der_eps, op_pos, do_kpoints, do_hfx_kpoints, bounds_i, bounds_j, bounds_k, ri_range, img_to_ri_cell)
Build 3-center derivative tensors.
Definition qs_tensors.F:932
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:138
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 compress_tensor(tensor, blk_indices, compressed, eps, memory)
...
subroutine, public neighbor_list_3c_iterator_destroy(iterator)
Destroy 3c-nl iterator.
Definition qs_tensors.F:440
subroutine, public neighbor_list_3c_destroy(ijk_list)
Destroy 3c neighborlist.
Definition qs_tensors.F:375
subroutine, public calc_2c_virial(work_virial, t2c_trace, pref, qs_env, nl_2c, basis_i, basis_j, potential_parameter)
Calculates the virial coming from 2c derivatives on the fly.
subroutine, public decompress_tensor(tensor, blk_indices, compressed, eps)
...
subroutine, public build_2c_derivatives(t2c_der, filter_eps, qs_env, nl_2c, basis_i, basis_j, potential_parameter, do_kpoints)
Calculates the derivatives of 2-center integrals, wrt to the first center.
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:274
integer function, public neighbor_list_3c_iterate(iterator, next_pair)
Iterate 3c-nl iterator.
Definition qs_tensors.F:464
subroutine, public neighbor_list_3c_iterator_create(iterator, ijk_nl)
Create a 3-center neighborlist iterator.
Definition qs_tensors.F:392
subroutine, public get_3c_iterator_info(iterator, ikind, jkind, kkind, nkind, iatom, jatom, katom, rij, rjk, rik, cell_j, cell_k)
Get info of current iteration.
Definition qs_tensors.F:568
Radial fundamentals for Gaussian two-electron integrals. Entry m+1 stores order m....
subroutine, public r12_fundamentals_init(m_max, potential_parameter, para_env)
Prepare shared radial evaluator tables before entering a threaded evaluation region.
All kind of helpful little routines.
Definition util.F:14
pure integer function, dimension(2), public get_limit(m, n, me)
divide m entries into n parts, return size of part me
Definition util.F:333
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
represent a pointer to a 2d array
structure to store local (to a processor) ordered lists of integers.
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.