types_xcpot.F90 7.75 KB
Newer Older
1 2 3 4 5
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------
Daniel Wortmann's avatar
Daniel Wortmann committed
6 7 8 9 10 11 12 13
!> This module defines two data-types used in the calculation of xc-potentials
!! a) the abstract t_xcpot which should be overwritten for actual implementations
!! b) the t_gradients that collects the gradients needed in GGAs
!!
!! Currently t_xcpot_inbuild implements the XC-pots directly build into FLEUR
!! and t_xcpot_libxc provides and interface to libxc.
!! In addition to overloading the t_xcpot datatype also mpi_bc_xcpot must be adjusted
!! for additional implementations.
Daniel Wortmann's avatar
Daniel Wortmann committed
14
MODULE m_types_xcpot
Matthias Redies's avatar
Matthias Redies committed
15
   use m_types_potden
Matthias Redies's avatar
Matthias Redies committed
16 17
   IMPLICIT NONE
   PRIVATE
Matthias Redies's avatar
Matthias Redies committed
18
   PUBLIC           :: t_xcpot,t_gradients
Matthias Redies's avatar
Matthias Redies committed
19

Matthias Redies's avatar
Matthias Redies committed
20 21 22 23 24 25 26
   TYPE t_kinED
      real, allocatable   :: is(:,:)   ! (nsp*jmtd, jspins)
      real, allocatable   :: mt(:,:,:) ! (nsp*jmtd, jspins, local num of types)
   contains
      procedure           :: alloc_mt => kED_alloc_mt
   END TYPE t_kinED

Matthias Redies's avatar
Matthias Redies committed
27 28
   TYPE,ABSTRACT :: t_xcpot
      REAL :: gmaxxc
29
      TYPE(t_potden)   :: core_den, val_den
Matthias Redies's avatar
Matthias Redies committed
30
      TYPE(t_kinED)    :: kinED
Daniel Wortmann's avatar
Daniel Wortmann committed
31
   CONTAINS
Matthias Redies's avatar
Matthias Redies committed
32 33
      PROCEDURE        :: vxc_is_LDA => xcpot_vxc_is_LDA
      PROCEDURE        :: vxc_is_GGA => xcpot_vxc_is_GGA
34 35 36

      PROCEDURE        :: vx_is_LDA     => xcpot_vx_is_LDA
      PROCEDURE        :: vx_is_GGA     => xcpot_vx_is_GGA
Matthias Redies's avatar
Matthias Redies committed
37
      PROCEDURE        :: vx_is_MetaGGA => xcpot_vx_is_MetaGGA
38

Matthias Redies's avatar
Matthias Redies committed
39 40
      PROCEDURE        :: vc_is_LDA => xcpot_vc_is_LDA
      PROCEDURE        :: vc_is_GGA => xcpot_vc_is_GGA
41 42 43 44 45

      PROCEDURE        :: exc_is_LDA     => xcpot_exc_is_LDA
      PROCEDURE        :: exc_is_GGA     => xcpot_exc_is_GGA
      PROCEDURE        :: exc_is_MetaGGA => xcpot_exc_is_MetaGGA

Matthias Redies's avatar
Matthias Redies committed
46 47
      PROCEDURE        :: needs_grad => xcpot_needs_grad
      PROCEDURE        :: is_hybrid  => xcpot_is_hybrid
48 49 50 51 52

      PROCEDURE        :: get_exchange_weight => xcpot_get_exchange_weight
      PROCEDURE        :: get_vxc             => xcpot_get_vxc
      PROCEDURE        :: get_exc             => xcpot_get_exc
      PROCEDURE,NOPASS :: alloc_gradients     => xcpot_alloc_gradients
Matthias Redies's avatar
Matthias Redies committed
53
   END TYPE t_xcpot
Daniel Wortmann's avatar
Daniel Wortmann committed
54

Matthias Redies's avatar
Matthias Redies committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
   TYPE t_gradients
      !Naming convention:
      !t,u,d as last letter for total,up,down
      !agr for absolute value of gradient
      !g2r for laplacien of gradient
      !+??
      REAL,ALLOCATABLE :: agrt(:),agru(:),agrd(:)
      REAL,ALLOCATABLE :: g2ru(:),g2rd(:),gggrt(:)
      REAL,ALLOCATABLE :: gggru(:),gzgr(:),g2rt(:)
      REAL,ALLOCATABLE :: gggrd(:),grgru(:),grgrd(:)
      !These are the contracted Gradients used in libxc
      REAL,ALLOCATABLE :: sigma(:,:)
      REAL,ALLOCATABLE :: vsigma(:,:)
      REAL,ALLOCATABLE :: gr(:,:,:)
      REAL,ALLOCATABLE :: laplace(:,:)
   END TYPE t_gradients
