Skip to content

Commit 2a45c6a

Browse files
Fix: Enhance the computational stability of ELF. (#6166)
* Fix: Enhance the computational stability of ELF. Update corresponding integrate tests. * Test: Update 119_PW_out_elf * Test: Update 119_PW_out_elf and 219_PW_out_elf. --------- Co-authored-by: Mohan Chen <[email protected]>
1 parent e1d44f6 commit 2a45c6a

File tree

5 files changed

+596
-589
lines changed

5 files changed

+596
-589
lines changed

source/module_io/write_elf.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,34 @@ void write_elf(
2222
std::vector<std::vector<double>> elf(nspin, std::vector<double>(rho_basis->nrxx, 0.));
2323
// 1) calculate the kinetic energy density of vW KEDF
2424
std::vector<std::vector<double>> tau_vw(nspin, std::vector<double>(rho_basis->nrxx, 0.));
25+
std::vector<double> phi(rho_basis->nrxx, 0.); // phi = sqrt(rho)
26+
2527
for (int is = 0; is < nspin; ++is)
2628
{
27-
std::vector<std::vector<double>> gradient_rho(3, std::vector<double>(rho_basis->nrxx, 0.));
28-
29-
std::vector<std::complex<double>> recip_rho(rho_basis->npw, 0.0);
30-
std::vector<std::complex<double>> recip_gradient_rho(rho_basis->npw, 0.0);
31-
rho_basis->real2recip(rho[is], recip_rho.data());
29+
for (int ir = 0; ir < rho_basis->nrxx; ++ir)
30+
{
31+
phi[ir] = std::sqrt(std::abs(rho[is][ir]));
32+
}
33+
34+
std::vector<std::vector<double>> gradient_phi(3, std::vector<double>(rho_basis->nrxx, 0.));
35+
std::vector<std::complex<double>> recip_phi(rho_basis->npw, 0.0);
36+
std::vector<std::complex<double>> recip_gradient_phi(rho_basis->npw, 0.0);
37+
38+
rho_basis->real2recip(phi.data(), recip_phi.data());
3239

3340
std::complex<double> img(0.0, 1.0);
3441
for (int j = 0; j < 3; ++j)
3542
{
3643
for (int ip = 0; ip < rho_basis->npw; ++ip)
3744
{
38-
recip_gradient_rho[ip] = img * rho_basis->gcar[ip][j] * recip_rho[ip] * rho_basis->tpiba;
45+
recip_gradient_phi[ip] = img * rho_basis->gcar[ip][j] * recip_phi[ip] * rho_basis->tpiba;
3946
}
4047

41-
rho_basis->recip2real(recip_gradient_rho.data(), gradient_rho[j].data());
48+
rho_basis->recip2real(recip_gradient_phi.data(), gradient_phi[j].data());
4249

4350
for (int ir = 0; ir < rho_basis->nrxx; ++ir)
4451
{
45-
tau_vw[is][ir] += gradient_rho[j][ir] * gradient_rho[j][ir] / (8. * rho[is][ir]) * 2.0; // convert Ha to Ry.
52+
tau_vw[is][ir] += gradient_phi[j][ir] * gradient_phi[j][ir] / 2. * 2.; // convert Ha to Ry.
4653
}
4754
}
4855
}

0 commit comments

Comments
 (0)