LCOV - code coverage report
Current view: top level - src/xc - xc_ke_gga.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:37370f3) Lines: 48.4 % 246 119
Test Date: 2026-11-05 01:01:37 Functions: 73.3 % 15 11

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Calculate the several different kinetic energy functionals
      10              : !>      with a GGA form
      11              : !> \par History
      12              : !>      JGH (26.02.2003) : OpenMP enabled
      13              : !>      fawzi (04.2004)  : adapted to the new xc interface
      14              : !> \author JGH (20.02.2002)
      15              : ! **************************************************************************************************
      16              : MODULE xc_ke_gga
      17              : 
      18              :    USE cp_array_utils,                  ONLY: cp_3d_r_cp_type
      19              :    USE kinds,                           ONLY: dp
      20              :    USE mathconstants,                   ONLY: pi
      21              :    USE xc_derivative_desc,              ONLY: deriv_norm_drho,&
      22              :                                               deriv_norm_drhoa,&
      23              :                                               deriv_norm_drhob,&
      24              :                                               deriv_rho,&
      25              :                                               deriv_rhoa,&
      26              :                                               deriv_rhob
      27              :    USE xc_derivative_set_types,         ONLY: xc_derivative_set_type,&
      28              :                                               xc_dset_get_derivative
      29              :    USE xc_derivative_types,             ONLY: xc_derivative_get,&
      30              :                                               xc_derivative_type
      31              :    USE xc_functionals_utilities,        ONLY: calc_wave_vector,&
      32              :                                               set_util
      33              :    USE xc_input_constants,              ONLY: ke_lc,&
      34              :                                               ke_llp,&
      35              :                                               ke_ol1,&
      36              :                                               ke_ol2,&
      37              :                                               ke_pbe,&
      38              :                                               ke_pw86,&
      39              :                                               ke_pw91,&
      40              :                                               ke_t92
      41              :    USE xc_rho_cflags_types,             ONLY: xc_rho_cflags_type
      42              :    USE xc_rho_set_types,                ONLY: xc_rho_set_get,&
      43              :                                               xc_rho_set_type
      44              : #include "../base/base_uses.f90"
      45              : 
      46              :    IMPLICIT NONE
      47              : 
      48              :    PRIVATE
      49              : 
      50              :    REAL(KIND=dp), PARAMETER :: f13 = 1.0_dp/3.0_dp, &
      51              :                                f23 = 2.0_dp*f13, &
      52              :                                f43 = 4.0_dp*f13, &
      53              :                                f53 = 5.0_dp*f13
      54              : 
      55              :    PUBLIC :: ke_gga_info, ke_gga_lda_eval, ke_gga_lsd_eval
      56              : 
      57              :    REAL(KIND=dp) :: cf, b, b_lda, b_lsd, flda, flsd, sfac, t13
      58              :    REAL(KIND=dp) :: fact, tact
      59              :    REAL(KIND=dp) :: eps_rho
      60              : 
      61              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xc_ke_gga'
      62              : 
      63              : CONTAINS
      64              : 
      65              : ! **************************************************************************************************
      66              : !> \brief ...
      67              : !> \param cutoff ...
      68              : ! **************************************************************************************************
      69         1780 :    SUBROUTINE ke_gga_init(cutoff)
      70              : 
      71              :       REAL(KIND=dp), INTENT(IN)                          :: cutoff
      72              : 
      73         1780 :       eps_rho = cutoff
      74         1780 :       CALL set_util(cutoff)
      75              : 
      76         1780 :       cf = 0.3_dp*(3.0_dp*pi*pi)**f23
      77         1780 :       flda = cf
      78         1780 :       flsd = flda*2.0_dp**f23
      79              : !   the_factor 2^(1/3) for LDA is here
      80         1780 :       b_lda = 2.0_dp**f43*(3.0_dp*pi*pi)**(f13)
      81         1780 :       b_lsd = 2.0_dp*(3.0_dp*pi*pi)**(f13)
      82         1780 :       sfac = 1.0_dp/(2.0_dp*(3.0_dp*pi*pi)**f13)
      83         1780 :       t13 = 2.0_dp**f13
      84              : 
      85         1780 :    END SUBROUTINE ke_gga_init
      86              : 
      87              : ! **************************************************************************************************
      88              : !> \brief ...
      89              : !> \param functional ...
      90              : !> \param lsd ...
      91              : !> \param reference ...
      92              : !> \param shortform ...
      93              : !> \param needs ...
      94              : !> \param max_deriv ...
      95              : ! **************************************************************************************************
      96         2042 :    SUBROUTINE ke_gga_info(functional, lsd, reference, shortform, needs, max_deriv)
      97              :       INTEGER, INTENT(in)                                :: functional
      98              :       LOGICAL, INTENT(in)                                :: lsd
      99              :       CHARACTER(LEN=*), INTENT(OUT), OPTIONAL            :: reference, shortform
     100              :       TYPE(xc_rho_cflags_type), INTENT(inout), OPTIONAL  :: needs
     101              :       INTEGER, INTENT(out), OPTIONAL                     :: max_deriv
     102              : 
     103         2042 :       IF (PRESENT(reference)) THEN
     104            0 :          SELECT CASE (functional)
     105              :          CASE (ke_ol1)
     106              :             reference = "H. Ou-Yang and M. Levy, "// &
     107            0 :                         "Intl. J. Quant. Chem. 40, 379 (1991); Functional 1"
     108              :          CASE (ke_ol2)
     109              :             reference = "H. Ou-Yang and M. Levy, "// &
     110            0 :                         "Intl. J. Quant. Chem. 40, 379 (1991); Functional 2"
     111              :          CASE (ke_llp)
     112            0 :             reference = "H. Lee, C. Lee, R.G. Parr, Phys. Rev. A, 44, 768 (1991)"
     113              :          CASE (ke_pw86)
     114            0 :             reference = "J.P. Perdew and Y. Wang, Phys. Rev. B, 33, 8800 (1986)"
     115              :          CASE (ke_pw91)
     116            0 :             reference = "J.P. Perdew and Y. Wang, Electronic Structure of Solids 91"
     117              :          CASE (ke_lc)
     118            0 :             reference = "A. Lembarki and H. Chermette, Phys. Rev. A, 50, 5328 (1994)"
     119              :          CASE (ke_t92)
     120            0 :             reference = "A.J. Thakkar, Phys. Rev. A, 46, 6920 (1992)"
     121              :          CASE (ke_pbe)
     122            0 :             reference = "J.P.Perdew, K.Burke, M.Ernzerhof, Phys. Rev. Letter, 77, 3865 (1996)"
     123              :          END SELECT
     124            0 :          IF (.NOT. lsd) THEN
     125            0 :             IF (LEN_TRIM(reference) + 6 < LEN(reference)) THEN
     126            0 :                reference(LEN_TRIM(reference):LEN_TRIM(reference) + 6) = ' {spin unpolarized}'
     127              :             END IF
     128              :          END IF
     129              :       END IF
     130         2042 :       IF (PRESENT(shortform)) THEN
     131            0 :          SELECT CASE (functional)
     132              :          CASE (ke_ol1)
     133            0 :             shortform = "Ou-Yang-Levy Functional 1"
     134              :          CASE (ke_ol2)
     135            0 :             shortform = "Ou-Yang-Levy Functional 2"
     136              :          CASE (ke_llp)
     137            0 :             shortform = "Lee-Lee-Parr Functional"
     138              :          CASE (ke_pw86)
     139            0 :             shortform = "Perdew-Wang 1986 Functional (kinetic energy)"
     140              :          CASE (ke_pw91)
     141            0 :             shortform = "Perdew-Wang 1991 Functional (kinetic energy)"
     142              :          CASE (ke_lc)
     143            0 :             shortform = "Lembarki-Chermette kinetic energy functional"
     144              :          CASE (ke_t92)
     145            0 :             shortform = "Thakkar 1992 Functional"
     146              :          CASE (ke_pbe)
     147            0 :             shortform = "Perdew-Burke-Ernzerhof Functional (kinetic energy)"
     148              :          END SELECT
     149            0 :          IF (.NOT. lsd) THEN
     150            0 :             IF (LEN_TRIM(shortform) + 6 < LEN(shortform)) THEN
     151            0 :                shortform(LEN_TRIM(shortform):LEN_TRIM(shortform) + 6) = ' {spin unpolarized}'
     152              :             END IF
     153              :          END IF
     154              :       END IF
     155         2042 :       IF (PRESENT(needs)) THEN
     156         2042 :          IF (lsd) THEN
     157            0 :             needs%rho_spin = .TRUE.
     158            0 :             needs%rho_spin_1_3 = .TRUE.
     159            0 :             needs%norm_drho_spin = .TRUE.
     160              :          ELSE
     161         2042 :             needs%rho = .TRUE.
     162         2042 :             needs%rho_1_3 = .TRUE.
     163         2042 :             needs%norm_drho = .TRUE.
     164              :          END IF
     165              :       END IF
     166         2042 :       IF (PRESENT(max_deriv)) max_deriv = 3
     167              : 
     168         2042 :    END SUBROUTINE ke_gga_info
     169              : 
     170              : ! **************************************************************************************************
     171              : !> \brief ...
     172              : !> \param functional ...
     173              : !> \param rho_set ...
     174              : !> \param deriv_set ...
     175              : !> \param order ...
     176              : ! **************************************************************************************************
     177         1780 :    SUBROUTINE ke_gga_lda_eval(functional, rho_set, deriv_set, order)
     178              : 
     179              :       INTEGER, INTENT(IN)                                :: functional
     180              :       TYPE(xc_rho_set_type), INTENT(IN)                  :: rho_set
     181              :       TYPE(xc_derivative_set_type), INTENT(IN)           :: deriv_set
     182              :       INTEGER, INTENT(IN)                                :: order
     183              : 
     184              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'ke_gga_lda_eval'
     185              : 
     186              :       INTEGER                                            :: handle, npoints
     187              :       INTEGER, DIMENSION(2, 3)                           :: bo
     188              :       REAL(KIND=dp)                                      :: drho_cutoff, rho_cutoff
     189              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)           :: s
     190              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)        :: fs
     191         1780 :       REAL(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), POINTER :: e_0, e_ndrho, e_ndrho_ndrho, &
     192         1780 :          e_ndrho_ndrho_ndrho, e_rho, e_rho_ndrho, e_rho_ndrho_ndrho, e_rho_rho, e_rho_rho_ndrho, &
     193         1780 :          e_rho_rho_rho, grho, rho, rho13
     194              :       TYPE(xc_derivative_type), POINTER                  :: deriv
     195              : 
     196         1780 :       CALL timeset(routineN, handle)
     197         1780 :       NULLIFY (rho, rho13, e_0, e_rho, e_ndrho, &
     198         1780 :                e_rho_rho, e_rho_ndrho, e_ndrho_ndrho, &
     199         1780 :                e_rho_rho_rho, e_rho_rho_ndrho, e_rho_ndrho_ndrho, e_ndrho_ndrho_ndrho)
     200              : 
     201              :       CALL xc_rho_set_get(rho_set, rho_1_3=rho13, rho=rho, &
     202              :                           norm_drho=grho, local_bounds=bo, rho_cutoff=rho_cutoff, &
     203         1780 :                           drho_cutoff=drho_cutoff)
     204         1780 :       npoints = (bo(2, 1) - bo(1, 1) + 1)*(bo(2, 2) - bo(1, 2) + 1)*(bo(2, 3) - bo(1, 3) + 1)
     205         1780 :       CALL ke_gga_init(rho_cutoff)
     206              : 
     207         5340 :       ALLOCATE (s(npoints))
     208         7120 :       ALLOCATE (fs(npoints, order + 1))
     209              : 
     210              : !      s = norm_drho/(rho^(4/3)*2*(pi*pi*3)^(1/3))
     211         1780 :       CALL calc_wave_vector("p", rho, grho, s)
     212              : 
     213         1780 :       fact = flda
     214              : !      Definition of s has changed
     215         1780 :       b = b_lda
     216              : !       tact = t13
     217         1780 :       tact = 1.0_dp
     218              : 
     219         1780 :       SELECT CASE (functional)
     220              :       CASE (ke_ol1)
     221            0 :          CALL efactor_ol1(s, fs, order)
     222            0 :          CPABORT("OL1 functional currently not working properly")
     223              :       CASE (ke_ol2)
     224            0 :          CALL efactor_ol2(s, fs, order)
     225            0 :          CPABORT("OL2 functional currently not working properly")
     226              :       CASE (ke_llp)
     227          736 :          CALL efactor_llp(s, fs, order)
     228              :       CASE (ke_pw86)
     229           54 :          CALL efactor_pw86(s, fs, order)
     230              :       CASE (ke_pw91)
     231           54 :          CALL efactor_pw91(s, fs, order, 1)
     232              :       CASE (ke_lc)
     233           54 :          CALL efactor_pw91(s, fs, order, 2)
     234              :       CASE (ke_t92)
     235          294 :          CALL efactor_t92(s, fs, order)
     236              :       CASE (ke_pbe)
     237          588 :          CALL efactor_pbex(s, fs, order, 1)
     238              :       CASE DEFAULT
     239         1780 :          CPABORT("Unsupported functional")
     240              :       END SELECT
     241              : 
     242              :       deriv => xc_dset_get_derivative(deriv_set, [INTEGER::], &
     243         1780 :                                       allocate_deriv=.TRUE.)
     244         1780 :       CALL xc_derivative_get(deriv, deriv_data=e_0)
     245              : 
     246         1780 :       CALL kex_p_0(rho, rho13, fs, e_0, npoints)
     247              : 
     248         1780 :       IF (order >= 1) THEN
     249              :          deriv => xc_dset_get_derivative(deriv_set, [deriv_rho], &
     250         1780 :                                          allocate_deriv=.TRUE.)
     251         1780 :          CALL xc_derivative_get(deriv, deriv_data=e_rho)
     252              :          deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho], &
     253         1780 :                                          allocate_deriv=.TRUE.)
     254         1780 :          CALL xc_derivative_get(deriv, deriv_data=e_ndrho)
     255              : 
     256              :          CALL kex_p_1(rho, rho13, s, fs, e_rho=e_rho, e_ndrho=e_ndrho, &
     257         1780 :                       npoints=npoints)
     258              :       END IF
     259         1780 :       IF (order >= 2) THEN
     260              :          deriv => xc_dset_get_derivative(deriv_set, [deriv_rho, deriv_rho], &
     261          138 :                                          allocate_deriv=.TRUE.)
     262          138 :          CALL xc_derivative_get(deriv, deriv_data=e_rho_rho)
     263              :          deriv => xc_dset_get_derivative(deriv_set, [deriv_rho, deriv_norm_drho], &
     264          138 :                                          allocate_deriv=.TRUE.)
     265          138 :          CALL xc_derivative_get(deriv, deriv_data=e_rho_ndrho)
     266              :          deriv => xc_dset_get_derivative(deriv_set, &
     267          138 :                                          [deriv_norm_drho, deriv_norm_drho], allocate_deriv=.TRUE.)
     268          138 :          CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrho)
     269              : 
     270              :          CALL kex_p_2(rho, rho13, s, fs, e_rho_rho=e_rho_rho, &
     271          138 :                       e_rho_ndrho=e_rho_ndrho, e_ndrho_ndrho=e_ndrho_ndrho, npoints=npoints)
     272              :       END IF
     273         1780 :       IF (order >= 3) THEN
     274              :          deriv => xc_dset_get_derivative(deriv_set, [deriv_rho, deriv_rho, deriv_rho], &
     275            0 :                                          allocate_deriv=.TRUE.)
     276            0 :          CALL xc_derivative_get(deriv, deriv_data=e_rho_rho_rho)
     277              :          deriv => xc_dset_get_derivative(deriv_set, &
     278            0 :                                          [deriv_rho, deriv_rho, deriv_norm_drho], allocate_deriv=.TRUE.)
     279            0 :          CALL xc_derivative_get(deriv, deriv_data=e_rho_rho_ndrho)
     280              :          deriv => xc_dset_get_derivative(deriv_set, &
     281            0 :                                          [deriv_rho, deriv_norm_drho, deriv_norm_drho], allocate_deriv=.TRUE.)
     282            0 :          CALL xc_derivative_get(deriv, deriv_data=e_rho_ndrho_ndrho)
     283              :          deriv => xc_dset_get_derivative(deriv_set, &
     284            0 :                                          [deriv_norm_drho, deriv_norm_drho, deriv_norm_drho], allocate_deriv=.TRUE.)
     285            0 :          CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrho_ndrho)
     286              : 
     287              :          CALL kex_p_3(rho, rho13, s, fs, e_rho_rho_rho=e_rho_rho_rho, &
     288              :                       e_rho_rho_ndrho=e_rho_rho_ndrho, e_rho_ndrho_ndrho=e_rho_ndrho_ndrho, &
     289            0 :                       e_ndrho_ndrho_ndrho=e_ndrho_ndrho_ndrho, npoints=npoints)
     290              :       END IF
     291         1780 :       IF (order > 3) THEN
     292            0 :          CPABORT("derivatives bigger than 3 not implemented")
     293              :       END IF
     294              : 
     295         1780 :       DEALLOCATE (s)
     296         1780 :       DEALLOCATE (fs)
     297              : 
     298         1780 :       CALL timestop(handle)
     299              : 
     300         1780 :    END SUBROUTINE ke_gga_lda_eval
     301              : 
     302              : ! **************************************************************************************************
     303              : !> \brief ...
     304              : !> \param functional ...
     305              : !> \param rho_set ...
     306              : !> \param deriv_set ...
     307              : !> \param order ...
     308              : ! **************************************************************************************************
     309            0 :    SUBROUTINE ke_gga_lsd_eval(functional, rho_set, deriv_set, order)
     310              : 
     311              :       INTEGER, INTENT(IN)                                :: functional
     312              :       TYPE(xc_rho_set_type), INTENT(IN)                  :: rho_set
     313              :       TYPE(xc_derivative_set_type), INTENT(IN)           :: deriv_set
     314              :       INTEGER, INTENT(IN), OPTIONAL                      :: order
     315              : 
     316              :       CHARACTER(len=*), PARAMETER                        :: routineN = 'ke_gga_lsd_eval'
     317              :       INTEGER, DIMENSION(2), PARAMETER :: &
     318              :          norm_drho_spin_name = [deriv_norm_drhoa, deriv_norm_drhob], &
     319              :          rho_spin_name = [deriv_rhoa, deriv_rhob]
     320              : 
     321              :       INTEGER                                            :: handle, ispin, npoints
     322              :       INTEGER, DIMENSION(2, 3)                           :: bo
     323              :       REAL(KIND=dp)                                      :: rho_cutoff
     324              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)           :: s
     325              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)        :: fs
     326            0 :       REAL(KIND=dp), CONTIGUOUS, DIMENSION(:, :, :), POINTER :: e_0, e_ndrho, e_ndrho_ndrho, &
     327            0 :          e_ndrho_ndrho_ndrho, e_rho, e_rho_ndrho, e_rho_ndrho_ndrho, e_rho_rho, e_rho_rho_ndrho, &
     328            0 :          e_rho_rho_rho
     329            0 :       TYPE(cp_3d_r_cp_type), DIMENSION(2)                :: norm_drho, rho, rho_1_3
     330              :       TYPE(xc_derivative_type), POINTER                  :: deriv
     331              : 
     332            0 :       CALL timeset(routineN, handle)
     333            0 :       NULLIFY (e_0, e_ndrho, e_ndrho_ndrho, e_ndrho_ndrho_ndrho, e_rho_ndrho_ndrho, &
     334            0 :                e_rho_ndrho, e_rho_rho_ndrho, e_rho, e_rho_rho, e_rho_rho_rho)
     335            0 :       DO ispin = 1, 2
     336            0 :          NULLIFY (norm_drho(ispin)%array, rho(ispin)%array, rho_1_3(ispin)%array)
     337              :       END DO
     338              : 
     339              :       CALL xc_rho_set_get(rho_set, rhoa_1_3=rho_1_3(1)%array, &
     340              :                           rhob_1_3=rho_1_3(2)%array, rhoa=rho(1)%array, &
     341              :                           rhob=rho(2)%array, norm_drhoa=norm_drho(1)%array, &
     342              :                           norm_drhob=norm_drho(2)%array, rho_cutoff=rho_cutoff, &
     343            0 :                           local_bounds=bo)
     344            0 :       npoints = (bo(2, 1) - bo(1, 1) + 1)*(bo(2, 2) - bo(1, 2) + 1)*(bo(2, 3) - bo(1, 3) + 1)
     345            0 :       CALL ke_gga_init(rho_cutoff)
     346              : 
     347            0 :       ALLOCATE (s(npoints))
     348            0 :       ALLOCATE (fs(npoints, order + 1))
     349              : 
     350            0 :       fact = flsd
     351            0 :       b = b_lsd
     352            0 :       tact = 1.0_dp
     353              : 
     354            0 :       DO ispin = 1, 2
     355              : 
     356            0 :          CALL calc_wave_vector("p", rho(ispin)%array, norm_drho(ispin)%array, s)
     357              : 
     358            0 :          SELECT CASE (functional)
     359              :          CASE (ke_ol1)
     360            0 :             CALL efactor_ol1(s, fs, order)
     361              :          CASE (ke_ol2)
     362            0 :             CALL efactor_ol2(s, fs, order)
     363              :          CASE (ke_llp)
     364            0 :             CALL efactor_llp(s, fs, order)
     365              :          CASE (ke_pw86)
     366            0 :             tact = (1.0_dp/2.0_dp)**(1.0_dp/3.0_dp)
     367            0 :             CALL efactor_pw86(s, fs, order, f2_lsd=tact)
     368            0 :             tact = 1.0_dp
     369              :          CASE (ke_pbe)
     370            0 :             tact = (1.0_dp/2.0_dp)**(1.0_dp/3.0_dp)
     371            0 :             CALL efactor_pbex(s, fs, order, 1, f2_lsd=tact)
     372            0 :             tact = 1.0_dp
     373              :          CASE (ke_pw91)
     374            0 :             tact = (1.0_dp/2.0_dp)**(1.0_dp/3.0_dp)
     375            0 :             CALL efactor_pw91(s, fs, order, 1, f2_lsd=tact)
     376            0 :             tact = 1.0_dp
     377              :          CASE (ke_lc)
     378            0 :             tact = (1.0_dp/2.0_dp)**(1.0_dp/3.0_dp)
     379            0 :             CALL efactor_pw91(s, fs, order, 2, f2_lsd=tact)
     380            0 :             tact = 1.0_dp
     381              :          CASE (ke_t92)
     382            0 :             CALL efactor_t92(s, fs, order)
     383              :          CASE DEFAULT
     384            0 :             CPABORT("Unsupported functional")
     385              :          END SELECT
     386              : 
     387              :          deriv => xc_dset_get_derivative(deriv_set, [INTEGER::], &
     388            0 :                                          allocate_deriv=.TRUE.)
     389            0 :          CALL xc_derivative_get(deriv, deriv_data=e_0)
     390              : 
     391              :          CALL kex_p_0(rho(ispin)%array, rho_1_3(ispin)%array, fs, &
     392            0 :                       e_0=e_0, npoints=npoints)
     393            0 :          IF (order >= 1) THEN
     394              :             deriv => xc_dset_get_derivative(deriv_set, [rho_spin_name(ispin)], &
     395            0 :                                             allocate_deriv=.TRUE.)
     396            0 :             CALL xc_derivative_get(deriv, deriv_data=e_rho)
     397              :             deriv => xc_dset_get_derivative(deriv_set, [norm_drho_spin_name(ispin)], &
     398            0 :                                             allocate_deriv=.TRUE.)
     399            0 :             CALL xc_derivative_get(deriv, deriv_data=e_ndrho)
     400              : 
     401              :             CALL kex_p_1(rho=rho(ispin)%array, &
     402              :                          r13=rho_1_3(ispin)%array, s=s, fs=fs, e_rho=e_rho, &
     403            0 :                          e_ndrho=e_ndrho, npoints=npoints)
     404              :          END IF
     405            0 :          IF (order >= 2) THEN
     406              :             deriv => xc_dset_get_derivative(deriv_set, [rho_spin_name(ispin), &
     407            0 :                                                         rho_spin_name(ispin)], allocate_deriv=.TRUE.)
     408            0 :             CALL xc_derivative_get(deriv, deriv_data=e_rho_rho)
     409              :             deriv => xc_dset_get_derivative(deriv_set, [rho_spin_name(ispin), &
     410            0 :                                                         norm_drho_spin_name(ispin)], allocate_deriv=.TRUE.)
     411            0 :             CALL xc_derivative_get(deriv, deriv_data=e_rho_ndrho)
     412              :             deriv => xc_dset_get_derivative(deriv_set, [norm_drho_spin_name(ispin), &
     413            0 :                                                         norm_drho_spin_name(ispin)], allocate_deriv=.TRUE.)
     414            0 :             CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrho)
     415              : 
     416              :             CALL kex_p_2(rho(ispin)%array, rho_1_3(ispin)%array, &
     417            0 :                          s, fs, e_rho_rho, e_rho_ndrho, e_ndrho_ndrho, npoints)
     418              :          END IF
     419            0 :          IF (order >= 3) THEN
     420              :             deriv => xc_dset_get_derivative(deriv_set, [rho_spin_name(ispin), &
     421              :                                                         rho_spin_name(ispin), rho_spin_name(ispin)], &
     422            0 :                                             allocate_deriv=.TRUE.)
     423            0 :             CALL xc_derivative_get(deriv, deriv_data=e_rho_rho_rho)
     424              :             deriv => xc_dset_get_derivative(deriv_set, [rho_spin_name(ispin), &
     425              :                                                         rho_spin_name(ispin), norm_drho_spin_name(ispin)], &
     426            0 :                                             allocate_deriv=.TRUE.)
     427            0 :             CALL xc_derivative_get(deriv, deriv_data=e_rho_rho_ndrho)
     428              :             deriv => xc_dset_get_derivative(deriv_set, [rho_spin_name(ispin), &
     429              :                                                         norm_drho_spin_name(ispin), norm_drho_spin_name(ispin)], &
     430            0 :                                             allocate_deriv=.TRUE.)
     431            0 :             CALL xc_derivative_get(deriv, deriv_data=e_rho_ndrho_ndrho)
     432              :             deriv => xc_dset_get_derivative(deriv_set, [norm_drho_spin_name(ispin), &
     433              :                                                         norm_drho_spin_name(ispin), norm_drho_spin_name(ispin)], &
     434            0 :                                             allocate_deriv=.TRUE.)
     435            0 :             CALL xc_derivative_get(deriv, deriv_data=e_ndrho_ndrho_ndrho)
     436              : 
     437              :             CALL kex_p_3(rho(ispin)%array, &
     438              :                          rho_1_3(ispin)%array, s, fs, e_rho_rho_rho, e_rho_rho_ndrho, &
     439            0 :                          e_rho_ndrho_ndrho, e_ndrho_ndrho_ndrho, npoints)
     440              :          END IF
     441            0 :          IF (order > 3) THEN
     442            0 :             CPABORT("derivatives bigger than 3 not implemented")
     443              :          END IF
     444              : 
     445              :       END DO
     446              : 
     447            0 :       DEALLOCATE (s)
     448            0 :       DEALLOCATE (fs)
     449            0 :       CALL timestop(handle)
     450            0 :    END SUBROUTINE ke_gga_lsd_eval
     451              : 
     452              : ! **************************************************************************************************
     453              : !> \brief ...
     454              : !> \param rho ...
     455              : !> \param r13 ...
     456              : !> \param fs ...
     457              : !> \param e_0 ...
     458              : !> \param npoints ...
     459              : ! **************************************************************************************************
     460         1780 :    SUBROUTINE kex_p_0(rho, r13, fs, e_0, npoints)
     461              : 
     462              :       REAL(KIND=dp), DIMENSION(*), INTENT(IN)            :: rho, r13
     463              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(IN)         :: fs
     464              :       REAL(KIND=dp), DIMENSION(*), INTENT(INOUT)         :: e_0
     465              :       INTEGER, INTENT(in)                                :: npoints
     466              : 
     467              :       INTEGER                                            :: ip
     468              : 
     469              : !$OMP     PARALLEL DO DEFAULT(NONE) &
     470              : !$OMP                 SHARED(npoints, rho, e_0, fact, r13, fs, eps_rho) &
     471         1780 : !$OMP                 PRIVATE(ip)
     472              : 
     473              :       DO ip = 1, npoints
     474              : 
     475              :          IF (rho(ip) > eps_rho) THEN
     476              :             e_0(ip) = e_0(ip) + fact*r13(ip)*r13(ip)*rho(ip)*fs(ip, 1)
     477              :          END IF
     478              : 
     479              :       END DO
     480              : 
     481              : !$OMP     END PARALLEL DO
     482              : 
     483         1780 :    END SUBROUTINE kex_p_0
     484              : 
     485              : ! **************************************************************************************************
     486              : !> \brief ...
     487              : !> \param rho ...
     488              : !> \param r13 ...
     489              : !> \param s ...
     490              : !> \param fs ...
     491              : !> \param e_rho ...
     492              : !> \param e_ndrho ...
     493              : !> \param npoints ...
     494              : ! **************************************************************************************************
     495         1780 :    SUBROUTINE kex_p_1(rho, r13, s, fs, e_rho, e_ndrho, npoints)
     496              : 
     497              :       REAL(KIND=dp), DIMENSION(*), INTENT(IN)            :: rho, r13, s
     498              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(IN)         :: fs
     499              :       REAL(KIND=dp), DIMENSION(*), INTENT(INOUT)         :: e_rho, e_ndrho
     500              :       INTEGER, INTENT(in)                                :: npoints
     501              : 
     502              :       INTEGER                                            :: ip
     503              :       REAL(KIND=dp)                                      :: a0, a1, sx, sy
     504              : 
     505              : !$OMP     PARALLEL DO DEFAULT(NONE) &
     506              : !$OMP                 SHARED(npoints, rho, eps_rho, fact, r13, sfac, tact) &
     507              : !$OMP                 SHARED(fs, e_rho, e_ndrho, s) &
     508         1780 : !$OMP                 PRIVATE(ip,a0,a1,sx,sy)
     509              : 
     510              :       DO ip = 1, npoints
     511              : 
     512              :          IF (rho(ip) > eps_rho) THEN
     513              : 
     514              :             a0 = fact*r13(ip)*r13(ip)*rho(ip)
     515              :             a1 = f53*fact*r13(ip)*r13(ip)
     516              :             sx = -f43*s(ip)/rho(ip)
     517              :             sy = sfac*tact/(r13(ip)*rho(ip))
     518              :             e_rho(ip) = e_rho(ip) + a1*fs(ip, 1) + a0*fs(ip, 2)*sx
     519              :             e_ndrho(ip) = e_ndrho(ip) + a0*fs(ip, 2)*sy
     520              : 
     521              :          END IF
     522              : 
     523              :       END DO
     524              : 
     525              : !$OMP     END PARALLEL DO
     526              : 
     527         1780 :    END SUBROUTINE kex_p_1
     528              : 
     529              : ! **************************************************************************************************
     530              : !> \brief ...
     531              : !> \param rho ...
     532              : !> \param r13 ...
     533              : !> \param s ...
     534              : !> \param fs ...
     535              : !> \param e_rho_rho ...
     536              : !> \param e_rho_ndrho ...
     537              : !> \param e_ndrho_ndrho ...
     538              : !> \param npoints ...
     539              : ! **************************************************************************************************
     540          138 :    SUBROUTINE kex_p_2(rho, r13, s, fs, e_rho_rho, e_rho_ndrho, e_ndrho_ndrho, &
     541              :                       npoints)
     542              : 
     543              :       REAL(KIND=dp), DIMENSION(*), INTENT(IN)            :: rho, r13, s
     544              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(IN)         :: fs
     545              :       REAL(KIND=dp), DIMENSION(*), INTENT(INOUT)         :: e_rho_rho, e_rho_ndrho, e_ndrho_ndrho
     546              :       INTEGER, INTENT(in)                                :: npoints
     547              : 
     548              :       INTEGER                                            :: ip
     549              :       REAL(KIND=dp)                                      :: a0, a1, a2, sx, sxx, sxy, sy
     550              : 
     551              : !$OMP     PARALLEL DO DEFAULT(NONE) &
     552              : !$OMP                 SHARED (npoints, rho, eps_rho, fact, r13) &
     553              : !$OMP                 SHARED (e_rho_rho, e_rho_ndrho, e_ndrho_ndrho, fs) &
     554              : !$OMP                 SHARED(s, sfac, tact) &
     555          138 : !$OMP                 PRIVATE(ip,a0,a1,a2,sx,sy,sxx,sxy)
     556              : 
     557              :       DO ip = 1, npoints
     558              : 
     559              :          IF (rho(ip) > eps_rho) THEN
     560              : 
     561              :             a0 = fact*r13(ip)*r13(ip)*rho(ip)
     562              :             a1 = f53*fact*r13(ip)*r13(ip)
     563              :             a2 = f23*f53*fact/r13(ip)
     564              :             sx = -f43*s(ip)/rho(ip)
     565              :             sy = sfac*tact/(r13(ip)*rho(ip))
     566              :             sxx = 28.0_dp/9.0_dp*s(ip)/(rho(ip)*rho(ip))
     567              :             sxy = -f43*sfac*tact/(r13(ip)*rho(ip)*rho(ip))
     568              :             e_rho_rho(ip) = e_rho_rho(ip) + a2*fs(ip, 1) + 2.0_dp*a1*fs(ip, 2)*sx + &
     569              :                             a0*fs(ip, 3)*sx*sx + a0*fs(ip, 2)*sxx
     570              :             e_rho_ndrho(ip) = e_rho_ndrho(ip) + a1*fs(ip, 2)*sy + a0*fs(ip, 3)*sx*sy + &
     571              :                               a0*fs(ip, 2)*sxy
     572              :             e_ndrho_ndrho(ip) = e_ndrho_ndrho(ip) + a0*fs(ip, 3)*sy*sy
     573              : 
     574              :          END IF
     575              : 
     576              :       END DO
     577              : 
     578              : !$OMP     END PARALLEL DO
     579              : 
     580          138 :    END SUBROUTINE kex_p_2
     581              : 
     582              : ! **************************************************************************************************
     583              : !> \brief ...
     584              : !> \param rho ...
     585              : !> \param r13 ...
     586              : !> \param s ...
     587              : !> \param fs ...
     588              : !> \param e_rho_rho_rho ...
     589              : !> \param e_rho_rho_ndrho ...
     590              : !> \param e_rho_ndrho_ndrho ...
     591              : !> \param e_ndrho_ndrho_ndrho ...
     592              : !> \param npoints ...
     593              : ! **************************************************************************************************
     594            0 :    SUBROUTINE kex_p_3(rho, r13, s, fs, e_rho_rho_rho, e_rho_rho_ndrho, &
     595              :                       e_rho_ndrho_ndrho, e_ndrho_ndrho_ndrho, npoints)
     596              : 
     597              :       REAL(KIND=dp), DIMENSION(*), INTENT(IN)            :: rho, r13, s
     598              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(IN)         :: fs
     599              :       REAL(KIND=dp), DIMENSION(*), INTENT(inout)         :: e_rho_rho_rho, e_rho_rho_ndrho, &
     600              :                                                             e_rho_ndrho_ndrho, e_ndrho_ndrho_ndrho
     601              :       INTEGER, INTENT(in)                                :: npoints
     602              : 
     603              :       INTEGER                                            :: ip
     604              :       REAL(KIND=dp)                                      :: a0, a1, a2, a3, sx, sxx, sxxx, sxxy, &
     605              :                                                             sxy, sy
     606              : 
     607              : !$OMP     PARALLEL DO DEFAULT(NONE) &
     608              : !$OMP                 SHARED(npoints, rho, eps_rho, fact, r13) &
     609              : !$OMP                 SHARED(s, sfac, tact, fs, e_rho_rho_rho) &
     610              : !$OMP                 SHARED(e_rho_rho_ndrho, e_rho_ndrho_ndrho) &
     611              : !$OMP                 SHARED(e_ndrho_ndrho_ndrho) &
     612            0 : !$OMP                 PRIVATE(ip,a0,a1,a2,a3,sx,sy,sxx,sxy,sxxx,sxxy)
     613              : 
     614              :       DO ip = 1, npoints
     615              : 
     616              :          IF (rho(ip) > eps_rho) THEN
     617              : 
     618              :             a0 = fact*r13(ip)*r13(ip)*rho(ip)
     619              :             a1 = f53*fact*r13(ip)*r13(ip)
     620              :             a2 = f23*f53*fact/r13(ip)
     621              :             a3 = -f13*f23*f53*fact/(r13(ip)*rho(ip))
     622              :             sx = -f43*s(ip)/rho(ip)
     623              :             sy = sfac*tact/(r13(ip)*rho(ip))
     624              :             sxx = 28.0_dp/9.0_dp*s(ip)/(rho(ip)*rho(ip))
     625              :             sxy = -f43*sfac*tact/(r13(ip)*rho(ip)*rho(ip))
     626              :             sxxx = -280.0_dp/27.0_dp*s(ip)/(rho(ip)*rho(ip)*rho(ip))
     627              :             sxxy = 28.0_dp/9.0_dp*sfac*tact/(r13(ip)*rho(ip)*rho(ip)*rho(ip))
     628              :             e_rho_rho_rho(ip) = e_rho_rho_rho(ip) + a3*fs(ip, 1) + 3.0_dp*a2*fs(ip, 2)*sx + &
     629              :                                 3.0_dp*a1*fs(ip, 3)*sx*sx + 3.0_dp*a1*fs(ip, 2)*sxx + &
     630              :                                 a0*fs(ip, 4)*sx*sx*sx + 3.0_dp*a0*fs(ip, 3)*sx*sxx + &
     631              :                                 a0*fs(ip, 2)*sxxx
     632              :             e_rho_rho_ndrho(ip) = e_rho_rho_ndrho(ip) + a2*fs(ip, 2)*sy + 2.0_dp*a1*fs(ip, 3)*sx*sy + &
     633              :                                   2.0_dp*a1*fs(ip, 2)*sxy + a0*fs(ip, 4)*sx*sx*sy + &
     634              :                                   2.0_dp*a0*fs(ip, 3)*sx*sxy + a0*fs(ip, 3)*sxx*sy + &
     635              :                                   a0*fs(ip, 2)*sxxy
     636              :             e_rho_ndrho_ndrho(ip) = e_rho_ndrho_ndrho(ip) + a1*fs(ip, 3)*sy*sy + a0*fs(ip, 4)*sx*sy*sy + &
     637              :                                     2.0_dp*a0*fs(ip, 3)*sxy*sy
     638              :             e_ndrho_ndrho_ndrho(ip) = e_ndrho_ndrho_ndrho(ip) + a0*fs(ip, 4)*sy*sy*sy
     639              : 
     640              :          END IF
     641              : 
     642              :       END DO
     643              : 
     644              : !$OMP     END PARALLEL DO
     645              : 
     646            0 :    END SUBROUTINE kex_p_3
     647              : 
     648              : ! Enhancement Factors
     649              : ! **************************************************************************************************
     650              : !> \brief ...
     651              : !> \param s ...
     652              : !> \param fs ...
     653              : !> \param m ...
     654              : ! **************************************************************************************************
     655            0 :    SUBROUTINE efactor_ol1(s, fs, m)
     656              :       REAL(KIND=dp), DIMENSION(:), INTENT(IN)            :: s
     657              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(OUT)        :: fs
     658              :       INTEGER, INTENT(IN)                                :: m
     659              : 
     660              :       INTEGER                                            :: ip
     661              :       REAL(KIND=dp)                                      :: t1, t2
     662              : 
     663            0 :       t1 = b*b/(72.0_dp*cf)
     664            0 :       t2 = 0.001878_dp*b
     665              : 
     666              : !$OMP     PARALLEL DO DEFAULT(NONE) &
     667              : !$OMP                 SHARED(s, m, fs, t1, t2) &
     668            0 : !$OMP                 PRIVATE(ip)
     669              : 
     670              :       DO ip = 1, SIZE(s)
     671              :          SELECT CASE (m)
     672              :          CASE (0)
     673              :             fs(ip, 1) = 1.0_dp + t1*s(ip)*s(ip) + t2*s(ip)
     674              :          CASE (1)
     675              :             fs(ip, 1) = 1.0_dp + t1*s(ip)*s(ip) + t2*s(ip)
     676              :             fs(ip, 2) = 2.0_dp*t1*s(ip) + t2
     677              :          CASE (2:3)
     678              :             fs(ip, 1) = 1.0_dp + t1*s(ip)*s(ip) + t2*s(ip)
     679              :             fs(ip, 2) = 2.0_dp*t1*s(ip) + t2
     680              :             fs(ip, 3) = 2.0_dp*t1
     681              :          CASE DEFAULT
     682              :             CPABORT("Illegal order.")
     683              :          END SELECT
     684              :       END DO
     685              : 
     686              : !$OMP     END PARALLEL DO
     687              : 
     688            0 :       IF (m == 3) fs(:, 4) = 0.0_dp
     689              : 
     690            0 :    END SUBROUTINE efactor_ol1
     691              : ! **************************************************************************************************
     692              : !> \brief ...
     693              : !> \param s ...
     694              : !> \param fs ...
     695              : !> \param m ...
     696              : ! **************************************************************************************************
     697            0 :    SUBROUTINE efactor_ol2(s, fs, m)
     698              :       REAL(KIND=dp), DIMENSION(:), INTENT(IN)            :: s
     699              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(OUT)        :: fs
     700              :       INTEGER, INTENT(IN)                                :: m
     701              : 
     702              :       INTEGER                                            :: ip
     703              :       REAL(KIND=dp)                                      :: t1, t2, t3, y
     704              : 
     705            0 :       t1 = b*b/(72.0_dp*cf)
     706            0 :       t2 = 0.0245_dp*b
     707            0 :       t3 = 2.0_dp**f53*b
     708              : 
     709              : !$OMP     PARALLEL DO DEFAULT(NONE) &
     710              : !$OMP                 SHARED(s, m, t1, t2, t3, fs) &
     711            0 : !$OMP                 PRIVATE(ip,y)
     712              : 
     713              :       DO ip = 1, SIZE(s)
     714              :          y = 1.0_dp/(1.0_dp + t3*s(ip))
     715              :          SELECT CASE (m)
     716              :          CASE (0)
     717              :             fs(ip, 1) = 1.0_dp + t1*s(ip)*s(ip) + t2*s(ip)*y
     718              :          CASE (1)
     719              :             fs(ip, 1) = 1.0_dp + t1*s(ip)*s(ip) + t2*s(ip)*y
     720              :             fs(ip, 2) = 2.0_dp*t1*s(ip) + t2*y*y
     721              :          CASE (2)
     722              :             fs(ip, 1) = 1.0_dp + t1*s(ip)*s(ip) + t2*s(ip)*y
     723              :             fs(ip, 2) = 2.0_dp*t1*s(ip) + t2*y*y
     724              :             fs(ip, 3) = 2.0_dp*(t1 - t2*t3*y*y*y)
     725              :          CASE (3)
     726              :             fs(ip, 1) = 1.0_dp + t1*s(ip)*s(ip) + t2*s(ip)*y
     727              :             fs(ip, 2) = 2.0_dp*t1*s(ip) + t2*y*y
     728              :             fs(ip, 3) = 2.0_dp*(t1 - t2*t3*y*y*y)
     729              :             fs(ip, 4) = 6.0_dp*t2*t3*t3*y*y*y*y
     730              :          CASE DEFAULT
     731              :             CPABORT("Illegal order.")
     732              :          END SELECT
     733              :       END DO
     734              : 
     735              : !$OMP     END PARALLEL DO
     736              : 
     737            0 :    END SUBROUTINE efactor_ol2
     738              : ! **************************************************************************************************
     739              : !> \brief ...
     740              : !> \param s ...
     741              : !> \param fs ...
     742              : !> \param m ...
     743              : ! **************************************************************************************************
     744          736 :    SUBROUTINE efactor_llp(s, fs, m)
     745              :       REAL(KIND=dp), DIMENSION(:), INTENT(IN)            :: s
     746              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(OUT)        :: fs
     747              :       INTEGER, INTENT(IN)                                :: m
     748              : 
     749              :       INTEGER                                            :: ip
     750              :       REAL(KIND=dp) :: as, bs, p, q, sas, sbs, t1, t10, t11, t12, t133, t16, t17, t19, t2, t20, &
     751              :          t22, t23, t26, t28, t29, t3, t30, t33, t36, t39, t4, t40, t42, t43, t45, t46, t47, t49, &
     752              :          t5, t50, t54, t55, t7, t71, t8, t9, x, ys
     753              : 
     754          736 :       p = 0.0044188_dp*b*b
     755          736 :       q = 0.0253_dp*b
     756              : 
     757              : !$OMP     PARALLEL DO DEFAULT(NONE) &
     758              : !$OMP                 SHARED(s, m, fs, p, q, b) &
     759              : !$OMP                 PRIVATE(ip,x,bs,sbs,as,sas,ys,t2,t4,t5,t8,t9,t10,t12) &
     760              : !$OMP                 PRIVATE(t1,t3,t7,t11,t16,t17,t20,t22,t23,t26,t30,t33) &
     761              : !$OMP                 PRIVATE(t40,t42,t43,t45,t46,t47,t49,t50,t71,t133) &
     762          736 : !$OMP                 PRIVATE(t19,t28,t29,t36,t39,t54,t55)
     763              : 
     764              :       DO ip = 1, SIZE(s)
     765              :          x = s(ip)
     766              :          bs = b*x
     767              :          sbs = SQRT(bs*bs + 1.0_dp)
     768              :          as = LOG(bs + sbs)
     769              :          sas = x*as
     770              :          ys = 1.0_dp/(1.0_dp + q*sas)
     771              :          SELECT CASE (m)
     772              :          CASE (0)
     773              :             fs(ip, 1) = 1.0_dp + p*x*x*ys
     774              :          CASE (1)
     775              :             fs(ip, 1) = 1.0_dp + p*x*x*ys
     776              :             t2 = q*x
     777              :             t4 = b**2
     778              :             t5 = x**2
     779              :             t8 = SQRT(1.0_dp + t4*t5)
     780              :             t9 = b*x + t8
     781              :             t10 = LOG(t9)
     782              :             t12 = 1.0_dp + t2*t10
     783              :             t17 = t12**2
     784              :             fs(ip, 2) = 2.0_dp*p*x/t12 - p*t5/t17*(q*t10 + t2*(b + 1.0_dp/t8*t4*x)/t9)
     785              : 
     786              :          CASE (2)
     787              :             fs(ip, 1) = 1.0_dp + p*x*x*ys
     788              :             ! first der
     789              :             t2 = q*x
     790              :             t4 = b**2
     791              :             t5 = x**2
     792              :             t8 = SQRT(1.0_dp + t4*t5)
     793              :             t9 = b*x + t8
     794              :             t10 = LOG(t9)
     795              :             t12 = 1.0_dp + t2*t10
     796              :             t17 = t12**2
     797              :             fs(ip, 2) = 2.0_dp*p*x/t12 - p*t5/t17*(q*t10 + t2*(b + 1.0_dp/t8*t4*x)/t9)
     798              : 
     799              :             ! second der
     800              :             t1 = q*x
     801              :             t3 = b**2
     802              :             t4 = x**2
     803              :             t7 = SQRT(1.0_dp + t3*t4)
     804              :             t8 = b*x + t7
     805              :             t9 = LOG(t8)
     806              :             t11 = 1.0_dp + t1*t9
     807              :             t16 = t11**2
     808              :             t17 = 1.0_dp/t16
     809              :             t20 = 1.0_dp/t7*t3
     810              :             t22 = b + t20*x
     811              :             t23 = 1/t8
     812              :             t26 = q*t9 + t1*t22*t23
     813              :             t30 = p*t4
     814              :             t33 = t26**2
     815              :             t40 = t7**2
     816              :             t43 = t3**2
     817              :             t49 = t22**2
     818              :             t50 = t8**2
     819              :             fs(ip, 3) = 2.0_dp*p/t11 - 4.0_dp*p*x*t17*t26 + 2.0_dp*t30/t16/ &
     820              :                         t11*t33 - t30*t17*(2.0_dp*q*t22*t23 + t1* &
     821              :                                            (-1.0_dp/t40/t7*t43*t4 + t20)*t23 - t1*t49/t50)
     822              : 
     823              :          CASE (3)
     824              : 
     825              :             fs(ip, 1) = 1.0_dp + p*x*x*ys
     826              :             ! first der
     827              :             t2 = q*x
     828              :             t4 = b**2
     829              :             t5 = x**2
     830              :             t8 = SQRT(1.0_dp + t4*t5)
     831              :             t9 = b*x + t8
     832              :             t10 = LOG(t9)
     833              :             t12 = 1.0_dp + t2*t10
     834              :             t17 = t12**2
     835              :             fs(ip, 2) = 2.0_dp*p*x/t12 - p*t5/t17*(q*t10 + t2*(b + 1.0_dp/t8*t4*x)/t9)
     836              : 
     837              :             ! second der
     838              :             t1 = q*x
     839              :             t3 = b**2
     840              :             t4 = x**2
     841              :             t7 = SQRT(1.0_dp + t3*t4)
     842              :             t8 = b*x + t7
     843              :             t9 = LOG(t8)
     844              :             t11 = 1.0_dp + t1*t9
     845              :             t16 = t11**2
     846              :             t17 = 1.0_dp/t16
     847              :             t20 = 1.0_dp/t7*t3
     848              :             t22 = b + t20*x
     849              :             t23 = 1/t8
     850              :             t26 = q*t9 + t1*t22*t23
     851              :             t30 = p*t4
     852              :             t33 = t26**2
     853              :             t40 = t7**2
     854              :             t43 = t3**2
     855              :             t49 = t22**2
     856              :             t50 = t8**2
     857              :             fs(ip, 3) = 2.0_dp*p/t11 - 4.0_dp*p*x*t17*t26 + 2.0_dp*t30/t16/ &
     858              :                         t11*t33 - t30*t17*(2.0_dp*q*t22*t23 + t1* &
     859              :                                            (-1.0_dp/t40/t7*t43*t4 + t20)*t23 - t1*t49/t50)
     860              : 
     861              :             t1 = q*x
     862              :             t3 = b**2
     863              :             t4 = x**2
     864              :             t7 = SQRT(1 + t3*t4)
     865              :             t8 = b*x + t7
     866              :             t9 = LOG(t8)
     867              :             t11 = 1.0_dp + t1*t9
     868              :             t12 = t11**2
     869              :             t133 = 1.0_dp/t12
     870              :             t17 = 1.0_dp/t7*t3
     871              :             t19 = b + t17*x
     872              :             t20 = 1.0_dp/t8
     873              :             t23 = q*t9 + t1*t19*t20
     874              :             t26 = p*x
     875              :             t28 = 1.0_dp/t12/t11
     876              :             t29 = t23**2
     877              :             t36 = t7**2
     878              :             t39 = t3**2
     879              :             t40 = 1.0_dp/t36/t7*t39
     880              :             t42 = -t40*t4 + t17
     881              :             t45 = t19**2
     882              :             t46 = t8**2
     883              :             t47 = 1.0_dp/t46
     884              :             t50 = 2.0_dp*q*t19*t20 + t1*t42*t20 - t1*t45*t47
     885              :             t54 = p*t4
     886              :             t55 = t12**2
     887              :             t71 = t36**2
     888              :             fs(ip, 4) = &
     889              :                -6.0_dp*p*t133*t23 + 12.0_dp*t26*t28*t29 - &
     890              :                6.0_dp*t26*t133*t50 - 6.0_dp*t54/t55*t29*t23 + &
     891              :                6.0_dp*t54*t28*t23*t50 - t54*t133* &
     892              :                (3.0_dp*q*t42*t20 - 3.0_dp*q*t45*t47 + 3.0_dp*t1* &
     893              :                 (1.0_dp/t71/t7*t39*t3*t4*x - t40*x)*t20 - &
     894              :                 3.0_dp*t1*t42*t47*t19 + 2.0_dp*t1*t45*t19/t46/t8)
     895              : 
     896              :          CASE DEFAULT
     897              :             CPABORT("Illegal order.")
     898              :          END SELECT
     899              :       END DO
     900              : 
     901              : !$OMP     END PARALLEL DO
     902              : 
     903          736 :    END SUBROUTINE efactor_llp
     904              : ! **************************************************************************************************
     905              : !> \brief ...
     906              : !> \param s ...
     907              : !> \param fs ...
     908              : !> \param m ...
     909              : !> \param f2_lsd ...
     910              : ! **************************************************************************************************
     911           54 :    SUBROUTINE efactor_pw86(s, fs, m, f2_lsd)
     912              :       REAL(KIND=dp), DIMENSION(:), INTENT(IN)            :: s
     913              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(OUT)        :: fs
     914              :       INTEGER, INTENT(IN)                                :: m
     915              :       REAL(dp), OPTIONAL                                 :: f2_lsd
     916              : 
     917              :       INTEGER                                            :: ip
     918              :       REAL(KIND=dp)                                      :: f15, ff, p0, p1, p15, p2, p3, s1, s2, &
     919              :                                                             s4, s6, t1, t2, t3
     920              : 
     921           54 :       t1 = 1.296_dp
     922           54 :       t2 = 14.0_dp
     923           54 :       t3 = 0.2_dp
     924           54 :       f15 = 1.0_dp/15.0_dp
     925           54 :       ff = 1.0_dp
     926           54 :       IF (PRESENT(f2_lsd)) ff = f2_lsd
     927              : 
     928              : !$OMP     PARALLEL DO DEFAULT(NONE) &
     929              : !$OMP                 SHARED(s, fs, m, t1, t2, t3, f15, ff) &
     930           54 : !$OMP                 PRIVATE(ip, s1, s2, s4, s6, p0, p1, p2, p3, p15)
     931              : 
     932              :       DO ip = 1, SIZE(s)
     933              :          s1 = s(ip)*ff
     934              :          s2 = s1*s1
     935              :          s4 = s2*s2
     936              :          s6 = s2*s4
     937              :          SELECT CASE (m)
     938              :          CASE (0)
     939              :             p0 = 1.0_dp + t1*s2 + t2*s4 + t3*s6
     940              :             fs(ip, 1) = p0**f15
     941              :          CASE (1)
     942              :             p0 = 1.0_dp + t1*s2 + t2*s4 + t3*s6
     943              :             p1 = s1*ff*(2.0_dp*t1 + 4.0_dp*t2*s2 + 6.0_dp*t3*s4)
     944              :             p15 = p0**f15
     945              :             fs(ip, 1) = p15
     946              :             fs(ip, 2) = f15*p1*p15/p0
     947              :          CASE (2)
     948              :             p0 = 1.0_dp + t1*s2 + t2*s4 + t3*s6
     949              :             p1 = s1*ff*(2.0_dp*t1 + 4.0_dp*t2*s2 + 6.0_dp*t3*s4)
     950              :             p2 = ff*ff*(2.0_dp*t1 + 12.0_dp*t2*s2 + 30.0_dp*t3*s4)
     951              :             p15 = p0**f15
     952              :             fs(ip, 1) = p15
     953              :             fs(ip, 2) = f15*p1*p15/p0
     954              :             fs(ip, 3) = f15*p15/p0*(p2 - 14.0_dp/15.0_dp*p1*p1/p0)
     955              :          CASE (3)
     956              :             p0 = 1.0_dp + t1*s2 + t2*s4 + t3*s6
     957              :             p1 = s1*ff*(2.0_dp*t1 + 4.0_dp*t2*s2 + 6.0_dp*t3*s4)
     958              :             p2 = ff*ff*(2.0_dp*t1 + 12.0_dp*t2*s2 + 30.0_dp*t3*s4)
     959              :             p3 = s1*ff*ff*ff*(24.0_dp*t2 + 120.0_dp*t3*s2)
     960              :             p15 = p0**f15
     961              :             fs(ip, 1) = p15
     962              :             fs(ip, 2) = f15*p1*p15/p0
     963              :             fs(ip, 3) = f15*p15/p0*(p2 - 14.0_dp/15.0_dp*p1*p1/p0)
     964              :             fs(ip, 4) = f15*p15/p0*(-14.0_dp*f15*p1*p1/p0 + 14.0_dp*14.0_dp*f15*p1*p1*p1/p0/p0 + &
     965              :                                     p3 - 14.0_dp*p2*p1/p0 + 14.0_dp*p1*p1/p0/p0)
     966              :          CASE DEFAULT
     967              :             CPABORT("Illegal order.")
     968              :          END SELECT
     969              :       END DO
     970              : 
     971              : !$OMP     END PARALLEL DO
     972              : 
     973           54 :    END SUBROUTINE efactor_pw86
     974              : ! **************************************************************************************************
     975              : !> \brief ...
     976              : !> \param s ...
     977              : !> \param fs ...
     978              : !> \param m ...
     979              : ! **************************************************************************************************
     980          294 :    SUBROUTINE efactor_t92(s, fs, m)
     981              :       REAL(KIND=dp), DIMENSION(:), INTENT(IN)            :: s
     982              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(OUT)        :: fs
     983              :       INTEGER, INTENT(IN)                                :: m
     984              : 
     985              :       INTEGER                                            :: ip
     986              :       REAL(KIND=dp)                                      :: a1, a2, as, asp, asp2, asp3, bs, p, q, &
     987              :                                                             s1, s2, sas, sbs, sbs3, sbs5, t0, w1, &
     988              :                                                             x, ys
     989              : 
     990          294 :       p = 0.0055_dp*b*b
     991          294 :       q = 0.0253_dp*b
     992          294 :       a1 = 0.072_dp*b
     993          294 :       a2 = 2.0_dp**f53*b
     994              : 
     995              : !$OMP     PARALLEL DO DEFAULT(NONE) &
     996              : !$OMP                 SHARED(s, fs, m, p, q, a1, a2, b) &
     997              : !$OMP                 PRIVATE(ip, x, bs, sbs, sas, ys, asp, sbs3, asp2, sbs5) &
     998          294 : !$OMP                 PRIVATE(asp3, as, s2, s1, t0, w1)
     999              : 
    1000              :       DO ip = 1, SIZE(s)
    1001              :          x = s(ip)
    1002              :          bs = b*x
    1003              :          sbs = SQRT(bs*bs + 1.0_dp)
    1004              :          as = LOG(bs + sbs)
    1005              :          sas = x*as
    1006              :          ys = 1.0_dp/(1.0_dp + q*sas)
    1007              :          SELECT CASE (m)
    1008              :          CASE (0)
    1009              :             fs(ip, 1) = 1.0_dp + p*x*x*ys - a1*x/(1 + a2*x)
    1010              :          CASE (1)
    1011              :             asp = as + bs/sbs
    1012              :             fs(ip, 1) = 1.0_dp + p*x*x*ys - a1*x/(1 + a2*x)
    1013              :             fs(ip, 2) = 2.0_dp*p*x*ys - p*q*x*x*asp*ys*ys - a1/(1 + a2*x)**2
    1014              :          CASE (2)
    1015              :             asp = as + bs/sbs
    1016              :             sbs3 = sbs*sbs*sbs
    1017              :             asp2 = 2.0_dp*b/sbs - b*bs*bs/sbs3
    1018              :             fs(ip, 1) = 1.0_dp + p*x*x*ys - a1*x/(1 + a2*x)
    1019              :             fs(ip, 2) = 2.0_dp*p*x*ys - p*q*x*x*asp*ys*ys - a1/(1 + a2*x)**2
    1020              :             fs(ip, 3) = 2.0_dp*p*ys - p*q*x*(4.0_dp*asp + x*asp2)*ys*ys + &
    1021              :                         2.0_dp*p*q*q*x*x*asp*asp*ys*ys*ys + 2.0_dp*a1*a2/(1 + a2*x)**3
    1022              :          CASE (3)
    1023              :             asp = as + bs/sbs
    1024              :             sbs3 = sbs*sbs*sbs
    1025              :             sbs5 = sbs3*sbs*sbs
    1026              :             asp2 = 2.0_dp*b/sbs - b*bs*bs/sbs3
    1027              :             asp3 = -4.0_dp*b*b*bs/sbs3 + 3.0_dp*b*b*bs*bs*bs/sbs5
    1028              :             w1 = (4.0_dp*asp + x*asp2)
    1029              :             fs(ip, 1) = 1.0_dp + p*x*x*ys - a1*x/(1 + a2*x)
    1030              :             fs(ip, 2) = 2.0_dp*p*x*ys - p*q*x*x*asp*ys*ys - a1/(1 + a2*x)**2
    1031              :             fs(ip, 3) = 2.0_dp*p*ys - p*q*x*w1*ys*ys + &
    1032              :                         2.0_dp*p*q*q*x*x*asp*asp*ys*ys*ys + 2.0_dp*a1*a2/(1 + a2*x)**3
    1033              : 
    1034              :             s2 = -6*p/(1 + q*x*LOG(b*x + SQRT(1 + b**2*x**2)))**2*(q*LOG(b*x + SQRT(1 + b**2*x**2)) + &
    1035              :                                                      q*x*(b + 1/SQRT(1 + b**2*x**2)*b**2*x)/(b*x + SQRT(1 + b**2*x**2))) + 12*p*x/ &
    1036              :                  (1 + q*x*LOG(b*x + SQRT(1 + b**2*x**2)))**3*(q*LOG(b*x + SQRT(1 + b**2*x**2)) + &
    1037              :                                                               q*x*(b + 1/SQRT(1 + b**2*x**2)*b**2*x)/(b*x + SQRT(1 + b**2*x**2)))**2
    1038              :             s1 = s2 - 6*p*x/(1 + q*x*LOG(b*x + SQRT(1 + b**2*x**2)))**2*(2*q*(b + 1/SQRT(1 + b**2*x**2)*b**2*x)/ &
    1039              :                              (b*x + SQRT(1 + b**2*x**2)) + q*x*(-1/SQRT(1 + b**2*x**2)**3*b**4*x**2 + 1/SQRT(1 + b**2*x**2)*b**2)/ &
    1040              :                                                           (b*x + SQRT(1 + b**2*x**2)) - q*x*(b + 1/SQRT(1 + b**2*x**2)*b**2*x)**2/ &
    1041              :                                             (b*x + SQRT(1 + b**2*x**2))**2) - 6*p*x**2/(1 + q*x*LOG(b*x + SQRT(1 + b**2*x**2)))**4 &
    1042              :                  *(q*LOG(b*x + SQRT(1 + b**2*x**2)) + q*x*(b + 1/SQRT(1 + b**2*x**2)*b**2*x)/(b*x + SQRT(1 + b**2*x**2)))**3
    1043              :             s2 = s1 + 6*p*x**2/(1 + q*x*LOG(b*x + SQRT(1 + b**2*x**2)))**3*(q*LOG(b*x + SQRT(1 + b**2*x**2)) + &
    1044              :                        q*x*(b + 1/SQRT(1 + b**2*x**2)*b**2*x)/(b*x + SQRT(1 + b**2*x**2)))*(2*q*(b + 1/SQRT(1 + b**2*x**2)*b**2*x) &
    1045              :                                   /(b*x + SQRT(1 + b**2*x**2)) + q*x*(-1/SQRT(1 + b**2*x**2)**3*b**4*x**2 + 1/SQRT(1 + b**2*x**2)* &
    1046              :                        b**2)/(b*x + SQRT(1 + b**2*x**2)) - q*x*(b + 1/SQRT(1 + b**2*x**2)*b**2*x)**2/(b*x + SQRT(1 + b**2*x**2))**2)
    1047              :             t0 = s2 - p*x**2/(1 + q*x*LOG(b*x + SQRT(1 + b**2*x**2)))**2*(3*q*(-1/SQRT(1 + b**2*x**2)**3*b**4*x**2 + &
    1048              :                               1/SQRT(1 + b**2*x**2)*b**2)/(b*x + SQRT(1 + b**2*x**2)) - 3*q*(b + 1/SQRT(1 + b**2*x**2)*b**2*x)**2/ &
    1049              :                       (b*x + SQRT(1 + b**2*x**2))**2 + q*x*(3/SQRT(1 + b**2*x**2)**5*b**6*x**3 - 3/SQRT(1 + b**2*x**2)**3*b**4*x)/ &
    1050              :                            (b*x + SQRT(1 + b**2*x**2)) - 3*q*x*(-1/SQRT(1 + b**2*x**2)**3*b**4*x**2 + 1/SQRT(1 + b**2*x**2)*b**2)/ &
    1051              :                              (b*x + SQRT(1 + b**2*x**2))**2*(b + 1/SQRT(1 + b**2*x**2)*b**2*x) + 2*q*x*(b + 1/SQRT(1 + b**2*x**2)* &
    1052              :                                   b**2*x)**3/(b*x + SQRT(1 + b**2*x**2))**3) - 6*a1/(1 + a2*x)**3*a2**2 + 6*a1*x/(1 + a2*x)**4*a2**3
    1053              : 
    1054              :             fs(ip, 4) = t0
    1055              : 
    1056              :          CASE DEFAULT
    1057              :             CPABORT("Illegal order")
    1058              :          END SELECT
    1059              :       END DO
    1060              : 
    1061              : !$OMP     END PARALLEL DO
    1062              : 
    1063          294 :    END SUBROUTINE efactor_t92
    1064              : ! **************************************************************************************************
    1065              : !> \brief ...
    1066              : !> \param s ...
    1067              : !> \param fs ...
    1068              : !> \param m ...
    1069              : !> \param pset ...
    1070              : !> \param f2_lsd ...
    1071              : ! **************************************************************************************************
    1072          588 :    SUBROUTINE efactor_pbex(s, fs, m, pset, f2_lsd)
    1073              : 
    1074              :       REAL(KIND=dp), DIMENSION(:), INTENT(IN)            :: s
    1075              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(OUT)        :: fs
    1076              :       INTEGER, INTENT(IN)                                :: m, pset
    1077              :       REAL(dp), OPTIONAL                                 :: f2_lsd
    1078              : 
    1079              :       REAL(KIND=dp), PARAMETER                           :: kappa1 = 0.804_dp, kappa2 = 1.245_dp, &
    1080              :                                                             mu = 0.2195149727645171_dp
    1081              : 
    1082              :       INTEGER                                            :: ip
    1083              :       REAL(KIND=dp)                                      :: f0, mk, x, x2, y
    1084              : 
    1085              :       IF (pset == 1) mk = mu/kappa1
    1086          588 :       IF (pset == 2) mk = mu/kappa2
    1087              : 
    1088          588 :       f0 = 1.0_dp/tact
    1089          588 :       IF (PRESENT(f2_lsd)) f0 = f2_lsd
    1090              : 
    1091              : !$OMP     PARALLEL DO DEFAULT(NONE) &
    1092              : !$OMP                 SHARED(s, m, fs, f0, mk) &
    1093          588 : !$OMP                 PRIVATE(ip,x,x2,y)
    1094              : 
    1095              :       DO ip = 1, SIZE(s)
    1096              :          x = s(ip)*f0
    1097              :          x2 = x*x
    1098              :          y = 1.0_dp/(1.0_dp + mk*x2)
    1099              :          SELECT CASE (m)
    1100              :          CASE (0)
    1101              :             fs(ip, 1) = 1.0_dp + mu*x2*y
    1102              :          CASE (1)
    1103              :             fs(ip, 1) = 1.0_dp + mu*x2*y
    1104              :             fs(ip, 2) = 2.0_dp*mu*x*y*y*f0
    1105              :          CASE (2)
    1106              :             fs(ip, 1) = 1.0_dp + mu*x2*y
    1107              :             fs(ip, 2) = 2.0_dp*mu*x*y*y*f0
    1108              :             fs(ip, 3) = -2.0_dp*mu*(3.0_dp*mk*x2 - 1.0_dp)*y*y*y*f0*f0
    1109              :          CASE (3)
    1110              :             fs(ip, 1) = 1.0_dp + mu*x2*y
    1111              :             fs(ip, 2) = 2.0_dp*mu*x*y*y*f0
    1112              :             fs(ip, 3) = -2.0_dp*mu*(3.0_dp*mk*x2 - 1.0_dp)*y*y*y*f0*f0
    1113              :             fs(ip, 4) = 24.0_dp*mu*mk*x*(mk*x2 - 1.0_dp)*y*y*y*y*f0*f0*f0
    1114              :          CASE DEFAULT
    1115              :             CPABORT("Illegal order.")
    1116              :          END SELECT
    1117              :       END DO
    1118              : 
    1119              : !$OMP     END PARALLEL DO
    1120              : 
    1121          588 :    END SUBROUTINE efactor_pbex
    1122              : 
    1123              : ! **************************************************************************************************
    1124              : !> \brief ...
    1125              : !> \param s ...
    1126              : !> \param fs ...
    1127              : !> \param m ...
    1128              : !> \param pset ...
    1129              : !> \param f2_lsd ...
    1130              : ! **************************************************************************************************
    1131          108 :    SUBROUTINE efactor_pw91(s, fs, m, pset, f2_lsd)
    1132              :       REAL(KIND=dp), DIMENSION(:), INTENT(IN)            :: s
    1133              :       REAL(KIND=dp), DIMENSION(:, :), INTENT(OUT)        :: fs
    1134              :       INTEGER, INTENT(IN)                                :: m, pset
    1135              :       REAL(dp), OPTIONAL                                 :: f2_lsd
    1136              : 
    1137              :       INTEGER                                            :: ip
    1138              :       REAL(dp) :: ff, t1, t10, t101, t106, t109, t111, t113, t119, t12, t123, t124, t13, t14, t15, &
    1139              :          t16, t17, t18, t19, t2, t20, t21, t22, t23, t25, t26, t27, t28, t29, t3, t30, t31, t33, &
    1140              :          t35, t37, t38, t39, t4, t40, t44, t47, t48, t5, t50, t51, t53, t55, t56, t57, t58, t59, &
    1141              :          t6, t60, t64, t65, t69, t7, t70, t71, t73, t77, t78, t8, t80, t82, t9, t90, t93, t94, &
    1142              :          t96, t98
    1143              :       REAL(KIND=dp)                                      :: a1, a2, a3, a4, a5, bb, o, pa(6, 2), x
    1144              : 
    1145              : ! parameter set 1: Perdew-Wang
    1146              : ! parameter set 2: Lembarki-Chermette
    1147              : 
    1148              :       pa(1:6, 1) = [0.19645_dp, 0.2743_dp, &
    1149              :                     0.1508_dp, 100.0_dp, &
    1150          756 :                     7.7956_dp, 0.004_dp]
    1151              :       pa(1:6, 2) = [0.093907_dp, 0.26608_dp, &
    1152              :                     0.0809615_dp, 100.0_dp, &
    1153          756 :                     76.320_dp, 0.57767e-4_dp]
    1154          108 :       o = 1.0_dp
    1155          108 :       ff = 1.0_dp
    1156          108 :       IF (PRESENT(f2_lsd)) ff = f2_lsd
    1157          108 :       a1 = pa(1, pset)*FF
    1158          108 :       a2 = pa(2, pset)*ff*ff
    1159          108 :       a3 = pa(3, pset)*ff*ff
    1160          108 :       a4 = pa(4, pset)*ff*ff
    1161          108 :       bb = pa(5, pset)*ff
    1162              : !   it should be valid also for lsd
    1163          108 :       a5 = pa(6, pset)*ff*ff*ff*ff
    1164              : 
    1165              : !$OMP     PARALLEL DEFAULT(NONE) &
    1166              : !$OMP              SHARED(s, fs, m, a1, a2, a3, a4, a5, bb, pa, o, ff) &
    1167              : !$OMP              PRIVATE(x,t1,t10,t101,t106,t109,t111,t113,t119,t12,t123) &
    1168              : !$OMP              PRIVATE(t124,t13,t14,t15,t16,t17,t18,t19,t2,t20,t21,t22) &
    1169              : !$OMP              PRIVATE(t23,t25,t26,t27,t28,t29,t3,t30,t31,t33,t35,t37) &
    1170              : !$OMP              PRIVATE(t38,t39,t4,t40,t44,t47,t48,t5,t50,t51,t53,t55) &
    1171              : !$OMP              PRIVATE(t56,t57,t58,t59,t6,t60,t64,t65,t69,t7,t70,t71) &
    1172          108 : !$OMP              PRIVATE(t73,t77,t78,t8,t80,t82,t9,t90,t93,t94,t96,t98,ip)
    1173              : 
    1174              :       IF (m >= 0) THEN
    1175              : !$OMP       DO
    1176              :          DO ip = 1, SIZE(s)
    1177              :             x = s(ip)
    1178              :             t3 = bb**2
    1179              :             t4 = x**2
    1180              :             t7 = SQRT(o + t3*t4)
    1181              :             t9 = LOG(bb*x + t7)
    1182              :             t10 = a1*x*t9
    1183              :             t12 = EXP(-a4*t4)
    1184              :             t17 = t4**2
    1185              :             fs(ip, 1) = (o + t10 + (a2 - a3*t12)*t4)/(o + t10 + a5*t17)
    1186              :          END DO
    1187              : !$OMP       END DO
    1188              :       END IF
    1189              :       IF (m >= 1) THEN
    1190              : !$OMP       DO
    1191              :          DO ip = 1, SIZE(s)
    1192              :             x = s(ip)
    1193              :             t2 = bb**2
    1194              :             t3 = x**2
    1195              :             t6 = SQRT(o + t2*t3)
    1196              :             t7 = bb*x + t6
    1197              :             t8 = LOG(t7)
    1198              :             t9 = a1*t8
    1199              :             t10 = a1*x
    1200              :             t17 = t10*(bb + 1/t6*t2*x)/t7
    1201              :             t19 = t3*x
    1202              :             t21 = EXP(-a4*t3)
    1203              :             t26 = a2 - a3*t21
    1204              :             t30 = t10*t8
    1205              :             t31 = t3**2
    1206              :             t33 = o + t30 + a5*t31
    1207              :             t38 = t33**2
    1208              :             fs(ip, 2) = &
    1209              :                (t9 + t17 + 2._dp*a3*a4*t19*t21 + 2._dp*t26*x)/ &
    1210              :                t33 - (o + t30 + t26*t3)/t38*(t9 + t17 + 4._dp*a5*t19)
    1211              :          END DO
    1212              : !$OMP       END DO
    1213              :       END IF
    1214              :       IF (m >= 2) THEN
    1215              : !$OMP       DO
    1216              :          DO ip = 1, SIZE(s)
    1217              :             x = s(ip)
    1218              :             t1 = bb**2
    1219              :             t2 = x**2
    1220              :             t5 = SQRT(o + t1*t2)
    1221              :             t7 = o/t5*t1
    1222              :             t9 = bb + t7*x
    1223              :             t12 = bb*x + t5
    1224              :             t13 = o/t12
    1225              :             t15 = 2._dp*a1*t9*t13
    1226              :             t16 = a1*x
    1227              :             t17 = t5**2
    1228              :             t20 = t1**2
    1229              :             t25 = t16*(-o/t17/t5*t20*t2 + t7)*t13
    1230              :             t26 = t9**2
    1231              :             t27 = t12**2
    1232              :             t30 = t16*t26/t27
    1233              :             t31 = a3*a4
    1234              :             t33 = EXP(-a4*t2)
    1235              :             t37 = a4**2
    1236              :             t39 = t2**2
    1237              :             t44 = a3*t33
    1238              :             t47 = LOG(t12)
    1239              :             t48 = t16*t47
    1240              :             t50 = o + t48 + a5*t39
    1241              :             t53 = a1*t47
    1242              :             t55 = t16*t9*t13
    1243              :             t56 = t2*x
    1244              :             t60 = a2 - t44
    1245              :             t64 = t50**2
    1246              :             t65 = o/t64
    1247              :             t69 = t53 + t55 + 4._dp*a5*t56
    1248              :             t73 = o + t48 + t60*t2
    1249              :             t77 = t69**2
    1250              :             fs(ip, 3) = &
    1251              :                (t15 + t25 - t30 + 10._dp*t31*t2*t33 - 4._dp*a3*t37*t39*t33 + &
    1252              :                 2._dp*a2 - 2._dp*t44)/t50 - 2._dp* &
    1253              :                (t53 + t55 + 2._dp*t31*t56*t33 + 2._dp*t60*x)* &
    1254              :                t65*t69 + 2._dp*t73/t64/t50*t77 - t73*t65*(t15 + t25 - t30 + 12._dp*a5*t2)
    1255              :          END DO
    1256              : !$OMP       END DO
    1257              :       END IF
    1258              :       IF (m >= 3) THEN
    1259              : !$OMP       DO
    1260              :          DO ip = 1, SIZE(s)
    1261              :             x = s(ip)
    1262              :             t1 = bb**2
    1263              :             t2 = x**2
    1264              :             t5 = SQRT(0.1e1_dp + t1*t2)
    1265              :             t6 = t5**2
    1266              :             t9 = t1**2
    1267              :             t10 = 1/t6/t5*t9
    1268              :             t13 = 1/t5*t1
    1269              :             t14 = -t10*t2 + t13
    1270              :             t17 = bb*x + t5
    1271              :             t18 = 1/t17
    1272              :             t20 = 3*a1*t14*t18
    1273              :             t22 = bb + t13*x
    1274              :             t23 = t22**2
    1275              :             t25 = t17**2
    1276              :             t26 = 1/t25
    1277              :             t28 = 3*a1*t23*t26
    1278              :             t29 = a1*x
    1279              :             t30 = t6**2
    1280              :             t35 = t2*x
    1281              :             t40 = 3*t29*(1/t30/t5*t1*t9*t35 - t10*x)*t18
    1282              :             t44 = 3*t29*t14*t26*t22
    1283              :             t50 = 2*t29*t23*t22/t25/t17
    1284              :             t51 = a3*a4
    1285              :             t53 = EXP(-a4*t2)
    1286              :             t57 = a4**2
    1287              :             t58 = a3*t57
    1288              :             t59 = t35*t53
    1289              :             t64 = t2**2
    1290              :             t70 = LOG(t17)
    1291              :             t71 = t29*t70
    1292              :             t73 = 0.1e1_dp + t71 + a5*t64
    1293              :             t78 = 2*a1*t22*t18
    1294              :             t80 = t29*t14*t18
    1295              :             t82 = t29*t23*t26
    1296              :             t90 = a3*t53
    1297              :             t93 = t73**2
    1298              :             t94 = 1/t93
    1299              :             t96 = a1*t70
    1300              :             t98 = t29*t18*t22
    1301              :             t101 = t96 + t98 + 4*a5*t35
    1302              :             t106 = a2 - t90
    1303              :             t109 = t96 + t98 + 2*t51*t59 + 2*t106*x
    1304              :             t111 = 1/t93/t73
    1305              :             t113 = t101**2
    1306              :             t119 = t78 + t80 - t82 + 12*a5*t2
    1307              :             t123 = 0.1e1_dp + t71 + t106*t2
    1308              :             t124 = t93**2
    1309              :             fs(ip, 4) = &
    1310              :                (t20 - t28 + t40 - t44 + t50 + 24*t51*x*t53 - 36._dp*t58*t59 + 8._dp*a3*t57*a4*t64* &
    1311              :                 x*t53)/t73 - 3._dp*(t78 + t80 - t82 + 10._dp*t51*t2*t53 - &
    1312              :                                     4._dp*t58*t64*t53 + 2._dp*a2 - 2._dp*t90)*t94*t101 + &
    1313              :                6._dp*t109*t111*t113 - 3._dp*t109*t94*t119 - 6*t123/t124*t113*t101 + &
    1314              :                6._dp*t123*t111*t101*t119 - t123*t94*(t20 - t28 + t40 - t44 + t50 + 24._dp*a5*x)
    1315              :          END DO
    1316              : !$OMP       END DO
    1317              :       END IF
    1318              : 
    1319              : !$OMP     END PARALLEL
    1320              : 
    1321          108 :    END SUBROUTINE efactor_pw91
    1322              : 
    1323              : END MODULE xc_ke_gga
    1324              : 
        

Generated by: LCOV version 2.0-1