LCOV - code coverage report
Current view: top level - src - hfx_screening_methods.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 99.5 % 408 406
Test Date: 2026-11-24 01:22:08 Functions: 100.0 % 6 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 Several screening methods used in HFX calcualtions
      10              : !> \par History
      11              : !>      04.2008 created [Manuel Guidon]
      12              : !> \author Manuel Guidon
      13              : ! **************************************************************************************************
      14              : MODULE hfx_screening_methods
      15              :    USE ao_util,                         ONLY: exp_radius_very_extended
      16              :    USE basis_set_types,                 ONLY: gto_basis_set_type
      17              :    USE four_center_integral_interface,  ONLY: evaluate_eri_screen,&
      18              :                                               four_center_integral_context_type
      19              :    USE hfx_types,                       ONLY: hfx_basis_type,&
      20              :                                               hfx_p_kind,&
      21              :                                               hfx_potential_type,&
      22              :                                               hfx_screen_coeff_type,&
      23              :                                               log_zero,&
      24              :                                               powell_min_log
      25              :    USE kinds,                           ONLY: dp,&
      26              :                                               int_8
      27              :    USE machine,                         ONLY: default_output_unit
      28              :    USE orbital_pointers,                ONLY: ncoset
      29              :    USE powell,                          ONLY: opt_state_type,&
      30              :                                               powell_optimize
      31              :    USE qs_environment_types,            ONLY: get_qs_env,&
      32              :                                               qs_environment_type
      33              :    USE qs_kind_types,                   ONLY: get_qs_kind,&
      34              :                                               qs_kind_type
      35              : #include "./base/base_uses.f90"
      36              : 
      37              :    IMPLICIT NONE
      38              :    PRIVATE
      39              : 
      40              :    PUBLIC :: update_pmax_mat, &
      41              :              calc_screening_functions, &
      42              :              calc_pair_dist_radii
      43              : 
      44              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'hfx_screening_methods'
      45              : 
      46              : !***
      47              : 
      48              : CONTAINS
      49              : 
      50              : ! **************************************************************************************************
      51              : !> \brief calculates max values of two-electron integrals in a quartet/shell
      52              : !>      w.r.t. different zetas using the library lib_int
      53              : !> \param context four-center integral context
      54              : !> \param ra position
      55              : !> \param rb position
      56              : !> \param zeta zeta
      57              : !> \param zetb zeta
      58              : !> \param la_min angular momentum
      59              : !> \param la_max angular momentum
      60              : !> \param lb_min angular momentum
      61              : !> \param lb_max angular momentum
      62              : !> \param npgfa number of primitive cartesian gaussian in actual shell
      63              : !> \param npgfb number of primitive cartesian gaussian in actual shell
      64              : !> \param max_val schwarz screening value
      65              : !> \param potential_parameter radial operator parameters
      66              : !> \param tmp_R_1 pgf_based screening coefficients
      67              : !> \param rab2 Squared Distance of centers ab
      68              : !> \par History
      69              : !>     03.2007 created [Manuel Guidon]
      70              : !>     02.2009 refactored [Manuel Guidon]
      71              : !> \author Manuel Guidon
      72              : ! **************************************************************************************************
      73     10067276 :    SUBROUTINE screen4(context, ra, rb, zeta, zetb, &
      74              :                       la_min, la_max, lb_min, lb_max, &
      75              :                       npgfa, npgfb, &
      76              :                       max_val, potential_parameter, tmp_R_1, &
      77              :                       rab2)
      78              : 
      79              :       TYPE(four_center_integral_context_type), &
      80              :          INTENT(INOUT)                                   :: context
      81              :       REAL(dp), INTENT(IN)                               :: ra(3), rb(3)
      82              :       REAL(dp), DIMENSION(:), INTENT(IN)                 :: zeta, zetb
      83              :       INTEGER, INTENT(IN)                                :: la_min, la_max, lb_min, lb_max, npgfa, &
      84              :                                                             npgfb
      85              :       REAL(dp), INTENT(INOUT)                            :: max_val
      86              :       TYPE(hfx_potential_type)                           :: potential_parameter
      87              :       TYPE(hfx_screen_coeff_type), DIMENSION(:, :), &
      88              :          POINTER                                         :: tmp_R_1
      89              :       REAL(dp)                                           :: rab2
      90              : 
      91              :       INTEGER                                            :: ipgf, jpgf, la, lb
      92              :       REAL(dp)                                           :: max_val_temp, R1
      93              : 
      94     10067276 :       max_val_temp = max_val
      95     27301916 :       DO ipgf = 1, npgfa
      96     62721000 :          DO jpgf = 1, npgfb
      97     35419084 :             R1 = MAX(0.0_dp, tmp_R_1(jpgf, ipgf)%x(1)*rab2 + tmp_R_1(jpgf, ipgf)%x(2))
      98     99235732 :             DO la = la_min, la_max
      99    146239112 :                DO lb = lb_min, lb_max
     100              :                   !Build primitives
     101              :                   CALL evaluate_eri_screen(context, ra, rb, ra, rb, &
     102              :                                            zeta(ipgf), zetb(jpgf), zeta(ipgf), zetb(jpgf), &
     103              :                                            la, lb, la, lb, &
     104     64238020 :                                            max_val_temp, potential_parameter, R1, R1)
     105              : 
     106    110820028 :                   max_val = MAX(max_val, max_val_temp)
     107              :                END DO !lb
     108              :             END DO !la
     109              :          END DO !jpgf
     110              :       END DO !ipgf
     111     10067276 :    END SUBROUTINE screen4
     112              : 
     113              : ! **************************************************************************************************
     114              : !> \brief updates the maximum of the density matrix in compressed form for screening purposes
     115              : !> \param pmax_set buffer to store matrix
     116              : !> \param map_atom_to_kind_atom ...
     117              : !> \param set_offset ...
     118              : !> \param atomic_block_offset ...
     119              : !> \param pmax_atom ...
     120              : !> \param full_density_alpha ...
     121              : !> \param full_density_beta ...
     122              : !> \param natom ...
     123              : !> \param kind_of ...
     124              : !> \param basis_parameter ...
     125              : !> \param nkind ...
     126              : !> \param is_assoc_atomic_block ...
     127              : !> \param nspins number of spin channels, used to express bounds in restricted-density units
     128              : !> \par History
     129              : !>     09.2007 created [Manuel Guidon]
     130              : !> \author Manuel Guidon
     131              : !> \note
     132              : !>      - stores log10(nspins*max(abs(p_alpha),abs(p_beta))) for each shell pair,
     133              : !>        so equivalent restricted and unrestricted closed-shell densities have the same bound
     134              : ! **************************************************************************************************
     135         1612 :    SUBROUTINE update_pmax_mat(pmax_set, map_atom_to_kind_atom, set_offset, atomic_block_offset, &
     136              :                               pmax_atom, full_density_alpha, full_density_beta, natom, &
     137              :                               kind_of, basis_parameter, &
     138          806 :                               nkind, is_assoc_atomic_block, nspins)
     139              : 
     140              :       TYPE(hfx_p_kind), DIMENSION(:), POINTER            :: pmax_set
     141              :       INTEGER, DIMENSION(:), POINTER                     :: map_atom_to_kind_atom
     142              :       INTEGER, DIMENSION(:, :, :, :), POINTER            :: set_offset
     143              :       INTEGER, DIMENSION(:, :), POINTER                  :: atomic_block_offset
     144              :       REAL(dp), DIMENSION(:, :), POINTER                 :: pmax_atom, full_density_alpha, &
     145              :                                                             full_density_beta
     146              :       INTEGER, INTENT(IN)                                :: natom
     147              :       INTEGER                                            :: kind_of(*)
     148              :       TYPE(hfx_basis_type), DIMENSION(:), POINTER        :: basis_parameter
     149              :       INTEGER                                            :: nkind
     150              :       INTEGER, DIMENSION(:, :)                           :: is_assoc_atomic_block
     151              :       INTEGER, INTENT(IN)                                :: nspins
     152              : 
     153              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'update_pmax_mat'
     154              : 
     155              :       INTEGER :: act_atomic_block_offset, act_set_offset, handle, i, img, jatom, jkind, jset, &
     156              :          katom, kind_kind_idx, kkind, kset, mb, mc, nimg, nsetb, nsetc
     157          806 :       INTEGER, DIMENSION(:), POINTER                     :: nsgfb, nsgfc
     158              :       REAL(dp)                                           :: pmax_tmp
     159              : 
     160          806 :       CALL timeset(routineN, handle)
     161              : 
     162         3124 :       DO i = 1, SIZE(pmax_set)
     163        78968 :          pmax_set(i)%p_kind = 0.0_dp
     164              :       END DO
     165              : 
     166        11838 :       pmax_atom = log_zero
     167              : 
     168          806 :       nimg = SIZE(full_density_alpha, 2)
     169              : 
     170         3316 :       DO jatom = 1, natom
     171         2510 :          jkind = kind_of(jatom)
     172         2510 :          nsetb = basis_parameter(jkind)%nset
     173         2510 :          nsgfb => basis_parameter(jkind)%nsgf
     174              : 
     175        11838 :          DO katom = 1, natom
     176         8522 :             IF (.NOT. is_assoc_atomic_block(jatom, katom) >= 1) CYCLE
     177         8474 :             kkind = kind_of(katom)
     178         8474 :             IF (kkind < jkind) CYCLE
     179         6768 :             nsetc = basis_parameter(kkind)%nset
     180         6768 :             nsgfc => basis_parameter(kkind)%nsgf
     181         6768 :             act_atomic_block_offset = atomic_block_offset(katom, jatom)
     182        26562 :             DO jset = 1, nsetb
     183        74770 :                DO kset = 1, nsetc
     184        66248 :                   IF (katom >= jatom) THEN
     185        42190 :                      pmax_tmp = 0.0_dp
     186        42190 :                      act_set_offset = set_offset(kset, jset, kkind, jkind)
     187        84380 :                      DO img = 1, nimg
     188        42190 :                         i = act_set_offset + act_atomic_block_offset - 1
     189       164582 :                         DO mc = 1, nsgfc(kset)
     190       347264 :                            DO mb = 1, nsgfb(jset)
     191       224872 :                               pmax_tmp = MAX(pmax_tmp, ABS(full_density_alpha(i, img)))
     192       224872 :                               IF (ASSOCIATED(full_density_beta)) THEN
     193        42600 :                                  pmax_tmp = MAX(pmax_tmp, ABS(full_density_beta(i, img)))
     194              :                               END IF
     195       305074 :                               i = i + 1
     196              :                            END DO
     197              :                         END DO
     198              :                      END DO
     199        42190 :                      IF (pmax_tmp == 0.0_dp) THEN
     200              :                         pmax_tmp = log_zero
     201              :                      ELSE
     202        41964 :                         pmax_tmp = LOG10(REAL(nspins, dp)*pmax_tmp)
     203              :                      END IF
     204        42190 :                      kind_kind_idx = INT(get_1D_idx(jkind, kkind, INT(nkind, int_8)))
     205              :                      pmax_set(kind_kind_idx)%p_kind(jset, &
     206              :                                                     kset, &
     207              :                                                     map_atom_to_kind_atom(jatom), &
     208        42190 :                                                     map_atom_to_kind_atom(katom)) = pmax_tmp
     209              :                   ELSE
     210         6774 :                      pmax_tmp = 0.0_dp
     211         6774 :                      act_set_offset = set_offset(jset, kset, jkind, kkind)
     212        13548 :                      DO img = 1, nimg
     213        26252 :                         DO mc = 1, nsgfc(kset)
     214        12704 :                            i = act_set_offset + act_atomic_block_offset - 1 + mc - 1
     215        48444 :                            DO mb = 1, nsgfb(jset)
     216        28966 :                               pmax_tmp = MAX(pmax_tmp, ABS(full_density_alpha(i, img)))
     217        28966 :                               IF (ASSOCIATED(full_density_beta)) THEN
     218         3010 :                                  pmax_tmp = MAX(pmax_tmp, ABS(full_density_beta(i, img)))
     219              :                               END IF
     220        41670 :                               i = i + nsgfc(kset)
     221              :                            END DO
     222              :                         END DO
     223              :                      END DO
     224         6774 :                      IF (pmax_tmp == 0.0_dp) THEN
     225              :                         pmax_tmp = log_zero
     226              :                      ELSE
     227         6748 :                         pmax_tmp = LOG10(REAL(nspins, dp)*pmax_tmp)
     228              :                      END IF
     229         6774 :                      kind_kind_idx = INT(get_1D_idx(jkind, kkind, INT(nkind, int_8)))
     230              :                      pmax_set(kind_kind_idx)%p_kind(jset, &
     231              :                                                     kset, &
     232              :                                                     map_atom_to_kind_atom(jatom), &
     233         6774 :                                                     map_atom_to_kind_atom(katom)) = pmax_tmp
     234              :                   END IF
     235              :                END DO
     236              :             END DO
     237              :          END DO
     238              :       END DO
     239              : 
     240         3316 :       DO jatom = 1, natom
     241         2510 :          jkind = kind_of(jatom)
     242         2510 :          nsetb = basis_parameter(jkind)%nset
     243        11838 :          DO katom = 1, natom
     244         8522 :             IF (.NOT. is_assoc_atomic_block(jatom, katom) >= 1) CYCLE
     245         8474 :             kkind = kind_of(katom)
     246         8474 :             IF (kkind < jkind) CYCLE
     247         6768 :             nsetc = basis_parameter(kkind)%nset
     248         6768 :             pmax_tmp = log_zero
     249        24052 :             DO jset = 1, nsetb
     250        73016 :                DO kset = 1, nsetc
     251        48964 :                   kind_kind_idx = INT(get_1D_idx(jkind, kkind, INT(nkind, int_8)))
     252              :                   pmax_tmp = MAX(pmax_set(kind_kind_idx)%p_kind(jset, &
     253              :                                                                 kset, &
     254              :                                                                 map_atom_to_kind_atom(jatom), &
     255        66248 :                                                                 map_atom_to_kind_atom(katom)), pmax_tmp)
     256              :                END DO
     257              :             END DO
     258         6768 :             pmax_atom(jatom, katom) = pmax_tmp
     259        11032 :             pmax_atom(katom, jatom) = pmax_tmp
     260              :          END DO
     261              :       END DO
     262              : 
     263          806 :       CALL timestop(handle)
     264              : 
     265          806 :    END SUBROUTINE update_pmax_mat
     266              : 
     267              : ! **************************************************************************************************
     268              : !> \brief calculates screening functions for schwarz screening
     269              : !> \param qs_env qs_env
     270              : !> \param basis_parameter ...
     271              : !> \param context structure to libint
     272              : !> \param potential_parameter contains infos on potential
     273              : !> \param coeffs_set set based coefficients
     274              : !> \param coeffs_kind kind based coefficients
     275              : !> \param coeffs_pgf pgf based coefficients
     276              : !> \param radii_pgf coefficients for long-range screening
     277              : !> \param max_set Maximum Number of basis set sets in the system
     278              : !> \param max_pgf Maximum Number of basis set pgfs in the system
     279              : !> \param n_threads ...
     280              : !> \param i_thread Thread ID of current task
     281              : !> \par History
     282              : !>     02.2009 created [Manuel Guidon]
     283              : !> \author Manuel Guidon
     284              : !> \note
     285              : !>      This routine calculates (ab|ab) for different distances Rab = |a-b|
     286              : !>      and uses the powell optimiztion routines in order to fit the results
     287              : !>      in the following form:
     288              : !>
     289              : !>                 (ab|ab) = (ab|ab)(Rab) = c2*Rab^2 + c0
     290              : !>
     291              : !>      The missing linear term assures that the functions is monotonically
     292              : !>      decaying such that c2 can be used as upper bound when applying the
     293              : !>      Minimum Image Convention in the periodic case. Furthermore
     294              : !>      it seems to be a good choice to fit the logarithm of the (ab|ab)
     295              : !>      The fitting takes place at several levels: kind, set and pgf within
     296              : !>      the corresponding ranges of the prodiuct charge distributions
     297              : !>      Doing so, we only need arrays of size nkinds^2*2 instead of big
     298              : !>      screening matrices
     299              : ! **************************************************************************************************
     300              : 
     301         1492 :    SUBROUTINE calc_screening_functions(qs_env, basis_parameter, context, potential_parameter, &
     302              :                                        coeffs_set, coeffs_kind, coeffs_pgf, radii_pgf, &
     303              :                                        max_set, max_pgf, n_threads, i_thread)
     304              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     305              :       TYPE(hfx_basis_type), DIMENSION(:), POINTER        :: basis_parameter
     306              :       TYPE(four_center_integral_context_type), &
     307              :          INTENT(INOUT)                                   :: context
     308              :       TYPE(hfx_potential_type)                           :: potential_parameter
     309              :       TYPE(hfx_screen_coeff_type), &
     310              :          DIMENSION(:, :, :, :), POINTER                  :: coeffs_set
     311              :       TYPE(hfx_screen_coeff_type), DIMENSION(:, :), &
     312              :          POINTER                                         :: coeffs_kind
     313              :       TYPE(hfx_screen_coeff_type), &
     314              :          DIMENSION(:, :, :, :, :, :), POINTER            :: coeffs_pgf, radii_pgf
     315              :       INTEGER, INTENT(IN)                                :: max_set, max_pgf, n_threads, i_thread
     316              : 
     317              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'calc_screening_functions'
     318              : 
     319              :       INTEGER                                            :: handle, i, ikind, ipgf, iset, jkind, &
     320              :                                                             jpgf, jset, la, lb, ncoa, ncob, nkind, &
     321              :                                                             nseta, nsetb, sgfa, sgfb
     322         1492 :       INTEGER, DIMENSION(:), POINTER                     :: la_max, la_min, lb_max, lb_min, npgfa, &
     323         1492 :                                                             npgfb, nsgfa, nsgfb
     324         1492 :       INTEGER, DIMENSION(:, :), POINTER                  :: first_sgfa, first_sgfb
     325              :       REAL(dp) :: kind_radius_a, kind_radius_b, max_contraction_a, max_contraction_b, max_val, &
     326              :          max_val_temp, R1, ra(3), radius, rb(3), x(2)
     327         1492 :       REAL(dp), DIMENSION(:), POINTER                    :: set_radius_a, set_radius_b
     328         1492 :       REAL(dp), DIMENSION(:, :), POINTER                 :: rpgfa, rpgfb, sphi_a, sphi_b, zeta, zetb
     329              :       REAL(dp), SAVE                                     :: DATA(2, 0:100)
     330              :       TYPE(gto_basis_set_type), POINTER                  :: orb_basis
     331              :       TYPE(hfx_screen_coeff_type), DIMENSION(:, :), &
     332         1492 :          POINTER                                         :: tmp_R_1
     333         1492 :       TYPE(qs_kind_type), DIMENSION(:), POINTER          :: qs_kind_set
     334              :       TYPE(qs_kind_type), POINTER                        :: qs_kind
     335              : 
     336         2984 : !$OMP MASTER
     337         1492 :       CALL timeset(routineN, handle)
     338              : !$OMP END MASTER
     339              : 
     340              :       CALL get_qs_env(qs_env=qs_env, &
     341         1492 :                       qs_kind_set=qs_kind_set)
     342              : 
     343         1492 :       nkind = SIZE(qs_kind_set, 1)
     344              : 
     345         1492 : !$OMP MASTER
     346      1369676 :       ALLOCATE (coeffs_pgf(max_pgf, max_pgf, max_set, max_set, nkind, nkind))
     347              : 
     348         4192 :       DO ikind = 1, nkind
     349        10388 :          DO jkind = 1, nkind
     350        26548 :             DO iset = 1, max_set
     351        94656 :                DO jset = 1, max_set
     352       311516 :                   DO ipgf = 1, max_pgf
     353      1328208 :                      DO jpgf = 1, max_pgf
     354      3326088 :                         coeffs_pgf(jpgf, ipgf, jset, iset, jkind, ikind)%x(:) = 0.0_dp
     355              :                      END DO
     356              :                   END DO
     357              :                END DO
     358              :             END DO
     359              :          END DO
     360              :       END DO
     361              : 
     362              : !$OMP END MASTER
     363         1492 : !$OMP BARRIER
     364         1492 :       ra = 0.0_dp
     365         1492 :       rb = 0.0_dp
     366         4192 :       DO ikind = 1, nkind
     367         2700 :          NULLIFY (qs_kind, orb_basis)
     368         2700 :          qs_kind => qs_kind_set(ikind)
     369         2700 :          CALL get_qs_kind(qs_kind=qs_kind, basis_set=orb_basis)
     370         2700 :          NULLIFY (la_max, la_min, npgfa, zeta)
     371              : 
     372         2700 :          la_max => basis_parameter(ikind)%lmax
     373         2700 :          la_min => basis_parameter(ikind)%lmin
     374         2700 :          npgfa => basis_parameter(ikind)%npgf
     375         2700 :          nseta = basis_parameter(ikind)%nset
     376         2700 :          zeta => basis_parameter(ikind)%zet
     377         2700 :          set_radius_a => basis_parameter(ikind)%set_radius
     378         2700 :          first_sgfa => basis_parameter(ikind)%first_sgf
     379         2700 :          sphi_a => basis_parameter(ikind)%sphi
     380         2700 :          nsgfa => basis_parameter(ikind)%nsgf
     381         2700 :          rpgfa => basis_parameter(ikind)%pgf_radius
     382              : 
     383        10388 :          DO jkind = 1, nkind
     384         6196 :             NULLIFY (qs_kind, orb_basis)
     385         6196 :             qs_kind => qs_kind_set(jkind)
     386         6196 :             CALL get_qs_kind(qs_kind=qs_kind, basis_set=orb_basis)
     387         6196 :             NULLIFY (lb_max, lb_min, npgfb, zetb)
     388              : 
     389         6196 :             lb_max => basis_parameter(jkind)%lmax
     390         6196 :             lb_min => basis_parameter(jkind)%lmin
     391         6196 :             npgfb => basis_parameter(jkind)%npgf
     392         6196 :             nsetb = basis_parameter(jkind)%nset
     393         6196 :             zetb => basis_parameter(jkind)%zet
     394         6196 :             set_radius_b => basis_parameter(jkind)%set_radius
     395         6196 :             first_sgfb => basis_parameter(jkind)%first_sgf
     396         6196 :             sphi_b => basis_parameter(jkind)%sphi
     397         6196 :             nsgfb => basis_parameter(jkind)%nsgf
     398         6196 :             rpgfb => basis_parameter(jkind)%pgf_radius
     399              : 
     400        24222 :             DO iset = 1, nseta
     401        15326 :                ncoa = npgfa(iset)*ncoset(la_max(iset))
     402        15326 :                sgfa = first_sgfa(1, iset)
     403       577728 :                max_contraction_a = MAXVAL([(SUM(ABS(sphi_a(1:ncoa, i))), i=sgfa, sgfa + nsgfa(iset) - 1)])
     404        71360 :                DO jset = 1, nsetb
     405        49838 :                   ncob = npgfb(jset)*ncoset(lb_max(jset))
     406        49838 :                   sgfb = first_sgfb(1, jset)
     407      1288214 :                   max_contraction_b = MAXVAL([(SUM(ABS(sphi_b(1:ncob, i))), i=sgfb, sgfb + nsgfb(jset) - 1)])
     408        49838 :                   radius = set_radius_a(iset) + set_radius_b(jset)
     409       150484 :                   DO ipgf = 1, npgfa(iset)
     410       310500 :                      DO jpgf = 1, npgfb(jset)
     411       175342 :                         radius = rpgfa(ipgf, iset) + rpgfb(jpgf, jset)
     412     17884884 :                         DO i = i_thread, 100, n_threads
     413     17709542 :                            rb(1) = 0.0_dp + REAL(i, dp)*0.01_dp*radius
     414     17709542 :                            max_val = 0.0_dp
     415              :                            R1 = MAX(0.0_dp, radii_pgf(jpgf, ipgf, jset, iset, jkind, ikind)%x(1)*rb(1)**2 + &
     416     17709542 :                                     radii_pgf(jpgf, ipgf, jset, iset, jkind, ikind)%x(2))
     417     41000546 :                            DO la = la_min(iset), la_max(iset)
     418     73119556 :                               DO lb = lb_min(jset), lb_max(jset)
     419              :                                  !Build primitives
     420     32119010 :                                  max_val_temp = 0.0_dp
     421              :                                  CALL evaluate_eri_screen(context, ra, rb, ra, rb, &
     422              :                                                           zeta(ipgf, iset), zetb(jpgf, jset), zeta(ipgf, iset), zetb(jpgf, jset), &
     423              :                                                           la, lb, la, lb, &
     424     32119010 :                                                           max_val_temp, potential_parameter, R1, R1)
     425     55410014 :                                  max_val = MAX(max_val, max_val_temp)
     426              :                               END DO !lb
     427              :                            END DO !la
     428     17709542 :                            max_val = SQRT(max_val)
     429     17709542 :                            max_val = max_val*max_contraction_a*max_contraction_b
     430     17709542 :                            DATA(1, i) = rb(1)
     431     17884884 :                            IF (max_val == 0.0_dp) THEN
     432            0 :                               DATA(2, i) = powell_min_log
     433              :                            ELSE
     434     17709542 :                               DATA(2, i) = LOG10((max_val))
     435              :                            END IF
     436              :                         END DO
     437       175342 : !$OMP BARRIER
     438       175342 : !$OMP MASTER
     439       175342 :                         CALL optimize_it(DATA, x, powell_min_log)
     440       526026 :                         coeffs_pgf(jpgf, ipgf, jset, iset, jkind, ikind)%x = x
     441              : !$OMP END MASTER
     442       260662 : !$OMP BARRIER
     443              : 
     444              :                      END DO
     445              :                   END DO
     446              :                END DO
     447              :             END DO
     448              :          END DO
     449              :       END DO
     450              : 
     451         1492 : !$OMP MASTER
     452       109292 :       ALLOCATE (coeffs_set(max_set, max_set, nkind, nkind))
     453              : 
     454         4192 :       DO ikind = 1, nkind
     455        10388 :          DO jkind = 1, nkind
     456        26548 :             DO iset = 1, max_set
     457        94656 :                DO jset = 1, max_set
     458       230076 :                   coeffs_set(jset, iset, jkind, ikind)%x(:) = 0.0_dp
     459              :                END DO
     460              :             END DO
     461              :          END DO
     462              :       END DO
     463              : !$OMP END MASTER
     464         1492 : !$OMP BARRIER
     465         1492 :       ra = 0.0_dp
     466         1492 :       rb = 0.0_dp
     467         4192 :       DO ikind = 1, nkind
     468         2700 :          NULLIFY (qs_kind, orb_basis)
     469         2700 :          qs_kind => qs_kind_set(ikind)
     470         2700 :          CALL get_qs_kind(qs_kind=qs_kind, basis_set=orb_basis)
     471         2700 :          NULLIFY (la_max, la_min, npgfa, zeta)
     472              : !      CALL get_gto_basis_set(gto_basis_set=orb_basis,&
     473              : !                             lmax=la_max,&
     474              : !                             lmin=la_min,&
     475              : !                             npgf=npgfa,&
     476              : !                             nset=nseta,&
     477              : !                             zet=zeta,&
     478              : !                             set_radius=set_radius_a,&
     479              : !                             first_sgf=first_sgfa,&
     480              : !                             sphi=sphi_a,&
     481              : !                             nsgf_set=nsgfa)
     482         2700 :          la_max => basis_parameter(ikind)%lmax
     483         2700 :          la_min => basis_parameter(ikind)%lmin
     484         2700 :          npgfa => basis_parameter(ikind)%npgf
     485         2700 :          nseta = basis_parameter(ikind)%nset
     486         2700 :          zeta => basis_parameter(ikind)%zet
     487         2700 :          set_radius_a => basis_parameter(ikind)%set_radius
     488         2700 :          first_sgfa => basis_parameter(ikind)%first_sgf
     489         2700 :          sphi_a => basis_parameter(ikind)%sphi
     490         2700 :          nsgfa => basis_parameter(ikind)%nsgf
     491              : 
     492        10388 :          DO jkind = 1, nkind
     493         6196 :             NULLIFY (qs_kind, orb_basis)
     494         6196 :             qs_kind => qs_kind_set(jkind)
     495         6196 :             CALL get_qs_kind(qs_kind=qs_kind, basis_set=orb_basis)
     496         6196 :             NULLIFY (lb_max, lb_min, npgfb, zetb)
     497              : 
     498         6196 :             lb_max => basis_parameter(jkind)%lmax
     499         6196 :             lb_min => basis_parameter(jkind)%lmin
     500         6196 :             npgfb => basis_parameter(jkind)%npgf
     501         6196 :             nsetb = basis_parameter(jkind)%nset
     502         6196 :             zetb => basis_parameter(jkind)%zet
     503         6196 :             set_radius_b => basis_parameter(jkind)%set_radius
     504         6196 :             first_sgfb => basis_parameter(jkind)%first_sgf
     505         6196 :             sphi_b => basis_parameter(jkind)%sphi
     506         6196 :             nsgfb => basis_parameter(jkind)%nsgf
     507              : 
     508        24222 :             DO iset = 1, nseta
     509        15326 :                ncoa = npgfa(iset)*ncoset(la_max(iset))
     510        15326 :                sgfa = first_sgfa(1, iset)
     511       577728 :                max_contraction_a = MAXVAL([(SUM(ABS(sphi_a(1:ncoa, i))), i=sgfa, sgfa + nsgfa(iset) - 1)])
     512        71360 :                DO jset = 1, nsetb
     513        49838 :                   ncob = npgfb(jset)*ncoset(lb_max(jset))
     514        49838 :                   sgfb = first_sgfb(1, jset)
     515      1288214 :                   max_contraction_b = MAXVAL([(SUM(ABS(sphi_b(1:ncob, i))), i=sgfb, sgfb + nsgfb(jset) - 1)])
     516        49838 :                   radius = set_radius_a(iset) + set_radius_b(jset)
     517        49838 :                   tmp_R_1 => radii_pgf(:, :, jset, iset, jkind, ikind)
     518      5083476 :                   DO i = i_thread, 100, n_threads
     519      5033638 :                      rb(1) = 0.0_dp + REAL(i, dp)*0.01_dp*radius
     520      5033638 :                      max_val = 0.0_dp
     521              :                      CALL screen4(context, ra, rb, &
     522              :                                   zeta(:, iset), zetb(:, jset), &
     523              :                                   la_min(iset), la_max(iset), lb_min(jset), lb_max(jset), &
     524              :                                   npgfa(iset), npgfb(jset), &
     525      5033638 :                                   max_val, potential_parameter, tmp_R_1, rb(1)**2)
     526      5033638 :                      max_val = SQRT(max_val)
     527      5033638 :                      max_val = max_val*max_contraction_a*max_contraction_b
     528      5033638 :                      DATA(1, i) = rb(1)
     529      5083476 :                      IF (max_val == 0.0_dp) THEN
     530            0 :                         DATA(2, i) = powell_min_log
     531              :                      ELSE
     532      5033638 :                         DATA(2, i) = LOG10((max_val))
     533              :                      END IF
     534              :                   END DO
     535        49838 : !$OMP BARRIER
     536        49838 : !$OMP MASTER
     537        49838 :                   CALL optimize_it(DATA, x, powell_min_log)
     538       149514 :                   coeffs_set(jset, iset, jkind, ikind)%x = x
     539              : !$OMP END MASTER
     540        65164 : !$OMP BARRIER
     541              :                END DO
     542              :             END DO
     543              : 
     544              :          END DO
     545              :       END DO
     546              : 
     547              :       ! ** now kinds
     548         1492 : !$OMP MASTER
     549        17848 :       ALLOCATE (coeffs_kind(nkind, nkind))
     550              : 
     551         4192 :       DO ikind = 1, nkind
     552        10388 :          DO jkind = 1, nkind
     553        21288 :             coeffs_kind(jkind, ikind)%x(:) = 0.0_dp
     554              :          END DO
     555              :       END DO
     556              : !$OMP END MASTER
     557         1492 :       ra = 0.0_dp
     558         1492 :       rb = 0.0_dp
     559         4192 :       DO ikind = 1, nkind
     560         2700 :          NULLIFY (qs_kind, orb_basis)
     561         2700 :          qs_kind => qs_kind_set(ikind)
     562         2700 :          CALL get_qs_kind(qs_kind=qs_kind, basis_set=orb_basis)
     563         2700 :          NULLIFY (la_max, la_min, npgfa, zeta)
     564              : 
     565         2700 :          la_max => basis_parameter(ikind)%lmax
     566         2700 :          la_min => basis_parameter(ikind)%lmin
     567         2700 :          npgfa => basis_parameter(ikind)%npgf
     568         2700 :          nseta = basis_parameter(ikind)%nset
     569         2700 :          zeta => basis_parameter(ikind)%zet
     570         2700 :          kind_radius_a = basis_parameter(ikind)%kind_radius
     571         2700 :          first_sgfa => basis_parameter(ikind)%first_sgf
     572         2700 :          sphi_a => basis_parameter(ikind)%sphi
     573         2700 :          nsgfa => basis_parameter(ikind)%nsgf
     574              : 
     575        10388 :          DO jkind = 1, nkind
     576         6196 :             NULLIFY (qs_kind, orb_basis)
     577         6196 :             qs_kind => qs_kind_set(jkind)
     578         6196 :             CALL get_qs_kind(qs_kind=qs_kind, basis_set=orb_basis)
     579         6196 :             NULLIFY (lb_max, lb_min, npgfb, zetb)
     580              : 
     581         6196 :             lb_max => basis_parameter(jkind)%lmax
     582         6196 :             lb_min => basis_parameter(jkind)%lmin
     583         6196 :             npgfb => basis_parameter(jkind)%npgf
     584         6196 :             nsetb = basis_parameter(jkind)%nset
     585         6196 :             zetb => basis_parameter(jkind)%zet
     586         6196 :             kind_radius_b = basis_parameter(jkind)%kind_radius
     587         6196 :             first_sgfb => basis_parameter(jkind)%first_sgf
     588         6196 :             sphi_b => basis_parameter(jkind)%sphi
     589         6196 :             nsgfb => basis_parameter(jkind)%nsgf
     590              : 
     591         6196 :             radius = kind_radius_a + kind_radius_b
     592        21522 :             DO iset = 1, nseta
     593        15326 :                ncoa = npgfa(iset)*ncoset(la_max(iset))
     594        15326 :                sgfa = first_sgfa(1, iset)
     595       577728 :                max_contraction_a = MAXVAL([(SUM(ABS(sphi_a(1:ncoa, i))), i=sgfa, sgfa + nsgfa(iset) - 1)])
     596        71360 :                DO jset = 1, nsetb
     597        49838 :                   ncob = npgfb(jset)*ncoset(lb_max(jset))
     598        49838 :                   sgfb = first_sgfb(1, jset)
     599      1288214 :                   max_contraction_b = MAXVAL([(SUM(ABS(sphi_b(1:ncob, i))), i=sgfb, sgfb + nsgfb(jset) - 1)])
     600      5098802 :                   DO i = i_thread, 100, n_threads
     601      5033638 :                      rb(1) = 0.0_dp + REAL(i, dp)*0.01_dp*radius
     602      5033638 :                      max_val = 0.0_dp
     603      5033638 :                      tmp_R_1 => radii_pgf(:, :, jset, iset, jkind, ikind)
     604              :                      CALL screen4(context, ra, rb, &
     605              :                                   zeta(:, iset), zetb(:, jset), &
     606              :                                   la_min(iset), la_max(iset), lb_min(jset), lb_max(jset), &
     607              :                                   npgfa(iset), npgfb(jset), &
     608      5033638 :                                   max_val, potential_parameter, tmp_R_1, rb(1)**2)
     609      5033638 :                      DATA(1, i) = rb(1)
     610      5033638 :                      max_val = SQRT(max_val)
     611      5033638 :                      max_val = max_val*max_contraction_a*max_contraction_b
     612      5083476 :                      IF (max_val == 0.0_dp) THEN
     613       151354 :                         DATA(2, i) = MAX(powell_min_log, DATA(2, i))
     614              :                      ELSE
     615      4882284 :                         DATA(2, i) = MAX(LOG10(max_val), DATA(2, i))
     616              :                      END IF
     617              :                   END DO
     618              :                END DO
     619              :             END DO
     620         6196 : !$OMP BARRIER
     621         6196 : !$OMP MASTER
     622         6196 :             CALL optimize_it(DATA, x, powell_min_log)
     623        18588 :             coeffs_kind(jkind, ikind)%x = x
     624              : !$OMP END MASTER
     625         8896 : !$OMP BARRIER
     626              :          END DO
     627              :       END DO
     628              : 
     629         1492 : !$OMP MASTER
     630         1492 :       CALL timestop(handle)
     631              : !$OMP END MASTER
     632              : 
     633         1492 :    END SUBROUTINE calc_screening_functions
     634              : 
     635              : ! **************************************************************************************************
     636              : !> \brief calculates radius functions for longrange screening
     637              : !> \param qs_env qs_env
     638              : !> \param basis_parameter ...
     639              : !> \param radii_pgf pgf based coefficients
     640              : !> \param max_set Maximum Number of basis set sets in the system
     641              : !> \param max_pgf Maximum Number of basis set pgfs in the system
     642              : !> \param eps_schwarz ...
     643              : !> \param n_threads ...
     644              : !> \param i_thread Thread ID of current task
     645              : !> \par History
     646              : !>     02.2009 created [Manuel Guidon]
     647              : !> \author Manuel Guidon
     648              : !> \note
     649              : !>      This routine calculates the pair-distribution radius of a product
     650              : !>      Gaussian and uses the powell optimiztion routines in order to fit
     651              : !>      the results in the following form:
     652              : !>
     653              : !>                 (ab| = (ab(Rab) = c2*Rab^2 + c0
     654              : !>
     655              : ! **************************************************************************************************
     656              : 
     657         1492 :    SUBROUTINE calc_pair_dist_radii(qs_env, basis_parameter, &
     658              :                                    radii_pgf, max_set, max_pgf, eps_schwarz, &
     659              :                                    n_threads, i_thread)
     660              : 
     661              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     662              :       TYPE(hfx_basis_type), DIMENSION(:), POINTER        :: basis_parameter
     663              :       TYPE(hfx_screen_coeff_type), &
     664              :          DIMENSION(:, :, :, :, :, :), POINTER            :: radii_pgf
     665              :       INTEGER, INTENT(IN)                                :: max_set, max_pgf
     666              :       REAL(dp)                                           :: eps_schwarz
     667              :       INTEGER, INTENT(IN)                                :: n_threads, i_thread
     668              : 
     669              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'calc_pair_dist_radii'
     670              : 
     671              :       INTEGER                                            :: handle, i, ikind, ipgf, iset, jkind, &
     672              :                                                             jpgf, jset, la, lb, ncoa, ncob, nkind, &
     673              :                                                             nseta, nsetb, sgfa, sgfb
     674         1492 :       INTEGER, DIMENSION(:), POINTER                     :: la_max, la_min, lb_max, lb_min, npgfa, &
     675         1492 :                                                             npgfb, nsgfa, nsgfb
     676         1492 :       INTEGER, DIMENSION(:, :), POINTER                  :: first_sgfa, first_sgfb
     677              :       REAL(dp) :: cutoff, ff, max_contraction_a, max_contraction_b, prefactor, R1, R_max, ra(3), &
     678              :          rab(3), rab2, radius, rap(3), rb(3), rp(3), x(2), zetp
     679         1492 :       REAL(dp), DIMENSION(:, :), POINTER                 :: rpgfa, rpgfb, sphi_a, sphi_b, zeta, zetb
     680              :       REAL(dp), SAVE                                     :: DATA(2, 0:100)
     681              :       TYPE(gto_basis_set_type), POINTER                  :: orb_basis
     682         1492 :       TYPE(qs_kind_type), DIMENSION(:), POINTER          :: qs_kind_set
     683              :       TYPE(qs_kind_type), POINTER                        :: qs_kind
     684              : 
     685         2984 : !$OMP MASTER
     686         1492 :       CALL timeset(routineN, handle)
     687              : !$OMP END MASTER
     688              :       CALL get_qs_env(qs_env=qs_env, &
     689         1492 :                       qs_kind_set=qs_kind_set)
     690              : 
     691         1492 :       nkind = SIZE(qs_kind_set, 1)
     692         1492 :       ra = 0.0_dp
     693         1492 :       rb = 0.0_dp
     694         1492 : !$OMP MASTER
     695      1369676 :       ALLOCATE (radii_pgf(max_pgf, max_pgf, max_set, max_set, nkind, nkind))
     696         4192 :       DO ikind = 1, nkind
     697        10388 :          DO jkind = 1, nkind
     698        26548 :             DO iset = 1, max_set
     699        94656 :                DO jset = 1, max_set
     700       311516 :                   DO ipgf = 1, max_pgf
     701      1328208 :                      DO jpgf = 1, max_pgf
     702      3326088 :                         radii_pgf(jpgf, ipgf, jset, iset, jkind, ikind)%x(:) = 0.0_dp
     703              :                      END DO
     704              :                   END DO
     705              :                END DO
     706              :             END DO
     707              :          END DO
     708              :       END DO
     709              : 
     710         1492 :       DATA = 0.0_dp
     711              : !$OMP END MASTER
     712         1492 : !$OMP BARRIER
     713              : 
     714         4192 :       DO ikind = 1, nkind
     715         2700 :          NULLIFY (qs_kind, orb_basis)
     716         2700 :          qs_kind => qs_kind_set(ikind)
     717         2700 :          CALL get_qs_kind(qs_kind=qs_kind, basis_set=orb_basis)
     718         2700 :          NULLIFY (la_max, la_min, npgfa, zeta)
     719              : 
     720         2700 :          la_max => basis_parameter(ikind)%lmax
     721         2700 :          la_min => basis_parameter(ikind)%lmin
     722         2700 :          npgfa => basis_parameter(ikind)%npgf
     723         2700 :          nseta = basis_parameter(ikind)%nset
     724         2700 :          zeta => basis_parameter(ikind)%zet
     725         2700 :          first_sgfa => basis_parameter(ikind)%first_sgf
     726         2700 :          sphi_a => basis_parameter(ikind)%sphi
     727         2700 :          nsgfa => basis_parameter(ikind)%nsgf
     728         2700 :          rpgfa => basis_parameter(ikind)%pgf_radius
     729              : 
     730        10388 :          DO jkind = 1, nkind
     731         6196 :             NULLIFY (qs_kind, orb_basis)
     732         6196 :             qs_kind => qs_kind_set(jkind)
     733         6196 :             CALL get_qs_kind(qs_kind=qs_kind, basis_set=orb_basis)
     734         6196 :             NULLIFY (lb_max, lb_min, npgfb, zetb)
     735              : 
     736         6196 :             lb_max => basis_parameter(jkind)%lmax
     737         6196 :             lb_min => basis_parameter(jkind)%lmin
     738         6196 :             npgfb => basis_parameter(jkind)%npgf
     739         6196 :             nsetb = basis_parameter(jkind)%nset
     740         6196 :             zetb => basis_parameter(jkind)%zet
     741         6196 :             first_sgfb => basis_parameter(jkind)%first_sgf
     742         6196 :             sphi_b => basis_parameter(jkind)%sphi
     743         6196 :             nsgfb => basis_parameter(jkind)%nsgf
     744         6196 :             rpgfb => basis_parameter(jkind)%pgf_radius
     745              : 
     746        24222 :             DO iset = 1, nseta
     747        15326 :                ncoa = npgfa(iset)*ncoset(la_max(iset))
     748        15326 :                sgfa = first_sgfa(1, iset)
     749       577728 :                max_contraction_a = MAXVAL([(SUM(ABS(sphi_a(1:ncoa, i))), i=sgfa, sgfa + nsgfa(iset) - 1)])
     750        71360 :                DO jset = 1, nsetb
     751        49838 :                   ncob = npgfb(jset)*ncoset(lb_max(jset))
     752        49838 :                   sgfb = first_sgfb(1, jset)
     753      1288214 :                   max_contraction_b = MAXVAL([(SUM(ABS(sphi_b(1:ncob, i))), i=sgfb, sgfb + nsgfb(jset) - 1)])
     754       150484 :                   DO ipgf = 1, npgfa(iset)
     755       310500 :                      DO jpgf = 1, npgfb(jset)
     756       175342 :                         radius = rpgfa(ipgf, iset) + rpgfb(jpgf, jset)
     757       175342 :                         DO i = i_thread, 100, n_threads
     758     17709542 :                            rb(1) = 0.0_dp + 0.01_dp*radius*i
     759     17709542 :                            R_max = 0.0_dp
     760     41000546 :                            DO la = la_min(iset), la_max(iset)
     761     73119556 :                               DO lb = lb_min(jset), lb_max(jset)
     762     32119010 :                                  zetp = zeta(ipgf, iset) + zetb(jpgf, jset)
     763     32119010 :                                  ff = zetb(jpgf, jset)/zetp
     764     32119010 :                                  rab = 0.0_dp
     765     32119010 :                                  rab(1) = rb(1)
     766     32119010 :                                  rab2 = rb(1)**2
     767     32119010 :                                  prefactor = EXP(-zeta(ipgf, iset)*ff*rab2)
     768    128476040 :                                  rap(:) = ff*rab(:)
     769    128476040 :                                  rp(:) = ra(:) + rap(:)
     770    128476040 :                                  rb(:) = ra(:) + rab(:)
     771     32119010 :                                  cutoff = 1.0_dp
     772              :                                  R1 = exp_radius_very_extended( &
     773              :                                       la, la, lb, lb, ra=ra, rb=rb, rp=rp, &
     774     32119010 :                                       zetp=zetp, eps=eps_schwarz, prefactor=prefactor, cutoff=cutoff, epsabs=1.0E-12_dp)
     775     55410014 :                                  R_max = MAX(R_max, R1)
     776              :                               END DO
     777              :                            END DO
     778     17709542 :                            DATA(1, i) = rb(1)
     779     17709542 :                            DATA(2, i) = R_max
     780              :                         END DO
     781              :                         ! the radius can not be negative, we take that into account in the code as well by using a MAX
     782              :                         ! the functional form we use for fitting does not seem particularly accurate
     783       175342 : !$OMP BARRIER
     784       175342 : !$OMP MASTER
     785       175342 :                         CALL optimize_it(DATA, x, 0.0_dp)
     786       526026 :                         radii_pgf(jpgf, ipgf, jset, iset, jkind, ikind)%x = x
     787              : !$OMP END MASTER
     788       260662 : !$OMP BARRIER
     789              :                      END DO !jpgf
     790              :                   END DO !ipgf
     791              :                END DO
     792              :             END DO
     793              :          END DO
     794              :       END DO
     795         1492 : !$OMP MASTER
     796         1492 :       CALL timestop(handle)
     797              : !$OMP END MASTER
     798         1492 :    END SUBROUTINE calc_pair_dist_radii
     799              : 
     800              : !
     801              : !
     802              : ! little driver routine for the powell minimizer
     803              : ! data is the data to fit, x is of the form (x(1)*DATA(1)**2+x(2))
     804              : ! only values of DATA(2) larger than fmin are taken into account
     805              : ! it constructs an approximate upper bound of the fitted function
     806              : !
     807              : !
     808              : ! **************************************************************************************************
     809              : !> \brief ...
     810              : !> \param DATA ...
     811              : !> \param x ...
     812              : !> \param fmin ...
     813              : ! **************************************************************************************************
     814       406718 :    SUBROUTINE optimize_it(DATA, x, fmin)
     815              : 
     816              :       REAL(KIND=dp), INTENT(IN)                          :: DATA(2, 0:100)
     817              :       REAL(KIND=dp), INTENT(OUT)                         :: x(2)
     818              :       REAL(KIND=dp), INTENT(IN)                          :: fmin
     819              : 
     820              :       INTEGER                                            :: i, k
     821              :       REAL(KIND=dp)                                      :: f, large_weight, small_weight, weight
     822              :       TYPE(opt_state_type)                               :: opt_state
     823              : 
     824              : ! initial values
     825              : 
     826       406718 :       x(1) = 0.0_dp
     827       406718 :       x(2) = 0.0_dp
     828              : 
     829              :       ! we go in two steps, first we do the symmetric weight to get a good, unique initial guess
     830              :       ! we restart afterwards for the assym.
     831              :       ! the assym function appears to have several local minima, depending on the data to fit
     832              :       ! the loop over k can make the switch gradual, but there is not much need, seemingly
     833       813436 :       DO k = 0, 4, 4
     834              : 
     835       813436 :          small_weight = 1.0_dp
     836       813436 :          large_weight = small_weight*(10.0_dp**k)
     837              : 
     838              :          ! init opt run
     839       813436 :          opt_state%state = 0
     840       813436 :          opt_state%nvar = 2
     841       813436 :          opt_state%iprint = 3
     842       813436 :          opt_state%unit = default_output_unit
     843       813436 :          opt_state%maxfun = 100000
     844       813436 :          opt_state%rhobeg = 0.1_dp
     845       813436 :          opt_state%rhoend = 0.000001_dp
     846              : 
     847     63011726 :          DO
     848              : 
     849              :             ! compute function
     850     63825162 :             IF (opt_state%state == 2) THEN
     851     61384854 :                opt_state%f = 0.0_dp
     852   6261255108 :                DO i = 0, 100
     853   6199870254 :                   f = x(1)*DATA(1, i)**2 + x(2)
     854   6199870254 :                   IF (f > DATA(2, i)) THEN
     855              :                      weight = small_weight
     856              :                   ELSE
     857   1314577274 :                      weight = large_weight
     858              :                   END IF
     859   6261255108 :                   IF (DATA(2, i) > fmin) opt_state%f = opt_state%f + weight*(f - DATA(2, i))**2
     860              :                END DO
     861              :             END IF
     862              : 
     863     63825162 :             IF (opt_state%state == -1) EXIT
     864     63011726 :             CALL powell_optimize(opt_state%nvar, x, opt_state)
     865              :          END DO
     866              : 
     867              :          ! dealloc mem
     868       813436 :          opt_state%state = 8
     869      1220154 :          CALL powell_optimize(opt_state%nvar, x, opt_state)
     870              : 
     871              :       END DO
     872              : 
     873       406718 :    END SUBROUTINE optimize_it
     874              : 
     875              : ! **************************************************************************************************
     876              : !> \brief Given a 2d index pair, this function returns a 1d index pair for
     877              : !>        a symmetric upper triangle NxN matrix
     878              : !>        The compiler should inline this function, therefore it appears in
     879              : !>        several modules
     880              : !> \param i 2d index
     881              : !> \param j 2d index
     882              : !> \param N matrix size
     883              : !> \return ...
     884              : !> \par History
     885              : !>      03.2009 created [Manuel Guidon]
     886              : !> \author Manuel Guidon
     887              : ! **************************************************************************************************
     888        97928 :    PURE FUNCTION get_1D_idx(i, j, N)
     889              :       INTEGER, INTENT(IN)                                :: i, j
     890              :       INTEGER(int_8), INTENT(IN)                         :: N
     891              :       INTEGER(int_8)                                     :: get_1D_idx
     892              : 
     893              :       INTEGER(int_8)                                     :: min_ij
     894              : 
     895        97928 :       min_ij = MIN(i, j)
     896        97928 :       get_1D_idx = min_ij*N + MAX(i, j) - (min_ij - 1)*min_ij/2 - N
     897              : 
     898        97928 :    END FUNCTION get_1D_idx
     899              : 
     900              : END MODULE hfx_screening_methods
        

Generated by: LCOV version 2.0-1