diff --git a/source/module_hamilt_general/module_xc/xc_functional_libxc.h b/source/module_hamilt_general/module_xc/xc_functional_libxc.h index 1d04f5ee20..75b2693d0e 100644 --- a/source/module_hamilt_general/module_xc/xc_functional_libxc.h +++ b/source/module_hamilt_general/module_xc/xc_functional_libxc.h @@ -96,7 +96,7 @@ namespace XC_Functional_Libxc std::vector exc); // converting vtxc and v from vrho and vsigma (libxc=>abacus) - extern double convert_vtxc_v( + extern std::pair convert_vtxc_v( const xc_func_type &func, const int nspin, const std::size_t nrxx, @@ -106,8 +106,7 @@ namespace XC_Functional_Libxc const std::vector &vrho, const std::vector &vsigma, const double tpiba, - const Charge* const chr, - ModuleBase::matrix &v); + const Charge* const chr); // dh for gga v extern std::vector> cal_dh( diff --git a/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp b/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp index 701502918d..6975d066b7 100644 --- a/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp +++ b/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp @@ -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 XC_Functional_Libxc::convert_vtxc_v( const xc_func_type &func, const int nspin, const std::size_t nrxx, @@ -174,13 +174,10 @@ double XC_Functional_Libxc::convert_vtxc_v( const std::vector &vrho, const std::vector &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) @@ -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)); } diff --git a/source/module_hamilt_general/module_xc/xc_functional_libxc_vxc.cpp b/source/module_hamilt_general/module_xc/xc_functional_libxc_vxc.cpp index ca08be0697..8b270cd233 100644 --- a/source/module_hamilt_general/module_xc/xc_functional_libxc_vxc.cpp +++ b/source/module_hamilt_general/module_xc/xc_functional_libxc_vxc.cpp @@ -110,12 +110,13 @@ std::tuple 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 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)