Skip to content

Commit 5778743

Browse files
committed
Merge branch 'convert_vtxc_v' of https://gitee.com/linpeize/abacus-develop into rdmft
2 parents 4f0e78e + 1e79ca3 commit 5778743

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

source/module_hamilt_general/module_xc/xc_functional_libxc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace XC_Functional_Libxc
6868
// calculating grho
6969
extern std::vector<std::vector<ModuleBase::Vector3<double>>> cal_gdr(
7070
const int nspin,
71+
const std::size_t nrxx,
7172
const std::vector<double> &rho,
7273
const double tpiba,
7374
const Charge* const chr);
@@ -95,7 +96,7 @@ namespace XC_Functional_Libxc
9596
std::vector<double> exc);
9697

9798
// converting vtxc and v from vrho and vsigma (libxc=>abacus)
98-
extern double convert_vtxc_v(
99+
extern std::pair<double,ModuleBase::matrix> convert_vtxc_v(
99100
const xc_func_type &func,
100101
const int nspin,
101102
const std::size_t nrxx,
@@ -105,8 +106,7 @@ namespace XC_Functional_Libxc
105106
const std::vector<double> &vrho,
106107
const std::vector<double> &vsigma,
107108
const double tpiba,
108-
const Charge* const chr,
109-
ModuleBase::matrix &v);
109+
const Charge* const chr);
110110

111111
// dh for gga v
112112
extern std::vector<std::vector<double>> cal_dh(

source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ XC_Functional_Libxc::convert_rho_amag_nspin4(
5151
std::vector<std::vector<ModuleBase::Vector3<double>>>
5252
XC_Functional_Libxc::cal_gdr(
5353
const int nspin,
54+
const std::size_t nrxx,
5455
const std::vector<double> &rho,
5556
const double tpiba,
5657
const Charge* const chr)
5758
{
5859
std::vector<std::vector<ModuleBase::Vector3<double>>> gdr(nspin);
59-
const std::size_t nrxx = rho.size();
6060
for( int is=0; is!=nspin; ++is )
6161
{
6262
std::vector<double> rhor(nrxx);
@@ -163,8 +163,8 @@ double XC_Functional_Libxc::convert_etxc(
163163
return etxc;
164164
}
165165

166-
// converting etxc from exc (libxc=>abacus)
167-
double XC_Functional_Libxc::convert_vtxc_v(
166+
// converting vtxc and v from vrho and vsigma (libxc=>abacus)
167+
std::pair<double,ModuleBase::matrix> XC_Functional_Libxc::convert_vtxc_v(
168168
const xc_func_type &func,
169169
const int nspin,
170170
const std::size_t nrxx,
@@ -174,13 +174,10 @@ double XC_Functional_Libxc::convert_vtxc_v(
174174
const std::vector<double> &vrho,
175175
const std::vector<double> &vsigma,
176176
const double tpiba,
177-
const Charge* const chr,
178-
ModuleBase::matrix &v)
177+
const Charge* const chr)
179178
{
180-
assert(v.nr==nspin);
181-
assert(v.nc==nrxx);
182-
183179
double vtxc = 0.0;
180+
ModuleBase::matrix v(nspin, nrxx);
184181

185182
#ifdef _OPENMP
186183
#pragma omp parallel for collapse(2) reduction(+:vtxc) schedule(static, 256)
@@ -215,7 +212,7 @@ double XC_Functional_Libxc::convert_vtxc_v(
215212
vtxc -= rvtxc;
216213
} // end if(func.info->family == XC_FAMILY_GGA || func.info->family == XC_FAMILY_HYB_GGA))
217214

218-
return vtxc;
215+
return std::make_pair(vtxc, std::move(v));
219216
}
220217

221218

source/module_hamilt_general/module_xc/xc_functional_libxc_vxc.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
6868
std::vector<double> sigma;
6969
if(is_gga)
7070
{
71-
gdr = XC_Functional_Libxc::cal_gdr(nspin, rho, tpiba, chr);
71+
gdr = XC_Functional_Libxc::cal_gdr(nspin, nrxx, rho, tpiba, chr);
7272
sigma = XC_Functional_Libxc::convert_sigma(gdr);
7373
}
7474

@@ -110,12 +110,13 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
110110
}
111111

112112
etxc += XC_Functional_Libxc::convert_etxc(nspin, nrxx, sgn, rho, exc);
113-
vtxc += XC_Functional_Libxc::convert_vtxc_v(
113+
const std::pair<double,ModuleBase::matrix> vtxc_v = XC_Functional_Libxc::convert_vtxc_v(
114114
func, nspin, nrxx,
115115
sgn, rho, gdr,
116116
vrho, vsigma,
117-
tpiba, chr,
118-
v);
117+
tpiba, chr);
118+
vtxc += std::get<0>(vtxc_v);
119+
v += std::get<1>(vtxc_v);
119120
} // end for( xc_func_type &func : funcs )
120121

121122
if(4==PARAM.inp.nspin)
@@ -183,7 +184,7 @@ std::tuple<double,double,ModuleBase::matrix,ModuleBase::matrix> XC_Functional_Li
183184

184185
const std::vector<double> rho = XC_Functional_Libxc::convert_rho(nspin, nrxx, chr);
185186
const std::vector<std::vector<ModuleBase::Vector3<double>>> gdr
186-
= XC_Functional_Libxc::cal_gdr(nspin, rho, tpiba, chr);
187+
= XC_Functional_Libxc::cal_gdr(nspin, nrxx, rho, tpiba, chr);
187188
const std::vector<double> sigma = XC_Functional_Libxc::convert_sigma(gdr);
188189

189190
//converting kin_r

0 commit comments

Comments
 (0)