Skip to content

Commit c234dd3

Browse files
authored
Fix: Fix the memory leak in integrated test case 919_OF_out_elf (#5211)
* Fix: Fix the memory leak caused by tau_vW * Fix the file name of spin polarised ELF Add a reference for epsilon defined in write_elf
1 parent 39df3b9 commit c234dd3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

source/module_hamilt_pw/hamilt_ofdft/kedf_vw.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ void KEDF_vW::tau_vw(const double* const* prho, ModulePW::PW_Basis* pw_rho, doub
129129
{
130130
std::vector<std::vector<double>> nabla_rho(3, std::vector<double>(pw_rho->nrxx, 0.));
131131

132-
std::complex<double> *recip_rho = new std::complex<double>[pw_rho->npw];
133-
std::complex<double> *recip_nabla_rho = new std::complex<double>[pw_rho->npw];
134-
pw_rho->real2recip(prho[is], recip_rho);
132+
std::vector<std::complex<double>> recip_rho(pw_rho->npw, 0.);
133+
std::vector<std::complex<double>> recip_nabla_rho(pw_rho->npw, 0.);
134+
pw_rho->real2recip(prho[is], recip_rho.data());
135135

136136
std::complex<double> img(0.0, 1.0);
137137
for (int j = 0; j < 3; ++j)
@@ -141,7 +141,7 @@ void KEDF_vW::tau_vw(const double* const* prho, ModulePW::PW_Basis* pw_rho, doub
141141
recip_nabla_rho[ip] = img * pw_rho->gcar[ip][j] * recip_rho[ip] * pw_rho->tpiba;
142142
}
143143

144-
pw_rho->recip2real(recip_nabla_rho, nabla_rho[j].data());
144+
pw_rho->recip2real(recip_nabla_rho.data(), nabla_rho[j].data());
145145

146146
for (int ir = 0; ir < pw_rho->nrxx; ++ir)
147147
{

source/module_io/write_elf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void write_elf(
6969
}
7070

7171
// 3) calculate the enhancement factor F = (tau_KS - tau_vw) / tau_TF, and then ELF = 1 / (1 + F^2)
72-
double eps = 1.0e-5; // suppress the numerical instability in LCAO
72+
double eps = 1.0e-5; // suppress the numerical instability in LCAO (Ref: Acta Phys. -Chim. Sin. 2011, 27(12), 2786-2792. doi: 10.3866/PKU.WHXB20112786)
7373
for (int is = 0; is < nspin; ++is)
7474
{
7575
for (int ir = 0; ir < rho_basis->nrxx; ++ir)
@@ -112,7 +112,7 @@ void write_elf(
112112
{
113113
for (int is = 0; is < nspin; ++is)
114114
{
115-
std::string fn_temp = out_dir + "/ELF_SPIN" + std::to_string(is) + ".cube";
115+
std::string fn_temp = out_dir + "/ELF_SPIN" + std::to_string(is + 1) + ".cube";
116116
int ispin = is + 1;
117117

118118
ModuleIO::write_cube(

0 commit comments

Comments
 (0)