Skip to content

Commit

Permalink
Refactor XC_Functional_Libxc::convert_vtxc_v() (#5212)
Browse files Browse the repository at this point in the history
* Fix memory bug in XC_Functional_Libxc::cal_gdr()

* Refactor XC_Functional_Libxc::convert_vtxc_v()
  • Loading branch information
PeizeLin authored Oct 18, 2024
1 parent 5ccb292 commit 39c29d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
5 changes: 2 additions & 3 deletions source/module_hamilt_general/module_xc/xc_functional_libxc.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace XC_Functional_Libxc
std::vector<double> exc);

// converting vtxc and v from vrho and vsigma (libxc=>abacus)
extern double convert_vtxc_v(
extern std::pair<double,ModuleBase::matrix> convert_vtxc_v(
const xc_func_type &func,
const int nspin,
const std::size_t nrxx,
Expand All @@ -106,8 +106,7 @@ namespace XC_Functional_Libxc
const std::vector<double> &vrho,
const std::vector<double> &vsigma,
const double tpiba,
const Charge* const chr,
ModuleBase::matrix &v);
const Charge* const chr);

// dh for gga v
extern std::vector<std::vector<double>> cal_dh(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ double XC_Functional_Libxc::convert_etxc(
return etxc;
}

// converting etxc from exc (libxc=>abacus)
double XC_Functional_Libxc::convert_vtxc_v(
// converting vtxc and v from vrho and vsigma (libxc=>abacus)
std::pair<double,ModuleBase::matrix> XC_Functional_Libxc::convert_vtxc_v(
const xc_func_type &func,
const int nspin,
const std::size_t nrxx,
Expand All @@ -174,13 +174,10 @@ double XC_Functional_Libxc::convert_vtxc_v(
const std::vector<double> &vrho,
const std::vector<double> &vsigma,
const double tpiba,
const Charge* const chr,
ModuleBase::matrix &v)
const Charge* const chr)
{
assert(v.nr==nspin);
assert(v.nc==nrxx);

double vtxc = 0.0;
ModuleBase::matrix v(nspin, nrxx);

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

return vtxc;
return std::make_pair(vtxc, std::move(v));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
}

etxc += XC_Functional_Libxc::convert_etxc(nspin, nrxx, sgn, rho, exc);
vtxc += XC_Functional_Libxc::convert_vtxc_v(
const std::pair<double,ModuleBase::matrix> vtxc_v = XC_Functional_Libxc::convert_vtxc_v(
func, nspin, nrxx,
sgn, rho, gdr,
vrho, vsigma,
tpiba, chr,
v);
tpiba, chr);
vtxc += std::get<0>(vtxc_v);
v += std::get<1>(vtxc_v);
} // end for( xc_func_type &func : funcs )

if(4==PARAM.inp.nspin)
Expand Down

0 comments on commit 39c29d3

Please sign in to comment.