1#ifndef ABACUS_SOURCE_LCAO_MODULE_LR_POTENTIALS_XC_KERNEL_H
2#define ABACUS_SOURCE_LCAO_MODULE_LR_POTENTIALS_XC_KERNEL_H
10#define CREF(x) const std::vector<double>& x = x##_
20 constexpr int p2[3][3] = { {0,1,2},{1,3,4},{2,4,5} };
23 constexpr int p3[3][3][3] = {
24 { {0,1,2},{1,3,4},{2,4,5} },
25 { {1,3,4},{3,6,7},{4,7,8} },
26 { {2,4,5},{4,7,8},{5,8,9} } };
28 inline constexpr int r3(
const int s0,
const int s1,
const int s2)
33 inline constexpr int r2(
const int s0,
const int s1)
38 inline constexpr int rs(
const int s,
const int a)
43 inline constexpr int r2s(
const int s0,
const int s1,
const int a)
45 return 3 * (s0 + s1) + a;
48 inline constexpr int rs2(
const int s,
const int a,
const int b)
50 return 6 * s +
p2[a][b];
55 constexpr double theta[2][3] = { {2., 1., 0.}, {0., 1., 2.} };
57 constexpr int chan[2][3] = { {0, 1, -1}, {-1, 0, 1} };
67 const int channel,
const double* density_response,
const double* sigma_response,
68 const int first_spin,
const int end_spin)
71 for (
int spin = first_spin; spin < end_spin; ++spin)
73 response += rho_sigma[
libxc_idx::rs(spin, channel)] * density_response[spin];
75 for (
int a = first_spin; a < end_spin + 1; ++a)
77 response += sigma_sigma[
libxc_idx::p2[channel][a]] * sigma_response[a];
85 using Tvec = std::vector<double>;
96 const std::string& kernel_name,
97 const std::vector<std::string>& lr_init_xc_kernel,
104 const int&
nspin,
const std::string& kernel_name,
105 const std::vector<std::string>& lr_init_xc_kernel,
bool openshell,
int gxc_spin);
117 const std::string&
name()
const
144 throw std::logic_error(
"Closed-shell GGA coefficients requested for an open-shell kernel");
190 throw std::runtime_error(
191 "KernelXC: the " + std::string(triplet ?
"triplet" :
"singlet")
192 +
" g^xc coefficients were not built; pass the matching `GxcSpin` flag to the constructor.");
218 void f_xc_libxc(
const int&
nspin,
const double& omega,
const double& tpiba,
const double*
const*
const rho_gs,
const double*
const rho_core =
nullptr);
220 void get_rho_drho_sigma(
const int&
nspin,
222 const double*
const*
const rho_gs,
223 const double*
const rho_core,
225 std::vector<double>& rho,
227 std::vector<double>& sigma);
240 std::vector<std::vector<ModuleBase::Vector3<double>>>
drho_gs_;
272 std::shared_ptr<const KernelXC>
build_xc_kernel(
const std::string& kernel_name,
274 const Parallel_Grid& pgrid,
const int nspin,
const bool openshell,
const int gxc_spin,
275 const std::vector<std::string>& lr_init_xc_kernel);
281 const std::vector<std::string>& lr_init_xc_kernel);
std::vector< double > Tvec
Definition xc_kernel.h:85
ClosedShellGga closed_shell_gga_t_
Definition xc_kernel.h:242
Tvec v3rho2sigma_
Definition xc_kernel.h:247
GxcCoef gxc_s_
Definition xc_kernel.h:253
~KernelXC()
Definition xc_kernel.h:106
const std::string kernel_name_
Definition xc_kernel.h:259
const GxcCoef & gxc(const bool triplet) const
Definition xc_kernel.h:185
int functional_type_
Definition xc_kernel.h:260
const ClosedShellGga & closed_shell_gga(const bool triplet) const
Definition xc_kernel.h:140
bool gs_sigma_fallback_used_
Definition xc_kernel.h:264
bool is_gga() const
Definition xc_kernel.h:210
Tvec v3rho3_
Definition xc_kernel.h:246
const std::string & name() const
Definition xc_kernel.h:117
int nspin() const
Metadata belongs to this coefficient set, independent of later global XC changes.
Definition xc_kernel.h:109
std::vector< double > v2rho2_
Definition xc_kernel.h:235
const Purpose purpose_
Definition xc_kernel.h:262
Tvec v3rhosigma2_
Definition xc_kernel.h:248
void build_gxc_coef(GxcCoef &dst, const bool triplet, const int &nspin, const bool &is_gga)
Fill dst for one spin combination. All the spin algebralives here, driven by the weight vectors that ...
GxcCoef gxc_t_
Definition xc_kernel.h:254
KernelXC(const ModulePW::PW_Basis &rho_basis, const UnitCell &ucell, const Charge &chg_gs, const Parallel_Grid &pgrid, const int &nspin, const std::string &kernel_name, const std::vector< std::string > &lr_init_xc_kernel, const bool openshell=false, const int gxc_spin=GxcSpin::NoGxc)
Definition xc_kernel.cpp:65
bool gs_sigma_fallback_used() const
Definition xc_kernel.h:124
std::vector< double > v2rhosigma_
Definition xc_kernel.h:236
const std::vector< std::vector< ModuleBase::Vector3< double > > > & drho_gs
Definition xc_kernel.h:203
const Tvec & sigma_jacobian() const
Definition xc_kernel.h:200
const int nspin_
Definition xc_kernel.h:258
const int gxc_spin_
which GxcCoef sets to build, see GxcSpin
Definition xc_kernel.h:261
std::vector< double > vrho_
Definition xc_kernel.h:233
const bool & openshell
Definition xc_kernel.h:202
std::vector< std::vector< ModuleBase::Vector3< double > > > drho_gs_
$\nabla\rho$ of the ground state, size: nspin*nrxx
Definition xc_kernel.h:240
GxcSpin
Which spin combinations of the $g^{xc}$ coefficient set (GxcCoef) to build.
Definition xc_kernel.h:88
@ BothSpins
Definition xc_kernel.h:88
@ Singlet
Definition xc_kernel.h:88
@ NoGxc
Definition xc_kernel.h:88
@ Triplet
Definition xc_kernel.h:88
ClosedShellGga closed_shell_gga_s_
Definition xc_kernel.h:241
std::vector< double > v2sigma2_
Definition xc_kernel.h:237
std::vector< double > vsigma_
Definition xc_kernel.h:234
int functional_type() const
Definition xc_kernel.h:113
const ModulePW::PW_Basis & rho_basis_
Definition xc_kernel.h:266
const bool openshell_
Definition xc_kernel.h:267
Tvec v3sigma3_
Definition xc_kernel.h:249
Tvec sigma_jacobian_
Definition xc_kernel.h:263
Purpose
GS response starts from raw sigma; non-finite HSE coefficients trigger a reported fallback.
Definition xc_kernel.h:90
@ GroundStateResponse
Definition xc_kernel.h:90
@ LinearResponse
Definition xc_kernel.h:90
3 elements vector
Definition vector3.h:21
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:60
Definition parallel_grid.h:8
Provide the basic information about unitcell.
Definition unitcell.h:16
Definition xc_kernel.h:18
constexpr double theta[2][3]
Definition xc_kernel.h:55
constexpr int chan[2][3]
which density-gradient channel goes with (tau, a); -1 where theta vanishes
Definition xc_kernel.h:57
constexpr int rs(const int s, const int a)
v2rhosigma (6): [rho u,d] x [sigma uu,ud,dd]
Definition xc_kernel.h:38
constexpr int p2[3][3]
unordered sigma PAIR -> v2sigma2 (6) and the per-rho block of v3rhosigma2
Definition xc_kernel.h:20
constexpr int r2(const int s0, const int s1)
v2rho2 (3): (uu,ud,dd)
Definition xc_kernel.h:33
constexpr int rs2(const int s, const int a, const int b)
v3rhosigma2 (12): [rho u,d] x [unordered sigma pair]
Definition xc_kernel.h:48
constexpr int r2s(const int s0, const int s1, const int a)
v3rho2sigma (9): [rho-pair uu,ud,dd] x [sigma uu,ud,dd]
Definition xc_kernel.h:43
constexpr int p3[3][3][3]
Definition xc_kernel.h:23
constexpr int r3(const int s0, const int s1, const int s2)
v3rho3 (4): (uuu,uud,udd,ddd) – indexed by the number of d's
Definition xc_kernel.h:28
Definition esolver_lr_lcao_tddft.h:28
double sigma_potential_derivative(const double *rho_sigma, const double *sigma_sigma, const int channel, const double *density_response, const double *sigma_response, const int first_spin, const int end_spin)
Definition xc_kernel.h:66
std::shared_ptr< const KernelXC > build_gs_xc_kernel(const std::string &kernel_name, const ModulePW::PW_Basis &rho_basis, const UnitCell &ucell, const Charge &chg_gs, const Parallel_Grid &pgrid, int nspin, bool openshell, const std::vector< std::string > &lr_init_xc_kernel)
Definition xc_kernel.cpp:79
std::shared_ptr< const KernelXC > build_xc_kernel(const std::string &kernel_name, const ModulePW::PW_Basis &rho_basis, const UnitCell &ucell, const Charge &chg_gs, const Parallel_Grid &pgrid, const int nspin, const bool openshell, const int gxc_spin, const std::vector< std::string > &lr_init_xc_kernel)
Definition xc_kernel.cpp:56
Definition xc_kernel.h:136
Tvec rho_sigma
Definition xc_kernel.h:137
Tvec sigma_sigma
Definition xc_kernel.h:138
The coefficients of $v^{(2)}(r)=\iint dr'dr''\,g^{xc}(r,r',r'')\rho^1(r')\rho^1(r'')$ for ONE spin co...
Definition xc_kernel.h:168
std::vector< double > a_st
Definition xc_kernel.h:173
bool built
Availability is independent of the number of points assigned to this rank.
Definition xc_kernel.h:170
std::vector< double > e_t2
Definition xc_kernel.h:179
std::vector< double > e_st
Definition xc_kernel.h:178
std::vector< double > e_q
Definition xc_kernel.h:180
std::vector< double > e_s2
Definition xc_kernel.h:177
std::vector< double > a_s2
Definition xc_kernel.h:172
std::vector< double > a_q
Definition xc_kernel.h:175
std::vector< double > a_t2
Definition xc_kernel.h:174