LCOV - code coverage report
Current view: top level - src - four_center_integral_interface.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 99.6 % 226 225
Test Date: 2026-11-24 01:22:08 Functions: 75.0 % 8 6

            Line data    Source code
       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 Four-center integral evaluation with an encapsulated Libint backend.
      10              : !> \par History
      11              : !>      11.2006 created [Manuel Guidon]
      12              : !>      11.2019 Fixed potential_id initial values (A. Bussy)
      13              : !> \author Manuel Guidon
      14              : ! **************************************************************************************************
      15              : MODULE four_center_integral_interface
      16              : 
      17              :    USE cell_types,                      ONLY: cell_type,&
      18              :                                               pbc,&
      19              :                                               real_to_scaled
      20              :    USE four_center_integral_preparation,ONLY: min_image_gap_sq,&
      21              :                                               prepare_eri4_pair,&
      22              :                                               prepare_eri4_primitive,&
      23              :                                               prepare_eri4_product
      24              :    USE four_center_integral_types,      ONLY: eri4_cell_type,&
      25              :                                               eri4_image_group_type,&
      26              :                                               eri4_pgf_image_type,&
      27              :                                               eri4_pgf_pair_type
      28              :    USE hfx_contraction_methods,         ONLY: contract
      29              :    USE input_constants,                 ONLY: do_potential_mix_cl_trunc,&
      30              :                                               do_potential_short,&
      31              :                                               do_potential_truncated
      32              :    USE integral_library_types,          ONLY: coulomb_operator_type
      33              :    USE kinds,                           ONLY: dp,&
      34              :                                               int_8
      35              :    USE libint_wrapper,                  ONLY: &
      36              :         cp_libint_cleanup_eri, cp_libint_cleanup_eri1, cp_libint_get_derivs, cp_libint_get_eris, &
      37              :         cp_libint_get_image_derivs, cp_libint_get_image_eris, cp_libint_image_workspace_type, &
      38              :         cp_libint_init_eri, cp_libint_init_eri1, cp_libint_set_contrdepth, &
      39              :         cp_libint_set_params_eri, cp_libint_set_params_eri_deriv, cp_libint_t, &
      40              :         eri_primitive_data_type, get_eri_permutation, libint_can_contract_images, reorder_eri_block
      41              :    USE orbital_pointers,                ONLY: nco
      42              : #include "./base/base_uses.f90"
      43              : 
      44              :    IMPLICIT NONE
      45              :    PRIVATE
      46              :    PUBLIC :: four_center_integral_init, four_center_integral_cleanup, &
      47              :              prepare_four_center_batch, evaluate_eri, &
      48              :              evaluate_deriv_eri, &
      49              :              evaluate_eri_screen
      50              : 
      51              : !> \brief Context owning the energy and first-derivative backend workspaces.
      52              : !> \note Each thread owns its context. Pass it directly without intrinsic copying.
      53              :    TYPE, PUBLIC :: four_center_integral_context_type
      54              :       PRIVATE
      55              :       TYPE(cp_libint_t) :: eri, deriv
      56              :       TYPE(cp_libint_image_workspace_type), ALLOCATABLE :: image_workspace
      57              :       TYPE(eri_primitive_data_type), ALLOCATABLE :: products(:)
      58              :       TYPE(eri4_image_group_type), ALLOCATABLE :: image_groups(:)
      59              :       INTEGER :: nproducts = 0, nimage_groups = 0
      60              :    END TYPE four_center_integral_context_type
      61              : 
      62              : CONTAINS
      63              : 
      64              : ! **************************************************************************************************
      65              : !> \brief Select image-resolved quartets and prepare their backend cache before angular traversal.
      66              : !> \param context owning per-thread geometry and backend workspace
      67              : !> \param list1 bra primitive pair with image topology and screening bounds
      68              : !> \param list2 ket primitive pair with image topology and screening bounds
      69              : !> \param nproducts number of retained image quartets
      70              : !> \param log10_pmax logarithmic density bound
      71              : !> \param log10_eps_schwarz logarithmic integral screening threshold
      72              : !> \param neighbor_cells periodic image translations
      73              : !> \param cell simulation cell
      74              : !> \param potential_parameter physical radial operator
      75              : !> \param m_max maximum radial order including any derivative increment
      76              : !> \param do_periodic whether to enumerate periodic translations
      77              : !> \param group_images whether the caller can consume unweighted sums over images
      78              : ! **************************************************************************************************
      79     88010559 :    SUBROUTINE prepare_four_center_batch(context, list1, list2, nproducts, &
      80              :                                         log10_pmax, log10_eps_schwarz, neighbor_cells, &
      81              :                                         cell, potential_parameter, m_max, do_periodic, group_images)
      82              : 
      83              :       TYPE(four_center_integral_context_type), &
      84              :          INTENT(INOUT)                                   :: context
      85              :       TYPE(eri4_pgf_pair_type)                           :: list1, list2
      86              :       INTEGER, INTENT(OUT)                               :: nproducts
      87              :       REAL(dp), INTENT(IN)                               :: log10_pmax, log10_eps_schwarz
      88              :       TYPE(eri4_cell_type), DIMENSION(:), POINTER        :: neighbor_cells
      89              :       TYPE(cell_type), POINTER                           :: cell
      90              :       TYPE(coulomb_operator_type)                        :: potential_parameter
      91              :       INTEGER, INTENT(IN)                                :: m_max
      92              :       LOGICAL, INTENT(IN)                                :: do_periodic, group_images
      93              : 
      94              :       REAL(dp), PARAMETER                                :: r_cutoff_eps = 1.0E-12_dp
      95              : 
      96              :       INTEGER                                            :: first, i, j, k, k_max, nimages1, &
      97              :                                                             nimages2, tmp_i4
      98              :       LOGICAL                                            :: has_r_cutoff
      99              :       REAL(dp) :: C11(3), EtaInv, min_img_delta, P(3), pgf_max_1, pgf_max_2, PQ(3), pq2, Q(3), R1, &
     100              :          R2, r_cutoff_sq, r_cutoff_sq_guard, rc(3), rcut_eff, rd(3), rpq2, S1234, S1234a, S1234b, &
     101              :          shift(3), temp(3), temp_CC(3), temp_DD(3), tmp_D(3), Zeta_C, Zeta_D
     102     88010559 :       TYPE(eri4_image_group_type), ALLOCATABLE           :: tmp_groups(:)
     103              :       TYPE(eri4_pgf_image_type)                          :: shifted_image
     104              :       TYPE(eri_primitive_data_type)                      :: product
     105              :       TYPE(eri_primitive_data_type), ALLOCATABLE, &
     106     88010559 :          DIMENSION(:)                                    :: tmp_product_list
     107              : 
     108     88010559 :       nimages1 = list1%nimages
     109     88010559 :       nimages2 = list2%nimages
     110     88010559 :       nproducts = 0
     111     88010559 :       context%nproducts = 0
     112     88010559 :       context%nimage_groups = 0
     113     88010559 :       IF (nimages1 == 0 .OR. nimages2 == 0) RETURN
     114     88010559 :       CALL prepare_eri4_product(list1, list2, m_max, product)
     115     88010559 :       EtaInv = list2%ZetaInv
     116     88010559 :       Zeta_C = list2%zeta
     117     88010559 :       Zeta_D = list2%zetb
     118     88010559 :       temp_CC = 0.0_dp
     119     88010559 :       temp_DD = 0.0_dp
     120     88010559 :       r_cutoff_sq = 0.0_dp
     121     88010559 :       r_cutoff_sq_guard = 0.0_dp
     122     99919488 :       SELECT CASE (potential_parameter%potential_type)
     123              :       CASE (do_potential_truncated, do_potential_short, do_potential_mix_cl_trunc)
     124     11908929 :          has_r_cutoff = .TRUE.
     125     11908929 :          rcut_eff = potential_parameter%cutoff_radius
     126              :       CASE DEFAULT
     127              :          has_r_cutoff = .FALSE.
     128     88010559 :          rcut_eff = 0.0_dp
     129              :       END SELECT
     130    187817022 :       DO i = 1, nimages1
     131    399225852 :          P = list1%image_list(i)%P
     132     99806463 :          R1 = list1%image_list(i)%R
     133     99806463 :          S1234a = list1%image_list(i)%S1234
     134     99806463 :          pgf_max_1 = list1%image_list(i)%pgf_max
     135    338053217 :          DO j = 1, nimages2
     136    150236195 :             pgf_max_2 = list2%image_list(j)%pgf_max
     137    150236195 :             IF (pgf_max_1 + pgf_max_2 + log10_pmax < log10_eps_schwarz) CYCLE
     138    401316192 :             Q = list2%image_list(j)%P
     139    100329048 :             R2 = list2%image_list(j)%R
     140    100329048 :             S1234b = list2%image_list(j)%S1234
     141    401316192 :             rc = list2%image_list(j)%ra
     142    401316192 :             rd = list2%image_list(j)%rb
     143              : 
     144    100329048 :             IF (has_r_cutoff) THEN
     145     31533584 :                r_cutoff_sq = (R1 + R2 + rcut_eff)**2
     146     31533584 :                r_cutoff_sq_guard = r_cutoff_sq*(1.0_dp + r_cutoff_eps)
     147              :             END IF
     148    100329048 :             k_max = SIZE(neighbor_cells)
     149    100329048 :             IF (do_periodic) THEN
     150    193484992 :                temp = P - Q
     151     48371248 :                PQ = pbc(temp, cell)
     152    193330708 :                IF (has_r_cutoff .AND. cell%orthorhombic .AND. ALL(cell%perd == 1) .AND. k_max >= 1) THEN
     153    103088020 :                   IF (ALL(neighbor_cells(1)%cell_r == 0.0_dp)) THEN
     154     25772005 :                      pq2 = PQ(1)**2 + PQ(2)**2 + PQ(3)**2
     155     25772005 :                      IF (pq2 > r_cutoff_sq_guard) CYCLE
     156     25601762 :                      min_img_delta = min_image_gap_sq(PQ, cell%hmat)
     157     25601762 :                      IF (min_img_delta >= 0.0_dp .AND. pq2 + min_img_delta > r_cutoff_sq_guard) k_max = 1
     158              :                   END IF
     159              :                END IF
     160    192804020 :                shift = -PQ + temp
     161    192804020 :                temp_CC = rc + shift
     162    192804020 :                temp_DD = rd + shift
     163              :             END IF
     164              : 
     165    100158805 :             S1234 = EXP(S1234a + S1234b)
     166    100158805 :             first = nproducts + 1
     167              : 
     168   2517985524 :             DO k = 1, k_max
     169   2417826719 :                IF (do_periodic) THEN
     170   2365868919 :                   IF (has_r_cutoff .AND. k_max > 1) THEN
     171   2337342937 :                      IF ((PQ(1) - neighbor_cells(k)%cell_r(1))**2 + &
     172              :                          (PQ(2) - neighbor_cells(k)%cell_r(2))**2 + &
     173              :                          (PQ(3) - neighbor_cells(k)%cell_r(3))**2 > r_cutoff_sq_guard) CYCLE
     174              :                   END IF
     175   1006775116 :                   C11 = temp_CC + neighbor_cells(k)%cell_r(:)
     176   1006775116 :                   tmp_D = temp_DD + neighbor_cells(k)%cell_r(:)
     177              :                ELSE
     178     51957800 :                   C11 = rc
     179     51957800 :                   tmp_D = rd
     180              :                END IF
     181   1214606316 :                Q = (Zeta_C*C11 + Zeta_D*tmp_D)*EtaInv
     182    303651579 :                rpq2 = (P(1) - Q(1))**2 + (P(2) - Q(2))**2 + (P(3) - Q(3))**2
     183    303651579 :                IF (has_r_cutoff) THEN
     184    234856115 :                   IF (rpq2 > r_cutoff_sq) CYCLE
     185              :                END IF
     186    303651562 :                nproducts = nproducts + 1
     187              : 
     188              :                ! Retain the enlarged buffer in this thread's owning context.
     189    303651562 :                IF (nproducts > SIZE(context%products)) THEN
     190         1536 :                   tmp_i4 = (3*nproducts + 1)/2
     191      7625840 :                   ALLOCATE (tmp_product_list(tmp_i4))
     192      5029340 :                   tmp_product_list(1:SIZE(context%products)) = context%products
     193         1536 :                   CALL MOVE_ALLOC(tmp_product_list, context%products)
     194              :                END IF
     195              : 
     196   1214606248 :                shifted_image%ra = C11
     197   1214606248 :                shifted_image%rb = tmp_D
     198   1214606248 :                shifted_image%P = Q
     199              :                CALL prepare_eri4_primitive(product, list1%image_list(i), shifted_image, S1234, rpq2, potential_parameter, &
     200   2517985524 :                                            context%products(nproducts))
     201              :             END DO
     202              : 
     203    199965268 :             IF (libint_can_contract_images .AND. group_images .AND. do_periodic .AND. nproducts > first) THEN
     204     17988293 :                IF (context%nimage_groups == SIZE(context%image_groups)) THEN
     205       196664 :                   ALLOCATE (tmp_groups((3*context%nimage_groups + 2)/2))
     206       122902 :                   tmp_groups(1:context%nimage_groups) = context%image_groups
     207         1190 :                   CALL MOVE_ALLOC(tmp_groups, context%image_groups)
     208              :                END IF
     209     17988293 :                context%nimage_groups = context%nimage_groups + 1
     210              :                ASSOCIATE (group => context%image_groups(context%nimage_groups))
     211     17988293 :                   group%first = first
     212     17988293 :                   group%last = nproducts
     213     71953172 :                   group%displacements(:, 1) = list1%image_list(i)%ra - list1%image_list(i)%rb
     214     89941465 :                   group%displacements(:, 2) = rc - rd
     215              :                END ASSOCIATE
     216              :             END IF
     217              :          END DO
     218              :       END DO
     219              : 
     220     88010559 :       context%nproducts = nproducts
     221   5368644099 :    END SUBROUTINE prepare_four_center_batch
     222              : 
     223              : ! **************************************************************************************************
     224              : !> \brief Initialize the four-center energy and first-derivative workspaces.
     225              : !> \param context owning context; global backend initialization is provided by init_cp2k
     226              : !> \param max_am maximum angular momentum on any center
     227              : ! **************************************************************************************************
     228         1640 :    SUBROUTINE four_center_integral_init(context, max_am)
     229              :       TYPE(four_center_integral_context_type), &
     230              :          INTENT(INOUT)                                   :: context
     231              :       INTEGER, INTENT(IN)                                :: max_am
     232              : 
     233         1640 :       CALL cp_libint_init_eri(context%eri, max_am)
     234         1640 :       CALL cp_libint_init_eri1(context%deriv, max_am)
     235         1640 :       CALL cp_libint_set_contrdepth(context%eri, 1)
     236         1640 :       CALL cp_libint_set_contrdepth(context%deriv, 1)
     237       301760 :       ALLOCATE (context%products(128))
     238        41000 :       IF (libint_can_contract_images) ALLOCATE (context%image_workspace, context%image_groups(16))
     239         1640 :    END SUBROUTINE four_center_integral_init
     240              : 
     241              : ! **************************************************************************************************
     242              : !> \brief Release the workspaces of an owning four-center context.
     243              : !> \param context original initialized owner
     244              : ! **************************************************************************************************
     245         1640 :    SUBROUTINE four_center_integral_cleanup(context)
     246              :       TYPE(four_center_integral_context_type), &
     247              :          INTENT(INOUT)                                   :: context
     248              : 
     249         1640 :       IF (ALLOCATED(context%image_workspace)) DEALLOCATE (context%image_workspace, context%image_groups)
     250         1640 :       CALL cp_libint_cleanup_eri(context%eri)
     251         1640 :       CALL cp_libint_cleanup_eri1(context%deriv)
     252         1640 :       DEALLOCATE (context%products)
     253         1640 :       context%nproducts = 0
     254         1640 :       context%nimage_groups = 0
     255         1640 :    END SUBROUTINE four_center_integral_cleanup
     256              : 
     257              : ! **************************************************************************************************
     258              : !> \brief Evaluates derivatives of electron repulsion integrals for a primitive quartet
     259              : !> \param context four-center integral context
     260              : !> \param n_a ...
     261              : !> \param n_b ...
     262              : !> \param n_c ...
     263              : !> \param n_d ...
     264              : !> \param ncoa ...
     265              : !> \param ncob ...
     266              : !> \param ncoc ...
     267              : !> \param ncod ...
     268              : !> \param nsgfa ...
     269              : !> \param nsgfb ...
     270              : !> \param nsgfc ...
     271              : !> \param nsgfd ...
     272              : !> \param primitives ...
     273              : !> \param max_contraction ...
     274              : !> \param tmp_max_all ...
     275              : !> \param eps_schwarz ...
     276              : !> \param neris ...
     277              : !> \param s_offset_a ...
     278              : !> \param s_offset_b ...
     279              : !> \param s_offset_c ...
     280              : !> \param s_offset_d ...
     281              : !> \param nl_a ...
     282              : !> \param nl_b ...
     283              : !> \param nl_c ...
     284              : !> \param nl_d ...
     285              : !> \param nsoa ...
     286              : !> \param nsob ...
     287              : !> \param nsoc ...
     288              : !> \param nsod ...
     289              : !> \param angular_a ...
     290              : !> \param angular_b ...
     291              : !> \param angular_c ...
     292              : !> \param angular_d ...
     293              : !> \param weight_a radial weights of the selected primitive on A
     294              : !> \param weight_b radial weights of the selected primitive on B
     295              : !> \param weight_c radial weights of the selected primitive on C
     296              : !> \param weight_d radial weights of the selected primitive on D
     297              : !> \param work ...
     298              : !> \param work2 ...
     299              : !> \param work_forces ...
     300              : !> \param buffer1 ...
     301              : !> \param buffer2 ...
     302              : !> \param use_virial ...
     303              : !> \param work_virial ...
     304              : !> \param work2_virial ...
     305              : !> \param primitives_virial ...
     306              : !> \param cell ...
     307              : !> \param tmp_max_all_virial ...
     308              : !> \par History
     309              : !>      03.2007 created [Manuel Guidon]
     310              : !>      08.2007 refactured permutation part [Manuel Guidon]
     311              : !> \author Manuel Guidon
     312              : ! **************************************************************************************************
     313     34107738 :    SUBROUTINE evaluate_deriv_eri(context, &
     314              :                                  n_a, n_b, n_c, n_d, &
     315              :                                  ncoa, ncob, ncoc, ncod, &
     316              :                                  nsgfa, nsgfb, nsgfc, nsgfd, &
     317     34107738 :                                  primitives, max_contraction, tmp_max_all, &
     318              :                                  eps_schwarz, neris, &
     319              :                                  s_offset_a, s_offset_b, s_offset_c, s_offset_d, &
     320              :                                  nl_a, nl_b, nl_c, nl_d, nsoa, nsob, nsoc, nsod, &
     321     34107738 :                                  angular_a, angular_b, angular_c, angular_d, &
     322     34107738 :                                  weight_a, weight_b, weight_c, weight_d, &
     323     34107738 :                                  work, work2, work_forces, buffer1, buffer2, &
     324     34107738 :                                  use_virial, work_virial, work2_virial, &
     325     34107738 :                                  primitives_virial, cell, tmp_max_all_virial)
     326              : 
     327              :       TYPE(four_center_integral_context_type), &
     328              :          INTENT(INOUT)                                   :: context
     329              :       INTEGER, INTENT(IN)                                :: n_a, n_b, n_c, n_d, ncoa, ncob, ncoc, &
     330              :                                                             ncod, nsgfa, nsgfb, nsgfc, nsgfd
     331              :       REAL(dp), &
     332              :          DIMENSION(nsgfa, nsgfb, nsgfc, nsgfd, 12)       :: primitives
     333              :       REAL(dp)                                           :: max_contraction, tmp_max_all, eps_schwarz
     334              :       INTEGER(int_8)                                     :: neris
     335              :       INTEGER                                            :: s_offset_a, s_offset_b, s_offset_c, &
     336              :                                                             s_offset_d, nl_a, nl_b, nl_c, nl_d, &
     337              :                                                             nsoa, nsob, nsoc, nsod
     338              :       REAL(dp), DIMENSION(ncoa, nsoa), INTENT(IN)        :: angular_a
     339              :       REAL(dp), DIMENSION(ncob, nsob), INTENT(IN)        :: angular_b
     340              :       REAL(dp), DIMENSION(ncoc, nsoc), INTENT(IN)        :: angular_c
     341              :       REAL(dp), DIMENSION(ncod, nsod), INTENT(IN)        :: angular_d
     342              :       REAL(dp), INTENT(IN)                               :: weight_a(nl_a), weight_b(nl_b), &
     343              :                                                             weight_c(nl_c), weight_d(nl_d)
     344              :       REAL(dp) :: work(ncoa*ncob*ncoc*ncod, 12), work2(ncoa, ncob, ncoc, ncod, 12), &
     345              :          work_forces(ncoa*ncob*ncoc*ncod, 12)
     346              :       REAL(dp), DIMENSION(ncoa*ncob*ncoc*ncod)           :: buffer1, buffer2
     347              :       LOGICAL, INTENT(IN)                                :: use_virial
     348              :       REAL(dp) :: work_virial(ncoa*ncob*ncoc*ncod, 12, 3), &
     349              :          work2_virial(ncoa, ncob, ncoc, ncod, 12, 3)
     350              :       REAL(dp), &
     351              :          DIMENSION(nsgfa, nsgfb, nsgfc, nsgfd, 12, 3)    :: primitives_virial
     352              :       TYPE(cell_type), POINTER                           :: cell
     353              :       REAL(dp)                                           :: tmp_max_all_virial
     354              : 
     355              :       INTEGER                                            :: angular_momenta(4), group_index, i, j, &
     356              :                                                             k, m, mysize, next_group, &
     357              :                                                             permutation(4)
     358              :       REAL(dp)                                           :: scoord(12)
     359              : 
     360     34107738 :       mysize = ncoa*ncob*ncoc*ncod
     361              : 
     362   4881735174 :       work = 0.0_dp
     363              : 
     364     34107738 :       IF (use_virial) THEN
     365    858458504 :          work_virial = 0.0_dp
     366              :       END IF
     367              : 
     368     34107738 :       CALL get_eri_permutation(n_a, n_b, n_c, n_d, permutation)
     369    170538690 :       angular_momenta = [n_a, n_b, n_c, n_d]
     370    341077380 :       angular_momenta = angular_momenta(permutation)
     371              : 
     372     34107738 :       i = 1
     373     34107738 :       group_index = 1
     374     34107738 :       next_group = 0
     375     34107738 :       IF (.NOT. use_virial .AND. context%nimage_groups > 0) next_group = context%image_groups(1)%first
     376     99525196 :       DO WHILE (i <= context%nproducts)
     377     65417458 :          IF (i == next_group) THEN
     378              :             ASSOCIATE (group => context%image_groups(group_index))
     379              :                CALL cp_libint_get_image_derivs(context%deriv, context%image_workspace, angular_momenta, &
     380              :                                                context%products(i:group%last), &
     381      9381522 :                                                permutation, group%displacements, work_forces)
     382      9381522 :                i = group%last
     383              :             END ASSOCIATE
     384      9381522 :             group_index = group_index + 1
     385      9381522 :             next_group = 0
     386      9381522 :             IF (group_index <= context%nimage_groups) next_group = context%image_groups(group_index)%first
     387              :          ELSE
     388              :             CALL cp_libint_set_params_eri_deriv(context%deriv, context%products(i), &
     389    280179680 :                                                 permutation, SUM(angular_momenta) + 1)
     390              :             CALL cp_libint_get_derivs(angular_momenta(4), angular_momenta(3), angular_momenta(2), &
     391     56035936 :                                       angular_momenta(1), context%deriv, work_forces)
     392              :          END IF
     393    850426954 :          DO k = 1, 12
     394   9252696490 :             DO j = 1, mysize
     395   9187279032 :                work(j, k) = work(j, k) + work_forces(j, k)
     396              :             END DO
     397              :          END DO
     398     65417458 :          IF (use_virial) THEN
     399    103732160 :             DO j = 1, 4
     400    103732160 :                CALL real_to_scaled(scoord(3*j - 2:3*j), context%products(i)%centers(:, permutation(j)), cell)
     401              :             END DO
     402    269703616 :             DO k = 1, 12
     403   2501243008 :                DO j = 1, mysize
     404   9175114752 :                   DO m = 1, 3
     405   8926157568 :                      work_virial(j, k, m) = work_virial(j, k, m) + work_forces(j, k)*scoord(INT((k - 1)/3)*3 + m)
     406              :                   END DO
     407              :                END DO
     408              :             END DO
     409              :          END IF
     410     65417458 :          i = i + 1
     411              :       END DO
     412     34107738 :       neris = neris + INT(context%nproducts, int_8)*12*mysize
     413              : 
     414   4881735174 :       tmp_max_all = MAX(tmp_max_all, max_contraction*MAXVAL(ABS(work)))
     415     34107738 :       IF (use_virial) THEN
     416    858458504 :          tmp_max_all_virial = MAX(tmp_max_all_virial, max_contraction*MAXVAL(ABS(work_virial)))
     417              :       END IF
     418              : 
     419     34107738 :       IF (tmp_max_all >= eps_schwarz) THEN
     420    146717930 :          CALL reorder_eri_block(work, work2, [ncoa, ncob, ncoc, ncod], permutation, 12, 1)
     421    381466618 :          DO i = 1, 12
     422              :             CALL contract(ncoa, ncob, ncoc, ncod, nsoa, nsob, nsoc, nsod, &
     423              :                           n_a, n_b, n_c, n_d, nl_a, nl_b, nl_c, nl_d, work2(1, 1, 1, 1, i), &
     424              :                           angular_a, angular_b, angular_c, angular_d, &
     425              :                           weight_a, weight_b, weight_c, weight_d, nsgfa, nsgfb, nsgfc, &
     426              :                           primitives(s_offset_a + 1, s_offset_b + 1, s_offset_c + 1, s_offset_d + 1, i), &
     427    381466618 :                           buffer1, buffer2)
     428              :          END DO
     429              :       END IF
     430              : 
     431     34107738 :       IF (use_virial .AND. tmp_max_all_virial >= eps_schwarz) THEN
     432      4675745 :          CALL reorder_eri_block(work_virial, work2_virial, [ncoa, ncob, ncoc, ncod], permutation, 12, 3)
     433     12156937 :          DO i = 1, 12
     434     45822301 :             DO m = 1, 3
     435              :                CALL contract(ncoa, ncob, ncoc, ncod, nsoa, nsob, nsoc, nsod, &
     436              :                              n_a, n_b, n_c, n_d, nl_a, nl_b, nl_c, nl_d, work2_virial(1, 1, 1, 1, i, m), &
     437              :                              angular_a, angular_b, angular_c, angular_d, &
     438              :                              weight_a, weight_b, weight_c, weight_d, nsgfa, nsgfb, nsgfc, &
     439              :                              primitives_virial(s_offset_a + 1, s_offset_b + 1, s_offset_c + 1, s_offset_d + 1, i, m), &
     440     44887152 :                              buffer1, buffer2)
     441              :             END DO
     442              :          END DO
     443              :       END IF
     444              : 
     445     34107738 :    END SUBROUTINE evaluate_deriv_eri
     446              : 
     447              : ! **************************************************************************************************
     448              : !> \brief Evaluates max-abs values of  electron repulsion integrals for a primitive quartet
     449              : !> \param context four-center integral context
     450              : !> \param A ...
     451              : !> \param B ...
     452              : !> \param C ...
     453              : !> \param D ...
     454              : !> \param Zeta_A ...
     455              : !> \param Zeta_B ...
     456              : !> \param Zeta_C ...
     457              : !> \param Zeta_D ...
     458              : !> \param n_a ...
     459              : !> \param n_b ...
     460              : !> \param n_c ...
     461              : !> \param n_d ...
     462              : !> \param max_val ...
     463              : !> \param potential_parameter ...
     464              : !> \param R1 ...
     465              : !> \param R2 ...
     466              : !> \par History
     467              : !>      03.2007 created [Manuel Guidon]
     468              : !>      08.2007 refactured permutation part [Manuel Guidon]
     469              : !> \author Manuel Guidon
     470              : ! **************************************************************************************************
     471     96357030 :    SUBROUTINE evaluate_eri_screen(context, A, B, C, D, Zeta_A, Zeta_B, Zeta_C, Zeta_D, &
     472              :                                   n_a, n_b, n_c, n_d, &
     473              :                                   max_val, potential_parameter, R1, R2)
     474              : 
     475              :       TYPE(four_center_integral_context_type), &
     476              :          INTENT(INOUT)                                   :: context
     477              :       REAL(dp), INTENT(IN)                               :: A(3), B(3), C(3), D(3), Zeta_A, Zeta_B, &
     478              :                                                             Zeta_C, Zeta_D
     479              :       INTEGER, INTENT(IN)                                :: n_a, n_b, n_c, n_d
     480              :       REAL(dp), INTENT(INOUT)                            :: max_val
     481              :       TYPE(coulomb_operator_type)                        :: potential_parameter
     482              :       REAL(dp)                                           :: R1, R2
     483              : 
     484              :       INTEGER                                            :: angular_momenta(4), i, m_max, mysize, &
     485              :                                                             permutation(4)
     486              :       REAL(dp)                                           :: centers(3, 4), exponents(4), PQ(3), PQ2, &
     487              :                                                             S1234
     488     96357030 :       REAL(dp), POINTER                                  :: p_work(:)
     489              :       TYPE(eri4_pgf_image_type)                          :: image_a, image_b
     490              :       TYPE(eri4_pgf_pair_type)                           :: pair_a, pair_b
     491              :       TYPE(eri_primitive_data_type)                      :: product
     492              : 
     493     96357030 :       m_max = n_a + n_b + n_c + n_d
     494     96357030 :       mysize = nco(n_a)*nco(n_b)*nco(n_c)*nco(n_d)
     495              : 
     496    481785150 :       angular_momenta = [n_a, n_b, n_c, n_d]
     497    385428120 :       centers(:, 1) = A
     498    385428120 :       centers(:, 2) = B
     499    385428120 :       centers(:, 3) = C
     500    385428120 :       centers(:, 4) = D
     501    481785150 :       exponents = [Zeta_A, Zeta_B, Zeta_C, Zeta_D]
     502              : 
     503     96357030 :       CALL get_eri_permutation(n_a, n_b, n_c, n_d, permutation)
     504    867213270 :       angular_momenta = angular_momenta(permutation)
     505   3179781990 :       centers = centers(:, permutation)
     506    867213270 :       exponents = exponents(permutation)
     507              : 
     508    385428120 :       PQ = centers(:, 1) - centers(:, 2)
     509              :       CALL prepare_eri4_pair(centers(:, 1), centers(:, 2), exponents(1), exponents(2), &
     510    385428120 :                              DOT_PRODUCT(PQ, PQ), pair_a, image_a)
     511    385428120 :       PQ = centers(:, 3) - centers(:, 4)
     512              :       CALL prepare_eri4_pair(centers(:, 3), centers(:, 4), exponents(3), exponents(4), &
     513    385428120 :                              DOT_PRODUCT(PQ, PQ), pair_b, image_b)
     514    385428120 :       PQ = image_a%P - image_b%P
     515    385428120 :       PQ2 = DOT_PRODUCT(PQ, PQ)
     516    113734080 :       SELECT CASE (potential_parameter%potential_type)
     517              :       CASE (do_potential_truncated, do_potential_short, do_potential_mix_cl_trunc)
     518     96357030 :          IF (PQ2 > (R1 + R2 + potential_parameter%cutoff_radius)**2) RETURN
     519              :       END SELECT
     520              : 
     521     96357030 :       CALL prepare_eri4_product(pair_a, pair_b, m_max, product)
     522     96357030 :       S1234 = EXP(image_a%S1234 + image_b%S1234)
     523     96357030 :       CALL prepare_eri4_primitive(product, image_a, image_b, S1234, PQ2, potential_parameter, context%products(1))
     524     96357030 :       IF (m_max == 0) THEN
     525     36443022 :          max_val = ABS(context%products(1)%Fm(1))
     526              :       ELSE
     527     59914008 :          CALL cp_libint_set_params_eri(context%eri, context%products(1), [1, 2, 3, 4], m_max)
     528              :          CALL cp_libint_get_eris(angular_momenta(4), angular_momenta(3), angular_momenta(2), &
     529     59914008 :                                  angular_momenta(1), context%eri, p_work)
     530   4074756726 :          DO i = 1, mysize
     531   4074756726 :             max_val = MAX(max_val, ABS(p_work(i)))
     532              :          END DO
     533              :       END IF
     534              : 
     535   6648635070 :    END SUBROUTINE evaluate_eri_screen
     536              : 
     537              : ! **************************************************************************************************
     538              : !> \brief Evaluate electron repulsion integrals for a primitive quartet
     539              : !> \param context four-center integral context
     540              : !> \param n_a ...
     541              : !> \param n_b ...
     542              : !> \param n_c ...
     543              : !> \param n_d ...
     544              : !> \param ncoa ...
     545              : !> \param ncob ...
     546              : !> \param ncoc ...
     547              : !> \param ncod ...
     548              : !> \param nsgfa ...
     549              : !> \param nsgfb ...
     550              : !> \param nsgfc ...
     551              : !> \param nsgfd ...
     552              : !> \param primitives ...
     553              : !> \param max_contraction ...
     554              : !> \param tmp_max ...
     555              : !> \param eps_schwarz ...
     556              : !> \param neris ...
     557              : !> \param s_offset_a ...
     558              : !> \param s_offset_b ...
     559              : !> \param s_offset_c ...
     560              : !> \param s_offset_d ...
     561              : !> \param nl_a ...
     562              : !> \param nl_b ...
     563              : !> \param nl_c ...
     564              : !> \param nl_d ...
     565              : !> \param nsoa ...
     566              : !> \param nsob ...
     567              : !> \param nsoc ...
     568              : !> \param nsod ...
     569              : !> \param angular_a ...
     570              : !> \param angular_b ...
     571              : !> \param angular_c ...
     572              : !> \param angular_d ...
     573              : !> \param weight_a radial weights of the selected primitive on A
     574              : !> \param weight_b radial weights of the selected primitive on B
     575              : !> \param weight_c radial weights of the selected primitive on C
     576              : !> \param weight_d radial weights of the selected primitive on D
     577              : !> \param work2 ...
     578              : !> \param buffer1 ...
     579              : !> \param buffer2 ...
     580              : !> \par History
     581              : !>      11.2006 created [Manuel Guidon]
     582              : !>      08.2007 refactured permutation part [Manuel Guidon]
     583              : !> \author Manuel Guidon
     584              : ! **************************************************************************************************
     585    167778296 :    SUBROUTINE evaluate_eri(context, &
     586              :                            n_a, n_b, n_c, n_d, &
     587              :                            ncoa, ncob, ncoc, ncod, &
     588              :                            nsgfa, nsgfb, nsgfc, nsgfd, &
     589    167778296 :                            primitives, max_contraction, tmp_max, &
     590              :                            eps_schwarz, neris, &
     591              :                            s_offset_a, s_offset_b, s_offset_c, s_offset_d, &
     592              :                            nl_a, nl_b, nl_c, nl_d, nsoa, nsob, nsoc, nsod, &
     593    167778296 :                            angular_a, angular_b, angular_c, angular_d, &
     594    167778296 :                            weight_a, weight_b, weight_c, weight_d, work2, buffer1, buffer2)
     595              : 
     596              :       TYPE(four_center_integral_context_type), &
     597              :          INTENT(INOUT)                                   :: context
     598              :       INTEGER, INTENT(IN)                                :: n_a, n_b, n_c, n_d, ncoa, ncob, ncoc, &
     599              :                                                             ncod, nsgfa, nsgfb, nsgfc, nsgfd
     600              :       REAL(dp), DIMENSION(nsgfa, nsgfb, nsgfc, nsgfd)    :: primitives
     601              :       REAL(dp)                                           :: max_contraction, tmp_max, eps_schwarz
     602              :       INTEGER(int_8)                                     :: neris
     603              :       INTEGER                                            :: s_offset_a, s_offset_b, s_offset_c, &
     604              :                                                             s_offset_d, nl_a, nl_b, nl_c, nl_d, &
     605              :                                                             nsoa, nsob, nsoc, nsod
     606              :       REAL(dp), DIMENSION(ncoa, nsoa), INTENT(IN)        :: angular_a
     607              :       REAL(dp), DIMENSION(ncob, nsob), INTENT(IN)        :: angular_b
     608              :       REAL(dp), DIMENSION(ncoc, nsoc), INTENT(IN)        :: angular_c
     609              :       REAL(dp), DIMENSION(ncod, nsod), INTENT(IN)        :: angular_d
     610              :       REAL(dp), INTENT(IN)                               :: weight_a(nl_a), weight_b(nl_b), &
     611              :                                                             weight_c(nl_c), weight_d(nl_d)
     612              :       REAL(dp)                                           :: work2(ncoa, ncob, ncoc, ncod)
     613              :       REAL(dp), DIMENSION(ncoa*ncob*ncoc*ncod), TARGET   :: buffer1
     614              :       REAL(dp), DIMENSION(ncoa*ncob*ncoc*ncod)           :: buffer2
     615              : 
     616              :       INTEGER                                            :: angular_momenta(4), group_index, i, &
     617              :                                                             m_max, mysize, next_group, &
     618              :                                                             permutation(4)
     619    167778296 :       REAL(dp), POINTER                                  :: p_work(:)
     620              : 
     621    196841146 :       IF (context%nproducts == 0) RETURN
     622    167778296 :       mysize = ncoa*ncob*ncoc*ncod
     623    167778296 :       m_max = n_a + n_b + n_c + n_d
     624    167778296 :       CALL get_eri_permutation(n_a, n_b, n_c, n_d, permutation)
     625    838891480 :       angular_momenta = [n_a, n_b, n_c, n_d]
     626   1510004664 :       angular_momenta = angular_momenta(permutation)
     627    167778296 :       IF (m_max /= 0) THEN
     628    252848628 :          IF (context%nproducts > 1) buffer1 = 0.0_dp
     629    132582981 :          i = 1
     630    132582981 :          group_index = 1
     631    132582981 :          next_group = 0
     632    132582981 :          IF (context%nimage_groups > 0) next_group = context%image_groups(1)%first
     633    293661025 :          DO WHILE (i <= context%nproducts)
     634    161078044 :             IF (i == next_group) THEN
     635              :                ASSOCIATE (group => context%image_groups(group_index))
     636              :                   CALL cp_libint_get_image_eris(context%eri, context%image_workspace, angular_momenta, &
     637              :                                                 context%products(i:group%last), &
     638     26202739 :                                                 permutation, group%displacements, p_work)
     639     26202739 :                   i = group%last
     640              :                END ASSOCIATE
     641     26202739 :                group_index = group_index + 1
     642     26202739 :                next_group = 0
     643     26202739 :                IF (group_index <= context%nimage_groups) next_group = context%image_groups(group_index)%first
     644              :             ELSE
     645    134875305 :                CALL cp_libint_set_params_eri(context%eri, context%products(i), permutation, m_max)
     646              :                CALL cp_libint_get_eris(angular_momenta(4), angular_momenta(3), angular_momenta(2), &
     647    134875305 :                                        angular_momenta(1), context%eri, p_work)
     648              :             END IF
     649   1312617856 :             IF (context%nproducts > 1) buffer1 = buffer1 + p_work(1:mysize)
     650    161078044 :             i = i + 1
     651              :          END DO
     652    132582981 :          IF (context%nproducts > 1) p_work => buffer1
     653   3367108718 :          tmp_max = MAX(tmp_max, MAXVAL(ABS(p_work)))
     654              :       ELSE
     655    175976575 :          work2 = 0.0_dp
     656    158321593 :          DO i = 1, context%nproducts
     657    158321593 :             work2(1, 1, 1, 1) = work2(1, 1, 1, 1) + context%products(i)%Fm(1)
     658              :          END DO
     659     35195315 :          tmp_max = MAX(tmp_max, ABS(work2(1, 1, 1, 1)))
     660              :       END IF
     661    167778296 :       neris = neris + INT(context%nproducts, int_8)*mysize
     662    167778296 :       tmp_max = tmp_max*max_contraction
     663    167778296 :       IF (tmp_max < eps_schwarz) RETURN
     664    563645150 :       IF (m_max /= 0) CALL reorder_eri_block(p_work, work2, [ncoa, ncob, ncoc, ncod], permutation, 1, 1)
     665              : 
     666              :       CALL contract(ncoa, ncob, ncoc, ncod, nsoa, nsob, nsoc, nsod, &
     667              :                     n_a, n_b, n_c, n_d, nl_a, nl_b, nl_c, nl_d, work2, &
     668              :                     angular_a, angular_b, angular_c, angular_d, &
     669              :                     weight_a, weight_b, weight_c, weight_d, nsgfa, nsgfb, nsgfc, &
     670              :                     primitives(s_offset_a + 1, s_offset_b + 1, s_offset_c + 1, s_offset_d + 1), &
     671    138715446 :                     buffer1, buffer2)
     672              : 
     673              :    END SUBROUTINE evaluate_eri
     674              : 
     675            0 : END MODULE four_center_integral_interface
        

Generated by: LCOV version 2.0-1