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 private:
87
88 static std::vector<int> func_id; // libxc id of functional
89 static int func_type; //0:none, 1:lda, 2:gga, 3:mgga, 4:hybrid lda/gga, 5:hybrid mgga
90 static bool ked_flag; // whether the functional has kinetic energy density
91 static bool use_libxc;
92
93 // exx_hybrid_alpha for mixing exx in hybrid functional:
94 static double hybrid_alpha;
95
96 // added by jghan, 2024-07-07
97 // as a scaling factor for different xc-functionals
98 static std::map<int, double> scaling_factor_xc;
99
100 public:
101 static std::vector<int> get_func_id() { return func_id; }
102
103//-------------------
104// xc_functional_wrapper_xc.cpp
105//-------------------
106
107// This file contains wrapper for the LDA functionals
108// it includes 3 subroutines:
109// 1. xc, which is the wrapper of LDA part
110// (i.e. LDA functional and LDA part of GGA functional)
111// 2. xc_spin, which is the spin polarized counterpart of xc
112// 3. xc_spin_libxc, which is the wrapper for LDA functional, spin polarized
113
114// NOTE : In our own realization of GGA functional, the LDA part
115// and gradient correction are calculated separately.
116// The LDA part is provided in xc, while the gradient correction is
117// provided in gradcorr through gcxc/gcx_spin+gcc_spin.
118// While in LIBXC, the entire GGA functional is provided.
119// As a result, xc/xc_spin and xc_spin_libxc are different for GGA,
120// the former gives nonzero result, while the latter returns 0.
121// Furthermore, the reason for not having xc_libxc is that something like
122// xc_libxc which evaluates functional for individual grid points
123// is not efficient. For nspin = 1 and 2, v_xc_libxc evaluates potential
124// on the entire grid. I'm having xc_spin_libxc because v_xc_libxc
125// does not support nspin = 4.
126
127 public:
128
129 // LDA
130 static void xc(const double &rho, double &exc, double &vxc);
131
132 // LSDA
133 static void xc_spin(const double &rho, const double &zeta,
134 double &exc, double &vxcup, double &vxcdw);
135
136//-------------------
137// xc_functional_wrapper_gcxc.cpp
138//-------------------
139
140// This file contains wrapper for the GGA functionals
141// it includes 4 subroutines:
142// 1. gcxc, which is the wrapper for gradient correction part
143// 2. gcx_spin, spin polarized, exchange only
144// 3. gcc_spin, spin polarized, correlation only
145
146// The difference between our realization (gcxc/gcx_spin/gcc_spin) and
147// LIBXC, and the reason for not having gcxc_libxc is explained
148// in the NOTE in the comment for xc_functional_wrapper_wc.cpp part
149
150 // GGA
151 static void gcxc(const double &rho, const double &grho,
152 double &sxc, double &v1xc, double &v2xc);
153
154 // spin polarized GGA
155 static void gcx_spin(double rhoup, double rhodw, double grhoup2, double grhodw2,
156 double &sx, double &v1xup, double &v1xdw, double &v2xup,
157 double &v2xdw);
158 static void gcc_spin(double rho, double &zeta, double grho, double &sc,
159 double &v1cup, double &v1cdw, double &v2c);
160
161//-------------------
162// xc_functional_gradcorr.cpp
163//-------------------
164
165// This file contains subroutines realted to gradient calculations
166// it contains 5 subroutines:
167// 1. gradcorr, which calculates gradient correction
168// 2. grad_wfc, which calculates gradient of wavefunction
169// it is used in stress_func_mgga.cpp
170// 3. grad_rho, which calculates gradient of density
171// 4. grad_dot, which calculates divergence of something
172// 5. noncolin_rho, which diagonalizes the spin density matrix
173// and gives the spin up and spin down components of the charge.
174
175 static void gradcorr(double& etxc,
176 double& vtxc,
178 const Charge* const chr,
179 ModulePW::PW_Basis* rhopw,
180 const UnitCell* ucell,
181 std::vector<double>& stress_gga,
182 const bool is_stress = false);
183 template <typename T, typename Device,
184 typename Real = typename GetTypeReal<T>::type>
185 static void grad_wfc(
186 const int ik,
187 const Real tpiba,
188 const ModulePW::PW_Basis_K* wfc_basis,
189 const T* rhog,
190 T* grad);
191 static void grad_rho(const std::complex<double>* rhog,
193 const ModulePW::PW_Basis* rho_basis,
194 const double tpiba);
195 static void grad_dot(const ModuleBase::Vector3<double>* h,
196 double* dh,
197 const ModulePW::PW_Basis* rho_basis,
198 const double tpiba);
199 static void noncolin_rho(double* rhoout1,
200 double* rhoout2,
201 double* seg,
202 const double* const* const rho,
203 const int nrxx,
204 const double* ux_,
205 const bool lsign_);
206
207 //-------------------
208 // xc_funct_exch_lda.cpp
209 //-------------------
210
211 // This file contains realization of LDA exchange functionals
212 // Spin unpolarized ones:
213 // 1. slater: ordinary Slater exchange with alpha=2/3
214 // 2. slater1: Slater exchange with alpha=1
215 // 3. slater_rxc : Slater exchange with alpha=2/3 and Relativistic exchange
216 // And their spin polarized counterparts:
217 // 1. slater_spin
218 // 2. slater1_spin
219 // 3. slater_rxc_spin
220
221 // For LDA exchange energy
222 static void slater(const double &rs, double &ex, double &vx);
223 static void slater1(const double &rs, double &ex, double &vx);
224 static void slater_rxc(const double &rs, double &ex, double &vx);
225
226 // For LSDA exchange energy
227 static void slater_spin( const double &rho, const double &zeta,
228 double &ex, double &vxup, double &vxdw);
229 static void slater1_spin( const double &rho, const double &zeta,
230 double &ex, double &vxup, double &vxdw);
231 static void slater_rxc_spin( const double &rho, const double &z,
232 double &ex, double &vxup, double &vxdw);
233
234//-------------------
235// xc_funct_corr_lda.cpp
236//-------------------
237
238// This file contains realization of LDA correlation functionals
239// Spin unpolarized ones:
240// 1. pw : Perdew-Wang LDA correlation
241// 2. pz : Perdew-Zunger LDA correlation
242// 3. lyp : Lee-Yang-Parr correlation
243// 4. vwn : Vosko-Wilk-Nusair LDA correlation
244// 5. wigner : Wigner
245// 6. hl : Hedin-Lunqvist
246// 7. gl : Gunnarson-Lunqvist
247// And some of their spin polarized counterparts:
248// 1. pw_spin
249// 2. pz_spin, which calls pz_polarized
250
251 // For LDA correlation energy
252 static void pw(const double &rs, const int &iflag, double &ec, double &vc);
253 static void pz(const double &rs, const int &iflag, double &ec, double &vc);
254 static void lyp(const double &rs, double &ec, double &vc);
255 static void vwn(const double &rs, double &ec, double &vc);
256 static void wigner(const double &rs, double &ec, double &vc);
257 static void hl(const double &rs, double &ec, double &vc);
258 static void gl(const double &rs, double &ec, double &vc);
259
260 // For LSDA correlation energy
261 static void pw_spin( const double &rs, const double &zeta,
262 double &ec, double &vcup, double &vcdw);
263 static void pz_spin( const double &rs, const double &zeta,
264 double &ec, double &vcup, double &vcdw);
265 static void pz_polarized( const double &rs, double &ec, double &vc);
266
267//-------------------
268// xc_funct_exch_gga.cpp
269//-------------------
270
271// This file contains realizations of gradient correction to exchange part
272// Spin unpolarized ones:
273// 1. becke88 : Becke88 exchange
274// 2. ggax : PW91 exchange
275// 3. pbex : PBE exchange (and revPBE)
276// 4. optx : OPTX, Handy et al.
277// 5. wcx : Wu-Cohen exchange
278// And some of their spin polarized counterparts:
279// 1. becke88_spin
280
281 static void becke88(const double &rho, const double &grho, double &sx, double &v1x, double &v2x);
282 static void ggax(const double &rho, const double &grho, double &sx, double &v1x, double &v2x);
283 static void pbex(const double &rho, const double &grho, const int &iflag,
284 double &sx, double &v1x, double &v2x);
285 static void optx(const double rho, const double grho, double &sx, double &v1x, double &v2x);
286 static void wcx(const double &rho,const double &grho, double &sx, double &v1x, double &v2x);
287
288 static void becke88_spin(double rho, double grho, double &sx, double &v1x,
289 double &v2x);
290
291//-------------------
292// xc_funct_corr_gga.cpp
293//-------------------
294
295// This file contains realizations of gradient correction to correlation part
296// Spin unpolarized ones:
297// 1. perdew86 : P86
298// 2. ggac : PW91
299// 3. pbec
300// 4. glyp
301// And some of their spin polarized counterparts:
302// 1. perdew86_spin
303// 2. ggac_spin
304// 3. pbec_spin
305
306 static void perdew86(const double rho, const double grho, double &sc, double &v1c, double &v2c);
307 static void ggac(const double &rho,const double &grho, double &sc, double &v1c, double &v2c);
308 static void pbec(const double &rho, const double &grho, const int &flag,
309 double &sc, double &v1c, double &v2c);
310 static void glyp(const double &rho, const double &grho, double &sc, double &v1c, double &v2c);
311
312 static void perdew86_spin(double rho, double zeta, double grho, double &sc,
313 double &v1cup, double &v1cdw, double &v2c);
314 //static void ggac_spin(double rho, double zeta, double grho, double &sc,
315 // double &v1cup, double &v1cdw, double &v2c);
316 static void pbec_spin(double rho, double zeta, double grho, const int &flag, double &sc,
317 double &v1cup, double &v1cdw, double &v2c);
318
319//-------------------
320// xc_funct_hcth.cpp
321//-------------------
322// This file contains realizations of the HCTH GGA functional
323// hcth calls pwcorr
324
325 static void hcth(const double rho, const double grho, double &sx, double &v1x, double &v2x);
326 static void pwcorr(const double r, const double c[], double &g, double &dg);
327
328};
329
330#endif //XC_FUNCTION_H
Definition charge.h:20
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:16
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:90
static void wcx(const double &rho, const double &grho, double &sx, double &v1x, double &v2x)
Definition xc_funct_exch_gga.cpp:185
static void pw(const double &rs, const int &iflag, double &ec, double &vc)
Definition xc_funct_corr_lda.cpp:16
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:94
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 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:48
static bool use_libxc
Definition xc_functional.h:91
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:88
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:89
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:101
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
T type
Definition macros.h:8