TABLE OF CONTENTS


ABINIT/m_libpaw_libxc [ Modules ]

[ Top ] [ Modules ]

NAME

  m_libpaw_libxc

FUNCTION

  Module used to interface libPAW with host code.
  At present, two cases are implemented:
   - Use of ABINIT m_libxc_functional module
   - Use of embedded m_libpaw_libxc_funcs module

COPYRIGHT

 Copyright (C) 2014-2018 ABINIT group (MT)
 This file is distributed under the terms of the
 GNU General Public License, see ~abinit/COPYING
 or http://www.gnu.org/copyleft/gpl.txt .

SOURCE

2017 module m_libpaw_libxc
2018 
2019 #if defined HAVE_LIBPAW_ABINIT
2020  use libxc_functionals
2021 
2022 #else
2023  use m_libpaw_libxc_funcs, only : &
2024 & libxc_functionals_check            => libpaw_libxc_check, &
2025 & libxc_functionals_init             => libpaw_libxc_init, &
2026 & libxc_functionals_end              => libpaw_libxc_end, &
2027 & libxc_functionals_fullname         => libpaw_libxc_fullname, &
2028 & libxc_functionals_getid            => libpaw_libxc_getid, &
2029 & libxc_functionals_family_from_id   => libpaw_libxc_family_from_id, &
2030 & libxc_functionals_ixc              => libpaw_libxc_ixc, &
2031 & libxc_functionals_getvxc           => libpaw_libxc_getvxc, &
2032 & libxc_functionals_isgga            => libpaw_libxc_isgga, &
2033 & libxc_functionals_ismgga           => libpaw_libxc_ismgga, &
2034 & libxc_functionals_is_hybrid        => libpaw_libxc_is_hybrid, &
2035 & libxc_functionals_has_kxc          => libpaw_libxc_has_kxc, &
2036 & libxc_functionals_nspin            => libpaw_libxc_nspin, &
2037 & libxc_functionals_get_hybridparams => libpaw_libxc_get_hybridparams, &
2038 & libxc_functionals_set_hybridparams => libpaw_libxc_set_hybridparams, &
2039 & libxc_functionals_gga_from_hybrid  => libpaw_libxc_gga_from_hybrid
2040 #endif
2041 
2042  implicit none
2043 
2044 end module m_libpaw_libxc

ABINIT/m_libpaw_libxc_funcs [ Modules ]

[ Top ] [ Modules ]

NAME

  m_libpaw_libxc_funcs

FUNCTION

  Module containing interfaces to the LibXC library, for exchange
  correlation potentials and energies.

COPYRIGHT

 Copyright (C) 2015-2018 ABINIT group (MO, MT)
 This file is distributed under the terms of the
 GNU General Public License, see ~abinit/COPYING
 or http://www.gnu.org/copyleft/gpl.txt .

NOTES

  This file comes directly from m_libpaw_libxc.F90 module delivered with ABINIT.
  It defines a structured datatype (libpaw_libxc_type) and associated methods
  to initialize/finalize it and get properties from it.
  * It uses by default a global variable (paw_xc_global, libpaw_libxc_type) which has
    to be initialized/finalized with the libpaw_libxc_init and libpaw_libxc_end methods.
  * It is also possible to define a local (private) variable of type libpaw_libxc_type.
    For that, the different methods have to be called with an extra optional
    argument (called xc_funcs in this example):
    !!!!! call libpaw_libxc_init(ixc,nspden,xc_funcs)
    !!!!! call libpaw_libxc_end(xc_funcs)

SOURCE

 31 !Need iso C bindings provided by the compiler
 32 #define LIBPAW_ISO_C_BINDING 1
 33 
 34 #include "libpaw.h"
 35 
 36 module m_libpaw_libxc_funcs
 37 
 38  USE_DEFS
 39  USE_MSG_HANDLING
 40  USE_MEMORY_PROFILING
 41 
 42 #ifdef LIBPAW_ISO_C_BINDING
 43  use iso_c_binding
 44 #endif
 45 
 46  implicit none
 47  private
 48 
 49 !Public functions
 50  public :: libpaw_libxc_check              ! Check if the code has been compiled with libXC
 51  public :: libpaw_libxc_init               ! Initialize the desired XC functional, from libXC
 52  public :: libpaw_libxc_end                ! End usage of libXC functional
 53  public :: libpaw_libxc_fullname           ! Return full name of the XC functional
 54  public :: libpaw_libxc_getid              ! Return identifer of a XC functional from its name
 55  public :: libpaw_libxc_family_from_id     ! Retrieve family of a XC functional from its id
 56  public :: libpaw_libxc_ixc                ! The value of ixc used to initialize the XC functionals
 57  public :: libpaw_libxc_getvxc             ! Return XC potential and energy, from input density
 58  public :: libpaw_libxc_isgga              ! Return TRUE if the XC functional is GGA or meta-GGA
 59  public :: libpaw_libxc_ismgga             ! Return TRUE if the XC functional is meta-GGA
 60  public :: libpaw_libxc_is_hybrid          ! Return TRUE if the XC functional is hybrid (GGA or meta-GGA)
 61  public :: libpaw_libxc_has_kxc            ! Return TRUE if Kxc (3rd der) is available for the XC functional
 62  public :: libpaw_libxc_nspin              ! The number of spin components for the XC functionals
 63  public :: libpaw_libxc_get_hybridparams   ! Retrieve parameter(s) of a hybrid functional
 64  public :: libpaw_libxc_set_hybridparams   ! Change parameter(s) of a hybrid functional
 65  public :: libpaw_libxc_gga_from_hybrid    ! Return the id of the XC-GGA used for the hybrid
 66 
 67 !Private functions
 68  private :: libpaw_libxc_constants_load    ! Load libXC constants from C headers
 69  private :: libpaw_libxc_set_tb09          ! Compute c parameter for Tran-Blaha 2009 functional
 70  private :: char_f_to_c                    ! Convert a string from Fortran to C
 71  private :: char_c_to_f                    ! Convert a string from C to Fortran
 72 
 73 !Public constants (use libpaw_libxc_constants_load to init them)
 74  integer,public,save :: LIBPAW_XC_FAMILY_UNKNOWN       = -1
 75  integer,public,save :: LIBPAW_XC_FAMILY_LDA           =  1
 76  integer,public,save :: LIBPAW_XC_FAMILY_GGA           =  2
 77  integer,public,save :: LIBPAW_XC_FAMILY_MGGA          =  4
 78  integer,public,save :: LIBPAW_XC_FAMILY_LCA           =  8
 79  integer,public,save :: LIBPAW_XC_FAMILY_OEP           = 16
 80  integer,public,save :: LIBPAW_XC_FAMILY_HYB_GGA       = 32
 81  integer,public,save :: LIBPAW_XC_FAMILY_HYB_MGGA      = 64
 82  integer,public,save :: LIBPAW_XC_FLAGS_HAVE_EXC       =  1
 83  integer,public,save :: LIBPAW_XC_FLAGS_HAVE_VXC       =  2
 84  integer,public,save :: LIBPAW_XC_FLAGS_HAVE_FXC       =  4
 85  integer,public,save :: LIBPAW_XC_FLAGS_HAVE_KXC       =  8
 86  integer,public,save :: LIBPAW_XC_FLAGS_HAVE_LXC       = 16
 87  integer,public,save :: LIBPAW_XC_EXCHANGE             =  0
 88  integer,public,save :: LIBPAW_XC_CORRELATION          =  1
 89  integer,public,save :: LIBPAW_XC_EXCHANGE_CORRELATION =  2
 90  integer,public,save :: LIBPAW_XC_KINETIC              =  3
 91  integer,public,save :: LIBPAW_XC_SINGLE_PRECISION     =  0
 92  logical,private,save :: libpaw_xc_constants_initialized=.false.
 93 
 94 !XC functional public type
 95  type,public :: libpaw_libxc_type
 96    integer  :: id              ! identifier
 97    integer  :: family          ! LDA, GGA, etc.
 98    integer  :: kind            ! EXCHANGE, CORRELATION, etc.
 99    integer  :: nspin           ! # of spin components
