LCOV - code coverage report
Current view: top level - src/xc - xc_xpbe_hole_t_c_lr.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:ccc2433) Lines: 592 616 96.1 %
Date: 2024-04-25 07:09:54 Functions: 15 15 100.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief Calculates the exchange energy for the pbe hole model in a truncated
      10             : !>        coulomb potential, considering the long range part only. Can be used
      11             : !>        as longrange correction to a truncated Hartree Fock calculation
      12             : !> \par History
      13             : !>      Manuel Guidon (01.2009)  : initial version
      14             : !> \author Manuel Guidon (01.2009)
      15             : ! **************************************************************************************************
      16             : 
      17             : MODULE xc_xpbe_hole_t_c_lr
      18             :    USE input_section_types,             ONLY: section_vals_type,&
      19             :                                               section_vals_val_get
      20             :    USE kinds,                           ONLY: dp
      21             :    USE mathconstants,                   ONLY: euler,&
      22             :                                               pi,&
      23             :                                               rootpi
      24             :    USE xc_derivative_desc,              ONLY: deriv_norm_drho,&
      25             :                                               deriv_norm_drhoa,&
      26             :                                               deriv_norm_drhob,&
      27             :                                               deriv_rho,&
      28             :                                               deriv_rhoa,&
      29             :                                               deriv_rhob
      30             :    USE xc_derivative_set_types,         ONLY: xc_derivative_set_type,&
      31             :                                               xc_dset_get_derivative
      32             :    USE xc_derivative_types,             ONLY: xc_derivative_get,&
      33             :                                               xc_derivative_type
      34             :    USE xc_rho_cflags_types,             ONLY: xc_rho_cflags_type
      35             :    USE xc_rho_set_types,                ONLY: xc_rho_set_get,&
      36             :                                               xc_rho_set_type
      37             : #include "../base/base_uses.f90"
      38             : 
      39             :    IMPLICIT NONE
      40             : 
      41             :    PRIVATE
      42             : 
      43             : ! *** Global parameters ***
      44             : 
      45             :    PUBLIC :: xpbe_hole_t_c_lr_lda_eval, xpbe_hole_t_c_lr_lda_info, &
      46             :              xpbe_hole_t_c_lr_lda_calc_1, xpbe_hole_t_c_lr_lda_calc_2, &
      47             :              xpbe_hole_t_c_lr_lsd_eval, xpbe_hole_t_c_lr_lsd_info
      48             : 
      49             :    REAL(KIND=dp), PARAMETER :: a1 = 0.00979681_dp, &
      50             :                                a2 = 0.04108340_dp, &
      51             :                                a3 = 0.18744000_dp, &
      52             :                                a4 = 0.00120824_dp, &
      53             :                                a5 = 0.0347188_dp
      54             :    REAL(KIND=dp), PARAMETER :: A = 1.0161144_dp, &
      55             :                                B = -0.37170836_dp, &
      56             :                                C = -0.077215461_dp, &
      57             :                                D = 0.57786348_dp, &
      58             :                                E = -0.051955731_dp, &
      59             :                                F2 = 0.47965830_dp, &
      60             :                                F1 = 6.4753871_dp, &
      61             :                                clda = -0.73855876638202240588423_dp
      62             :    REAL(KIND=dp), PARAMETER :: expcutoff = 700.0_dp
      63             :    REAL(KIND=dp), PARAMETER :: smax = 8.572844_dp, &
      64             :                                sconst = 18.79622316_dp, &
      65             :                                scutoff = 8.3_dp
      66             :    REAL(KIND=dp), PARAMETER :: gcutoff = 0.08_dp, &
      67             :                                g1 = -0.02628417880_dp/E, &
      68             :                                g2 = -0.07117647788_dp/E, &
      69             :                                g3 = 0.08534541323_dp/E, &
      70             :                                g4 = 0.0_dp
      71             :    REAL(KIND=dp), PARAMETER :: wcutoff = 14.0_dp
      72             : 
      73             :    REAL(KIND=dp), PARAMETER :: EPS_RHO = 0.00000001_dp
      74             : 
      75             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xc_xpbe_hole_t_c_lr'
      76             : 
      77             : CONTAINS
      78             : 
      79             : ! **************************************************************************************************
      80             : !> \brief returns various information on the functional
      81             : !> \param reference string with the reference of the actual functional
      82             : !> \param shortform string with the shortform of the functional name
      83             : !> \param needs the components needed by this functional are set to
      84             : !>        true (does not set the unneeded components to false)
      85             : !> \param max_deriv controls the number of derivatives
      86             : !> \par History
      87             : !>        01.2009 created [mguidon]
      88             : !> \author mguidon
      89             : ! **************************************************************************************************
      90        1528 :    SUBROUTINE xpbe_hole_t_c_lr_lda_info(reference, shortform, needs, max_deriv)
      91             :       CHARACTER(LEN=*), INTENT(OUT), OPTIONAL            :: reference, shortform
      92             :       TYPE(xc_rho_cflags_type), INTENT(inout), OPTIONAL  :: needs
      93             :       INTEGER, INTENT(out), OPTIONAL                     :: max_deriv
      94             : 
      95        1528 :       IF (PRESENT(reference)) THEN
      96           2 :          reference = "{LDA version}"
      97             :       END IF
      98        1528 :       IF (PRESENT(shortform)) THEN
      99           2 :          shortform = "{LDA}"
     100             :       END IF
     101        1528 :       IF (PRESENT(needs)) THEN
     102        1526 :          needs%rho = .TRUE.
     103        1526 :          needs%norm_drho = .TRUE.
     104             :       END IF
     105        1528 :       IF (PRESENT(max_deriv)) max_deriv = 1
     106             : 
     107        1528 :    END SUBROUTINE xpbe_hole_t_c_lr_lda_info
     108             : 
     109             : ! **************************************************************************************************
     110             : !> \brief returns various information on the functional
     111             : !> \param reference string with the reference of the actual functional
     112             : !> \param shortform string with the shortform of the functional name
     113             : !> \param needs the components needed by this functional are set to
     114             : !>        true (does not set the unneeded components to false)
     115             : !> \param max_deriv controls the number of derivatives
     116             : !> \par History
     117             : !>        01.2009 created [mguidon]
     118             : !> \author mguidon
     119             : ! **************************************************************************************************
     120         706 :    SUBROUTINE xpbe_hole_t_c_lr_lsd_info(reference, shortform, needs, max_deriv)
     121             :       CHARACTER(LEN=*), INTENT(OUT), OPTIONAL            :: reference, shortform
     122             :       TYPE(xc_rho_cflags_type), INTENT(inout), OPTIONAL  :: needs
     123             :       INTEGER, INTENT(out), OPTIONAL                     :: max_deriv
     124             : 
     125         706 :       IF (PRESENT(reference)) THEN
     126           2 :          reference = "{LSD version}"
     127             :       END IF
     128         706 :       IF (PRESENT(shortform)) THEN
     129           2 :          shortform = "{LSD}"
     130             :       END IF
     131         706 :       IF (PRESENT(needs)) THEN
     132         704 :          needs%rho_spin = .TRUE.
     133         704 :          needs%norm_drho_spin = .TRUE.
     134             :       END IF
     135         706 :       IF (PRESENT(max_deriv)) max_deriv = 1
     136             : 
     137         706 :    END SUBROUTINE xpbe_hole_t_c_lr_lsd_info
     138             : 
     139             : ! **************************************************************************************************
     140             : !> \brief evaluates the pbe-hole exchange in a truncated coulomb potential
     141             : !> \param rho_set the density where you want to evaluate the functional
     142             : !> \param deriv_set place where to store the functional derivatives (they are
     143             : !>        added to the derivatives)
     144             : !> \param order degree of the derivative that should be evaluated,
     145             : !>        if positive all the derivatives up to the given degree are evaluated,
     146             : !>        if negative only the given degree is calculated
     147             : !> \param params input parameters (scaling,cutoff)
     148             : !> \par History
     149             : !>      01.2009 created [Manuel Guidon]
     150             : !> \author Manuel Guidon
     151             : !> \note
     152             : ! **************************************************************************************************
     153        6616 :    SUBROUTINE xpbe_hole_t_c_lr_lda_eval(rho_set, deriv_set, order, params)
     154             : 
     155             :       TYPE(xc_rho_set_type), INTENT(IN)                  :: rho_set
     156             :       TYPE(xc_derivative_set_type), INTENT(IN)           :: deriv_set
     157             :       INTEGER, INTENT(IN)                                :: order
     158             :       TYPE(section_vals_type), POINTER                   :: params
     159             : 
     160             :       CHARACTER(len=*), PARAMETER :: routineN = 'xpbe_hole_t_c_lr_lda_eval'
     161             : 
     162             :       INTEGER                                            :: handle, npoints
     163             :       INTEGER, DIMENSION(2, 3)                           :: bo
     164             :       REAL(kind=dp)                                      :: epsilon_rho, R, sx
     165             :       REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :, :), &
     166        1654 :          POINTER                                         :: dummy, e_0, e_ndrho, e_rho, norm_drho, &
     167        1654 :                                                             rho
     168             :       TYPE(xc_derivative_type), POINTER                  :: deriv
     169             : 
     170        1654 :       CALL timeset(routineN, handle)
     171             : 
     172        1654 :       CALL section_vals_val_get(params, "SCALE_X", r_val=sx)
     173        1654 :       CALL section_vals_val_get(params, "CUTOFF_RADIUS", r_val=R)
     174             : 
     175             :       CALL xc_rho_set_get(rho_set, rho=rho, &
     176        1654 :                           norm_drho=norm_drho, local_bounds=bo, rho_cutoff=epsilon_rho)
     177        1654 :       npoints = (bo(2, 1) - bo(1, 1) + 1)*(bo(2, 2) - bo(1, 2) + 1)*(bo(2, 3) - bo(1, 3) + 1)
     178             : 
     179        1654 :       dummy => rho
     180             : 
     181        1654 :       e_0 => dummy
     182        1654 :       e_rho => dummy
     183        1654 :       e_ndrho => dummy
     184             : 
     185        1654 :       IF (order >= 0) THEN
     186             :          deriv => xc_dset_get_derivative(deriv_set, [INTEGER::], &
     187        1654 :                                          allocate_deriv=.TRUE.)
     188        1654 :          CALL xc_derivative_get(deriv, deriv_data=e_0)
     189             :       END IF
     190        1654 :       IF (order >= 1 .OR. order == -1) THEN
     191             :          deriv => xc_dset_get_derivative(deriv_set, [deriv_rho], &
     192        1400 :                                          allocate_deriv=.TRUE.)
     193        1400 :          CALL xc_derivative_get(deriv, deriv_data=e_rho)
     194             :          deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho], &
     195        1400 :                                          allocate_deriv=.TRUE.)
     196        1400 :          CALL xc_derivative_get(deriv, deriv_data=e_ndrho)
     197             :       END IF
     198        1654 :       IF (order > 1 .OR. order < -1) THEN
     199           0 :          CPABORT("derivatives bigger than 1 not implemented")
     200             :       END IF
     201             : 
     202        1654 :       IF (R == 0.0_dp) THEN
     203           0 :          CPABORT("Cutoff_Radius 0.0 not implemented")
     204             :       END IF
     205             : 
     206             : !$OMP     PARALLEL DEFAULT(NONE) &
     207             : !$OMP              SHARED(npoints, order, rho, norm_drho, e_0, e_rho) &
     208             : !$OMP              SHARED(e_ndrho, epsilon_rho) &
     209        1654 : !$OMP              SHARED(sx, r)
     210             : 
     211             :       CALL xpbe_hole_t_c_lr_lda_calc(npoints, order, rho=rho, norm_drho=norm_drho, &
     212             :                                      e_0=e_0, e_rho=e_rho, e_ndrho=e_ndrho, &
     213             :                                      epsilon_rho=epsilon_rho, &
     214             :                                      sx=sx, R=R)
     215             : 
     216             : !$OMP     END PARALLEL
     217             : 
     218        1654 :       CALL timestop(handle)
     219             : 
     220        1654 :    END SUBROUTINE xpbe_hole_t_c_lr_lda_eval
     221             : 
     222             : ! **************************************************************************************************
     223             : !> \brief intermediate level routine in order to decide which branch has to be
     224             : !>        taken
     225             : !> \param npoints number of points on the grid
     226             : !> \param order order of the derivatives
     227             : !> \param rho value of density on the grid
     228             : !> \param norm_drho value of gradient on the grid
     229             : !> \param e_0 derivatives of the energy on the grid
     230             : !> \param e_rho derivatives of the energy on the grid
     231             : !> \param e_ndrho derivatives of the energy on the grid
     232             : !> \param epsilon_rho cutoffs
     233             : !> \param sx functional parameters
     234             : !> \param R functional parameters
     235             : !> \par History
     236             : !>      01.2009 created [Manuel Guidon]
     237             : !> \author Manuel Guidon
     238             : !> \note For numerical reasons there are two different branches
     239             : !>
     240             : ! **************************************************************************************************
     241        1654 :    SUBROUTINE xpbe_hole_t_c_lr_lda_calc(npoints, order, rho, norm_drho, e_0, e_rho, e_ndrho, &
     242             :                                         epsilon_rho, sx, R)
     243             : 
     244             :       INTEGER, INTENT(in)                                :: npoints, order
     245             :       REAL(kind=dp), DIMENSION(1:npoints), INTENT(inout) :: rho, norm_drho, e_0, e_rho, e_ndrho
     246             :       REAL(kind=dp), INTENT(in)                          :: epsilon_rho, sx, R
     247             : 
     248             :       INTEGER                                            :: ip
     249             :       REAL(dp)                                           :: my_ndrho, my_rho
     250             :       REAL(KIND=dp)                                      :: ss, ss2, sscale, t1, t2, t3, t4, t6, t7, &
     251             :                                                             t8
     252             : 
     253             : !$OMP     DO
     254             : 
     255             :       DO ip = 1, npoints
     256    41163994 :          my_rho = MAX(rho(ip), 0.0_dp)
     257    41163994 :          IF (my_rho > epsilon_rho) THEN
     258    35637976 :             my_ndrho = MAX(norm_drho(ip), EPSILON(0.0_dp)*1.e4_dp)
     259             :             ! *** Do some precalculation in order to catch the correct branch afterwards
     260    35637976 :             sscale = 1.0_dp
     261    35637976 :             t1 = pi**2
     262    35637976 :             t2 = t1*my_rho
     263    35637976 :             t3 = t2**(0.1e1_dp/0.3e1_dp)
     264    35637976 :             t4 = 0.1e1_dp/t3
     265    35637976 :             t6 = my_ndrho*t4
     266    35637976 :             t7 = 0.1e1_dp/my_rho
     267    35637976 :             t8 = t7*sscale
     268    35637976 :             ss = 0.3466806371753173524216762e0_dp*t6*t8
     269    35637976 :             IF (ss > scutoff) THEN
     270    21229850 :                ss2 = ss*ss
     271    21229850 :                sscale = (smax*ss2 - sconst)/(ss2*ss)
     272             :             END IF
     273    35637976 :             IF (ss*sscale > gcutoff) THEN
     274             :                CALL xpbe_hole_t_c_lr_lda_calc_1(e_0(ip), e_rho(ip), e_ndrho(ip), &
     275             :                                                 my_rho, &
     276    35613081 :                                                 my_ndrho, sscale, sx, R, order)
     277             :             ELSE
     278             :                CALL xpbe_hole_t_c_lr_lda_calc_2(e_0(ip), e_rho(ip), e_ndrho(ip), &
     279             :                                                 my_rho, &
     280       24895 :                                                 my_ndrho, sscale, sx, R, order)
     281             :             END IF
     282             :          END IF
     283             :       END DO
     284             : 
     285             : !$OMP     END DO
     286             : 
     287        1654 :    END SUBROUTINE xpbe_hole_t_c_lr_lda_calc
     288             : 
     289             : ! **************************************************************************************************
     290             : !> \brief evaluates the pbe-hole exchange in a truncated coulomb potential
     291             : !> \param rho_set the density where you want to evaluate the functional
     292             : !> \param deriv_set place where to store the functional derivatives (they are
     293             : !>        added to the derivatives)
     294             : !> \param order degree of the derivative that should be evaluated,
     295             : !>        if positive all the derivatives up to the given degree are evaluated,
     296             : !>        if negative only the given degree is calculated
     297             : !> \param params input parameters (scaling,cutoff)
     298             : !> \par History
     299             : !>      01.2009 created [Manuel Guidon]
     300             : !> \author Manuel Guidon
     301             : !> \note
     302             : ! **************************************************************************************************
     303        2912 :    SUBROUTINE xpbe_hole_t_c_lr_lsd_eval(rho_set, deriv_set, order, params)
     304             : 
     305             :       TYPE(xc_rho_set_type), INTENT(IN)                  :: rho_set
     306             :       TYPE(xc_derivative_set_type), INTENT(IN)           :: deriv_set
     307             :       INTEGER, INTENT(IN)                                :: order
     308             :       TYPE(section_vals_type), POINTER                   :: params
     309             : 
     310             :       CHARACTER(len=*), PARAMETER :: routineN = 'xpbe_hole_t_c_lr_lsd_eval'
     311             : 
     312             :       INTEGER                                            :: handle, npoints
     313             :       INTEGER, DIMENSION(2, 3)                           :: bo
     314             :       REAL(kind=dp)                                      :: epsilon_rho, R, sx
     315             :       REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :, :), &
     316         728 :          POINTER                                         :: dummy, e_0, e_ndrhoa, e_ndrhob, e_rhoa, &
     317         728 :                                                             e_rhob, norm_drhoa, norm_drhob, rhoa, &
     318         728 :                                                             rhob
     319             :       TYPE(xc_derivative_type), POINTER                  :: deriv
     320             : 
     321         728 :       CALL timeset(routineN, handle)
     322             : 
     323         728 :       CALL section_vals_val_get(params, "SCALE_X", r_val=sx)
     324         728 :       CALL section_vals_val_get(params, "CUTOFF_RADIUS", r_val=R)
     325             : 
     326             :       CALL xc_rho_set_get(rho_set, rhoa=rhoa, rhob=rhob, &
     327         728 :                           norm_drhoa=norm_drhoa, norm_drhob=norm_drhob, local_bounds=bo, rho_cutoff=epsilon_rho)
     328         728 :       npoints = (bo(2, 1) - bo(1, 1) + 1)*(bo(2, 2) - bo(1, 2) + 1)*(bo(2, 3) - bo(1, 3) + 1)
     329             : 
     330         728 :       dummy => rhoa
     331             : 
     332         728 :       e_0 => dummy
     333         728 :       e_rhoa => dummy
     334         728 :       e_rhob => dummy
     335         728 :       e_ndrhoa => dummy
     336         728 :       e_ndrhob => dummy
     337             : 
     338         728 :       IF (order >= 0) THEN
     339             :          deriv => xc_dset_get_derivative(deriv_set, [INTEGER::], &
     340         728 :                                          allocate_deriv=.TRUE.)
     341         728 :          CALL xc_derivative_get(deriv, deriv_data=e_0)
     342             :       END IF
     343         728 :       IF (order >= 1 .OR. order == -1) THEN
     344             :          deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa], &
     345         580 :                                          allocate_deriv=.TRUE.)
     346         580 :          CALL xc_derivative_get(deriv, deriv_data=e_rhoa)
     347             :          deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob], &
     348         580 :                                          allocate_deriv=.TRUE.)
     349         580 :          CALL xc_derivative_get(deriv, deriv_data=e_rhob)
     350             :          deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa], &
     351         580 :                                          allocate_deriv=.TRUE.)
     352         580 :          CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa)
     353             :          deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob], &
     354         580 :                                          allocate_deriv=.TRUE.)
     355         580 :          CALL xc_derivative_get(deriv, deriv_data=e_ndrhob)
     356             :       END IF
     357         728 :       IF (order > 1 .OR. order < -1) THEN
     358           0 :          CPABORT("derivatives bigger than 1 not implemented")
     359             :       END IF
     360             : 
     361         728 :       IF (R == 0.0_dp) THEN
     362           0 :          CPABORT("Cutoff_Radius 0.0 not implemented")
     363             :       END IF
     364             : 
     365             : !$OMP     PARALLEL DEFAULT(NONE) &
     366             : !$OMP              SHARED(npoints, order, rhoa, norm_drhoa, e_0, e_rhoa) &
     367             : !$OMP              SHARED(epsilon_rho, sx, r) &
     368         728 : !$OMP              SHARED(rhob, norm_drhob, e_rhob, e_ndrhoa, e_ndrhob)
     369             : 
     370             :       CALL xpbe_hole_t_c_lr_lsd_calc(npoints, order, rho=rhoa, norm_drho=norm_drhoa, &
     371             :                                      e_0=e_0, e_rho=e_rhoa, e_ndrho=e_ndrhoa, &
     372             :                                      epsilon_rho=epsilon_rho, sx=sx, R=R)
     373             :       CALL xpbe_hole_t_c_lr_lsd_calc(npoints, order, rho=rhob, norm_drho=norm_drhob, &
     374             :                                      e_0=e_0, e_rho=e_rhob, e_ndrho=e_ndrhob, &
     375             :                                      epsilon_rho=epsilon_rho, sx=sx, R=R)
     376             : 
     377             : !$OMP     END PARALLEL
     378             : 
     379         728 :       CALL timestop(handle)
     380             : 
     381         728 :    END SUBROUTINE xpbe_hole_t_c_lr_lsd_eval
     382             : 
     383             : ! **************************************************************************************************
     384             : !> \brief intermediate level routine in order to decide which branch has to be
     385             : !>        taken
     386             : !> \param npoints number of points on the grid
     387             : !> \param order order of the derivatives
     388             : !> \param rho density on the grid
     389             : !> \param norm_drho gradient on the grid
     390             : !> \param e_0 derivatives of the energy on the grid
     391             : !> \param e_rho derivatives of the energy on the grid
     392             : !> \param e_ndrho derivatives of the energy on the grid
     393             : !> \param epsilon_rho cutoffs
     394             : !> \param sx functional parameters
     395             : !> \param R functional parameters
     396             : !> \par History
     397             : !>      01.2009 created [Manuel Guidon]
     398             : !> \author Manuel Guidon
     399             : !> \note For numerical reasons there are two different branches. This code calls
     400             : !>       the lda version applying spin scaling relations
     401             : ! **************************************************************************************************
     402        1456 :    SUBROUTINE xpbe_hole_t_c_lr_lsd_calc(npoints, order, rho, norm_drho, e_0, e_rho, e_ndrho, &
     403             :                                         epsilon_rho, sx, R)
     404             : 
     405             :       INTEGER, INTENT(in)                                :: npoints, order
     406             :       REAL(kind=dp), DIMENSION(1:npoints), INTENT(inout) :: rho, norm_drho, e_0, e_rho, e_ndrho
     407             :       REAL(kind=dp), INTENT(in)                          :: epsilon_rho, sx, R
     408             : 
     409             :       INTEGER                                            :: ip
     410             :       REAL(dp)                                           :: my_ndrho, my_rho
     411             :       REAL(KIND=dp)                                      :: e_tmp, ss, ss2, sscale, t1, t2, t3, t4, &
     412             :                                                             t6, t7, t8
     413             : 
     414             : !$OMP     DO
     415             : 
     416             :       DO ip = 1, npoints
     417    24008010 :          my_rho = MAX(2.0_dp*rho(ip), 0.0_dp)
     418    24008010 :          IF (my_rho > epsilon_rho) THEN
     419    23882393 :             my_ndrho = MAX(2.0_dp*norm_drho(ip), 0.0_dp)
     420             : 
     421             :             ! *** Do some precalculation in order to catch the correct branch afterwards
     422    23882393 :             sscale = 1.0_dp
     423    23882393 :             t1 = pi**2
     424    23882393 :             t2 = t1*my_rho
     425    23882393 :             t3 = t2**(0.1e1_dp/0.3e1_dp)
     426    23882393 :             t4 = 0.1e1_dp/t3
     427    23882393 :             t6 = my_ndrho*t4
     428    23882393 :             t7 = 0.1e1_dp/my_rho
     429    23882393 :             t8 = t7*sscale
     430    23882393 :             ss = 0.3466806371753173524216762e0_dp*t6*t8
     431    23882393 :             IF (ss > scutoff) THEN
     432    11295621 :                ss2 = ss*ss
     433    11295621 :                sscale = (smax*ss2 - sconst)/(ss2*ss)
     434             :             END IF
     435    23882393 :             e_tmp = 0.0_dp
     436    23882393 :             IF (ss*sscale > gcutoff) THEN
     437             :                CALL xpbe_hole_t_c_lr_lda_calc_1(e_tmp, e_rho(ip), e_ndrho(ip), &
     438             :                                                 my_rho, &
     439    23876738 :                                                 my_ndrho, sscale, sx, R, order)
     440             :             ELSE
     441             :                CALL xpbe_hole_t_c_lr_lda_calc_2(e_tmp, e_rho(ip), e_ndrho(ip), &
     442             :                                                 my_rho, &
     443        5655 :                                                 my_ndrho, sscale, sx, R, order)
     444             :             END IF
     445    23882393 :             e_0(ip) = e_0(ip) + 0.5_dp*e_tmp
     446             : 
     447             :          END IF
     448             :       END DO
     449             : 
     450             : !$OMP     END DO
     451             : 
     452        1456 :    END SUBROUTINE xpbe_hole_t_c_lr_lsd_calc
     453             : 
     454             : ! **************************************************************************************************
     455             : !> \brief low level routine that calculates the energy derivatives in one point
     456             : !> \param e_0 derivatives of the energy on the grid
     457             : !> \param e_rho derivatives of the energy on the grid
     458             : !> \param e_ndrho derivatives of the energy on the grid
     459             : !> \param rho value of density on the grid
     460             : !> \param ndrho value of gradient on the grid
     461             : !> \param sscale functional parameters
     462             : !> \param sx functional parameters
     463             : !> \param R functional parameters
     464             : !> \param order order of the derivatives
     465             : !> \par History
     466             : !>      01.2009 created [Manuel Guidon]
     467             : !> \author Manuel Guidon
     468             : ! **************************************************************************************************
     469    65487207 :    ELEMENTAL SUBROUTINE xpbe_hole_t_c_lr_lda_calc_1(e_0, e_rho, e_ndrho, &
     470             :                                                     rho, ndrho, sscale, sx, R, order)
     471             :       REAL(KIND=dp), INTENT(INOUT)                       :: e_0, e_rho, e_ndrho
     472             :       REAL(KIND=dp), INTENT(IN)                          :: rho, ndrho, sscale, sx, R
     473             :       INTEGER, INTENT(IN)                                :: order
     474             : 
     475             :       REAL(KIND=dp) :: p, pndrho, prho, q, qndrho, qrho, sndrho, srho, ssval, t1, t103, t104, &
     476             :          t105, t106, t107, t108, t109, t11, t113, t115, t116, t117, t118, t119, t12, t121, t123, &
     477             :          t125, t126, t129, t13, t133, t136, t14, t140, t142, t143, t144, t147, t150, t152, t155, &
     478             :          t156, t159, t162, t163, t164, t167, t17, t170, t173, t175, t176, t177, t178, t181, t183, &
     479             :          t187, t19, t190, t194, t195, t196, t199, t2, t202, t209, t21, t214, t216, t217, t218, &
     480             :          t22, t222, t223, t224, t227, t228, t229, t232, t234, t235, t236, t237, t240, t244, t248, &
     481             :          t25, t251, t255, t256, t257, t261, t262, t265, t269, t27, t273, t276
     482             :       REAL(KIND=dp) :: t279, t280, t281, t29, t292, t3, t308, t31, t312, t314, t318, t320, t322, &
     483             :          t33, t331, t334, t339, t34, t341, t347, t349, t35, t359, t362, t368, t37, t370, t373, &
     484             :          t38, t382, t385, t39, t393, t4, t40, t401, t402, t404, t405, t409, t41, t42, t420, t421, &
     485             :          t424, t425, t426, t429, t430, t431, t437, t44, t445, t446, t45, t451, t46, t473, t475, &
     486             :          t479, t48, t484, t497, t498, t5, t50, t503, t504, t51, t517, t52, t523, t524, t527, t53, &
     487             :          t533, t534, t54, t541, t56, t568, t57, t58, t581, t590, t6, t60, t603, t604, t61, t611, &
     488             :          t612, t64, t640, t65, t653, t667, t675, t677, t69, t7, t71, t716
     489             :       REAL(KIND=dp) :: t717, t720, t723, t73, t739, t758, t762, t77, t8, t800, t803, t808, t85, &
     490             :          t86, t87, t88, t91, t92, t93, t94, t95, t98, t99
     491             : 
     492    65487207 :       IF (order >= 0) THEN
     493    65487207 :          t1 = 3**(0.1e1_dp/0.3e1_dp)
     494    65487207 :          t2 = t1**2
     495    65487207 :          t3 = ndrho*t2
     496    65487207 :          t4 = pi**2
     497    65487207 :          t5 = t4*rho
     498    65487207 :          t6 = t5**(0.1e1_dp/0.3e1_dp)
     499    65487207 :          t7 = 0.1e1_dp/t6
     500    65487207 :          t8 = 0.1e1_dp/rho
     501    65487207 :          ssval = t3*t7*t8/0.6e1_dp
     502    65487207 :          t11 = red(rho, ndrho)
     503    65487207 :          t12 = t11**2
     504    65487207 :          t13 = sscale**2
     505    65487207 :          t14 = t12*t13
     506    65487207 :          t17 = t12**2
     507    65487207 :          t19 = t13**2
     508    65487207 :          t21 = a1*t12*t13 + a2*t17*t19
     509    65487207 :          t22 = t14*t21
     510    65487207 :          t25 = t17*t11
     511    65487207 :          t27 = t19*sscale
     512    65487207 :          t29 = t17*t12
     513    65487207 :          t31 = t19*t13
     514    65487207 :          t33 = 1 + a3*t17*t19 + a4*t25*t27 + a5*t29*t31
     515    65487207 :          t34 = 0.1e1_dp/t33
     516    65487207 :          t35 = R**2
     517    65487207 :          t37 = t6**2
     518    65487207 :          t38 = t2*t37
     519    65487207 :          t39 = t34*t35*t38
     520    65487207 :          q = t22*t39
     521    65487207 :          t40 = t21*t34
     522    65487207 :          t41 = 0.1e1_dp/A
     523    65487207 :          t42 = t40*t41
     524    65487207 :          p = 0.9e1_dp/0.4e1_dp*t14*t42
     525    65487207 :          t44 = rho**(0.1e1_dp/0.3e1_dp)
     526    65487207 :          t45 = t44*rho
     527    65487207 :          t46 = exei(P, Q)
     528    65487207 :          t48 = expint(1, q)
     529    65487207 :          t50 = t14*t40
     530    65487207 :          t51 = D + t50
     531    65487207 :          t52 = t51*t35
     532    65487207 :          t53 = t52*t38
     533    65487207 :          t54 = expint(1, t53)
     534    65487207 :          t56 = t51**2
     535    65487207 :          t57 = t56*t51
     536    65487207 :          t58 = 0.1e1_dp/t57
     537    65487207 :          t60 = D*C
     538    65487207 :          t61 = D**2
     539    65487207 :          t64 = D*t21
     540    65487207 :          t65 = t34*B
     541    65487207 :          t69 = rootpi
     542    65487207 :          t71 = F1*t21
     543    65487207 :          t73 = t71*t34 + F2
     544    65487207 :          t77 = C*(1 + t73*t12*t13)
     545    65487207 :          t85 = t69*(15*E + 6*t77*t51 + 4*B*t56 + 8*A*t57)
     546    65487207 :          t86 = SQRT(t51)
     547    65487207 :          t87 = t86*t57
     548    65487207 :          t88 = 0.1e1_dp/t87
     549    65487207 :          t91 = SQRT(A)
     550    65487207 :          t92 = pi*t91
     551    65487207 :          t93 = EXP(p)
     552    65487207 :          t94 = t11*sscale
     553    65487207 :          t95 = SQRT(t42)
     554    65487207 :          t98 = erf(0.3e1_dp/0.2e1_dp*t94*t95)
     555    65487207 :          t99 = 1 - t98
     556             :          t103 = 0.3e1_dp/0.4e1_dp*pi + t85*t88/0.16e2_dp - 0.3e1_dp/0.4e1_dp*t92 &
     557    65487207 :                 *t93*t99
     558    65487207 :          t104 = 0.1e1_dp/t69
     559    65487207 :          t105 = t103*t104
     560    65487207 :          t106 = 0.1e1_dp/t12
     561    65487207 :          t107 = 0.1e1_dp/t13
     562    65487207 :          t108 = t106*t107
     563    65487207 :          t109 = t108*t87
     564             :          t113 = t40*C + REAL(2*t64*t65, KIND=dp) - 0.32e2_dp/0.15e2_dp*t105*t109 &
     565    65487207 :                 + t60*t73
     566    65487207 :          t115 = t17*t19
     567    65487207 :          t116 = t21**2
     568    65487207 :          t117 = t33**2
     569    65487207 :          t118 = 0.1e1_dp/t117
     570    65487207 :          t119 = t116*t118
     571    65487207 :          t121 = C*t73
     572    65487207 :          t123 = t119*B + t40*t121
     573    65487207 :          t125 = t35*t2
     574    65487207 :          t126 = t61*C
     575    65487207 :          t129 = E*t21
     576    65487207 :          t133 = D*t103*t104
     577    65487207 :          t136 = t34*C
     578             :          t140 = REAL(2*t129*t34, KIND=dp) - 0.32e2_dp/0.15e2_dp*t133*t109 + REAL(2 &
     579    65487207 :                                                                                  *t64*t136, KIND=dp) + t126*t73
     580    65487207 :          t142 = t105*t106
     581    65487207 :          t143 = t107*t87
     582    65487207 :          t144 = t143*t40
     583    65487207 :          t147 = t136*t73
     584    65487207 :          t150 = C*t116
     585             :          t152 = -0.32e2_dp/0.15e2_dp*t142*t144 + REAL(2*t64*t147, KIND=dp) + t150 &
     586    65487207 :                 *t118
     587    65487207 :          t155 = t29*t31*C
     588    65487207 :          t156 = t73*t116
     589             :          t159 = t126 + 2*D*E + t14*t140 + t115*t152 + t155*t156* &
     590    65487207 :                 t118
     591    65487207 :          t162 = t35**2
     592    65487207 :          t163 = t162*t1
     593    65487207 :          t164 = t6*t5
     594    65487207 :          t167 = t61*t103*t104
     595    65487207 :          t170 = t34*E
     596    65487207 :          t173 = -0.16e2_dp/0.15e2_dp*t167*t109 + REAL(2*t64*t170, KIND=dp)
     597    65487207 :          t175 = t34*t103
     598    65487207 :          t176 = t64*t175
     599    65487207 :          t177 = t104*t106
     600    65487207 :          t178 = t177*t143
     601    65487207 :          t181 = E*t116
     602    65487207 :          t183 = -0.32e2_dp/0.15e2_dp*t176*t178 + t181*t118
     603    65487207 :          t187 = t104*t87*t119
     604             :          t190 = t61*E + t14*t173 + t115*t183 - 0.16e2_dp/0.15e2_dp*t115 &
     605    65487207 :                 *t103*t187
     606             :          t194 = 2*E + t60 + t61*B + t14*t113 + t115*t123 + t125*t37 &
     607    65487207 :                 *t159 + 3*t163*t164*t190
     608    65487207 :          t195 = t58*t194
     609    65487207 :          t196 = D*t35
     610    65487207 :          t199 = EXP(-t196*t38 - q)
     611             :          t202 = -0.4e1_dp/0.9e1_dp*A*t46 + 0.4e1_dp/0.9e1_dp*A*t48 - 0.4e1_dp/ &
     612    65487207 :                 0.9e1_dp*A*t54 - 0.4e1_dp/0.9e1_dp*t195*t199
     613    65487207 :          e_0 = e_0 + (t45*t202*Clda)*sx
     614             :       END IF
     615    65487207 :       IF (order >= 1 .OR. order >= -1) THEN
     616    65487207 :          t209 = rho**2
     617    65487207 :          srho = -t3/t164*t8*t4/0.18e2_dp - t3*t7/t209/0.6e1_dp
     618             : 
     619    65487207 :          t214 = t2*t7
     620    65487207 :          sndrho = t214*t8/0.6e1_dp
     621    65487207 :          t216 = t11*t13
     622    65487207 :          t217 = t216*t40
     623    65487207 :          t218 = dsdrho(rho, ndrho)
     624    65487207 :          t222 = 2*t217*t125*t37*t218
     625    65487207 :          t223 = a1*t11
     626    65487207 :          t224 = t13*t218
     627    65487207 :          t227 = t12*t11
     628    65487207 :          t228 = a2*t227
     629    65487207 :          t229 = t19*t218
     630    65487207 :          t232 = 2*t223*t224 + 4*t228*t229
     631    65487207 :          t234 = t14*t232*t39
     632    65487207 :          t235 = t21*t118
     633    65487207 :          t236 = t14*t235
     634    65487207 :          t237 = a3*t227
     635    65487207 :          t240 = a4*t17
     636    65487207 :          t244 = a5*t25
     637    65487207 :          t248 = 4*t237*t229 + 5*t240*t27*t218 + 6*t244*t31*t218
     638    65487207 :          t251 = t236*t125*t37*t248
     639    65487207 :          t255 = 0.2e1_dp/0.3e1_dp*t50*t125*t7*t4
     640    65487207 :          qrho = t222 + t234 - t251 + t255
     641    65487207 :          t256 = t216*t21
     642    65487207 :          t257 = t34*t41
     643    65487207 :          t261 = t232*t34
     644    65487207 :          t262 = t261*t41
     645    65487207 :          t265 = t118*t41
     646             :          prho = 0.9e1_dp/0.2e1_dp*t256*t257*t218 + 0.9e1_dp/0.4e1_dp*t14*t262 &
     647    65487207 :                 - 0.9e1_dp/0.4e1_dp*t22*t265*t248
     648    65487207 :          t269 = dsdndrho(rho)
     649    65487207 :          t273 = t13*t269
     650    65487207 :          t276 = t19*t269
     651    65487207 :          t279 = 2*t223*t273 + 4*t228*t276
     652    65487207 :          t280 = t279*t34
     653    65487207 :          t281 = t280*t41
     654    65487207 :          t292 = 4*t237*t276 + 5*t240*t27*t269 + 6*t244*t31*t269
     655             :          pndrho = 0.9e1_dp/0.2e1_dp*t256*t257*t269 + 0.9e1_dp/0.4e1_dp*t14* &
     656    65487207 :                   t281 - 0.9e1_dp/0.4e1_dp*t22*t265*t292
     657             :          qndrho = 2*t217*t125*t37*t269 + t14*t279*t39 - t236*t125 &
     658    65487207 :                   *t37*t292
     659    65487207 :          t308 = dexeirho(P, Q, Prho, Qrho)
     660    65487207 :          t312 = EXP(-q)
     661    65487207 :          t314 = t312*t106*t107
     662    65487207 :          t318 = 0.1e1_dp/t35
     663    65487207 :          t320 = 0.1e1_dp/t37
     664    65487207 :          t322 = 0.1e1_dp/t21*t33*t318*t1*t320
     665    65487207 :          t331 = 2*t216*t40*t218 + t14*t261 - t14*t235*t248
     666    65487207 :          t334 = t214*t4
     667    65487207 :          t339 = EXP(-t53)
     668    65487207 :          t341 = 0.1e1_dp/t51
     669    65487207 :          t347 = t56**2
     670    65487207 :          t349 = 0.1e1_dp/t347*t194
     671    65487207 :          t359 = D*t232
     672    65487207 :          t362 = t118*B
     673    65487207 :          t368 = t118*t248
     674    65487207 :          t370 = F1*t232*t34 - t71*t368
     675    65487207 :          t373 = t73*t11
     676    65487207 :          t382 = B*t51
     677    65487207 :          t385 = A*t56
     678    65487207 :          t393 = 0.1e1_dp/t86/t347
     679    65487207 :          t401 = t92*t93
     680    65487207 :          t402 = SQRT(0.31415926535897932385e1_dp)
     681    65487207 :          t404 = EXP(-p)
     682    65487207 :          t405 = 0.1e1_dp/t402*t404
     683    65487207 :          t409 = 0.1e1_dp/t95
     684             :          t420 = REAL(t69*(6*C*(t370*t12*t13 + 2*t373*t224)*t51 &
     685             :                           + 6*t77*t331 + 8*t382*t331 + 24*t385*t331)*t88, KIND=dp)/ &
     686             :                 0.16e2_dp - 0.7e1_dp/0.32e2_dp*REAL(t85, KIND=dp)*REAL(t393, KIND=dp)* &
     687             :                 REAL(t331, KIND=dp) - 0.3e1_dp &
     688             :                 /0.4e1_dp*t92*prho*t93*t99 + 0.3e1_dp/0.2e1_dp*t401*t405 &
     689             :                 *(0.3e1_dp/0.2e1_dp*t218*sscale*t95 + 0.3e1_dp/0.4e1_dp*t94*t409 &
     690    65487207 :                   *(t262 - t235*t41*t248))
     691    65487207 :          t421 = t420*t104
     692    65487207 :          t424 = 0.1e1_dp/t227
     693    65487207 :          t425 = t105*t424
     694    65487207 :          t426 = t143*t218
     695    65487207 :          t429 = t86*t56
     696    65487207 :          t430 = t107*t429
     697    65487207 :          t431 = t430*t331
     698    65487207 :          t437 = t227*t19
     699    65487207 :          t445 = 0.1e1_dp/t117/t33
     700    65487207 :          t446 = t116*t445
     701    65487207 :          t451 = t121*t248
     702    65487207 :          t473 = t424*t107
     703    65487207 :          t475 = t473*t87*t218
     704    65487207 :          t479 = t108*t429*t331
     705    65487207 :          t484 = t118*C
     706    65487207 :          t497 = t105*t473
     707    65487207 :          t498 = t87*t21
     708    65487207 :          t503 = t105*t108
     709    65487207 :          t504 = t429*t21
     710    65487207 :          t517 = t64*t118
     711    65487207 :          t523 = C*t21
     712    65487207 :          t524 = t118*t232
     713    65487207 :          t527 = t445*t248
     714    65487207 :          t533 = t25*t31*C
     715    65487207 :          t534 = t118*t218
     716    65487207 :          t541 = t73*t21
     717    65487207 :          t568 = t118*E
     718    65487207 :          t581 = t64*t118*t103
     719    65487207 :          t590 = t104*t424
     720    65487207 :          t603 = t437*t105
     721    65487207 :          t604 = t87*t116
     722    65487207 :          t611 = t115*t105
     723    65487207 :          t612 = t429*t116
     724             :          e_rho = e_rho + (0.4e1_dp/0.3e1_dp*t44*t202*Clda + t45*(-0.4e1_dp/0.9e1_dp* &
     725             :                                                                  A*t308 - 0.4e1_dp/0.27e2_dp*A*qrho*t314*t322 + 0.4e1_dp/0.27e2_dp &
     726             :                                                                  *A*(t331*t35*t38 + 0.2e1_dp/0.3e1_dp*t52*t334)*t339*t341 &
     727             :                                                                  *t318*t1*t320 + 0.4e1_dp/0.3e1_dp*t349*t199*t331 - 0.4e1_dp &
     728             :                                                                  /0.9e1_dp*t58*(REAL(2*t216*t113*t218, KIND=dp) + t14*(t261*C &
     729             :                                                         - t235*C*REAL(t248, KIND=dp) + REAL(2*t359*t65, KIND=dp) - REAL(2*t64*t362 &
     730             :                                                         *t248, KIND=dp) - 0.32e2_dp/0.15e2_dp*t421*t109 + 0.64e2_dp/0.15e2_dp*t425 &
     731             :                                                                       *t426 - 0.112e3_dp/0.15e2_dp*t142*t431 + t60*t370) + REAL(4* &
     732             :                                                              t437*t123*t218, KIND=dp) + t115*(0.2e1_dp*t235*B*t232 - 0.2e1_dp*t446 &
     733             :                                                                       *B*REAL(t248, KIND=dp) + t261*t121 - t235*t451 + t40*C*t370) &
     734             :                                                                            + 0.2e1_dp/0.3e1_dp*t125*t7*t159*t4 + t125*t37*(REAL(2* &
     735             :                                                                  t216*t140*t218, KIND=dp) + t14*(0.2e1_dp*E*t232*t34 - REAL(2*t129 &
     736             :                                                       *t368, KIND=dp) - 0.32e2_dp/0.15e2_dp*D*t420*t104*t109 + 0.64e2_dp/0.15e2_dp &
     737             :                                                                          *t133*t475 - 0.112e3_dp/0.15e2_dp*t133*t479 + REAL(2*t359 &
     738             :                                                            *t136, KIND=dp) - REAL(2*t64*t484*t248, KIND=dp) + t126*t370) + REAL(4* &
     739             :                                                               t437*t152*t218, KIND=dp) + t115*(-0.32e2_dp/0.15e2_dp*t421*t106*t144 &
     740             :                                                     + 0.64e2_dp/0.15e2_dp*t497*t498*t34*REAL(t218, KIND=dp) - 0.112e3_dp/0.15e2_dp &
     741             :                                                                               *t503*t504*t34*t331 - 0.32e2_dp/0.15e2_dp*t142*t143* &
     742             :                                                             t261 + 0.32e2_dp/0.15e2_dp*t503*t498*REAL(t368, KIND=dp) + REAL(2*t359 &
     743             :                                            *t147, KIND=dp) - 0.2e1_dp*t517*t451 + 0.2e1_dp*REAL(t64, KIND=dp)*REAL(t136, KIND=dp)* &
     744             :                                                      t370 + REAL(2*t523*t524, KIND=dp) - REAL(2*t150*t527, KIND=dp)) + REAL(6*t533 &
     745             :                                                                    *t156*t534, KIND=dp) + t155*t370*t116*t118 + 0.2e1_dp*t155*t541 &
     746             :                                           *REAL(t524, KIND=dp) - 0.2e1_dp*t155*REAL(t156, KIND=dp)*REAL(t527, KIND=dp)) + 0.4e1_dp &
     747             :                                                                            *t163*t6*t190*t4 + 0.3e1_dp*t163*t164*(REAL(2*t216*t173 &
     748             :                                                                   *t218, KIND=dp) + t14*(-0.16e2_dp/0.15e2_dp*t61*t420*t104*t109 + &
     749             :                                                             0.32e2_dp/0.15e2_dp*t167*t475 - 0.56e2_dp/0.15e2_dp*t167*t479 + REAL(2 &
     750             :                                                               *t359*t170, KIND=dp) - REAL(2*t64*t568*t248, KIND=dp)) + REAL(4*t437 &
     751             :                                          *t183*t218, KIND=dp) + t115*(-0.32e2_dp/0.15e2_dp*REAL(t359, KIND=dp)*REAL(t175, KIND=dp) &
     752             :                                                      *REAL(t178, KIND=dp) + 0.32e2_dp/0.15e2_dp*t581*t177*t143*REAL(t248, KIND=dp) &
     753             :                                                  - 0.32e2_dp/0.15e2_dp*REAL(t64, KIND=dp)*t34*t420*REAL(t178, KIND=dp) + 0.64e2_dp &
     754             :                                                                        /0.15e2_dp*t176*t590*t426 - 0.112e3_dp/0.15e2_dp*t176*t177* &
     755             :                                                       t431 + REAL(2*t129*t524, KIND=dp) - REAL(2*t181*t527, KIND=dp)) - 0.64e2_dp/ &
     756             :                                       0.15e2_dp*REAL(t603, KIND=dp)*REAL(t604, KIND=dp)*REAL(t534, KIND=dp) - 0.16e2_dp/0.15e2_dp* &
     757             :                                                                         t115*t420*t187 - 0.56e2_dp/0.15e2_dp*t611*t612*t118*t331 - &
     758             :                                                       0.32e2_dp/0.15e2_dp*t611*t498*REAL(t524, KIND=dp) + 0.32e2_dp/0.15e2_dp*t611 &
     759             :                                                *REAL(t604, KIND=dp)*REAL(t527, KIND=dp)))*t199 - 0.4e1_dp/0.9e1_dp*t195*(-0.2e1_dp &
     760             :                                                                            /0.3e1_dp*t196*t334 - t222 - t234 + t251 - t255)*t199)* &
     761    65487207 :                           Clda)*sx
     762    65487207 :          t640 = dexeindrho(P, Q, Pndrho, Qndrho)
     763    65487207 :          t653 = 2*t216*t40*t269 + t14*t280 - t14*t235*t292
     764    65487207 :          t667 = D*t279
     765    65487207 :          t675 = t118*t292
     766    65487207 :          t677 = F1*t279*t34 - t71*t675
     767             :          t716 = REAL(t69*(6*C*(t677*t12*t13 + 2*t373*t273)*t51 &
     768             :                           + 6*t77*t653 + 8*t382*t653 + 24*t385*t653)*t88, KIND=dp)/ &
     769             :                 0.16e2_dp - 0.7e1_dp/0.32e2_dp*REAL(t85, KIND=dp)*REAL(t393, KIND=dp)* &
     770             :                 REAL(t653, KIND=dp) - 0.3e1_dp &
     771             :                 /0.4e1_dp*t92*pndrho*t93*t99 + 0.3e1_dp/0.2e1_dp*t401*t405 &
     772             :                 *(0.3e1_dp/0.2e1_dp*t269*sscale*t95 + 0.3e1_dp/0.4e1_dp*t94* &
     773    65487207 :                   t409*(t281 - t235*t41*t292))
     774    65487207 :          t717 = t716*t104
     775    65487207 :          t720 = t143*t269
     776    65487207 :          t723 = t430*t653
     777    65487207 :          t739 = t121*t292
     778    65487207 :          t758 = t473*t87*t269
     779    65487207 :          t762 = t108*t429*t653
     780    65487207 :          t800 = t118*t279
     781    65487207 :          t803 = t445*t292
     782    65487207 :          t808 = t118*t269
     783             :          e_ndrho = e_ndrho + (t45*(-0.4e1_dp/0.9e1_dp*A*t640 - 0.4e1_dp/0.27e2_dp*A*qndrho &
     784             :                                    *t314*t322 + 0.4e1_dp/0.9e1_dp*A*t653*t339*t341 + 0.4e1_dp &
     785             :                                    /0.3e1_dp*t349*t199*t653 - 0.4e1_dp/0.9e1_dp*t58*(REAL(2*t216 &
     786             :                                                           *t113*t269, KIND=dp) + t14*(t280*C - t235*C*REAL(t292, KIND=dp) + REAL(2 &
     787             :                                                         *t667*t65, KIND=dp) - REAL(2*t64*t362*t292, KIND=dp) - 0.32e2_dp/0.15e2_dp &
     788             :                                                                 *t717*t109 + 0.64e2_dp/0.15e2_dp*t425*t720 - 0.112e3_dp/0.15e2_dp* &
     789             :                                                                    t142*t723 + t60*t677) + REAL(4*t437*t123*t269, KIND=dp) + t115* &
     790             :                                                                (0.2e1_dp*t235*B*t279 - 0.2e1_dp*t446*B*REAL(t292, KIND=dp) + t280* &
     791             :                                                                             t121 - t235*t739 + t40*C*t677) + t125*t37*(REAL(2*t216 &
     792             :                                                                     *t140*t269, KIND=dp) + t14*(0.2e1_dp*E*t279*t34 - REAL(2*t129* &
     793             :                                                        t675, KIND=dp) - 0.32e2_dp/0.15e2_dp*D*t716*t104*t109 + 0.64e2_dp/0.15e2_dp &
     794             :                                                                         *t133*t758 - 0.112e3_dp/0.15e2_dp*t133*t762 + REAL(2*t667* &
     795             :                                                         t136, KIND=dp) - REAL(2*t64*t484*t292, KIND=dp) + t126*t677) + REAL(4*t437 &
     796             :                                                                 *t152*t269, KIND=dp) + t115*(-0.32e2_dp/0.15e2_dp*t717*t106*t144 + &
     797             :                                                       0.64e2_dp/0.15e2_dp*t497*t498*t34*REAL(t269, KIND=dp) - 0.112e3_dp/0.15e2_dp &
     798             :                                                                           *t503*t504*t34*t653 - 0.32e2_dp/0.15e2_dp*t142*t143*t280 &
     799             :                                                                 + 0.32e2_dp/0.15e2_dp*t503*t498*REAL(t675, KIND=dp) + REAL(2*t667* &
     800             :                                         t147, KIND=dp) - 0.2e1_dp*t517*t739 + 0.2e1_dp*REAL(t64, KIND=dp)*REAL(t136, KIND=dp)*t677 &
     801             :                                                           + REAL(2*t523*t800, KIND=dp) - REAL(2*t150*t803, KIND=dp)) + REAL(6*t533 &
     802             :                                                                    *t156*t808, KIND=dp) + t155*t677*t116*t118 + 0.2e1_dp*t155*t541 &
     803             :                                      *REAL(t800, KIND=dp) - 0.2e1_dp*t155*REAL(t156, KIND=dp)*REAL(t803, KIND=dp)) + 0.3e1_dp*t163 &
     804             :                                                                 *t164*(REAL(2*t216*t173*t269, KIND=dp) + t14*(-0.16e2_dp/0.15e2_dp &
     805             :                                                                    *t61*t716*t104*t109 + 0.32e2_dp/0.15e2_dp*t167*t758 - 0.56e2_dp &
     806             :                                                                     /0.15e2_dp*t167*t762 + REAL(2*t667*t170, KIND=dp) - REAL(2*t64 &
     807             :                                                         *t568*t292, KIND=dp)) + REAL(4*t437*t183*t269, KIND=dp) + t115*(-0.32e2_dp &
     808             :                                       /0.15e2_dp*REAL(t667, KIND=dp)*REAL(t175, KIND=dp)*REAL(t178, KIND=dp) + 0.32e2_dp/0.15e2_dp &
     809             :                                                      *t581*t177*t143*REAL(t292, KIND=dp) - 0.32e2_dp/0.15e2_dp*REAL(t64, KIND=dp)* &
     810             :                                                     t34*t716*REAL(t178, KIND=dp) + 0.64e2_dp/0.15e2_dp*t176*t590*t720 - 0.112e3_dp &
     811             :                                                                    /0.15e2_dp*t176*t177*t723 + REAL(2*t129*t800, KIND=dp) - REAL(2 &
     812             :                                               *t181*t803, KIND=dp)) - 0.64e2_dp/0.15e2_dp*REAL(t603, KIND=dp)*REAL(t604, KIND=dp)* &
     813             :                                                     REAL(t808, KIND=dp) - 0.16e2_dp/0.15e2_dp*t115*t716*t187 - 0.56e2_dp/0.15e2_dp &
     814             :                                                           *t611*t612*t118*t653 - 0.32e2_dp/0.15e2_dp*t611*t498*REAL(t800, KIND=dp) &
     815             :                                                          + 0.32e2_dp/0.15e2_dp*t611*REAL(t604, KIND=dp)*REAL(t803, KIND=dp)))*t199 &
     816    65487207 :                                    + 0.4e1_dp/0.9e1_dp*t195*qndrho*t199)*Clda)*sx
     817             :       END IF
     818             : 
     819    65487207 :    END SUBROUTINE xpbe_hole_t_c_lr_lda_calc_1
     820             : 
     821             : ! **************************************************************************************************
     822             : !> \brief low level routine that calculates the energy derivatives in one point
     823             : !> \param e_0 derivatives of the energy on the grid
     824             : !> \param e_rho derivatives of the energy on the grid
     825             : !> \param e_ndrho derivatives of the energy on the grid
     826             : !> \param rho value of density on the grid
     827             : !> \param ndrho value of gradient on the grid
     828             : !> \param sscale functional parameters
     829             : !> \param sx functional parameters
     830             : !> \param R functional parameters
     831             : !> \param order order of the derivatives
     832             : !> \par History
     833             : !>      01.2009 created [Manuel Guidon]
     834             : !> \author Manuel Guidon
     835             : ! **************************************************************************************************
     836       30910 :    ELEMENTAL SUBROUTINE xpbe_hole_t_c_lr_lda_calc_2(e_0, e_rho, e_ndrho, &
     837             :                                                     rho, ndrho, sscale, sx, R, order)
     838             :       REAL(KIND=dp), INTENT(INOUT)                       :: e_0, e_rho, e_ndrho
     839             :       REAL(KIND=dp), INTENT(IN)                          :: rho, ndrho, sscale, sx, R
     840             :       INTEGER, INTENT(IN)                                :: order
     841             : 
     842             :       REAL(KIND=dp) :: p, pndrho, prho, q, qndrho, qrho, sndrho, srho, ssval, t1, t102, t106, t11, &
     843             :          t110, t113, t115, t117, t118, t119, t12, t122, t125, t126, t127, t128, t13, t130, t133, &
     844             :          t135, t138, t14, t140, t142, t143, t146, t150, t151, t152, t155, t158, t165, t17, t170, &
     845             :          t172, t173, t174, t178, t179, t180, t183, t184, t185, t188, t19, t190, t191, t192, t193, &
     846             :          t196, t197, t2, t200, t204, t207, t21, t211, t212, t213, t217, t22, t221, t225, t229, &
     847             :          t232, t235, t236, t242, t248, t25, t264, t268, t27, t272, t276, t278, t280, t287, t289, &
     848             :          t29, t292, t297, t299, t3, t305, t307, t31, t317, t320, t324
     849             :       REAL(KIND=dp) :: t327, t33, t330, t333, t334, t338, t34, t340, t344, t35, t352, t353, t358, &
     850             :          t37, t38, t380, t39, t394, t398, t399, t4, t40, t401, t406, t407, t408, t41, t415, t435, &
     851             :          t44, t45, t454, t46, t461, t48, t485, t496, t498, t5, t50, t51, t512, t52, t524, t525, &
     852             :          t529, t53, t531, t54, t545, t56, t579, t58, t581, t586, t6, t60, t61, t64, t65, t7, t74, &
     853             :          t75, t77, t79, t8, t81, t83, t84, t85, t86, t89, t91, t93, t94, t95, t97
     854             : 
     855       30910 :       IF (order >= 0) THEN
     856       30910 :          t1 = 3**(0.1e1_dp/0.3e1_dp)
     857       30910 :          t2 = t1**2
     858       30910 :          t3 = ndrho*t2
     859       30910 :          t4 = pi**2
     860       30910 :          t5 = t4*rho
     861       30910 :          t6 = t5**(0.1e1_dp/0.3e1_dp)
     862       30910 :          t7 = 0.1e1_dp/t6
     863       30910 :          t8 = 0.1e1_dp/rho
     864       30910 :          ssval = t3*t7*t8/0.6e1_dp
     865             : 
     866       30910 :          t11 = red(rho, ndrho)
     867       30910 :          t12 = t11**2
     868       30910 :          t13 = sscale**2
     869       30910 :          t14 = t12*t13
     870       30910 :          t17 = t12**2
     871       30910 :          t19 = t13**2
     872       30910 :          t21 = a1*t12*t13 + a2*t17*t19
     873       30910 :          t22 = t14*t21
     874       30910 :          t25 = t17*t11
     875       30910 :          t27 = t19*sscale
     876       30910 :          t29 = t17*t12
     877       30910 :          t31 = t19*t13
     878       30910 :          t33 = 1 + a3*t17*t19 + a4*t25*t27 + a5*t29*t31
     879       30910 :          t34 = 0.1e1_dp/t33
     880       30910 :          t35 = R**2
     881       30910 :          t37 = t6**2
     882       30910 :          t38 = t2*t37
     883       30910 :          t39 = t34*t35*t38
     884       30910 :          q = t22*t39
     885       30910 :          t40 = t21*t34
     886       30910 :          t41 = 0.1e1_dp/A
     887       30910 :          p = 0.9e1_dp/0.4e1_dp*t14*t40*t41
     888       30910 :          t44 = rho**(0.1e1_dp/0.3e1_dp)
     889       30910 :          t45 = t44*rho
     890       30910 :          t46 = exei(P, Q)
     891       30910 :          t48 = expint(1, q)
     892       30910 :          t50 = t14*t40
     893       30910 :          t51 = D + t50
     894       30910 :          t52 = t51*t35
     895       30910 :          t53 = t52*t38
     896       30910 :          t54 = expint(1, t53)
     897       30910 :          t56 = t51**2
     898       30910 :          t58 = 0.1e1_dp/t56/t51
     899       30910 :          t60 = D*C
     900       30910 :          t61 = D**2
     901       30910 :          t64 = D*t21
     902       30910 :          t65 = t34*B
     903       30910 :          t74 = g1 + g2*t12*t13 + g3*t17*t19 + g4*t25*t27
     904       30910 :          t75 = E*t74
     905       30910 :          t77 = F1*t21
     906       30910 :          t79 = t77*t34 + F2
     907       30910 :          t81 = t40*C + 2*t64*t65 + 2*t75 + t60*t79
     908       30910 :          t83 = t17*t19
     909       30910 :          t84 = t21**2
     910       30910 :          t85 = t33**2
     911       30910 :          t86 = 0.1e1_dp/t85
     912       30910 :          t89 = C*t79
     913       30910 :          t91 = t84*t86*B + t40*t89
     914       30910 :          t93 = t35*t2
     915       30910 :          t94 = t61*C
     916       30910 :          t95 = D*E
     917       30910 :          t97 = E*t21
     918       30910 :          t102 = t34*C
     919       30910 :          t106 = 2*t97*t34 + 2*t95*t74 + 2*t64*t102 + t94*t79
     920       30910 :          t110 = t102*t79
     921       30910 :          t113 = C*t84
     922       30910 :          t115 = 2*t75*t40 + 2*t64*t110 + t113*t86
     923       30910 :          t117 = t29*t31
     924       30910 :          t118 = t117*C
     925       30910 :          t119 = t79*t84
     926       30910 :          t122 = t94 + 2*t95 + t14*t106 + t83*t115 + t118*t119*t86
     927       30910 :          t125 = t35**2
     928       30910 :          t126 = t125*t1
     929       30910 :          t127 = t6*t5
     930       30910 :          t128 = t61*E
     931       30910 :          t130 = t34*E
     932       30910 :          t133 = t128*t74 + 2*t64*t130
     933       30910 :          t135 = t130*t74
     934       30910 :          t138 = E*t84
     935       30910 :          t140 = 2*t64*t135 + t138*t86
     936       30910 :          t142 = t117*E
     937       30910 :          t143 = t74*t84
     938       30910 :          t146 = t128 + t14*t133 + t83*t140 + t142*t143*t86
     939             :          t150 = 2*E + t60 + t61*B + t14*t81 + t83*t91 + t93*t37* &
     940       30910 :                 t122 + 3*t126*t127*t146
     941       30910 :          t151 = t58*t150
     942       30910 :          t152 = D*t35
     943       30910 :          t155 = EXP(-t152*t38 - q)
     944             :          t158 = -0.4e1_dp/0.9e1_dp*A*t46 + 0.4e1_dp/0.9e1_dp*A*t48 - 0.4e1_dp/ &
     945       30910 :                 0.9e1_dp*A*t54 - 0.4e1_dp/0.9e1_dp*t151*t155
     946       30910 :          e_0 = e_0 + (t45*t158*Clda)*sx
     947             :       END IF
     948       30910 :       IF (order >= 1 .OR. order == -1) THEN
     949       27619 :          t165 = rho**2
     950       27619 :          srho = -t3/t127*t8*t4/0.18e2_dp - t3*t7/t165/0.6e1_dp
     951       27619 :          t170 = t2*t7
     952       27619 :          sndrho = t170*t8/0.6e1_dp
     953       27619 :          t172 = t11*t13
     954       27619 :          t173 = t172*t40
     955       27619 :          t174 = dsdrho(rho, ndrho)
     956       27619 :          t178 = 2*t173*t93*t37*t174
     957       27619 :          t179 = a1*t11
     958       27619 :          t180 = t13*t174
     959       27619 :          t183 = t12*t11
     960       27619 :          t184 = a2*t183
     961       27619 :          t185 = t19*t174
     962       27619 :          t188 = 2*t179*t180 + 4*t184*t185
     963       27619 :          t190 = t14*t188*t39
     964       27619 :          t191 = t21*t86
     965       27619 :          t192 = t14*t191
     966       27619 :          t193 = a3*t183
     967       27619 :          t196 = a4*t17
     968       27619 :          t197 = t27*t174
     969       27619 :          t200 = a5*t25
     970       27619 :          t204 = 4*t193*t185 + 5*t196*t197 + 6*t200*t31*t174
     971       27619 :          t207 = t192*t93*t37*t204
     972       27619 :          t211 = 0.2e1_dp/0.3e1_dp*t50*t93*t7*t4
     973       27619 :          qrho = t178 + t190 - t207 + t211
     974       27619 :          t212 = t172*t21
     975       27619 :          t213 = t34*t41
     976       27619 :          t217 = t188*t34
     977       27619 :          t221 = t86*t41
     978             :          prho = 0.9e1_dp/0.2e1_dp*t212*t213*t174 + 0.9e1_dp/0.4e1_dp*t14*t217 &
     979       27619 :                 *t41 - 0.9e1_dp/0.4e1_dp*t22*t221*t204
     980       27619 :          t225 = dsdndrho(rho)
     981       27619 :          t229 = t13*t225
     982       27619 :          t232 = t19*t225
     983       27619 :          t235 = 2*t179*t229 + 4*t184*t232
     984       27619 :          t236 = t235*t34
     985       27619 :          t242 = t27*t225
     986       27619 :          t248 = 4*t193*t232 + 5*t196*t242 + 6*t200*t31*t225
     987             :          pndrho = 0.9e1_dp/0.2e1_dp*t212*t213*t225 + 0.9e1_dp/0.4e1_dp*t14* &
     988       27619 :                   t236*t41 - 0.9e1_dp/0.4e1_dp*t22*t221*t248
     989             :          qndrho = 2*t173*t93*t37*t225 + t14*t235*t39 - t192*t93 &
     990       27619 :                   *t37*t248
     991       27619 :          t264 = dexeirho(P, Q, Prho, Qrho)
     992       27619 :          t268 = EXP(-q)
     993       27619 :          t272 = t268/t12/t13
     994       27619 :          t276 = 0.1e1_dp/t35
     995       27619 :          t278 = 0.1e1_dp/t37
     996       27619 :          t280 = 0.1e1_dp/t21*t33*t276*t1*t278
     997       27619 :          t287 = t191*t204
     998       27619 :          t289 = 2*t172*t40*t174 + t14*t217 - t14*t287
     999       27619 :          t292 = t170*t4
    1000       27619 :          t297 = EXP(-t53)
    1001       27619 :          t299 = 0.1e1_dp/t51
    1002       27619 :          t305 = t56**2
    1003       27619 :          t307 = 0.1e1_dp/t305*t150
    1004       27619 :          t317 = D*t188
    1005       27619 :          t320 = t86*B
    1006       27619 :          t324 = g2*t11
    1007       27619 :          t327 = g3*t183
    1008       27619 :          t330 = g4*t17
    1009       27619 :          t333 = 2*t324*t180 + 4*t327*t185 + 5*t330*t197
    1010       27619 :          t334 = E*t333
    1011       27619 :          t338 = t86*t204
    1012       27619 :          t340 = F1*t188*t34 - t77*t338
    1013       27619 :          t344 = t183*t19
    1014       27619 :          t352 = 0.1e1_dp/t85/t33
    1015       27619 :          t353 = t84*t352
    1016       27619 :          t358 = t89*t204
    1017       27619 :          t380 = t86*C
    1018       27619 :          t394 = t64*t86
    1019       27619 :          t398 = C*t21
    1020       27619 :          t399 = t86*t188
    1021       27619 :          t401 = t352*t204
    1022       27619 :          t406 = t25*t31
    1023       27619 :          t407 = t406*C
    1024       27619 :          t408 = t86*t174
    1025       27619 :          t415 = t79*t21
    1026       27619 :          t435 = t86*E
    1027       27619 :          t454 = t406*E
    1028       27619 :          t461 = t74*t21
    1029             :          e_rho = e_rho + (0.4e1_dp/0.3e1_dp*t44*t158*Clda + t45*(-0.4e1_dp/0.9e1_dp* &
    1030             :                                                                  A*t264 - 0.4e1_dp/0.27e2_dp*A*qrho*t272*t280 + 0.4e1_dp/0.27e2_dp &
    1031             :                                                                  *A*(t289*t35*t38 + 0.2e1_dp/0.3e1_dp*t52*t292)*t297*t299 &
    1032             :                                                                  *t276*t1*t278 + 0.4e1_dp/0.3e1_dp*t307*t155*t289 - 0.4e1_dp &
    1033             :                                                                  /0.9e1_dp*t58*(REAL(2*t172*t81*t174, KIND=dp) + REAL(t14*(t217 &
    1034             :                                                                                *C - t191*C*t204 + 2*t317*t65 - 2*t64*t320*t204 + 2 &
    1035             :                                                           *t334 + t60*t340), KIND=dp) + REAL(4*t344*t91*t174, KIND=dp) + REAL(t83* &
    1036             :                                                                              (2*t191*B*t188 - 2*t353*B*t204 + t217*t89 - t191*t358 &
    1037             :                                                                   + t40*C*t340), KIND=dp) + 0.2e1_dp/0.3e1_dp*t93*t7*t122*t4 + t93 &
    1038             :                                                                                 *t37*REAL(2*t172*t106*t174 + t14*(2*E*t188*t34 &
    1039             :                                                                               - 2*t97*t338 + 2*t95*t333 + 2*t317*t102 - 2*t64*t380 &
    1040             :                                                                                 *t204 + t94*t340) + 4*t344*t115*t174 + t83*(2*t334 &
    1041             :                                                                              *t40 + 2*t75*t217 - 2*t75*t287 + 2*t317*t110 - 2*t394 &
    1042             :                                                                                    *t358 + 2*t64*t102*t340 + 2*t398*t399 - 2*t113* &
    1043             :                                                                              t401) + 6*t407*t119*t408 + t118*t340*t84*t86 + 2*t118 &
    1044             :                                                                    *t415*t399 - 2*t118*t119*t401, KIND=dp) + 0.4e1_dp*t126*t6*t146 &
    1045             :                                                                               *t4 + 0.3e1_dp*t126*t127*REAL(2*t172*t133*t174 + t14 &
    1046             :                                                                              *(t128*t333 + 2*t317*t130 - 2*t64*t435*t204) + 4*t344 &
    1047             :                                                                                    *t140*t174 + t83*(2*t317*t135 - 2*t394*t75*t204 &
    1048             :                                                                                 + 2*t64*t130*t333 + 2*t97*t399 - 2*t138*t401) + 6* &
    1049             :                                                                              t454*t143*t408 + t142*t333*t84*t86 + 2*t142*t461*t399 &
    1050             :                                                             - 2*t142*t143*t401, KIND=dp))*t155 - 0.4e1_dp/0.9e1_dp*t151*(-0.2e1_dp &
    1051             :                                                                            /0.3e1_dp*t152*t292 - t178 - t190 + t207 - t211)*t155)* &
    1052       27619 :                           Clda)*sx
    1053       27619 :          t485 = dexeindrho(P, Q, Pndrho, Qndrho)
    1054       27619 :          t496 = t191*t248
    1055       27619 :          t498 = 2*t172*t40*t225 + t14*t236 - t14*t496
    1056       27619 :          t512 = D*t235
    1057       27619 :          t524 = 2*t324*t229 + 4*t327*t232 + 5*t330*t242
    1058       27619 :          t525 = E*t524
    1059       27619 :          t529 = t86*t248
    1060       27619 :          t531 = F1*t235*t34 - t77*t529
    1061       27619 :          t545 = t89*t248
    1062       27619 :          t579 = t86*t235
    1063       27619 :          t581 = t352*t248
    1064       27619 :          t586 = t86*t225
    1065             :          e_ndrho = e_ndrho + (t45*(-0.4e1_dp/0.9e1_dp*A*t485 - 0.4e1_dp/0.27e2_dp*A*qndrho &
    1066             :                                    *t272*t280 + 0.4e1_dp/0.9e1_dp*A*t498*t297*t299 + 0.4e1_dp &
    1067             :                                    /0.3e1_dp*t307*t155*t498 - 0.4e1_dp/0.9e1_dp*t58*REAL(2*t172 &
    1068             :                                                                                 *t81*t225 + t14*(t236*C - t191*C*t248 + 2*t512*t65 &
    1069             :                                                                                - 2*t64*t320*t248 + 2*t525 + t60*t531) + 4*t344*t91 &
    1070             :                                                                                  *t225 + t83*(2*t191*B*t235 - 2*t353*B*t248 + t236 &
    1071             :                                                                                  *t89 - t191*t545 + t40*C*t531) + t93*t37*(2*t172* &
    1072             :                                                                                 t106*t225 + t14*(2*E*t235*t34 - 2*t97*t529 + 2*t95 &
    1073             :                                                                                *t524 + 2*t512*t102 - 2*t64*t380*t248 + t94*t531) + &
    1074             :                                                                                  4*t344*t115*t225 + t83*(2*t525*t40 + 2*t75*t236 - &
    1075             :                                                                                2*t75*t496 + 2*t512*t110 - 2*t394*t545 + 2*t64*t102 &
    1076             :                                                                                  *t531 + 2*t398*t579 - 2*t113*t581) + 6*t407*t119* &
    1077             :                                                                               t586 + t118*t531*t84*t86 + 2*t118*t415*t579 - 2*t118 &
    1078             :                                                                                  *t119*t581) + 3*t126*t127*(2*t172*t133*t225 + t14 &
    1079             :                                                                              *(t128*t524 + 2*t512*t130 - 2*t64*t435*t248) + 4*t344 &
    1080             :                                                                                    *t140*t225 + t83*(2*t512*t135 - 2*t394*t75*t248 &
    1081             :                                                                                 + 2*t64*t130*t524 + 2*t97*t579 - 2*t138*t581) + 6* &
    1082             :                                                                              t454*t143*t586 + t142*t524*t84*t86 + 2*t142*t461*t579 &
    1083             :                                                                 - 2*t142*t143*t581), KIND=dp)*t155 + 0.4e1_dp/0.9e1_dp*t151*qndrho &
    1084       27619 :                                    *t155)*Clda)*sx
    1085             :       END IF
    1086             : 
    1087       30910 :    END SUBROUTINE xpbe_hole_t_c_lr_lda_calc_2
    1088             : 
    1089             : ! **************************************************************************************************
    1090             : !> \brief These functions evaluate products exp(x)*Ei(x) and pi*exp(x)*erfc(sqrt(x)),
    1091             : !>      as well as their derivatives with respect to various combinations of
    1092             : !>      rho and norm_drho.
    1093             : !> \param P = 9/4*s^2*H/A
    1094             : !> \param Q = s^2*H*R^2*kf^2
    1095             : !> \return ...
    1096             : !> \par History
    1097             : !>      01.2009 created [Manuel Guidon]
    1098             : !> \author Manuel Guidon
    1099             : !> \note
    1100             : !>     - In order to avoid numerical instabilities, these routines use Taylor-
    1101             : !>       expansions for the above core-products for large arguments.
    1102             : !>     - red calculates the reduced gradient in a save way (i.e. using a fixed
    1103             : !>       cutoff EPS_RHO)
    1104             : ! **************************************************************************************************
    1105   196547769 :    ELEMENTAL FUNCTION exei(P, Q)
    1106             :       REAL(dp), INTENT(IN)                               :: P, Q
    1107             :       REAL(dp)                                           :: exei
    1108             : 
    1109             :       REAL(dp)                                           :: Q2, Q3, Q4, tmp
    1110             : 
    1111   196547769 :       exei = 0.0_dp
    1112   196547769 :       IF (P < expcutoff) THEN
    1113             :          !Use exact product
    1114   196547769 :          IF (P + Q < 0.5_dp) THEN
    1115    10002267 :             tmp = -euler - LOG(P + Q) + P + Q
    1116    10002267 :             tmp = tmp - 0.25_dp*(P + Q)**2 + 1.0_dp/18.0_dp*(P + Q)**3 - 1.0_dp/96.0_dp*(P + Q)**4
    1117    10002267 :             tmp = tmp + 1.0_dp/600.0_dp*(P + Q)**5
    1118    10002267 :             exei = EXP(P)*tmp
    1119             :          ELSE
    1120   186545502 :             exei = EXP(P)*expint(1, Q + P)
    1121             :          END IF
    1122             :       ELSE
    1123             :          !Use approximation
    1124           0 :          tmp = 1.0_dp/P
    1125             :          ! *** 1st order
    1126           0 :          exei = tmp
    1127             :          ! *** 2nd order
    1128           0 :          tmp = tmp/P
    1129           0 :          exei = exei - (Q + 1.0_dp)*tmp
    1130             :          ! *** 3rd order
    1131           0 :          tmp = tmp/P
    1132           0 :          Q2 = Q*Q
    1133           0 :          exei = exei + (2.0_dp*Q + Q2 + 2.0_dp)*tmp
    1134             :          ! *** 4th order
    1135           0 :          tmp = tmp/P
    1136           0 :          Q3 = Q2*Q
    1137           0 :          exei = exei - (3.0_dp*Q2 + 6.0_dp*Q + Q3 + 6.0_dp)*tmp
    1138             :          ! *** 5th order
    1139           0 :          tmp = tmp/P
    1140           0 :          Q4 = Q3*Q
    1141           0 :          exei = exei + (24.0_dp + 4.0_dp*Q3 + Q4 + 12.0_dp*Q2 + 24.0_dp*Q)*tmp
    1142             : 
    1143             :          ! *** scaling factor
    1144           0 :          exei = EXP(-Q)*exei
    1145             :       END IF
    1146   196547769 :    END FUNCTION exei
    1147             : 
    1148             : ! **************************************************************************************************
    1149             : !> \brief ...
    1150             : !> \param P ...
    1151             : !> \param Q ...
    1152             : !> \param dPrho ...
    1153             : !> \param dQrho ...
    1154             : !> \return ...
    1155             : ! **************************************************************************************************
    1156    65514826 :    ELEMENTAL FUNCTION dexeirho(P, Q, dPrho, dQrho)
    1157             :       REAL(dp), INTENT(IN)                               :: P, Q, dPrho, dQrho
    1158             :       REAL(dp)                                           :: dexeirho
    1159             : 
    1160    65514826 :       dexeirho = dPrho*exei(P, Q) - (dPrho + dQrho)/(P + Q)*EXP(-Q)
    1161    65514826 :    END FUNCTION dexeirho
    1162             : 
    1163             : ! **************************************************************************************************
    1164             : !> \brief ...
    1165             : !> \param P ...
    1166             : !> \param Q ...
    1167             : !> \param dPndrho ...
    1168             : !> \param dQndrho ...
    1169             : !> \return ...
    1170             : ! **************************************************************************************************
    1171    65514826 :    ELEMENTAL FUNCTION dexeindrho(P, Q, dPndrho, dQndrho)
    1172             :       REAL(dp), INTENT(IN)                               :: P, Q, dPndrho, dQndrho
    1173             :       REAL(dp)                                           :: dexeindrho
    1174             : 
    1175    65514826 :       dexeindrho = dPndrho*exei(P, Q) - (dPndrho + dQndrho)/(P + Q)*EXP(-Q)
    1176    65514826 :    END FUNCTION dexeindrho
    1177             : 
    1178             : ! **************************************************************************************************
    1179             : !> \brief ...
    1180             : !> \param rho ...
    1181             : !> \param ndrho ...
    1182             : !> \return ...
    1183             : ! **************************************************************************************************
    1184    65518117 :    ELEMENTAL FUNCTION red(rho, ndrho)
    1185             :       REAL(dp), INTENT(IN)                               :: rho, ndrho
    1186             :       REAL(dp)                                           :: red
    1187             : 
    1188    65518117 :       red = 1.0_dp/6.0_dp*ndrho*3.0_dp**(2.0_dp/3.0_dp)
    1189    65518117 :       red = red/(pi**(2.0_dp/3.0_dp))
    1190    65518117 :       red = red*MAX(1.0_dp/rho**(4.0_dp/3.0_dp), EPS_RHO)
    1191    65518117 :    END FUNCTION red
    1192             : 
    1193             : ! **************************************************************************************************
    1194             : !> \brief ...
    1195             : !> \param rho ...
    1196             : !> \param ndrho ...
    1197             : !> \return ...
    1198             : ! **************************************************************************************************
    1199    65514826 :    ELEMENTAL FUNCTION dsdrho(rho, ndrho)
    1200             :       REAL(dp), INTENT(IN)                               :: rho, ndrho
    1201             :       REAL(dp)                                           :: dsdrho
    1202             : 
    1203    65514826 :       dsdrho = -2.0_dp/9.0_dp*ndrho*3.0**(2.0_dp/3.0_dp)
    1204    65514826 :       dsdrho = dsdrho/(pi**(2.0_dp/3.0_dp))
    1205    65514826 :       dsdrho = dsdrho*MAX(1.0_dp/rho**(7.0_dp/3.0_dp), EPS_RHO)
    1206    65514826 :    END FUNCTION dsdrho
    1207             : 
    1208             : ! **************************************************************************************************
    1209             : !> \brief ...
    1210             : !> \param rho ...
    1211             : !> \return ...
    1212             : ! **************************************************************************************************
    1213    65514826 :    ELEMENTAL FUNCTION dsdndrho(rho)
    1214             :       REAL(dp), INTENT(IN)                               :: rho
    1215             :       REAL(dp)                                           :: dsdndrho
    1216             : 
    1217             :       dsdndrho = 1.0_dp/6.0_dp*3.0_dp**(2.0_dp/3.0_dp)
    1218    65514826 :       dsdndrho = dsdndrho/(pi**(2.0_dp/3.0_dp))
    1219    65514826 :       dsdndrho = dsdndrho*MAX(1.0_dp/rho**(4.0_dp/3.0_dp), EPS_RHO)
    1220    65514826 :    END FUNCTION dsdndrho
    1221             : 
    1222             : ! **************************************************************************************************
    1223             : !> \brief computes the exponential integral
    1224             : !>      En(x) = Int(exp(-x*t)/t^n,t=1..infinity)  x>0, n=0,1,..
    1225             : !>      Note: Ei(-x) = -E1(x)
    1226             : !> \param n ...
    1227             : !> \param x ...
    1228             : !> \return ...
    1229             : !> \par History
    1230             : !>      05.2007 Created
    1231             : !> \author Manuel Guidon (adapted from Numerical recipies, cleaner version of mathlib)
    1232             : ! **************************************************************************************************
    1233   317581736 :    ELEMENTAL FUNCTION expint(n, x)
    1234             :       INTEGER, INTENT(IN)                                :: n
    1235             :       REAL(dp), INTENT(IN)                               :: x
    1236             :       REAL(dp)                                           :: expint
    1237             : 
    1238             :       INTEGER, PARAMETER                                 :: maxit = 100
    1239             :       REAL(dp), PARAMETER :: eps = 6.e-14_dp, euler = 0.5772156649015328606065120_dp, &
    1240             :          fpmin = TINY(0.0_dp)
    1241             : 
    1242             :       INTEGER                                            :: i, ii, nm1
    1243             :       REAL(dp)                                           :: a, b, c, d, del, fact, h, psi
    1244             : 
    1245   317581736 :       nm1 = n - 1
    1246             : 
    1247   317581736 :       IF (n .LT. 0 .OR. x .LT. 0.0_dp .OR. (x .EQ. 0.0_dp .AND. (n .EQ. 0 .OR. n .EQ. 1))) THEN
    1248             :          expint = HUGE(1.0_dp)
    1249   317581736 :       ELSE IF (n .EQ. 0) THEN !Special case.
    1250           0 :          expint = EXP(-x)/x
    1251   317581736 :       ELSE IF (x .EQ. 0.0_dp) THEN !Another special case.
    1252           0 :          expint = 1.0_dp/nm1
    1253   317581736 :       ELSE IF (x .GT. 1.0_dp) THEN !Lentz's algorithm (5.2).
    1254   207989551 :          b = x + n
    1255   207989551 :          c = 1.0_dp/FPMIN
    1256   207989551 :          d = 1.0_dp/b
    1257   207989551 :          h = d
    1258  6508232362 :          DO i = 1, MAXIT
    1259  6508232362 :             a = -i*(nm1 + i)
    1260  6508232362 :             b = b + 2.0_dp
    1261  6508232362 :             d = 1.0_dp/(a*d + b)
    1262  6508232362 :             c = b + a/c
    1263  6508232362 :             del = c*d
    1264  6508232362 :             h = h*del
    1265  6508232362 :             IF (ABS(del - 1.0_dp) .LT. EPS .OR. i == MAXIT) THEN
    1266   207989551 :                expint = h*EXP(-x)
    1267   207989551 :                RETURN
    1268             :             END IF
    1269             :          END DO
    1270             :       ELSE !Evaluate series.
    1271   109592185 :          IF (nm1 .NE. 0) THEN !Set first term.
    1272           0 :             expint = 1.0_dp/nm1
    1273             :          ELSE
    1274   109592185 :             expint = -LOG(x) - euler
    1275             :          END IF
    1276             :          fact = 1.0_dp
    1277   942539858 :          DO i = 1, MAXIT
    1278   942539858 :             fact = -fact*x/i
    1279   942539858 :             IF (i .NE. nm1) THEN
    1280   942539858 :                del = -fact/(i - nm1)
    1281             :             ELSE
    1282             :                psi = -euler !Compute I(n).
    1283           0 :                DO ii = 1, nm1
    1284           0 :                   psi = psi + 1.0_dp/ii
    1285             :                END DO
    1286           0 :                del = fact*(-LOG(x) + psi)
    1287             :             END IF
    1288   942539858 :             expint = expint + del
    1289   942539858 :             IF (ABS(del) .LT. ABS(expint)*EPS) RETURN
    1290             :          END DO
    1291             :       END IF
    1292             :       RETURN
    1293             :    END FUNCTION expint
    1294             : 
    1295             : END MODULE xc_xpbe_hole_t_c_lr
    1296             : 

Generated by: LCOV version 1.15