Branch data Line data Source code
1 : : !!****m* ABINIT/m_xcdata
2 : : !! NAME
3 : : !! m_xcdata
4 : : !!
5 : : !! FUNCTION
6 : : !! This module provides the definition of
7 : : !! the xcdata_type used to drive the computation of the XC energy, potential, kernel, etc.
8 : : !!
9 : : !! COPYRIGHT
10 : : !! Copyright (C) 2017-2026 ABINIT group (XG)
11 : : !! This file is distributed under the terms of the
12 : : !! GNU General Public License, see ~abinit/COPYING
13 : : !! or http://www.gnu.org/copyleft/gpl.txt .
14 : : !!
15 : : !! NOTES
16 : : !!
17 : : !! SOURCE
18 : :
19 : : #if defined HAVE_CONFIG_H
20 : : #include "config.h"
21 : : #endif
22 : :
23 : : #include "abi_common.h"
24 : :
25 : : module m_xcdata
26 : :
27 : : use defs_basis
28 : : use m_errors
29 : : use libxc_functionals
30 : : use m_dtset, only : dataset_type
31 : : use m_drivexc, only : size_dvxc
32 : :
33 : : implicit none
34 : :
35 : : private
36 : :
37 : : !!***
38 : :
39 : : !!****t* m_xcdata/xcdata_type
40 : : !! NAME
41 : : !! xcdata_type
42 : : !!
43 : : !! FUNCTION
44 : : !! This object stores the input variables (and derived parameters) needed to compute the exchange-correlation functional,
45 : : !! not simply to define it.
46 : : !!
47 : : !! NOTES
48 : : !!
49 : : !! SOURCE
50 : :
51 : : type, public :: xcdata_type
52 : :
53 : : ! Integer scalars
54 : :
55 : : integer :: auxc_ixc
56 : : ! Choice of auxiliary exchange-correlation functional. See input variable documentation
57 : : ! If 0, there is no auxiliary xc functional, the one corresponding to ixc has to be used.
58 : :
59 : : integer :: intxc
60 : : ! 1 if the XC functional has to be interpolated on a more refined mesh than the FFT one.
61 : : ! 0 stick to the original FFT mesh
62 : :
63 : : integer :: ixc
64 : : ! Choice of exchange-correlation functional. See input variable documentation
65 : :
66 : : integer :: nspden
67 : : ! Number of spin components of the density
68 : :
69 : : integer :: usefock
70 : : ! 1 if the XC functional includes a (possibly screened) Fock contribution
71 : :
72 : : integer :: usegradient
73 : : ! 1 if the XC functional depends on the density gradient
74 : :
75 : : integer :: uselaplacian
76 : : ! 1 if the XC functional depends on the density laplacian
77 : :
78 : : integer :: usekden
79 : : ! 1 if the XC functional depends on the kinetic energy density
80 : :
81 : : integer :: vdw_xc
82 : : ! Choice of van-der-Waals density functional. See input variable documentation
83 : :
84 : : integer :: xclevel
85 : : ! Determined from ixc
86 : : ! 0 if no XC functional
87 : : ! 1 if LDA-type XC functional
88 : : ! 2 if GGA-type XC functional
89 : : ! 3 if for TDDFT kernel
90 : :
91 : : ! Real scalars
92 : :
93 : : real(dp) :: hyb_mixing
94 : : ! Parameter for mixing Fock exchange in native PBEx functionals
95 : :
96 : : real(dp) :: nelect
97 : : ! Number of electrons in the cell (for Fermi-Amaldi only)
98 : :
99 : : real(dp) :: tphysel
100 : : ! Physical temperature (for temperature-dependent functional)
101 : :
102 : : real(dp) :: xc_denpos
103 : : ! density positivity value
104 : :
105 : : real(dp) :: xc_taupos
106 : : ! kinetic energy density positivity value (mGGA)
107 : :
108 : : end type xcdata_type
109 : :
110 : : !----------------------------------------------------------------------
111 : :
112 : : public :: xcdata_init ! Initialize the object.
113 : : public :: get_xclevel ! Get the xclevel from ixc (as well as usefock)
114 : : public :: get_auxc_ixc ! Get the auxiliary xc functional (if it exists)
115 : :
116 : : contains
117 : : !!***
118 : :
119 : : !!****f* m_xcdata/xcdata_init
120 : : !! NAME
121 : : !! xcdata_init
122 : : !!
123 : : !! FUNCTION
124 : : !! Init the structure. Mostly copy input variables, except compute and usefock and xclevel.
125 : : !!
126 : : !! INPUTS
127 : : !! [dtset = the dataset from which the other input variables are taken, if they are not present]
128 : : !! [auxc_ixc = possibly the index of the auxiliary xc functional, otherwise 0.]
129 : : !! [hyb_mixing = parameter for mixing Fock exchange in native PBEx functionals]
130 : : !! [intxc = 1 if the XC functional has to be interpolated on a more refined mesh than the FFT one]
131 : : !! [ixc= index of exchange-correlation functional]
132 : : !! [nelect = Number of electrons in the cell (for Fermi-Amaldi only)]
133 : : !! [tphysel = Physical temperature (for temperature-dependent functional)]
134 : : !! [vdw_xc = Choice of van-der-Waals density functional]
135 : : !! [xc_denpos = density positivity value]
136 : : !! [xc_taupos = kinetic energy density positivity value (mGGA)]
137 : : !!
138 : : !! OUTPUT
139 : : !! xcdata <type(xcdata_type)>= the data to calculate exchange-correlation are initialized
140 : : !!
141 : : !! SOURCE
142 : :
143 : 57141 : subroutine xcdata_init(xcdata,auxc_ixc,dtset,hyb_mixing,intxc,ixc,nelect,nspden,tphysel,&
144 : : & vdw_xc,xc_denpos,xc_taupos)
145 : :
146 : : !Arguments ------------------------------------
147 : : !scalars
148 : : integer, intent(in),optional :: auxc_ixc,intxc,ixc,nspden,vdw_xc
149 : : real(dp),intent(in),optional :: hyb_mixing,nelect,tphysel,xc_denpos,xc_taupos
150 : : type(dataset_type), intent(in),optional :: dtset
151 : : type(xcdata_type), intent(out) :: xcdata
152 : : !Local variables-------------------------------
153 : : integer :: nspden_updn
154 : : character(len=500) :: msg
155 : :
156 : : ! *************************************************************************
157 : :
158 [ + - ]: 57141 : if(present(dtset))then
159 : 57141 : xcdata%auxc_ixc=dtset%auxc_ixc
160 : 57141 : xcdata%intxc=dtset%intxc
161 : 57141 : xcdata%ixc=dtset%ixc
162 : 57141 : xcdata%nspden=dtset%nspden
163 : 57141 : xcdata%vdw_xc=dtset%vdw_xc
164 : :
165 : 57141 : xcdata%hyb_mixing=abs(dtset%hyb_mixing) ! Warning : the absolute value is needed, because of the singular way
166 : : ! to define the default values for this input variable.
167 : 57141 : xcdata%nelect=dtset%nelect
168 [ + + + - : 57141 : xcdata%tphysel=merge(dtset%tphysel,dtset%tsmear,dtset%tphysel>tol8.and.dtset%occopt/=3.and.dtset%occopt/=9)
- + ]
169 : :
170 : 57141 : xcdata%xc_denpos=dtset%xc_denpos
171 : 57141 : xcdata%xc_taupos=dtset%xc_taupos
172 : :
173 : : else
174 [ # # # # : 0 : if(.not.(present(auxc_ixc).and.present(intxc).and.present(ixc).and.&
# # # # #
# ]
175 : : & present(vdw_xc).and.present(hyb_mixing).and.&
176 : : & present(nelect).and.present(nspden).and.&
177 : : & present(tphysel).and.present(xc_denpos).and.present(xc_taupos)))then
178 : 0 : msg='If dtset is not provided, all the other optional arguments must be provided, which is not the case!'
179 : 0 : ABI_BUG(msg)
180 : : endif
181 : : endif
182 : :
183 [ + + ]: 57141 : if(present(auxc_ixc)) xcdata%auxc_ixc=auxc_ixc
184 [ + + ]: 57141 : if(present(intxc)) xcdata%intxc=intxc
185 [ + + ]: 57141 : if(present(ixc)) xcdata%ixc=ixc
186 [ + + ]: 57141 : if(present(nspden)) xcdata%nspden=nspden
187 [ - + ]: 57141 : if(present(vdw_xc)) xcdata%vdw_xc=vdw_xc
188 : :
189 [ - + ]: 57141 : if(present(hyb_mixing))xcdata%hyb_mixing=hyb_mixing
190 [ - + ]: 57141 : if(present(nelect)) xcdata%nelect=nelect
191 [ - + ]: 57141 : if(present(tphysel)) xcdata%tphysel=tphysel
192 [ - + ]: 57141 : if(present(xc_denpos)) xcdata%xc_denpos=xc_denpos
193 [ - + ]: 57141 : if(present(xc_taupos)) xcdata%xc_taupos=xc_taupos
194 : :
195 : : !Compute xclevel
196 : 57141 : call get_xclevel(xcdata%ixc,xcdata%xclevel,usefock=xcdata%usefock)
197 : :
198 : : !Compute usegradient,uselaplacian,usekden
199 : 57141 : nspden_updn=min(xcdata%nspden,2)
200 : : call size_dvxc(xcdata%ixc,1,nspden_updn,usegradient=xcdata%usegradient,&
201 : 57141 : & uselaplacian=xcdata%uselaplacian,usekden=xcdata%usekden)
202 : :
203 : 57141 : end subroutine xcdata_init
204 : : !!***
205 : :
206 : : !----------------------------------------------------------------------
207 : :
208 : : !!****f* m_xcdata/get_xclevel
209 : : !! NAME
210 : : !! get_xclevel
211 : : !!
212 : : !! FUNCTION
213 : : !! Compute xclevel.
214 : : !!
215 : : !! INPUTS
216 : : !! ixc= index of exchange-correlation functional
217 : : !!
218 : : !! OUTPUT
219 : : !! [usefock = 1 if the XC functional needs the Fock operator]
220 : : !! xclevel= 0 if no XC functional except possibly Fock; 1 if LDA; 2 if GGA ; 3 for TDDFT kernel tests
221 : : !!
222 : : !! SOURCE
223 : :
224 : 64381 : subroutine get_xclevel(ixc, xclevel, usefock)
225 : :
226 : : !Arguments ------------------------------------
227 : : !scalars
228 : : integer, intent(in) :: ixc
229 : : integer, intent(out) :: xclevel
230 : : integer, intent(out), optional :: usefock
231 : :
232 : : !Local variables-------------------------------
233 : : integer :: ii,isiz,jj
234 : : character(len=500) :: msg
235 : :
236 : : ! *************************************************************************
237 : :
238 [ + - ]: 64381 : xclevel=0 ; if(present(usefock)) usefock=0
239 [ + + ]: 64381 : if( ( 1<=ixc .and. ixc<=10).or.(30<=ixc .and. ixc<=39).or.(ixc==50) )xclevel=1 ! LDA
240 [ + + ]: 64381 : if ( ( ixc==51) ) xclevel=1 ! temperature-dependant LDA functionals (TLDA)
241 [ + + + + ]: 64381 : if( (11<=ixc .and. ixc<=19).or.(23<=ixc .and. ixc<=29).or. ixc==1402000)xclevel=2 ! GGA
242 [ + + ]: 64381 : if ( ( ixc==60) ) xclevel=2 ! temperature-dependant GGA functionals (TGGA)
243 [ + + ]: 64381 : if( 20<=ixc .and. ixc<=22 )xclevel=3 ! ixc for TDDFT kernel tests
244 [ + - ]: 64381 : if(present(usefock))then
245 [ + + ]: 64381 : if( ixc>=40 .and. ixc<=42 )usefock=1 ! Hartree-Fock or internal hybrid functionals
246 : : endif
247 [ + + ]: 64381 : if( ixc>=31 .and. ixc<=35)xclevel=2 ! ixc for internal fake mGGA
248 [ + + ]: 64381 : if( ixc>=41 .and. ixc<=42)xclevel=2 ! ixc for internal hybrids using GGA
249 [ + + ]: 64381 : if (ixc<0) then ! libXC: metaGGA and hybrid functionals
250 : 14587 : xclevel=1
251 [ + + ]: 43761 : do isiz=1,2
252 : : ! ixc has ABINIT sign convention
253 : : ! ii has Libxc sign convention
254 [ + + ]: 29174 : if (isiz==1) ii=-ixc/1000
255 [ + + ]: 29174 : if (isiz==2) ii=-ixc-ii*1000
256 [ + + ]: 29174 : if (ii<=0) cycle
257 : 28048 : jj=libxc_functionals_family_from_id(ii)
258 [ + + + + ]: 28048 : if (jj==XC_FAMILY_GGA .or.jj==XC_FAMILY_MGGA) xclevel=2
259 [ + + - + ]: 28048 : if (jj==XC_FAMILY_HYB_GGA.or.jj==XC_FAMILY_HYB_MGGA) xclevel=2
260 [ + - ]: 42635 : if (present(usefock)) then
261 [ + + ]: 28048 : if (libxc_functionals_is_hybrid_from_id(ii)) usefock=1
262 [ + + ]: 28048 : if (usefock==1) then
263 [ - + ]: 931 : if (.not.libxc_functionals_gga_from_hybrid(hybrid_id=ii)) then
264 : : write(msg, '(a,i8,3a,2i8,2a)' )&
265 : 0 : 'ixc=',ixc,' (libXC hybrid functional) is presently not allowed.',ch10,&
266 : 0 : 'ii,jj=',ii,jj,ch10,&
267 : 0 : 'Action: try another hybrid functional.'
268 : 0 : ABI_ERROR(msg)
269 : : end if
270 : : end if
271 : : end if
272 : : end do
273 : : end if
274 : :
275 : 64381 : end subroutine get_xclevel
276 : : !!***
277 : :
278 : : !----------------------------------------------------------------------
279 : :
280 : : !!****f* m_xcdata/get_auxc_ixc
281 : : !! NAME
282 : : !! get_auxc_ixc
283 : : !!
284 : : !! FUNCTION
285 : : !! Returns the ixc of an auxiliary XC functional to be used instead of the input ixc
286 : : !! For most of the functionals, there is no need of an auxiliary functional, in which case auxc_ixc=0
287 : : !! For hybrid functionals, on the contrary, some speedup can be achieved by using such an auxiliary functional
288 : : !! Note that this XC functional intend to replace the whole ixc functional. Generally speakin, it should be
289 : : !! mistaken for the GGA part of the hybrid functional (that is for exchange only, actually).
290 : : !!
291 : : !! At present, always return ixc=1, but this might change in the future ...
292 : : !!
293 : : !! INPUTS
294 : : !! ixc= index of exchange-correlation functional
295 : : !!
296 : : !! OUTPUT
297 : : !! auxc_ixc= 0 if no need of an auxiliary functional, otherwise, returns the ixc of an auxiliary functional.
298 : : !!
299 : : !! SIDE EFFECTS
300 : : !!
301 : : !! SOURCE
302 : :
303 : 23 : subroutine get_auxc_ixc(auxc_ixc,ixc)
304 : :
305 : : !Arguments ------------------------------------
306 : : !scalars
307 : : integer, intent(in) :: ixc
308 : : integer, intent(out) :: auxc_ixc
309 : :
310 : : !Local variables-------------------------------
311 : : integer :: usefock,xclevel
312 : : !integer :: gga_id(2)
313 : :
314 : : ! *************************************************************************
315 : :
316 : 23 : auxc_ixc=11
317 : : !Native hybrid functionals from ABINIT
318 [ + + ]: 23 : if (ixc==40.or.ixc==41.or.ixc==42) then
319 : : auxc_ixc = 11
320 : : !Hybrid functionals from libxc
321 [ + - ]: 18 : else if (ixc<0) then
322 : 18 : call get_xclevel(ixc,xclevel,usefock)
323 [ + - ]: 18 : if(usefock==1)then
324 : 18 : auxc_ixc=11
325 : : ! if (libxc_functionals_gga_from_hybrid(hybrid_id=ixc,gga_id=gga_id)) then
326 : : ! auxc_ixc=-gga_id(1)*1000-gga_id(2)
327 : : ! endif
328 : : end if
329 : : end if
330 : :
331 : 23 : end subroutine get_auxc_ixc
332 : :
333 : 0 : end module m_xcdata
334 : : !!***
|