Skip to content

Commit 39c29d3

Browse files
authored
Refactor XC_Functional_Libxc::convert_vtxc_v() (#5212)
* Fix memory bug in XC_Functional_Libxc::cal_gdr() * Refactor XC_Functional_Libxc::convert_vtxc_v()
1 parent 5ccb292 commit 39c29d3

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

source/module_hamilt_general/module_xc/xc_functional_libxc.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace XC_Functional_Libxc
9696
std::vector<double> exc);
9797

9898
// converting vtxc and v from vrho and vsigma (libxc=>abacus)
99-
extern double convert_vtxc_v(
99+
extern std::pair<double,ModuleBase::matrix> convert_vtxc_v(
100100
const xc_func_type &func,
101101
const int nspin,
102102
const std::size_t nrxx,
@@ -106,8 +106,7 @@ namespace XC_Functional_Libxc
106106
const std::vector<double> &vrho,
107107
const std::vector<double> &vsigma,
108108
const double tpiba,
109-
const Charge* const chr,
110-
ModuleBase::matrix &v);
109+
const Charge* const chr);
111110

112111
// dh for gga v
113112
extern std::vector<std::vector<double>> cal_dh(

source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

0 commit comments

Comments
 (0)