@@ -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