100    integer  :: abi_ixc         ! Abinit IXC id for this functional
101    logical  :: has_exc         ! TRUE is exc is available for the functional
102    logical  :: has_vxc         ! TRUE is vxc is available for the functional
103    logical  :: has_fxc         ! TRUE is fxc is available for the functional
104    logical  :: has_kxc         ! TRUE is kxc is available for the functional
105    real(dp) :: hyb_mixing      ! Hybrid functional: mixing factor of Fock contribution (default=0)
106    real(dp) :: hyb_mixing_sr   ! Hybrid functional: mixing factor of SR Fock contribution (default=0)
107    real(dp) :: hyb_range       ! Range (for separation) for a hybrid functional (default=0)
108 #ifdef LIBPAW_ISO_C_BINDING
109    type(C_PTR),pointer :: conf => null() ! C pointer to the functional itself
110 #endif
111  end type libpaw_libxc_type
112 
113 !----------------------------------------------------------------------
114 
115 !Private global XC functional
116  type(libpaw_libxc_type),target,save :: paw_xc_global(2)
117 
118 !----------------------------------------------------------------------
119 
120 !Interfaces for C bindings
121 #ifdef LIBPAW_ISO_C_BINDING
122  interface
123    integer(C_INT) function xc_func_init(xc_func,functional,nspin) bind(C,name="xc_func_init")
124      use iso_c_binding, only : C_INT,C_PTR
125      integer(C_INT),value :: functional,nspin
126      type(C_PTR) :: xc_func
127    end function xc_func_init
128  end interface
129 !
130  interface
131    subroutine xc_func_end(xc_func) bind(C,name="xc_func_end")
132      use iso_c_binding, only : C_PTR
133      type(C_PTR) :: xc_func
134    end subroutine xc_func_end
135  end interface
136 !
137  interface
138    integer(C_INT) function xc_functional_get_number(name) &
139 &                          bind(C,name="xc_functional_get_number")
140      use iso_c_binding, only : C_INT,C_PTR
141      type(C_PTR),value :: name
142    end function xc_functional_get_number
143  end interface
144 !
145  interface
146    type(C_PTR) function xc_functional_get_name(number) &
147 &                       bind(C,name="xc_functional_get_name")
148      use iso_c_binding, only : C_INT,C_PTR
149      integer(C_INT),value :: number
150    end function xc_functional_get_name
151  end interface
152 !
153  interface
154    integer(C_INT) function xc_family_from_id(id,family,number) &
155 &                          bind(C,name="xc_family_from_id")
156      use iso_c_binding, only : C_INT,C_PTR
157      integer(C_INT),value :: id
158      type(C_PTR),value :: family,number
159    end function xc_family_from_id
160  end interface
161 !
162  interface
163    subroutine xc_hyb_cam_coef(xc_func,omega,alpha,beta) &
164 &             bind(C,name="xc_hyb_cam_coef")
165      use iso_c_binding, only : C_DOUBLE,C_PTR
166      real(C_DOUBLE) :: omega,alpha,beta
167      type(C_PTR) :: xc_func
168    end subroutine xc_hyb_cam_coef
169  end interface
170 !
171  interface
172    subroutine xc_lda(xc_func,np,rho,zk,vrho,v2rho2,v3rho3) &
173 &             bind(C,name="xc_lda")
174      use iso_c_binding, only : C_INT,C_PTR
175      integer(C_INT),value :: np
176      type(C_PTR),value :: rho,zk,vrho,v2rho2,v3rho3
177      type(C_PTR) :: xc_func
178    end subroutine xc_lda
179  end interface
180 !
181  interface
182    subroutine xc_gga(xc_func,np,rho,sigma,zk,vrho,vsigma, &
183 &             v2rho2,v2rhosigma,v2sigma2,v3rho3,v3rho2sigma,v3rhosigma2,v3sigma3) &
184 &             bind(C,name="xc_gga")
185      use iso_c_binding, only : C_INT,C_PTR
186      integer(C_INT),value :: np
187      type(C_PTR),value :: rho,sigma,zk,vrho,vsigma,v2rho2,v2rhosigma,v2sigma2, &
188 &                         v3rho3,v3rho2sigma,v3rhosigma2,v3sigma3
189      type(C_PTR) :: xc_func
190    end subroutine xc_gga
191  end interface
192 !
193  interface
194    subroutine xc_mgga(xc_func,np,rho,sigma,lapl,tau,zk,vrho,vsigma,vlapl,vtau, &
195 &             v2rho2,v2sigma2,v2lapl2,v2tau2,v2rhosigma,v2rholapl,v2rhotau, &
196 &             v2sigmalapl,v2sigmatau,v2lapltau) &
197 &             bind(C,name="xc_mgga")
198      use iso_c_binding, only : C_INT,C_PTR
199      integer(C_INT),value :: np
200      type(C_PTR),value :: rho,sigma,lapl,tau,zk,vrho,vsigma,vlapl,vtau, &
201 &                         v2rho2,v2sigma2,v2lapl2,v2tau2,v2rhosigma,v2rholapl,v2rhotau, &
202 &                         v2sigmalapl,v2sigmatau,v2lapltau
203      type(C_PTR) :: xc_func
204    end subroutine xc_mgga
205  end interface
206 !
207  interface
208    subroutine xc_hyb_gga_xc_pbeh_set_params(xc_func,alpha) &
209 &             bind(C,name="xc_hyb_gga_xc_pbeh_set_params")
210      use iso_c_binding, only : C_DOUBLE,C_PTR
211      real(C_DOUBLE),value :: alpha
212      type(C_PTR) :: xc_func
213    end subroutine xc_hyb_gga_xc_pbeh_set_params
214  end interface
215 !
216  interface
217    subroutine xc_hyb_gga_xc_hse_set_params(xc_func,alpha,omega) &
218 &             bind(C,name="xc_hyb_gga_xc_hse_set_params")
219      use iso_c_binding, only : C_DOUBLE,C_PTR
220      real(C_DOUBLE),value :: alpha, omega
221      type(C_PTR) :: xc_func
222    end subroutine xc_hyb_gga_xc_hse_set_params
223  end interface
224 !
225  interface
226    subroutine xc_lda_c_xalpha_set_params(xc_func,alpha) &
227 &             bind(C,name="xc_lda_c_xalpha_set_params")
228      use iso_c_binding, only : C_DOUBLE,C_PTR
229      real(C_DOUBLE),value :: alpha
230      type(C_PTR) :: xc_func
231    end subroutine xc_lda_c_xalpha_set_params
232  end interface
233 !
234  interface
235    subroutine xc_mgga_x_tb09_set_params(xc_func,c) &
236 &             bind(C,name="xc_mgga_x_tb09_set_params")
237      use iso_c_binding, only : C_DOUBLE,C_PTR
238      real(C_DOUBLE),value :: c
239      type(C_PTR) :: xc_func
240    end subroutine xc_mgga_x_tb09_set_params
241  end interface
242 !
243  interface
244    subroutine libpaw_xc_get_singleprecision_constant(xc_cst_singleprecision) &
245 &             bind(C,name="libpaw_xc_get_singleprecision_constant")
246      use iso_c_binding, only : C_INT
247      integer(C_INT) :: xc_cst_singleprecision
248    end subroutine libpaw_xc_get_singleprecision_constant
249  end interface
250 !
251  interface
252    subroutine libpaw_xc_get_family_constants(xc_cst_unknown,xc_cst_lda,xc_cst_gga, &
253 &             xc_cst_mgga,xc_cst_lca,xc_cst_oep,xc_cst_hyb_gga,xc_cst_hyb_mgga) &
254 &             bind(C,name="libpaw_xc_get_family_constants")
255      use iso_c_binding, only : C_INT
256      integer(C_INT) :: xc_cst_unknown,xc_cst_lda,xc_cst_gga,xc_cst_mgga, &
257 &                      xc_cst_lca,xc_cst_oep,xc_cst_hyb_gga,xc_cst_hyb_mgga
258    end subroutine libpaw_xc_get_family_constants
259  end interface
260 !
261  interface
262    subroutine libpaw_xc_get_flags_constants(xc_cst_flags_have_exc,xc_cst_flags_have_vxc, &
263               xc_cst_flags_have_fxc,xc_cst_flags_have_kxc,xc_cst_flags_have_lxc) &
264 &             bind(C,name="libpaw_xc_get_flags_constants")
265      use iso_c_binding, only : C_INT
266      integer(C_INT) :: xc_cst_flags_have_exc,xc_cst_flags_have_vxc,xc_cst_flags_have_fxc, &
267 &                      xc_cst_flags_have_kxc,xc_cst_flags_have_lxc
268    end subroutine libpaw_xc_get_flags_constants
269  end interface
270 !
271  interface
272    subroutine libpaw_xc_get_kind_constants(xc_cst_exchange,xc_cst_correlation, &
273 &             xc_cst_exchange_correlation,xc_cst_kinetic) &
274 &             bind(C,name="libpaw_xc_get_kind_constants")
275      use iso_c_binding, only : C_INT
276      integer(C_INT) :: xc_cst_exchange,xc_cst_correlation, &
277 &                      xc_cst_exchange_correlation,xc_cst_kinetic
278    end subroutine libpaw_xc_get_kind_constants
279  end interface
280 !
281  interface
282    type(C_PTR) function libpaw_xc_func_type_malloc() &
283 &                       bind(C,name="libpaw_xc_func_type_malloc")
284      use iso_c_binding, only : C_PTR
285    end function libpaw_xc_func_type_malloc
286  end interface
287 !
288  interface
289    subroutine libpaw_xc_func_type_free(xc_func) &
290 &             bind(C,name="libpaw_xc_func_type_free")
291      use iso_c_binding, only : C_PTR
292      type(C_PTR) :: xc_func
293    end subroutine libpaw_xc_func_type_free
294  end interface
295 !
296  interface
297    type(C_PTR) function libpaw_xc_get_info_name(xc_func) &
298 &                       bind(C,name="libpaw_xc_get_info_name")
299      use iso_c_binding, only : C_PTR
300      type(C_PTR) :: xc_func
301    end function libpaw_xc_get_info_name
302  end interface
303 !
304  interface
305    type(C_PTR) function libpaw_xc_get_info_refs(xc_func,iref) &
306 &                       bind(C,name="libpaw_xc_get_info_refs")
307      use iso_c_binding, only : C_INT,C_PTR
308      type(C_PTR) :: xc_func
309      integer(C_INT) :: iref
310    end function libpaw_xc_get_info_refs
311  end interface
312 !
313  interface
314    integer(C_INT) function libpaw_xc_get_info_flags(xc_func) &
315 &                          bind(C,name="libpaw_xc_get_info_flags")
316      use iso_c_binding, only : C_INT,C_PTR
317      type(C_PTR) :: xc_func
318    end function libpaw_xc_get_info_flags
319  end interface
320 !
321  interface
322    integer(C_INT) function libpaw_xc_get_info_kind(xc_func) &
323 &                          bind(C,name="libpaw_xc_get_info_kind")
324      use iso_c_binding, only : C_INT,C_PTR
325      type(C_PTR) :: xc_func
326    end function libpaw_xc_get_info_kind
327  end interface
328 #endif
329 
330 contains

libpaw_libxc/libpaw_libxc_set_hybridparams [ Functions ]

[ Top ] [ Functions ]

NAME

  libpaw_libxc_set_hybridparams

FUNCTION

  Set the parameters of an hybrid functional (mixing coefficient(s) and range separation)

INPUTS

 [hyb_mixing]       = mixing factor of Fock contribution
 [hyb_mixing_sr]    = mixing factor of short-range Fock contribution
 [hyb_range]        = Range (for separation)
 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

OUTPUT

PARENTS

CHILDREN

SOURCE

