From 4f35e360c77fdad597b903320b98ade0b447e3af Mon Sep 17 00:00:00 2001 From: linpz Date: Tue, 8 Oct 2024 13:31:03 +0800 Subject: [PATCH] Fix memory bug in XC_Functional_Libxc::cal_gdr() --- source/module_hamilt_general/module_xc/xc_functional_libxc.h | 1 + .../module_xc/xc_functional_libxc_tools.cpp | 2 +- .../module_xc/xc_functional_libxc_vxc.cpp | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) 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 73bf03e51c..1d04f5ee20 100644 --- a/source/module_hamilt_general/module_xc/xc_functional_libxc.h +++ b/source/module_hamilt_general/module_xc/xc_functional_libxc.h @@ -68,6 +68,7 @@ namespace XC_Functional_Libxc // calculating grho extern std::vector>> cal_gdr( const int nspin, + const std::size_t nrxx, const std::vector &rho, const double tpiba, const Charge* const chr); 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 c8513001a3..701502918d 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 @@ -51,12 +51,12 @@ XC_Functional_Libxc::convert_rho_amag_nspin4( std::vector>> XC_Functional_Libxc::cal_gdr( const int nspin, + const std::size_t nrxx, const std::vector &rho, const double tpiba, const Charge* const chr) { std::vector>> gdr(nspin); - const std::size_t nrxx = rho.size(); for( int is=0; is!=nspin; ++is ) { std::vector rhor(nrxx); 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 a215c02fe9..ca08be0697 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 @@ -68,7 +68,7 @@ std::tuple XC_Functional_Libxc::v_xc_libxc( / std::vector sigma; if(is_gga) { - gdr = XC_Functional_Libxc::cal_gdr(nspin, rho, tpiba, chr); + gdr = XC_Functional_Libxc::cal_gdr(nspin, nrxx, rho, tpiba, chr); sigma = XC_Functional_Libxc::convert_sigma(gdr); } @@ -183,7 +183,7 @@ std::tuple XC_Functional_Li const std::vector rho = XC_Functional_Libxc::convert_rho(nspin, nrxx, chr); const std::vector>> gdr - = XC_Functional_Libxc::cal_gdr(nspin, rho, tpiba, chr); + = XC_Functional_Libxc::cal_gdr(nspin, nrxx, rho, tpiba, chr); const std::vector sigma = XC_Functional_Libxc::convert_sigma(gdr); //converting kin_r