71
CONTAINS
Matthias Redies's avatar
Matthias Redies committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
   subroutine kED_alloc_mt(kED,nsp_x_jmtd, jspins, n_start, n_types, n_stride)
      implicit none
      class(t_kinED), intent(inout)   :: kED
      integer, intent(in)            :: nsp_x_jmtd, jspins, n_start, n_types, n_stride
      integer                        :: cnt, n

      if(.not. allocated(kED%mt)) then
         cnt = 0
         do n = n_start,n_types,n_stride
            cnt = cnt + 1
         enddo
         allocate(kED%mt(nsp_x_jmtd, jspins, cnt))
      endif
   end subroutine kED_alloc_mt

Matthias Redies's avatar
Matthias Redies committed
87
   ! LDA
88 89 90 91 92 93 94 95 96 97 98 99
   LOGICAL FUNCTION xcpot_vc_is_LDA(xcpot)
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
      xcpot_vc_is_LDA=.false.
   END FUNCTION xcpot_vc_is_LDA

   LOGICAL FUNCTION xcpot_vx_is_LDA(xcpot)
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
      xcpot_vx_is_LDA=.false.
   END FUNCTION xcpot_vx_is_LDA
   
Matthias Redies's avatar
Matthias Redies committed
100 101 102
   LOGICAL FUNCTION xcpot_vxc_is_LDA(xcpot)
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
103
      xcpot_vxc_is_LDA = xcpot%vx_is_LDA() .and. xcpot%vc_is_LDA()
Matthias Redies's avatar
Matthias Redies committed
104 105 106 107 108 109 110 111 112
   END FUNCTION xcpot_vxc_is_LDA

   LOGICAL FUNCTION xcpot_exc_is_LDA(xcpot)
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
      xcpot_exc_is_LDA=.false.
   END FUNCTION xcpot_exc_is_LDA

   ! GGA
113 114 115 116 117 118 119 120 121 122 123 124
   LOGICAL FUNCTION xcpot_vc_is_GGA(xcpot)
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
      xcpot_vc_is_GGA=.false.
   END FUNCTION xcpot_vc_is_GGA

   LOGICAL FUNCTION xcpot_vx_is_GGA(xcpot)
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
      xcpot_vx_is_GGA=.false.
   END FUNCTION xcpot_vx_is_GGA
   
125
   LOGICAL FUNCTION xcpot_vxc_is_gga(xcpot)
Matthias Redies's avatar
Matthias Redies committed
126 127
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
128
      xcpot_vxc_is_gga= xcpot%vx_is_GGA() .and. xcpot%vc_is_GGA()
129
   END FUNCTION xcpot_vxc_is_gga
Matthias Redies's avatar
Matthias Redies committed
130

131
   LOGICAL FUNCTION xcpot_exc_is_gga(xcpot)
Matthias Redies's avatar
Matthias Redies committed
132 133
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
134 135 136
      xcpot_exc_is_gga=.false.
   END FUNCTION xcpot_exc_is_gga

Matthias Redies's avatar
Matthias Redies committed
137 138 139 140 141 142
   LOGICAL FUNCTION xcpot_vx_is_MetaGGA(xcpot)
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
      xcpot_vx_is_MetaGGA=.false.
   END FUNCTION xcpot_vx_is_MetaGGA

143 144 145 146 147
   LOGICAL FUNCTION xcpot_exc_is_MetaGGA(xcpot)
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
      xcpot_exc_is_MetaGGA=.false.
   END FUNCTION xcpot_exc_is_MetaGGA
Daniel Wortmann's avatar
Daniel Wortmann committed
148

Matthias Redies's avatar
Matthias Redies committed
149 150 151
   LOGICAL FUNCTION xcpot_needs_grad(xcpot)
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
Matthias Redies's avatar
Matthias Redies committed
152

Matthias Redies's avatar
Matthias Redies committed
153
      xcpot_needs_grad= xcpot%vc_is_gga()
Matthias Redies's avatar
Matthias Redies committed
154
   END FUNCTION xcpot_needs_grad
155

Matthias Redies's avatar
Matthias Redies committed
156 157 158 159 160
   LOGICAL FUNCTION xcpot_is_hybrid(xcpot)
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
      xcpot_is_hybrid=.FALSE.
   END FUNCTION xcpot_is_hybrid
161

Matthias Redies's avatar
Matthias Redies committed
162 163 164 165 166 167 168
   FUNCTION xcpot_get_exchange_weight(xcpot) RESULT(a_ex)
      USE m_judft
      IMPLICIT NONE
      CLASS(t_xcpot),INTENT(IN):: xcpot
      REAL:: a_ex
      a_ex=-1
   END FUNCTION xcpot_get_exchange_weight