1588 subroutine libpaw_libxc_set_hybridparams(hyb_mixing,hyb_mixing_sr,hyb_range,xc_functionals)
1589 
1590 
1591 !This section has been created automatically by the script Abilint (TD).
1592 !Do not modify the following lines by hand.
1593 #undef ABI_FUNC
1594 #define ABI_FUNC 'libpaw_libxc_set_hybridparams'
1595 !End of the abilint section
1596 
1597  implicit none
1598 
1599 !Arguments ------------------------------------
1600  real(dp),intent(in),optional :: hyb_mixing,hyb_mixing_sr,hyb_range
1601  type(libpaw_libxc_type),intent(in),optional,target :: xc_functionals(2)
1602 !Local variables -------------------------------
1603  integer :: ii
1604  logical :: is_pbe0,is_hse
1605  character(len=500) :: msg
1606 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
1607  real(C_DOUBLE) :: alpha_c,beta_c,omega_c
1608 #endif
1609  type(libpaw_libxc_type),pointer :: xc_func
1610 
1611 ! *************************************************************************
1612 
1613  is_pbe0=.false.
1614  is_hse =.false.
1615 
1616  do ii = 1, 2
1617 
1618 !  Select XC functional
1619    if (present(xc_functionals)) then
1620      xc_func => xc_functionals(ii)
1621    else
1622      xc_func => paw_xc_global(ii)
1623    end if
1624 
1625 !  Doesnt work with all hybrid functionals
1626    if (is_pbe0.or.is_hse) then
1627      msg='Invalid XC functional: contains 2 hybrid exchange functionals!'
1628      MSG_ERROR(msg)
1629    end if
1630    is_pbe0=(xc_func%id==libpaw_libxc_getid('HYB_GGA_XC_PBEH'))
1631    is_hse=((xc_func%id==libpaw_libxc_getid('HYB_GGA_XC_HSE03')).or.&
1632 &          (xc_func%id==libpaw_libxc_getid('HYB_GGA_XC_HSE06')))
1633    if ((.not.is_pbe0).and.(.not.is_hse)) cycle
1634 
1635 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
1636 !  First retrieve current values of parameters
1637    call xc_hyb_cam_coef(xc_func%conf,omega_c,alpha_c,beta_c)
1638 
1639 !  New values for parameters
1640    if (present(hyb_mixing)) alpha_c=real(hyb_mixing,kind=C_DOUBLE)
1641    if (present(hyb_mixing_sr)) beta_c=real(hyb_mixing_sr,kind=C_DOUBLE)
1642    if (present(hyb_range)) omega_c=real(hyb_range,kind=C_DOUBLE)
1643 
1644 !  PBE0: set parameters
1645    if (is_pbe0) then
1646        call xc_hyb_gga_xc_pbeh_set_params(xc_func%conf,alpha_c)
1647    end if
1648 
1649 !  HSE: set parameters
1650    if (is_hse) then
1651      call xc_hyb_gga_xc_hse_set_params(xc_func%conf,beta_c,omega_c)
1652    end if
1653 #else
1654 !  This is to avoid unused arguments
1655    if(.false. .and. present(hyb_mixing) .and. present(hyb_mixing_sr) .and. present(hyb_range))then
1656      msg='One should not be here'
1657    endif
1658 #endif
1659 
1660  end do
1661 
1662  if ((.not.is_pbe0).and.(.not.is_hse)) then
1663    msg='Invalid XC functional: not able to change parameters for this functional!'
1664    MSG_WARNING(msg)
1665  end if
1666 
1667 end subroutine libpaw_libxc_set_hybridparams

