ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
xc_functional.h
Go to the documentation of this file.
1//==========================================================
2// AUTHOR : mohan
3// DATE : 2009-04-04
4//==========================================================
5#ifndef XC_FUNCTIONAL_H
6#define XC_FUNCTIONAL_H
7
8#ifdef USE_LIBXC
9#include <xc.h>
10#else
11#include "xc_funcs.h"
12#endif // ifdef USE_LIBXC
13#include "source_base/macros.h"
16#include "source_base/vector3.h"
17#include "source_base/matrix.h"
18#include "exx_info.h"
22
23#include <map> // added by jghan, 2024-10-10
24
26{
27 public:
28
31
32//-------------------
33// subroutines, grouped according to the file they are in:
34//-------------------
35
36//-------------------
37// xc_functional_vxc.cpp
38//-------------------
39
40// This file contains interface to the xc_functional class
41// it includes 3 subroutines:
42// 1. v_xc : which takes rho as input, and [etxc, vtxc, v_xc] as output
43// 2. v_xc_libxc : which does the same thing as v_xc, but calling libxc
44// NOTE : it is only used for nspin = 1 and 2, the nspin = 4 case is treated in v_xc
45// 3. v_xc_meta : which takes rho and tau as input, and v_xc as output
46
47 // compute the exchange-correlation energy
48 // [etxc, vtxc, v] = v_xc(...)
49 static std::tuple<double,double,ModuleBase::matrix> v_xc(
50 const int &nrxx, // number of real-space grid
51 const Charge* const chr,
52 const UnitCell *ucell); // charge density
53
54//-------------------
55// xc_functional.cpp
56//-------------------
57
58// This file contains subroutines for setting the functional
59// it includes 4 subroutines:
60// 1. get_func_type : which returns the type of functional (func_type):
61// 0 = none; 1 = lda; 2 = gga; 3 = mgga; 4 = hybrid lda/gga; 5 = hybrid mgga
62// 2. set_xc_type : sets the value of:
63// func_id, which is the LIBXC id of functional
64// func_type, which is as specified in get_func_type
65// use_libxc, whether to use LIBXC. The rule is to NOT use it for functionals that we already have.
66
67 static int get_func_type()
68 {
69 return func_type;
70 };
71 static void set_xc_type(const std::string xc_func_in);
72
73 // For hybrid functional
74 static void set_hybrid_alpha(const double alpha_in);
75 static double get_hybrid_alpha()
76 {
77 return hybrid_alpha;
78 };
79 static bool get_ked_flag()
80 {
81 return ked_flag;
82 };
84 static void set_xc_first_loop(const UnitCell& ucell);
85
86 static std::string output_info();
87
88 private:
89
90 static std::vector<int> func_id; // libxc id of functional
91 static int func_type; //0:none, 1:lda, 2:gga, 3:mgga, 4:hybrid lda/gga, 5:hybrid mgga
92 static bool ked_flag; // whether the functional has kinetic energy density
93 static bool use_libxc;
94
95 // exx_hybrid_alpha for mixing exx in hybrid functional:
96 static double hybrid_alpha;
97
98 // added by jghan, 2024-07-07
99 // as a scaling factor for different xc-functionals
100 static std::map<int, double> scaling_factor_xc;
101
102 public:
103 static std::vector<int> get_func_id() { return func_id; }
104
105//-------------------
106// xc_functional_wrapper_xc.cpp
107//-------------------
108
109// This file contains wrapper for the LDA functionals
110// it includes 3 subroutines:
111// 1. xc, which is the wrapper of LDA part
112// (i.e. LDA functional and LDA part of GGA functional)
113// 2. xc_spin, which is the spin polarized counterpart of xc
114// 3. xc_spin_libxc, which is the wrapper for LDA functional, spin polarized
115
116// NOTE : In our own realization of GGA functional, the LDA part
117// and gradient correction are calculated separately.
118// The LDA part is provided in xc, while the gradient correction is
119// provided in gradcorr through gcxc/gcx_spin+gcc_spin.
120// While in LIBXC, the entire GGA functional is provided.
121// As a result, xc/xc_spin and xc_spin_libxc are different for GGA,
122// the former gives nonzero result, while the latter returns 0.
123// Furthermore, the reason for not having xc_libxc is that something like
124// xc_libxc which evaluates functional for individual grid points
125// is not efficient. For nspin = 1 and 2, v_xc_libxc evaluates potential
126// on the entire grid. I'm having xc_spin_libxc because v_xc_libxc
127// does not support nspin = 4.
128
129 public:
130
131 // LDA
132 static void xc(const double &rho, double &exc, double &vxc);
133
134 // LSDA
135 static void xc_spin(const double &rho, const double &zeta,
136 double &exc, double &vxcup, double &vxcdw);
137
138//-------------------
139// xc_functional_wrapper_gcxc.cpp
140//-------------------
141
142// This file contains wrapper for the GGA functionals
143// it includes 4 subroutines:
144// 1. gcxc, which is the wrapper for gradient correction part
145// 2. gcx_spin, spin polarized, exchange only
146// 3. gcc_spin, spin polarized, correlation only
147
148// The difference between our realization (gcxc/gcx_spin/gcc_spin) and
149// LIBXC, and the reason for not having gcxc_libxc is explained
150// in the NOTE in the comment for xc_functional_wrapper_wc.cpp part
151
152 // GGA
153 static void gcxc(const double &rho, const double &grho,
154 double &sxc, double &v1xc, double &v2xc);
155
156 // spin polarized GGA
157 static void gcx_spin(double rhoup, double rhodw, double grhoup2, double grhodw2,
158 double &sx, double &v1xup, double &v1xdw, double &v2xup,
159 double &v2xdw);
160 static void gcc_spin(double rho, double &zeta, double grho, double &sc,
161 double &v1cup, double &v1cdw, double &v2c);
162
163//-------------------
164// xc_functional_gradcorr.cpp
165//-------------------
166
167// This file contains subroutines realted to gradient calculations
168// it contains 5 subroutines:
169// 1. gradcorr, which calculates gradient correction
170// 2. grad_wfc, which calculates gradient of wavefunction
171// it is used in stress_func_mgga.cpp
172// 3. grad_rho, which calculates gradient of density
173// 4. grad_dot, which calculates divergence of something
174// 5. noncolin_rho, which diagonalizes the spin density matrix
175// and gives the spin up and spin down components of the charge.
176
177 static void gradcorr(double& etxc,
178 double& vtxc,
180 const Charge* const chr,
181 ModulePW::PW_Basis* rhopw,
182 const UnitCell* ucell,
183 std::vector<double>& stress_gga,
184 const bool is_stress = false);
185 template <typename T, typename Device,
186 typename Real = typename GetTypeReal<T>::type>
187 static void grad_wfc(
188 const int ik,
189 const Real tpiba,
190 const ModulePW::PW_Basis_K* wfc_basis,
191 const T* rhog,
192 T* grad);
193 static void grad_rho(const std::complex<double>* rhog,
195 const ModulePW::PW_Basis* rho_basis,
196 const double tpiba);
197 static void grad_dot(const ModuleBase::Vector3<double>* h,
198 double* dh,
199 const ModulePW::PW_Basis* rho_basis,
200 const double tpiba);
201 static void noncolin_rho(double* rhoout1,
202 double* rhoout2,
203 double* seg,
204 const double* const* const rho,
205 const int nrxx,
206 const double* ux_,
207 const bool lsign_);
208
209 //-------------------
210 // xc_funct_exch_lda.cpp
211 //-------------------
212
213 // This file contains realization of LDA exchange functionals
214 // Spin unpolarized ones:
215 // 1. slater: ordinary Slater exchange with alpha=2/3
216 // 2. slater1: Slater exchange with alpha=1
217 // 3. slater_rxc : Slater exchange with alpha=2/3 and Relativistic exchange
218 // And their spin polarized counterparts:
219 // 1. slater_spin
220 // 2. slater1_spin
221 // 3. slater_rxc_spin
222
223 // For LDA exchange energy
224 static void slater(const double &rs, double &ex, double &vx);
225 static void slater1(const double &rs, double &ex, double &vx);
226 static void slater_rxc(const double &rs, double &ex, double &vx);
227
228 // For LSDA exchange energy
229 static void slater_spin( const double &rho, const double &zeta,
230 double &ex, double &vxup, double &vxdw);
231 static void slater1_spin( const double &rho, const double &zeta,
232 double &ex, double &vxup, double &vxdw);
233 static void slater_rxc_spin( const double &rho, const double &z,
234 double &ex, double &vxup, double &vxdw);
235
236//-------------------
237// xc_funct_corr_lda.cpp
238//-------------------
239
240// This file contains realization of LDA correlation functionals
241// Spin unpolarized ones:
242// 1. pw : Perdew-Wang LDA correlation
243// 2. pz : Perdew-Zunger LDA correlation
244// 3. lyp : Lee-Yang-Parr correlation
245// 4. vwn : Vosko-Wilk-Nusair LDA correlation
246// 5. wigner : Wigner
247// 6. hl : Hedin-Lunqvist
248// 7. gl : Gunnarson-Lunqvist
249// And some of their spin polarized counterparts:
250// 1. pw_spin
251// 2. pz_spin, which calls pz_polarized
252
253 // For LDA correlation energy
254 static void pw(const double &rs, const int &iflag, double &ec, double &vc);
255 static void pz(const double &rs, const int &iflag, double &ec, double &vc);
256 static void lyp(const double &rs, double &ec, double &vc);
257 static void vwn(const double &rs, double &ec, double &vc);
258 static void wigner(const double &rs, double &ec, double &vc);
259 static void hl(const double &rs, double &ec, double &vc);
260 static void gl(const double &rs, double &ec, double &vc);
261
262 // For LSDA correlation energy
263 static void pw_spin( const double &rs, const double &zeta,
264 double &ec, double &vcup, double &vcdw);
265 static void pz_spin( const double &rs, const double &zeta,
266 double &ec, double &vcup, double &vcdw);
267 static void pz_polarized( const double &rs, double &ec, double &vc);
268
269//-------------------
270// xc_funct_exch_gga.cpp
271//-------------------
272
273// This file contains realizations of gradient correction to exchange part
274// Spin unpolarized ones:
275// 1. becke88 : Becke88 exchange
276// 2. ggax : PW91 exchange
277// 3. pbex : PBE exchange (and revPBE)
278// 4. optx : OPTX, Handy et al.
279// 5. wcx : Wu-Cohen exchange
280// And some of their spin polarized counterparts:
281// 1. becke88_spin
282
283 static void becke88(const double &rho, const double &grho, double &sx, double &v1x, double &v2x);
284 static void ggax(const double &rho, const double &grho, double &sx, double &v1x, double &v2x);
285 static void pbex(const double &rho, const double &grho, const int &iflag,
286 double &sx, double &v1x, double &v2x);
287 static void optx(const double rho, const double grho, double &sx, double &v1x, double &v2x);
288 static void wcx(const double &rho,const double &grho, double &sx, double &v1x, double &v2x);
289
290 static void becke88_spin(double rho, double grho, double &sx, double &v1x,
291 double &v2x);
292
293//-------------------
294// xc_funct_corr_gga.cpp
295//-------------------
296
297// This file contains realizations of gradient correction to correlation part
298// Spin unpolarized ones:
299// 1. perdew86 : P86
300// 2. ggac : PW91
301// 3. pbec
302// 4. glyp
303// And some of their spin polarized counterparts:
304// 1. perdew86_spin
305// 2. ggac_spin
306// 3. pbec_spin
307
308 static void perdew86(const double rho, const double grho, double &sc, double &v1c, double &v2c);
309 static void ggac(const double &rho,const double &grho, double &sc, double &v1c, double &v2c);
310 static void pbec(const double &rho, const double &grho, const int &flag,
311 double &sc, double &v1c, double &v2c);
312 static void glyp(const double &rho, const double &grho, double &sc, double &v1c, double &v2c);
313
314 static void perdew86_spin(double rho, double zeta, double grho, double &sc,
315 double &v1cup, double &v1cdw, double &v2c);
316 //static void ggac_spin(double rho, double zeta, double grho, double &sc,
317 // double &v1cup, double &v1cdw, double &v2c);
318 static void pbec_spin(double rho, double zeta, double grho, const int &flag, double &sc,
319 double &v1cup, double &v1cdw, double &v2c);
320
321//-------------------
322// xc_funct_hcth.cpp
323//-------------------
324// This file contains realizations of the HCTH GGA functional
325// hcth calls pwcorr
326
327 static void hcth(const double rho, const double grho, double &sx, double &v1x, double &v2x);
328 static void pwcorr(const double r, const double c[], double &g, double &dg);
329
330};
331
332#endif //XC_FUNCTION_H
Definition charge.h:18
3 elements vector
Definition vector3.h:22
Definition matrix.h:19
Special pw_basis class. It includes different k-points.
Definition pw_basis_k.h:57
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:56
Definition unitcell.h:17
Definition xc_functional.h:26
static void set_xc_first_loop(const UnitCell &ucell)
Usually in exx caculation, the first SCF loop should be converged with PBE.
Definition xc_functional.cpp:26
static void gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v, const Charge *const chr, ModulePW::PW_Basis *rhopw, const UnitCell *ucell, std::vector< double > &stress_gga, const bool is_stress=false)
Definition xc_functional_gradcorr.cpp:25
static void gcx_spin(double rhoup, double rhodw, double grhoup2, double grhodw2, double &sx, double &v1xup, double &v1xdw, double &v2xup, double &v2xdw)
Definition xc_functional_wrapper_gcxc.cpp:108
static std::tuple< double, double, ModuleBase::matrix > v_xc(const int &nrxx, const Charge *const chr, const UnitCell *ucell)
Definition xc_functional_vxc.cpp:17
static void set_hybrid_alpha(const double alpha_in)
Definition xc_functional.cpp:21
static bool ked_flag
Definition xc_functional.h:92
static void wcx(const double &rho, const double &grho, double &sx, double &v1x, double &v2x)
Definition xc_funct_exch_gga.cpp:185
static void grad_dot(const ModuleBase::Vector3< double > *h, double *dh, const ModulePW::PW_Basis *rho_basis, const double tpiba)
Definition xc_functional_gradcorr.cpp:692
static void gcc_spin(double rho, double &zeta, double grho, double &sc, double &v1cup, double &v1cdw, double &v2c)
Definition xc_functional_wrapper_gcxc.cpp:226
static void pbex(const double &rho, const double &grho, const int &iflag, double &sx, double &v1x, double &v2x)
Definition xc_funct_exch_gga.cpp:78
static void lyp(const double &rs, double &ec, double &vc)
Definition xc_funct_corr_lda.cpp:106
static void grad_rho(const std::complex< double > *rhog, ModuleBase::Vector3< double > *gdr, const ModulePW::PW_Basis *rho_basis, const double tpiba)
Definition xc_functional_gradcorr.cpp:657
static void becke88_spin(double rho, double grho, double &sx, double &v1x, double &v2x)
Definition xc_funct_exch_gga.cpp:247
static void becke88(const double &rho, const double &grho, double &sx, double &v1x, double &v2x)
Definition xc_funct_exch_gga.cpp:13
static void ggac(const double &rho, const double &grho, double &sc, double &v1c, double &v2c)
Definition xc_funct_corr_gga.cpp:61
static int get_func_type()
Definition xc_functional.h:67
static void pz(const double &rs, const int &iflag, double &ec, double &vc)
Definition xc_funct_corr_lda.cpp:71
static double hybrid_alpha
Definition xc_functional.h:96
static void pbec(const double &rho, const double &grho, const int &flag, double &sc, double &v1c, double &v2c)
Definition xc_funct_corr_gga.cpp:135
static void optx(const double rho, const double grho, double &sx, double &v1x, double &v2x)
Definition xc_funct_exch_gga.cpp:133
static void slater_spin(const double &rho, const double &zeta, double &ex, double &vxup, double &vxdw)
Definition xc_funct_exch_lda.cpp:59
static void noncolin_rho(double *rhoout1, double *rhoout2, double *seg, const double *const *const rho, const int nrxx, const double *ux_, const bool lsign_)
Definition xc_functional_gradcorr.cpp:743
static std::string output_info()
Definition xc_functional.cpp:331
static void pw_spin(const double &rs, const double &zeta, double &ec, double &vcup, double &vcdw)
Definition xc_funct_corr_lda.cpp:192
static std::map< int, double > scaling_factor_xc
Definition xc_functional.h:19
static void wigner(const double &rs, double &ec, double &vc)
Definition xc_funct_corr_lda.cpp:154
~XC_Functional()
Definition xc_functional.cpp:12
static void hl(const double &rs, double &ec, double &vc)
Definition xc_funct_corr_lda.cpp:167
static void xc_spin(const double &rho, const double &zeta, double &exc, double &vxcup, double &vxcdw)
Definition xc_functional_wrapper_xc.cpp:73
static void pbec_spin(double rho, double zeta, double grho, const int &flag, double &sc, double &v1cup, double &v1cdw, double &v2c)
Definition xc_funct_corr_gga.cpp:372
static void hcth(const double rho, const double grho, double &sx, double &v1x, double &v2x)
Definition xc_funct_hcth.cpp:5
static void set_xc_type(const std::string xc_func_in)
Definition xc_functional.cpp:59
static bool use_libxc
Definition xc_functional.h:93
static void grad_wfc(const int ik, const Real tpiba, const ModulePW::PW_Basis_K *wfc_basis, const T *rhog, T *grad)
Definition xc_functional_gradcorr.cpp:618
static void perdew86(const double rho, const double grho, double &sc, double &v1c, double &v2c)
Definition xc_funct_corr_gga.cpp:14
static bool get_ked_flag()
Definition xc_functional.h:79
static void slater1(const double &rs, double &ex, double &vx)
Definition xc_funct_exch_lda.cpp:26
static void slater_rxc(const double &rs, double &ex, double &vx)
Definition xc_funct_exch_lda.cpp:36
static void pz_polarized(const double &rs, double &ec, double &vc)
Definition xc_funct_corr_lda.cpp:331
static void ggax(const double &rho, const double &grho, double &sx, double &v1x, double &v2x)
Definition xc_funct_exch_gga.cpp:41
static std::vector< int > func_id
Definition xc_functional.h:90
static void slater_rxc_spin(const double &rho, const double &z, double &ex, double &vxup, double &vxdw)
Definition xc_funct_exch_lda.cpp:100
static void xc(const double &rho, double &exc, double &vxc)
Definition xc_functional_wrapper_xc.cpp:15
static int func_type
Definition xc_functional.h:91
static double get_hybrid_alpha()
Definition xc_functional.h:75
static void gl(const double &rs, double &ec, double &vc)
Definition xc_funct_corr_lda.cpp:179
static void vwn(const double &rs, double &ec, double &vc)
Definition xc_funct_corr_lda.cpp:125
static void pz_spin(const double &rs, const double &zeta, double &ec, double &vcup, double &vcdw)
Definition xc_funct_corr_lda.cpp:300
static void slater(const double &rs, double &ex, double &vx)
Definition xc_funct_exch_lda.cpp:14
static void slater1_spin(const double &rho, const double &zeta, double &ex, double &vxup, double &vxdw)
Definition xc_funct_exch_lda.cpp:80
static void gcxc(const double &rho, const double &grho, double &sxc, double &v1xc, double &v2xc)
Definition xc_functional_wrapper_gcxc.cpp:18
XC_Functional()
Definition xc_functional.cpp:10
static void glyp(const double &rho, const double &grho, double &sc, double &v1c, double &v2c)
Definition xc_funct_corr_gga.cpp:178
static void perdew86_spin(double rho, double zeta, double grho, double &sc, double &v1cup, double &v1cdw, double &v2c)
Definition xc_funct_corr_gga.cpp:212
static std::vector< int > get_func_id()
Definition xc_functional.h:103
static void pwcorr(const double r, const double c[], double &g, double &dg)
Definition xc_funct_hcth.cpp:129
#define T
Definition exp.cpp:237
Definition setup_pot.h:14
T type
Definition macros.h:8