169

Matthias Redies's avatar
Matthias Redies committed
170
   SUBROUTINE xcpot_get_vxc(xcpot,jspins,rh,vxc,vx,grad)
Matthias Redies's avatar
Matthias Redies committed
171
      USE m_judft
Matthias Redies's avatar
Matthias Redies committed
172 173
      IMPLICIT NONE

Matthias Redies's avatar
Matthias Redies committed
174 175 176 177 178 179 180
      CLASS(t_xcpot),INTENT(IN) :: xcpot
      INTEGER, INTENT (IN)     :: jspins
      !--> charge density
      REAL,INTENT (IN)         :: rh(:,:)
      !---> xc potential
      REAL, INTENT (OUT)       :: vxc (:,:),vx(:,:)
      TYPE(t_gradients),OPTIONAL,INTENT(INOUT)::grad
Matthias Redies's avatar
Matthias Redies committed
181 182 183 184

      vxc = 0.0
      vx  = 0.0
      call juDFT_error("Can't use XC-parrent class")
Matthias Redies's avatar
Matthias Redies committed
185
   END SUBROUTINE xcpot_get_vxc
186

187
   SUBROUTINE xcpot_get_exc(xcpot,jspins,rh,exc,grad,kinEnergyDen_KS, mt_call)
Matthias Redies's avatar
Matthias Redies committed
188
      USE m_types_misc
189
      USE m_judft
Matthias Redies's avatar
Matthias Redies committed
190
      USE, INTRINSIC :: IEEE_ARITHMETIC
Matthias Redies's avatar
Matthias Redies committed
191 192
      IMPLICIT NONE

Matthias Redies's avatar
Matthias Redies committed
193 194
      CLASS(t_xcpot),INTENT(IN)             :: xcpot
      INTEGER, INTENT (IN)                  :: jspins
Matthias Redies's avatar
Matthias Redies committed
195
      !--> charge density
Matthias Redies's avatar
Matthias Redies committed
196
      REAL,INTENT (IN)                      :: rh(:,:)
Matthias Redies's avatar
Matthias Redies committed
197
      !--> kinetic energy density
Matthias Redies's avatar
Matthias Redies committed
198
      !---> xc energy density
Matthias Redies's avatar
Matthias Redies committed
199 200
      REAL, INTENT (OUT)                    :: exc (:)
      TYPE(t_gradients),OPTIONAL,INTENT(IN) :: grad
201
      LOGICAL, OPTIONAL, INTENT(IN)         :: mt_call    
Matthias Redies's avatar
Matthias Redies committed
202
      REAL, INTENT(IN), OPTIONAL            :: kinEnergyDen_KS(:,:)
Matthias Redies's avatar
Matthias Redies committed
203 204 205

      exc = 0.0
      call juDFT_error("Can't use XC-parrent class")
Matthias Redies's avatar
Matthias Redies committed
206
   END SUBROUTINE xcpot_get_exc
207

Matthias Redies's avatar
Matthias Redies committed
208
   SUBROUTINE xcpot_alloc_gradients(ngrid,jspins,grad)
Matthias Redies's avatar
Matthias Redies committed
209 210
      IMPLICIT NONE

Matthias Redies's avatar
Matthias Redies committed
211 212
      INTEGER, INTENT (IN)         :: jspins,ngrid
      TYPE(t_gradients),INTENT(INOUT):: grad
213

Matthias Redies's avatar
Matthias Redies committed
214 215 216 217 218 219 220 221 222 223 224
      IF (allocated(grad%agrt)) THEN
         DEALLOCATE(grad%agrt,grad%agru,grad%agrd)
         DEALLOCATE(grad%g2ru,grad%g2rd,grad%gggrt)
         DEALLOCATE(grad%gggru,grad%gzgr,grad%g2rt)
         DEALLOCATE(grad%gggrd,grad%grgru,grad%grgrd)
      ENDIF
      !For the in-build xc-pots
      ALLOCATE(grad%agrt(ngrid),grad%agru(ngrid),grad%agrd(ngrid))
      ALLOCATE(grad%g2ru(ngrid),grad%g2rd(ngrid),grad%gggrt(ngrid))
      ALLOCATE(grad%gggru(ngrid),grad%gzgr(ngrid),grad%g2rt(ngrid))
      ALLOCATE(grad%gggrd(ngrid),grad%grgru(ngrid),grad%grgrd(ngrid))
Matthias Redies's avatar
Matthias Redies committed
225
  END SUBROUTINE xcpot_alloc_gradients
226

Daniel Wortmann's avatar
Daniel Wortmann committed
227
END MODULE m_types_xcpot