m_libpaw_libxc_funcs/char_c_to_f [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  char_c_to_f

FUNCTION

 Helper function to convert a C string to a Fortran string
 Based on a routine by Joseph M. Krahn

INPUTS

  c_string=C string

OUTPUT

  f_string=Fortran string

PARENTS

      m_libpaw_libxc

CHILDREN

SOURCE

1967 #if defined LIBPAW_ISO_C_BINDING
1968 subroutine char_c_to_f(c_string,f_string)
1969 !Arguments ------------------------------------
1970 
1971 !This section has been created automatically by the script Abilint (TD).
1972 !Do not modify the following lines by hand.
1973 #undef ABI_FUNC
1974 #define ABI_FUNC 'char_c_to_f'
1975 !End of the abilint section
1976 
1977  character(kind=C_CHAR,len=1),intent(in) :: c_string(*)
1978  character(len=*),intent(out) :: f_string
1979 !Local variables -------------------------------
1980  integer :: ii
1981 !! *************************************************************************
1982  ii=1
1983  do while(c_string(ii)/=C_NULL_CHAR.and.ii<=len(f_string))
1984    f_string(ii:ii)=c_string(ii) ; ii=ii+1
1985  end do
1986  if (ii<len(f_string)) f_string(ii:)=' '
1987  end subroutine char_c_to_f
1988 #endif

m_libpaw_libxc_funcs/char_f_to_c [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  char_f_to_c

FUNCTION

 Helper function to convert a Fortran string to a C string
 Based on a routine by Joseph M. Krahn

INPUTS

  f_string=Fortran string

OUTPUT

  c_string=C string

SOURCE

1920 #if defined LIBPAW_ISO_C_BINDING
1921 function char_f_to_c(f_string) result(c_string)
1922 !Arguments ------------------------------------
1923 
1924 !This section has been created automatically by the script Abilint (TD).
1925 !Do not modify the following lines by hand.
1926 #undef ABI_FUNC
1927 #define ABI_FUNC 'char_f_to_c'
1928 !End of the abilint section
1929 
1930  character(len=*),intent(in) :: f_string
1931  character(kind=C_CHAR,len=1) :: c_string(len_trim(f_string)+1)
1932 !Local variables -------------------------------
1933  integer :: ii,strlen
1934 !! *************************************************************************
1935  strlen=len_trim(f_string)
1936  forall(ii=1:strlen)
1937    c_string(ii)=f_string(ii:ii)
1938  end forall
1939  c_string(strlen+1)=C_NULL_CHAR
1940  end function char_f_to_c
1941 #endif

m_libpaw_libxc_funcs/libpaw_libxc_check [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_check

FUNCTION

  Check if the code has been compiled with an usable version of libXC

INPUTS

 [stop_if_error]=optional flag; if TRUE the code stops if libXC is not correctly used

SOURCE

410  function libpaw_libxc_check(stop_if_error)
411 
412 
413 !This section has been created automatically by the script Abilint (TD).
414 !Do not modify the following lines by hand.
415 #undef ABI_FUNC
416 #define ABI_FUNC 'libpaw_libxc_check'
417 !End of the abilint section
418 
419  implicit none
420 
421 !Arguments ------------------------------------
422  logical :: libpaw_libxc_check
423  logical,intent(in),optional :: stop_if_error
424 !Local variables-------------------------------
425  character(len=100) :: msg
426 
427 ! *************************************************************************
428 
429 #if defined LIBPAW_HAVE_LIBXC
430 #if defined FC_G95
431  libpaw_libxc_check=.false.
432  msg='LibXC cannot be used with G95 Fortran compiler!'
433 #endif
434 #if defined LIBPAW_ISO_C_BINDING
435  if (.not.libpaw_xc_constants_initialized) call libpaw_libxc_constants_load()
436  if (LIBPAW_XC_SINGLE_PRECISION==1) then
437    libpaw_libxc_check=.false.
438    msg='LibXC should be compiled with double precision!'
439  end if
440 #else
441  libpaw_libxc_check=.false.
442  msg='LibXC cannot be used without ISO_C_BINDING support by the Fortran compiler!'
443 #endif
444 #else
445  libpaw_libxc_check=.false.
446  msg='LibPAW was not compiled with LibXC support.'
447 #endif
448 
449  if (present(stop_if_error)) then
450    if (stop_if_error.and.trim(msg)/="") then
451      MSG_ERROR(msg)
452    end if
453  end if
454 
455  end function libpaw_libxc_check

m_libpaw_libxc_funcs/libpaw_libxc_constants_load [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_constants_load

FUNCTION

  Load libXC constants from C headers

PARENTS

      m_libpaw_libxc

CHILDREN

SOURCE

349  subroutine libpaw_libxc_constants_load()
350 
351 
352 !This section has been created automatically by the script Abilint (TD).
353 !Do not modify the following lines by hand.
354 #undef ABI_FUNC
355 #define ABI_FUNC 'libpaw_libxc_constants_load'
356 !End of the abilint section
357 
358  implicit none
359 
360 !Local variables-------------------------------
361 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
362  integer(C_INT) :: i1,i2,i3,i4,i5,i6,i7,i8
363 #endif
364 
365 ! *************************************************************************
366 
367 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
368   call libpaw_xc_get_singleprecision_constant(i1)
369   LIBPAW_XC_SINGLE_PRECISION     = int(i1)
370   call libpaw_xc_get_family_constants(i1,i2,i3,i4,i5,i6,i7,i8)
371   LIBPAW_XC_FAMILY_UNKNOWN       = int(i1)
372   LIBPAW_XC_FAMILY_LDA           = int(i2)
373   LIBPAW_XC_FAMILY_GGA           = int(i3)
374   LIBPAW_XC_FAMILY_MGGA          = int(i4)
375   LIBPAW_XC_FAMILY_LCA           = int(i5)
376   LIBPAW_XC_FAMILY_OEP           = int(i6)
377   LIBPAW_XC_FAMILY_HYB_GGA       = int(i7)
378   LIBPAW_XC_FAMILY_HYB_MGGA      = int(i8)
379   call libpaw_xc_get_flags_constants(i1,i2,i3,i4,i5)
380   LIBPAW_XC_FLAGS_HAVE_EXC       = int(i1)
381   LIBPAW_XC_FLAGS_HAVE_VXC       = int(i2)
382   LIBPAW_XC_FLAGS_HAVE_FXC       = int(i3)
383   LIBPAW_XC_FLAGS_HAVE_KXC       = int(i4)
384   LIBPAW_XC_FLAGS_HAVE_LXC       = int(i5)
385   call libpaw_xc_get_kind_constants(i1,i2,i3,i4)
386   LIBPAW_XC_EXCHANGE             = int(i1)
387   LIBPAW_XC_CORRELATION          = int(i2)
388   LIBPAW_XC_EXCHANGE_CORRELATION = int(i3)
389   LIBPAW_XC_KINETIC              = int(i4)
390  libpaw_xc_constants_initialized=.true.
391 #endif
392 
393  end subroutine libpaw_libxc_constants_load

m_libpaw_libxc_funcs/libpaw_libxc_end [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_end

FUNCTION

  End usage of LibXC functional. Call LibXC end function,
  and deallocate module contents.

SIDE EFFECTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

PARENTS

CHILDREN

SOURCE

646  subroutine libpaw_libxc_end(xc_functionals)
647 
648 
649 !This section has been created automatically by the script Abilint (TD).
650 !Do not modify the following lines by hand.
651 #undef ABI_FUNC
652 #define ABI_FUNC 'libpaw_libxc_end'
653 !End of the abilint section
654 
655  implicit none
656 
657 !Arguments ------------------------------------
658  type(libpaw_libxc_type),intent(inout),optional,target :: xc_functionals(2)
659 !Local variables-------------------------------
660  integer :: ii
661  type(libpaw_libxc_type),pointer :: xc_func
662 
663 ! *************************************************************************
664 
665  do ii = 1,2
666 
667 !  Select XC functional
668    if (present(xc_functionals)) then
669      xc_func => xc_functionals(ii)
670    else
671      xc_func => paw_xc_global(ii)
672    end if
673 
674    if (xc_func%id == 0) cycle
675    xc_func%id=-1
676    xc_func%family=-1
677    xc_func%kind=-1
678    xc_func%nspin=1
679    xc_func%abi_ixc=huge(0)
680    xc_func%has_exc=.false.
681    xc_func%has_vxc=.false.
682    xc_func%has_fxc=.false.
683    xc_func%has_kxc=.false.
684    xc_func%hyb_mixing=zero
685    xc_func%hyb_mixing_sr=zero
686    xc_func%hyb_range=zero
687    if (associated(xc_func%conf)) then
688 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
689      call xc_func_end(xc_func%conf)
690      call libpaw_xc_func_type_free(c_loc(xc_func%conf))
691 #endif
692    end if
693 
694  end do
695 
696  end subroutine libpaw_libxc_end

m_libpaw_libxc_funcs/libpaw_libxc_family_from_id [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_family_from_id

FUNCTION

  Return family of a XC functional from its id

INPUTS

  xcid= id of a LibXC functional

SOURCE

783  function libpaw_libxc_family_from_id(xcid)
784 
785 
786 !This section has been created automatically by the script Abilint (TD).
787 !Do not modify the following lines by hand.
788 #undef ABI_FUNC
789 #define ABI_FUNC 'libpaw_libxc_family_from_id'
790 !End of the abilint section
791 
792  implicit none
793 
794 !Arguments ------------------------------------
795  integer :: libpaw_libxc_family_from_id
796  integer,intent(in) :: xcid
797 !Local variables-------------------------------
798 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
799  integer(C_INT) :: xcid_c
800 #endif
801 
802 ! *************************************************************************
803 
804 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
805  xcid_c=int(xcid,kind=C_INT)
806  libpaw_libxc_family_from_id=int(xc_family_from_id(xcid_c,C_NULL_PTR,C_NULL_PTR))
807 #else
808  libpaw_libxc_family_from_id=-1
809  if (.false.) write(std_out,*) xcid
810 #endif
811 
812 end function libpaw_libxc_family_from_id

m_libpaw_libxc_funcs/libpaw_libxc_fullname [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_fullname

FUNCTION

  Return full name of the XC functional

INPUTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

SOURCE

714  function libpaw_libxc_fullname(xc_functionals)
715 
716 
717 !This section has been created automatically by the script Abilint (TD).
718 !Do not modify the following lines by hand.
719 #undef ABI_FUNC
720 #define ABI_FUNC 'libpaw_libxc_fullname'
721 !End of the abilint section
722 
723  implicit none
724 
725 !Arguments ------------------------------------
726  character(len=100) :: libpaw_libxc_fullname
727  type(libpaw_libxc_type),intent(in),optional,target :: xc_functionals(2)
728 !Local variables-------------------------------
729  type(libpaw_libxc_type),pointer :: xc_funcs(:)
730 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
731  character(len=100) :: xcname
732  character(kind=C_CHAR,len=1),pointer :: strg_c
733 #endif
734 
735 ! *************************************************************************
736 
737  libpaw_libxc_fullname='No XC functional'
738 
739  if (present(xc_functionals)) then
740    xc_funcs => xc_functionals
741  else
742    xc_funcs => paw_xc_global
743  end if
744 
745 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
746  if (xc_funcs(1)%id == 0) then
747    if (xc_funcs(2)%id /= 0) then
748      call c_f_pointer(xc_functional_get_name(xc_funcs(2)%id),strg_c)
749      call char_c_to_f(strg_c,libpaw_libxc_fullname)
750    end if
751  else if (xc_funcs(2)%id == 0) then
752    if (xc_funcs(1)%id /= 0) then
753      call c_f_pointer(xc_functional_get_name(xc_funcs(1)%id),strg_c)
754      call char_c_to_f(strg_c,libpaw_libxc_fullname)
755    end if
756  else
757    call c_f_pointer(xc_functional_get_name(xc_funcs(1)%id),strg_c)
758    call char_c_to_f(strg_c,libpaw_libxc_fullname)
759    call c_f_pointer(xc_functional_get_name(xc_funcs(2)%id),strg_c)
760    call char_c_to_f(strg_c,xcname)
761    libpaw_libxc_fullname=trim(libpaw_libxc_fullname)//'+'//trim(xcname)
762  end if
763  libpaw_libxc_fullname=trim(libpaw_libxc_fullname)
764 #endif
765 
766 end function libpaw_libxc_fullname

m_libpaw_libxc_funcs/libpaw_libxc_get_hybridparams [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_get_hybridparams

FUNCTION

  Returns the parameters of an hybrid functional (mixing coefficient(s) and range separation)

INPUTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

OUTPUT

  [hyb_mixing]  = mixing factor of Fock contribution
  [hyb_mixing_sr]= mixing factor of short-range Fock contribution
  [hyb_range]    = Range (for separation)

PARENTS

CHILDREN

SOURCE

1489 subroutine libpaw_libxc_get_hybridparams(hyb_mixing,hyb_mixing_sr,hyb_range,xc_functionals)
1490 
1491 
1492 !This section has been created automatically by the script Abilint (TD).
1493 !Do not modify the following lines by hand.
1494 #undef ABI_FUNC
1495 #define ABI_FUNC 'libpaw_libxc_get_hybridparams'
1496 !End of the abilint section
1497 
1498  implicit none
1499 
1500 !Arguments ------------------------------------
1501  real(dp),intent(out),optional :: hyb_mixing,hyb_mixing_sr,hyb_range
1502  type(libpaw_libxc_type),intent(in),optional,target :: xc_functionals(2)
1503 !Local variables -------------------------------
1504  integer :: ii
1505  character(len=500) :: msg
1506  type(libpaw_libxc_type),pointer :: xc_func
1507 
1508 ! *************************************************************************
1509 
1510  if (present(hyb_mixing   )) hyb_mixing   =zero
1511  if (present(hyb_mixing_sr)) hyb_mixing_sr=zero
1512  if (present(hyb_range    )) hyb_range    =zero
1513 
1514  do ii = 1, 2
1515 
1516 !  Select XC functional
1517    if (present(xc_functionals)) then
1518      xc_func => xc_functionals(ii)
1519    else
1520      xc_func => paw_xc_global(ii)
1521    end if
1522 
1523 !  Mixing coefficient for the Fock contribution
1524    if (present(hyb_mixing)) then
1525      if (abs(xc_func%hyb_mixing) > tol8) then
1526        if (abs(hyb_mixing) <= tol8) then
1527          hyb_mixing=xc_func%hyb_mixing
1528        else
1529          msg='Invalid XC functional: contains 2 hybrid exchange functionals!'
1530          MSG_ERROR(msg)
1531        end if
1532      end if
1533    end if
1534 
1535 !  Mixing coefficient for the short-range Fock contribution
1536    if (present(hyb_mixing_sr)) then
1537      if (abs(xc_func%hyb_mixing_sr) > tol8) then
1538        if (abs(hyb_mixing_sr) <= tol8) then
1539          hyb_mixing_sr=xc_func%hyb_mixing_sr
1540        else
1541          msg='Invalid XC functional: contains 2 hybrid exchange functionals!'
1542          MSG_ERROR(msg)
1543        end if
1544      end if
1545    end if
1546 
1547 !  Range separation
1548    if (present(hyb_range)) then
1549      if (abs(xc_func%hyb_range) > tol8) then
1550        if (abs(hyb_range) <= tol8) then
1551          hyb_range=xc_func%hyb_range
1552        else
1553          msg='Invalid XC functional: contains 2 hybrid exchange functionals!'
1554          MSG_ERROR(msg)
1555        end if
1556      end if
1557    end if
1558 
1559  end do
1560 
1561 end subroutine libpaw_libxc_get_hybridparams

m_libpaw_libxc_funcs/libpaw_libxc_getid [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_getid

FUNCTION

  Return identifer of a XC functional from its name
  Return -1 if undefined

INPUTS

  xcname= string containing the name of a XC functional

SOURCE

830  function libpaw_libxc_getid(xcname)
831 
832 
833 !This section has been created automatically by the script Abilint (TD).
834 !Do not modify the following lines by hand.
835 #undef ABI_FUNC
836 #define ABI_FUNC 'libpaw_libxc_getid'
837 !End of the abilint section
838 
839  implicit none
840 
841 !Arguments ------------------------------------
842  integer :: libpaw_libxc_getid
843  character(len=*),intent(in) :: xcname
844 !Local variables-------------------------------
845 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
846  character(len=256) :: str
847  character(kind=C_CHAR,len=1),target :: name_c(len_trim(xcname)+1)
848  character(kind=C_CHAR,len=1),target :: name_c_xc(len_trim(xcname)-2)
849  type(C_PTR) :: name_c_ptr
850 #endif
851 
852 ! *************************************************************************
853 
854 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
855  str=trim(xcname)
856  if (xcname(1:3)=="XC_".or.xcname(1:3)=="xc_") then
857    str=xcname(4:);name_c_xc=char_f_to_c(str)
858    name_c_ptr=c_loc(name_c_xc)
859  else
860    name_c=char_f_to_c(str)
861    name_c_ptr=c_loc(name_c)
862  end if
863  libpaw_libxc_getid=int(xc_functional_get_number(name_c_ptr))
864 #else
865  libpaw_libxc_getid=-1
866  if (.false.) write(std_out,*) xcname
867 #endif
868 
869 end function libpaw_libxc_getid

m_libpaw_libxc_funcs/libpaw_libxc_getvxc [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_getvxc

FUNCTION

  Return XC potential and energy, from input density (gradient etc...)

INPUTS

 ndvxc=size of dvxc
 nd2vxc=size of d2vxc
 npts=number of of points for the density
 nspden=number of spin-density components
 order=requested order of derivation
 rho(npts,nspden)=electronic density
 grho2(npts,nspden)=squared gradient of the density
 lrho(npts,nspden)=laplacian of the density
 tau(npts,nspden)= kinetic energy density
 xc_tb09_c=input value for the TB09 C parameter;
           if set to 99, C is computed from rho and grho2

OUTPUT

 exc(npts)=XC energy density
 vxc(npts,nspden)=derivative of the energy density wrt to the density
 vxclrho(npts,nspden)=derivative of the energy density wrt to the density laplacian
 vxctau(npts,nspden)=derivative of the energy density wrt to the kinetic energy density
 dvxc(npts,ndvxc)=2nd derivative of the energy density wrt to the density
 vxcgr(npts,3)=2nd derivative of the energy density wrt to the gradient
               2nd derivative of the energy density wrt to the density and the gradient
 d2vxc(npts,nd2vxc)=3rd derivative of the energy density wrt to the density

SIDE EFFECTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

PARENTS

CHILDREN

SOURCE

1185  subroutine libpaw_libxc_getvxc(ndvxc,nd2vxc,npts,nspden,order,rho,exc,vxc,&
1186 &           grho2,vxcgr,lrho,vxclrho,tau,vxctau,dvxc,d2vxc,xc_tb09_c,xc_functionals) ! Optional arguments
1187 
1188 
1189 !This section has been created automatically by the script Abilint (TD).
1190 !Do not modify the following lines by hand.
1191 #undef ABI_FUNC
1192 #define ABI_FUNC 'libpaw_libxc_getvxc'
1193 !End of the abilint section
1194 
1195  implicit none
1196 
1197 !Arguments ------------------------------------
1198  integer, intent(in) :: ndvxc,nd2vxc,npts,nspden,order
1199  real(dp),intent(in)  :: rho(npts,nspden)
1200  real(dp),intent(out) :: vxc(npts,nspden),exc(npts)
1201  real(dp),intent(in),optional :: grho2(npts,2*min(nspden,2)-1)
1202  real(dp),intent(out),optional :: vxcgr(npts,3)
1203  real(dp),intent(in),optional :: lrho(npts,nspden)
1204  real(dp),intent(out),optional :: vxclrho(npts,nspden)
1205  real(dp),intent(in),optional :: tau(npts,nspden)
1206  real(dp),intent(out),optional :: vxctau(npts,nspden)
1207  real(dp),intent(out),optional :: dvxc(npts,ndvxc)
1208  real(dp),intent(out),optional :: d2vxc(npts,nd2vxc)
1209  real(dp),intent(in),optional :: xc_tb09_c
1210  type(libpaw_libxc_type),intent(inout),optional,target :: xc_functionals(2)
1211 !Local variables -------------------------------
1212 !scalars
1213  integer  :: ii,ipts
1214  logical :: is_gga,is_mgga
1215  real(dp) :: xc_tb09_c_
1216 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
1217  type(C_PTR) :: rho_c,sigma_c,lrho_c,tau_c
1218 #endif
1219 !arrays
1220  real(dp),target :: rhotmp(nspden),sigma(3),exctmp,vxctmp(nspden),vsigma(3)
1221  real(dp),target :: v2rho2(3),v2rhosigma(6),v2sigma2(6),v3rho3(4)
1222  real(dp),target :: lrhotmp(nspden),tautmp(nspden),vlrho(nspden),vtau(nspden)
1223  type(libpaw_libxc_type),pointer :: xc_funcs(:)
1224 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
1225  type(C_PTR) :: exc_c(2),vxc_c(2),vsigma_c(2)
1226  type(C_PTR) :: v2rho2_c(2),v2rhosigma_c(2),v2sigma2_c(2)
1227  type(C_PTR) :: v3rho3_c(2),vlrho_c(2),vtau_c(2)
1228 #endif
1229 
1230 ! *************************************************************************
1231 
1232  if (.not.libpaw_xc_constants_initialized) call libpaw_libxc_constants_load()
1233 
1234 !Select XC functional(s)
1235  if (present(xc_functionals)) then
1236    xc_funcs => xc_functionals
1237  else
1238    xc_funcs => paw_xc_global
1239  end if
1240 
1241  is_gga =libpaw_libxc_isgga (xc_funcs)
1242  is_mgga=libpaw_libxc_ismgga(xc_funcs)
1243 
1244 !Inititalize all output arrays to zero
1245  exc=zero ; vxc=zero
1246  if (present(dvxc)) dvxc=zero
1247  if (present(d2vxc)) d2vxc=zero
1248  if (is_gga.or.is_mgga.and.present(vxcgr)) vxcgr=zero
1249  if (is_mgga.and.present(vxclrho)) vxclrho=zero
1250  if (is_mgga.and.present(vxctau)) vxctau=zero
1251 
1252 !Determine which XC outputs can be computed
1253 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
1254  do ii = 1,2
1255    if (xc_funcs(ii)%has_exc) then
1256      exc_c(ii)=c_loc(exctmp)
1257    else
1258      exc_c(ii)=C_NULL_PTR
1259    end if
1260    if (xc_funcs(ii)%has_vxc) then
1261      vxc_c(ii)=c_loc(vxctmp)
1262      vsigma_c(ii)=c_loc(vsigma)
1263      vlrho_c(ii)=c_loc(vlrho)
1264      vtau_c(ii)=c_loc(vtau)
1265    else
1266      vxc_c(ii)=C_NULL_PTR
1267      vsigma_c(ii)=c_NULL_PTR
1268      vlrho_c(ii)=C_NULL_PTR
1269      vtau_c(ii)=C_NULL_PTR
1270    end if
1271    if ((xc_funcs(ii)%has_fxc).and.(order**2>1)) then
1272      v2rho2_c(ii)=c_loc(v2rho2)
1273      v2sigma2_c(ii)=c_loc(v2sigma2)
1274      v2rhosigma_c(ii)=c_loc(v2rhosigma)
1275    else
1276      v2rho2_c(ii)=C_NULL_PTR
1277      v2sigma2_c(ii)=C_NULL_PTR
1278      v2rhosigma_c(ii)=C_NULL_PTR
1279    end if
1280    if ((xc_funcs(ii)%has_kxc).and.(order**2>4)) then
1281      v3rho3_c(ii)=c_loc(v3rho3)
1282    else
1283      v3rho3_c(ii)=C_NULL_PTR
1284    end if
1285  end do
1286 #endif
1287 
1288 !Initialize temporary arrays
1289 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
1290  rhotmp=zero ; rho_c=c_loc(rhotmp)
1291  if (is_gga.or.is_mgga) then
1292    sigma=zero ; sigma_c=c_loc(sigma)
1293  end if
1294  if (is_mgga) then
1295    lrhotmp=zero ; lrho_c=c_loc(lrhotmp)
1296    tautmp=zero ; tau_c=c_loc(tautmp)
1297  end if
1298 #endif
1299 
1300 !Some mGGA functionals require a special treatment
1301  if (is_mgga) then
1302    !TB09 functional requires the c parameter to be set
1303    xc_tb09_c_=99._dp;if (present(xc_tb09_c)) xc_tb09_c_=xc_tb09_c
1304    call libpaw_libxc_set_tb09(npts,nspden,rho,grho2,xc_tb09_c_,xc_funcs)
1305  end if
1306 
1307 !Loop over points
1308  do ipts=1,npts
1309 
1310 !  Convert the quantities provided to the ones needed by libxc
1311    if (nspden == 1) then
1312      ! rho_up is passed in the spin-unpolarized case, while the libxc
1313      ! expects the total density
1314      rhotmp(1:nspden) = two*rho(ipts,1:nspden)
1315    else
1316      rhotmp(1:nspden) = rho(ipts,1:nspden)
1317    end if
1318    if (is_gga.or.is_mgga) then
1319      if (nspden==1) then
1320        ! |grho_up|^2 is passed while Libxc needs |grho_tot|^2
1321        sigma(1) = four*grho2(ipts,1)
1322      else
1323        ! |grho_up|^2, |grho_dn|^2, and |grho_tot|^2 are passed
1324        ! while Libxc needs |grho_up|^2, grho_up.grho_dn, and |grho_dn|^2
1325        sigma(1) = grho2(ipts,1)
1326        sigma(2) = (grho2(ipts,3) - grho2(ipts,1) - grho2(ipts,2))/two
1327        sigma(3) = grho2(ipts,2)
1328      end if
1329    end if
1330    if (is_mgga) then
1331      if (nspden==1) then
1332        lrhotmp(1:nspden) = two*lrho(ipts,1:nspden)
1333        tautmp(1:nspden) = two*tau(ipts,1:nspden)
1334      else
1335        lrhotmp(1:nspden) = lrho(ipts,1:nspden)
1336        tautmp(1:nspden) = tau(ipts,1:nspden)
1337      end if
1338    end if
1339 
1340 !  Loop over functionals
1341    do ii = 1,2
1342      if (xc_funcs(ii)%id==0) cycle
1343 
1344 !    Get the potential (and possibly the energy)
1345 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
1346      exctmp=zero ; vxctmp=zero
1347 !    ===== LDA =====
1348      if (xc_funcs(ii)%family==LIBPAW_XC_FAMILY_LDA) then
1349        exctmp=zero ; vxctmp=zero ; v2rho2=zero ; v3rho3=zero
1350        call xc_lda(xc_funcs(ii)%conf,1,rho_c, &
1351 &                  exc_c(ii),vxc_c(ii),v2rho2_c(ii),v3rho3_c(ii))
1352 !    ===== GGA =====
1353      else if (xc_funcs(ii)%family==LIBPAW_XC_FAMILY_GGA.or. &
1354 &             xc_funcs(ii)%family==LIBPAW_XC_FAMILY_HYB_GGA) then
1355        exctmp=zero ; vxctmp=zero ; vsigma=zero
1356        v2rho2=zero ; v2sigma2=zero ; v2rhosigma=zero
1357        call xc_gga(xc_funcs(ii)%conf,1,rho_c,sigma_c, &
1358 &                  exc_c(ii),vxc_c(ii),vsigma_c(ii), &
1359 &                  v2rho2_c(ii),v2rhosigma_c(ii),v2sigma2_c(ii), &
1360 &                  C_NULL_PTR,C_NULL_PTR,C_NULL_PTR,C_NULL_PTR)
1361 !    ===== mGGA =====
1362      else if (xc_funcs(ii)%family==LIBPAW_XC_FAMILY_MGGA) then
1363        exctmp=zero ; vxctmp=zero ; vsigma=zero ; vlrho=zero ; vtau=zero
1364        call xc_mgga(xc_funcs(ii)%conf,1,rho_c,sigma_c,lrho_c,tau_c, &
1365 &                   exc_c(ii),vxc_c(ii),vsigma_c(ii),vlrho_c(ii),vtau_c(ii), &
1366 &                   C_NULL_PTR,C_NULL_PTR,C_NULL_PTR,C_NULL_PTR,C_NULL_PTR, &
1367 &                   C_NULL_PTR,C_NULL_PTR,C_NULL_PTR,C_NULL_PTR,C_NULL_PTR)
1368      end if
1369 #endif
1370 
1371      exc(ipts) = exc(ipts) + exctmp
1372      vxc(ipts,1:nspden) = vxc(ipts,1:nspden) + vxctmp(1:nspden)
1373 
1374 !    Deal with fxc and kxc
1375      if (order**2>1) then
1376 !      ----- LDA -----
1377        if (xc_funcs(ii)%family==LIBPAW_XC_FAMILY_LDA) then
1378          if (nspden==1) then
1379            if(order>=2) then
1380              dvxc(ipts,1)=dvxc(ipts,1)+v2rho2(1)
1381              if(order==3) then
1382                d2vxc(ipts,1)=d2vxc(ipts,1)+v3rho3(1)
1383              endif
1384            else
1385              dvxc(ipts,1)=dvxc(ipts,1)+v2rho2(1)
1386              dvxc(ipts,2)=dvxc(ipts,2)+v2rho2(1)
1387            endif
1388          else
1389            dvxc(ipts,1)=dvxc(ipts,1)+v2rho2(1)
1390            dvxc(ipts,2)=dvxc(ipts,2)+v2rho2(2)
1391            dvxc(ipts,3)=dvxc(ipts,3)+v2rho2(3)
1392            if(order==3) then
1393              d2vxc(ipts,1)=d2vxc(ipts,1)+v3rho3(1)
1394              d2vxc(ipts,2)=d2vxc(ipts,2)+v3rho3(2)
1395              d2vxc(ipts,3)=d2vxc(ipts,3)+v3rho3(3)
1396              d2vxc(ipts,4)=d2vxc(ipts,4)+v3rho3(4)
1397            endif
1398          endif
1399 !      ----- GGA -----
1400        else if (xc_funcs(ii)%family==LIBPAW_XC_FAMILY_GGA.or. &
1401 &               xc_funcs(ii)%family==LIBPAW_XC_FAMILY_HYB_GGA) then
1402          if (xc_funcs(ii)%kind==LIBPAW_XC_EXCHANGE) then
1403            if (nspden==1) then
1404              dvxc(ipts,1)=v2rho2(1)*two
1405              dvxc(ipts,2)=dvxc(ipts,1)
1406              dvxc(ipts,3)=two*two*vsigma(1)
1407              dvxc(ipts,4)=dvxc(ipts,3)
1408              dvxc(ipts,5)=four*two*v2rhosigma(1)
1409              dvxc(ipts,6)=dvxc(ipts,5)
1410              dvxc(ipts,7)=two*four*four*v2sigma2(1)
1411              dvxc(ipts,8)=dvxc(ipts,7)
1412            else
1413              dvxc(ipts,1)=v2rho2(1)
1414              dvxc(ipts,2)=v2rho2(3)
1415              dvxc(ipts,3)=two*vsigma(1)
1416              dvxc(ipts,4)=two*vsigma(3)
1417              dvxc(ipts,5)=two*v2rhosigma(1)
1418              dvxc(ipts,6)=two*v2rhosigma(6)
1419              dvxc(ipts,7)=four*v2sigma2(1)
1420              dvxc(ipts,8)=four*v2sigma2(6)
1421            end if
1422          else if (xc_funcs(ii)%kind==LIBPAW_XC_CORRELATION) then
1423            if (nspden==1) then
1424              dvxc(ipts,9)=v2rho2(1)
1425              dvxc(ipts,10)=dvxc(ipts,9)
1426              dvxc(ipts,11)=dvxc(ipts,9)
1427              dvxc(ipts,12)=two*vsigma(1)
1428              dvxc(ipts,13)=two*v2rhosigma(1)
1429              dvxc(ipts,14)=dvxc(ipts,13)
1430              dvxc(ipts,15)=four*v2sigma2(1)
1431            else
1432              dvxc(ipts,9)=v2rho2(1)
1433              dvxc(ipts,10)=v2rho2(2)
1434              dvxc(ipts,11)=v2rho2(3)
1435              dvxc(ipts,12)=two*vsigma(1)
1436              dvxc(ipts,13)=two*v2rhosigma(1)
1437              dvxc(ipts,14)=two*v2rhosigma(6)
1438              dvxc(ipts,15)=four*v2sigma2(1)
1439            end if
1440          end if
1441        end if
1442      end if
1443 
1444 !    Convert the quantities returned by Libxc
1445      if (is_gga.or.is_mgga) then
1446        if (nspden==1) then
1447          vxcgr(ipts,3) = vxcgr(ipts,3) + vsigma(1)*two
1448        else
1449          vxcgr(ipts,1) = vxcgr(ipts,1) + two*vsigma(1) - vsigma(2)
1450          vxcgr(ipts,2) = vxcgr(ipts,2) + two*vsigma(3) - vsigma(2)
1451          vxcgr(ipts,3) = vxcgr(ipts,3) + vsigma(2)
1452        end if
1453      end if
1454      if (is_mgga) then
1455        vxclrho(ipts,1:nspden) = vxclrho(ipts,1:nspden) + vlrho(1:nspden)
1456        vxctau(ipts,1:nspden)  = vxctau(ipts,1:nspden)  + vtau(1:nspden)
1457      end if
1458 
1459    end do ! ii
1460  end do   ! ipts
1461 
1462 end subroutine libpaw_libxc_getvxc

m_libpaw_libxc_funcs/libpaw_libxc_gga_from_hybrid [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_gga_from_hybrid

FUNCTION

  Returns a logical flag: TRUE if one can deduce, from the id of a hybrid functional,
  the id(s) of the GGA functional on which it is based.
  Optionally returns the id of the GGA functional on which the hybrid functional is based
  (2 integers defining the GGA X and C functionals).
  - If an id is provided as input argument, it is used as input id;
  - If not, the input id is taken from the optional xc_functionals datastructure;
  - If no input argument is given, the input id is taken from the global paw_xc_global datastructure.

INPUTS

 [hybrid_id]=<type(libpaw_libxc_type)>, optional : id of an input hybrid functional
 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional : XC functionals from which
                     the id(s) can to be used

OUTPUT

 [gga_id(2)]=array that contains the GGA libXC id(s)
 libpaw_libxc_gga_from_hybrid=.true. if the GGA has been found from the input id

SOURCE

1696 function libpaw_libxc_gga_from_hybrid(gga_id,hybrid_id,xc_functionals)
1697 
1698 
1699 !This section has been created automatically by the script Abilint (TD).
1700 !Do not modify the following lines by hand.
1701 #undef ABI_FUNC
1702 #define ABI_FUNC 'libpaw_libxc_gga_from_hybrid'
1703 !End of the abilint section
1704 
1705  implicit none
1706 
1707 !Arguments ------------------------------------
1708 !scalars
1709  integer,intent(in),optional :: hybrid_id
1710  logical :: libpaw_libxc_gga_from_hybrid
1711 !arrays
1712  integer,intent(out),optional :: gga_id(2)
1713  type(libpaw_libxc_type),intent(inout),optional,target :: xc_functionals(2)
1714 !Local variables -------------------------------
1715 !scalars
1716  integer :: family,ii
1717  character(len=100) :: c_name,x_name,msg
1718 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
1719  character(len=100) :: xc_name
1720  character(kind=C_CHAR,len=1),pointer :: strg_c
1721 #endif
1722 !arrays
1723  integer :: trial_id(2)
1724 
1725 ! *************************************************************************
1726 
1727  libpaw_libxc_gga_from_hybrid=.false.
1728 
1729  if (present(hybrid_id)) then
1730    trial_id(1)=hybrid_id
1731    trial_id(2)=0
1732  else if (present(xc_functionals)) then
1733    trial_id(1)=xc_functionals(1)%id
1734    trial_id(2)=xc_functionals(2)%id
1735  else
1736    trial_id(1)=paw_xc_global(1)%id
1737    trial_id(2)=paw_xc_global(2)%id
1738  end if
1739 
1740  c_name="unknown" ; x_name="unknown"
1741 
1742  do ii = 1, 2
1743 
1744    if (trial_id(ii)==0) cycle
1745    family=libpaw_libxc_family_from_id(trial_id(ii))
1746    if (family/=LIBPAW_XC_FAMILY_HYB_GGA.and.family/=LIBPAW_XC_FAMILY_HYB_MGGA) cycle
1747 
1748    if (libpaw_libxc_gga_from_hybrid) then
1749      msg='Invalid XC functional: contains 2 hybrid functionals!'
1750      MSG_ERROR(msg)
1751    end if
1752 
1753 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
1754 
1755    call c_f_pointer(xc_functional_get_name(trial_id(ii)),strg_c)
1756    call char_c_to_f(strg_c,xc_name)
1757 
1758 !  AVAILABLE FUNCTIONALS
1759 
1760 !  ===== PBE0 =====
1761    if (xc_name=="hyb_gga_xc_pbeh" .or. &
1762 &      xc_name=="hyb_gga_xc_pbe0_13") then
1763      c_name="GGA_C_PBE"
1764      x_name="GGA_X_PBE"
1765      libpaw_libxc_gga_from_hybrid=.true.
1766 
1767 !  ===== HSE =====
1768    else if (xc_name=="hyb_gga_xc_hse03" .or. &
1769 &           xc_name=="hyb_gga_xc_hse06" ) then
1770      c_name="GGA_C_PBE"
1771      x_name="GGA_X_PBE"
1772      libpaw_libxc_gga_from_hybrid=.true.
1773    end if
1774 
1775 #endif
1776 
1777  enddo ! ii
1778 
1779  if (present(gga_id)) then
1780    if (libpaw_libxc_gga_from_hybrid) then
1781      gga_id(1)=libpaw_libxc_getid(c_name)
1782      gga_id(2)=libpaw_libxc_getid(x_name)
1783    else
1784      gga_id(:)=-1
1785    end if
1786  end if
1787 
1788 end function libpaw_libxc_gga_from_hybrid

m_libpaw_libxc_funcs/libpaw_libxc_has_kxc [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_has_kxc

FUNCTION

  Test function to identify whether the presently used functional
  provides Kxc or not (fxc in the libXC convention)

INPUTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

SOURCE

1068 function libpaw_libxc_has_kxc(xc_functionals)
1069 
1070 
1071 !This section has been created automatically by the script Abilint (TD).
1072 !Do not modify the following lines by hand.
1073 #undef ABI_FUNC
1074 #define ABI_FUNC 'libpaw_libxc_has_kxc'
1075 !End of the abilint section
1076 
1077  implicit none
1078 
1079 !Arguments ------------------------------------
1080  logical :: libpaw_libxc_has_kxc
1081  type(libpaw_libxc_type),intent(in),optional,target :: xc_functionals(2)
1082 !Local variables-------------------------------
1083  integer :: ii
1084 
1085 ! *************************************************************************
1086 
1087  libpaw_libxc_has_kxc=.true.
1088 
1089  do ii=1,2
1090    if (present(xc_functionals)) then
1091      if (.not.xc_functionals(ii)%has_fxc) libpaw_libxc_has_kxc=.false.
1092    else
1093      if (.not.paw_xc_global(ii)%has_fxc) libpaw_libxc_has_kxc=.false.
1094    end if
1095  end do
1096 
1097 end function libpaw_libxc_has_kxc

m_libpaw_libxc_funcs/libpaw_libxc_init [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_init

FUNCTION

  Initialize the desired XC functional, from LibXC.
  * Call the LibXC initializer
  * Fill preliminary fields in module structures.

INPUTS

 ixc=XC code for Abinit
 nspden=number of spin-density components

SIDE EFFECTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

PARENTS

CHILDREN

SOURCE

483  subroutine libpaw_libxc_init(ixc,nspden,xc_functionals)
484 
485 
486 !This section has been created automatically by the script Abilint (TD).
487 !Do not modify the following lines by hand.
488 #undef ABI_FUNC
489 #define ABI_FUNC 'libpaw_libxc_init'
490 !End of the abilint section
491 
492  implicit none
493 
494 !Arguments ------------------------------------
495  integer, intent(in) :: nspden
496  integer, intent(in) :: ixc
497  type(libpaw_libxc_type),intent(inout),optional,target :: xc_functionals(2)
498 !Local variables-------------------------------
499  integer :: ii,nspden_eff
500  character(len=500) :: msg
501  type(libpaw_libxc_type),pointer :: xc_func
502 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
503  integer :: flags
504  integer(C_INT) :: func_id_c,iref_c,nspin_c,success_c
505  real(C_DOUBLE) :: alpha_c,beta_c,omega_c
506  character(kind=C_CHAR,len=1),pointer :: strg_c
507  type(C_PTR) :: func_ptr_c
508 #endif
509 
510 ! *************************************************************************
511 
512 !Check libXC
513  if (.not.libpaw_libxc_check(stop_if_error=.true.)) return
514  if (.not.libpaw_xc_constants_initialized) call libpaw_libxc_constants_load()
515 
516  nspden_eff=min(nspden,2)
517 
518 !Select XC functional(s) identifiers
519  if (present(xc_functionals)) then
520    xc_functionals(1)%id = -ixc/1000
521    xc_functionals(2)%id = -ixc + (ixc/1000)*1000
522  else
523    paw_xc_global(1)%id = -ixc/1000
524    paw_xc_global(2)%id = -ixc + (ixc/1000)*1000
525  end if
526 
527  do ii = 1,2
528 
529 !  Select XC functional
530    if (present(xc_functionals)) then
531      xc_func => xc_functionals(ii)
532    else
533      xc_func => paw_xc_global(ii)
534    end if
535 
536    xc_func%abi_ixc=ixc !Save abinit value for reference
537 
538    xc_func%family=LIBPAW_XC_FAMILY_UNKNOWN
539    xc_func%kind=-1
540    xc_func%nspin=nspden_eff
541    xc_func%has_exc=.false.
542    xc_func%has_vxc=.false.
543    xc_func%has_fxc=.false.
544    xc_func%has_kxc=.false.
545    xc_func%hyb_mixing=zero
546    xc_func%hyb_mixing_sr=zero
547    xc_func%hyb_range=zero
548 
549    if (xc_func%id==0) cycle
550 
551 !  Get XC functional family
552    xc_func%family=libpaw_libxc_family_from_id(xc_func%id)
553    if (xc_func%family/=LIBPAW_XC_FAMILY_LDA.and. &
554 &      xc_func%family/=LIBPAW_XC_FAMILY_GGA.and. &
555 &      xc_func%family/=LIBPAW_XC_FAMILY_HYB_GGA.and. &
556 &      xc_func%family/=LIBPAW_XC_FAMILY_MGGA) then
557      write(msg, '(a,i8,2a,i8,6a)' )&
558 &      'Invalid IXC = ',ixc,ch10,&
559 &      'The LibXC functional family ',xc_func%family,&
560 &      'is currently unsupported by LibPAW',ch10,&
561 &      '(-1 means the family is unknown to the LibXC itself)',ch10,&
562 &      'Please consult the LibXC documentation',ch10
563      MSG_ERROR(msg)
564    end if
565 
566 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
567 
568 !  Allocate functional
569    func_ptr_c=libpaw_xc_func_type_malloc()
570    call c_f_pointer(func_ptr_c,xc_func%conf)
571 
572 !  Initialize functional
573    func_id_c=int(xc_func%id,kind=C_INT)
574    nspin_c=int(nspden_eff,kind=C_INT)
575    success_c=xc_func_init(xc_func%conf,func_id_c,nspin_c)
576    if (success_c/=0) then
577      msg='Error in libXC functional initialization!'
578      MSG_ERROR(msg)
579    end if
580 
581 !  Special treatment for LDA_C_XALPHA functional
582    if (xc_func%id==libpaw_libxc_getid('XC_LDA_C_XALPHA')) then
583      alpha_c=real(zero,kind=C_DOUBLE)
584      call xc_lda_c_xalpha_set_params(xc_func%conf,alpha_c);
585    end if
586 
587 !  Get functional kind
588    xc_func%kind=int(libpaw_xc_get_info_kind(xc_func%conf))
589 
590 !  Get functional flags
591    flags=int(libpaw_xc_get_info_flags(xc_func%conf))
592    xc_func%has_exc=(iand(flags,LIBPAW_XC_FLAGS_HAVE_EXC)>0)
593    xc_func%has_vxc=(iand(flags,LIBPAW_XC_FLAGS_HAVE_VXC)>0)
594    xc_func%has_fxc=(iand(flags,LIBPAW_XC_FLAGS_HAVE_FXC)>0)
595    xc_func%has_kxc=(iand(flags,LIBPAW_XC_FLAGS_HAVE_KXC)>0)
596 
597 !  Retrieve parameters for hybrid functionals
598    call xc_hyb_cam_coef(xc_func%conf,omega_c,alpha_c,beta_c)
599    xc_func%hyb_mixing=real(alpha_c,kind=dp)
600    xc_func%hyb_mixing_sr=real(beta_c,kind=dp)
601    xc_func%hyb_range=real(omega_c,kind=dp)
602 
603 !  Dump functional information
604    call c_f_pointer(libpaw_xc_get_info_name(xc_func%conf),strg_c)
605    call char_c_to_f(strg_c,msg)
606    call wrtout(std_out,msg,'COLL')
607    iref_c=0
608    do while (iref_c>=0)
609      call c_f_pointer(libpaw_xc_get_info_refs(xc_func%conf,iref_c),strg_c)
610      if (associated(strg_c)) then
611        call char_c_to_f(strg_c,msg)
612        call wrtout(std_out,msg,'COLL')
613        iref_c=iref_c+1
614      else
615        iref_c=-1
616      end if
617    end do
618 
619 #endif
620 
621  end do
622 
623 end subroutine libpaw_libxc_init

m_libpaw_libxc_funcs/libpaw_libxc_is_hybrid [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_is_hybrid

FUNCTION

  Test function to identify whether the presently used functional
  is hybrid or not

INPUTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

SOURCE

1021  function libpaw_libxc_is_hybrid(xc_functionals)
1022 
1023 
1024 !This section has been created automatically by the script Abilint (TD).
1025 !Do not modify the following lines by hand.
1026 #undef ABI_FUNC
1027 #define ABI_FUNC 'libpaw_libxc_is_hybrid'
1028 !End of the abilint section
1029 
1030  implicit none
1031 
1032 !Arguments ------------------------------------
1033  logical :: libpaw_libxc_is_hybrid
1034  type(libpaw_libxc_type),intent(in),optional :: xc_functionals(2)
1035 
1036 ! *************************************************************************
1037 
1038  libpaw_libxc_is_hybrid = .false.
1039  if (.not.libpaw_xc_constants_initialized) call libpaw_libxc_constants_load()
1040 
1041  if (present(xc_functionals)) then
1042    libpaw_libxc_is_hybrid=(any(xc_functionals%family==LIBPAW_XC_FAMILY_HYB_GGA) .or. &
1043 &                          any(xc_functionals%family==LIBPAW_XC_FAMILY_HYB_MGGA))
1044  else
1045    libpaw_libxc_is_hybrid=(any(paw_xc_global%family==LIBPAW_XC_FAMILY_HYB_GGA) .or. &
1046 &                          any(paw_xc_global%family==LIBPAW_XC_FAMILY_HYB_MGGA))
1047  end if
1048 
1049 end function libpaw_libxc_is_hybrid

m_libpaw_libxc_funcs/libpaw_libxc_isgga [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_isgga

FUNCTION

  Test function to identify whether the presently used functional
  is a GGA or not

INPUTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

SOURCE

929  function libpaw_libxc_isgga(xc_functionals)
930 
931 
932 !This section has been created automatically by the script Abilint (TD).
933 !Do not modify the following lines by hand.
934 #undef ABI_FUNC
935 #define ABI_FUNC 'libpaw_libxc_isgga'
936 !End of the abilint section
937 
938  implicit none
939 
940 !Arguments ------------------------------------
941  logical :: libpaw_libxc_isgga
942  type(libpaw_libxc_type),intent(in),optional :: xc_functionals(2)
943 
944 ! *************************************************************************
945 
946  libpaw_libxc_isgga = .false.
947  if (.not.libpaw_xc_constants_initialized) call libpaw_libxc_constants_load()
948 
949  if (present(xc_functionals)) then
950    libpaw_libxc_isgga=(any(xc_functionals%family==LIBPAW_XC_FAMILY_GGA) .or. &
951 &                      any(xc_functionals%family==LIBPAW_XC_FAMILY_HYB_GGA))
952  else
953    libpaw_libxc_isgga=(any(paw_xc_global%family==LIBPAW_XC_FAMILY_GGA) .or. &
954 &                      any(paw_xc_global%family==LIBPAW_XC_FAMILY_HYB_GGA))
955  end if
956 
957 end function libpaw_libxc_isgga

m_libpaw_libxc_funcs/libpaw_libxc_ismgga [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_ismgga

FUNCTION

  Test function to identify whether the presently used functional
  is a Meta-GGA or not

INPUTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

SOURCE

 976 function libpaw_libxc_ismgga(xc_functionals)
 977 
 978 
 979 !This section has been created automatically by the script Abilint (TD).
 980 !Do not modify the following lines by hand.
 981 #undef ABI_FUNC
 982 #define ABI_FUNC 'libpaw_libxc_ismgga'
 983 !End of the abilint section
 984 
 985  implicit none
 986 
 987 !Arguments ------------------------------------
 988  logical :: libpaw_libxc_ismgga
 989  type(libpaw_libxc_type),intent(in),optional :: xc_functionals(2)
 990 
 991 ! *************************************************************************
 992 
 993  libpaw_libxc_ismgga = .false.
 994  if (.not.libpaw_xc_constants_initialized) call libpaw_libxc_constants_load()
 995 
 996  if (present(xc_functionals)) then
 997    libpaw_libxc_ismgga =(any(xc_functionals%family==LIBPAW_XC_FAMILY_MGGA))
 998  else
 999    libpaw_libxc_ismgga =(any(paw_xc_global%family==LIBPAW_XC_FAMILY_MGGA))
1000  end if
1001 
1002 end function libpaw_libxc_ismgga

m_libpaw_libxc_funcs/libpaw_libxc_ixc [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_ixc

FUNCTION

  Return the value of ixc used to initialize the XC structure

INPUTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

SOURCE

887  function libpaw_libxc_ixc(xc_functionals)
888 
889 
890 !This section has been created automatically by the script Abilint (TD).
891 !Do not modify the following lines by hand.
892 #undef ABI_FUNC
893 #define ABI_FUNC 'libpaw_libxc_ixc'
894 !End of the abilint section
895 
896  implicit none
897 
898 !Arguments ------------------------------------
899  integer :: libpaw_libxc_ixc
900  type(libpaw_libxc_type),intent(in),optional :: xc_functionals(2)
901 
902 ! *************************************************************************
903 
904  if (present(xc_functionals)) then
905    libpaw_libxc_ixc=xc_functionals(1)%abi_ixc
906  else
907    libpaw_libxc_ixc=paw_xc_global(1)%abi_ixc
908  end if
909 
910 end function libpaw_libxc_ixc

m_libpaw_libxc_funcs/libpaw_libxc_nspin [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_nspin

FUNCTION

  Returns the number of spin components for the XC functionals

INPUTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

SOURCE

1115 function libpaw_libxc_nspin(xc_functionals)
1116 
1117 
1118 !This section has been created automatically by the script Abilint (TD).
1119 !Do not modify the following lines by hand.
1120 #undef ABI_FUNC
1121 #define ABI_FUNC 'libpaw_libxc_nspin'
1122 !End of the abilint section
1123 
1124  implicit none
1125 
1126 !Arguments ------------------------------------
1127  integer :: libpaw_libxc_nspin
1128  type(libpaw_libxc_type),intent(in),optional :: xc_functionals(2)
1129 
1130 ! *************************************************************************
1131 
1132  libpaw_libxc_nspin = 1
1133 
1134  if (present(xc_functionals)) then
1135    if (any(xc_functionals%nspin==2)) libpaw_libxc_nspin=2
1136  else
1137    if (any(paw_xc_global%nspin==2)) libpaw_libxc_nspin=2
1138  end if
1139 
1140 end function libpaw_libxc_nspin

m_libpaw_libxc_funcs/libpaw_libxc_set_tb09 [ Functions ]

[ Top ] [ m_libpaw_libxc_funcs ] [ Functions ]

NAME

  libpaw_libxc_set_tb09

FUNCTION

  Compute c parameter for Tran-Blaha 2009 functional and set it

INPUTS

 npts=number of of points for the density
 nspden=number of spin-density components
 rho(npts,nspden)=electronic density
 grho2(npts,nspden)=squared gradient of the density
 xc_tb09_c=input value for the TB09 C parameter;
           if set to 99, C is computed from rho and grho2

OUTPUT

SIDE EFFECTS

 [xc_functionals(2)]=<type(libpaw_libxc_type)>, optional argument
                     XC functionals to initialize

PARENTS

      m_libpaw_libxc

CHILDREN

SOURCE

1821  subroutine libpaw_libxc_set_tb09(npts,nspden,rho,grho2,xc_tb09_c,xc_functionals)
1822 
1823 
1824 !This section has been created automatically by the script Abilint (TD).
1825 !Do not modify the following lines by hand.
1826 #undef ABI_FUNC
1827 #define ABI_FUNC 'libpaw_libxc_set_tb09'
1828 !End of the abilint section
1829 
1830  implicit none
1831 
1832 !Arguments ------------------------------------
1833  integer, intent(in) :: npts,nspden
1834  real(dp),intent(in)  :: rho(npts,nspden),grho2(npts,2*min(nspden,2)-1)
1835  real(dp),intent(in) :: xc_tb09_c
1836  type(libpaw_libxc_type),intent(inout),optional,target :: xc_functionals(2)
1837 !Local variables -------------------------------
1838 !scalars
1839  integer  :: ii,ipts
1840  logical :: is_mgga_tb09
1841  real(dp) :: cc
1842  character(len=500) :: msg
1843 !arrays
1844  type(libpaw_libxc_type),pointer :: xc_funcs(:)
1845  real(dp),allocatable :: gnon(:)
1846 
1847 ! *************************************************************************
1848 
1849  if (.not.libpaw_xc_constants_initialized) call libpaw_libxc_constants_load()
1850 
1851 !Select XC functional(s)
1852  if (present(xc_functionals)) then
1853    xc_funcs => xc_functionals
1854  else
1855    xc_funcs => paw_xc_global
1856  end if
1857 
1858  is_mgga_tb09=(any(xc_funcs%id==libpaw_libxc_getid('XC_MGGA_X_TB09')))
1859 
1860  if (is_mgga_tb09) then
1861 
1862 !  C is fixed by the user
1863    if (abs(xc_tb09_c-99._dp)>tol12) then
1864      cc=xc_tb09_c
1865      write(msg,'(2a,f9.6)' ) ch10,&
1866 &      'In the mGGA functional TB09, c is fixed by the user and is equal to ',cc
1867      call wrtout(std_out,msg,'COLL')
1868 
1869 !  C is computed
1870    else
1871      LIBPAW_ALLOCATE(gnon,(npts))
1872      do ipts=1,npts
1873        if (sum(rho(ipts,:))<=1e-7_dp) then
1874          gnon(ipts)=zero
1875        else
1876          if (nspden==1) then
1877            gnon(ipts)=sqrt(grho2(ipts,1))/rho(ipts,1)
1878          else
1879            gnon(ipts)=sqrt(grho2(ipts,3))/sum(rho(ipts,:))
1880          end if
1881        end if
1882      end do
1883      cc= -0.012_dp + 1.023_dp*sqrt(sum(gnon)/npts)
1884      LIBPAW_DEALLOCATE(gnon)
1885      write(msg,'(2a,f9.6)' ) ch10,'In the mGGA functional TB09, c = ',cc
1886      call wrtout(std_out,msg,'COLL')
1887    end if
1888 
1889 !  Set c in XC data structure
1890    do ii=1,2
1891      if (xc_funcs(ii)%id==libpaw_libxc_getid('XC_MGGA_X_TB09')) then
1892 #if defined LIBPAW_HAVE_LIBXC && defined LIBPAW_ISO_C_BINDING
1893        call xc_mgga_x_tb09_set_params(xc_funcs(ii)%conf,cc)
1894 #endif
1895      end if
1896    end do
1897  end if
1898 
1899 end subroutine libpaw_libxc_set_tb09