Skip to content

Commit a94716b

Browse files
committed
Fix: Enhance the computational stability of ELF.
Update corresponding integrate tests.
1 parent 8fc7c42 commit a94716b

File tree

7 files changed

+4637
-598
lines changed

7 files changed

+4637
-598
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
}

tests/integrate/119_PW_out_elf/INPUT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ symmetry 1
88
pseudo_dir ../../PP_ORB
99

1010
#Parameters (2.Iteration)
11-
ecutwfc 5
11+
ecutwfc 10
1212
scf_thr 1e-9
1313
scf_nmax 100
1414

tests/integrate/119_PW_out_elf/refELF.cube

Lines changed: 2307 additions & 291 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
etotref -194.6234112615314
2-
etotperatomref -97.3117056308
1+
etotref -197.140564442101
2+
etotperatomref -98.5702822211
33
ComparePot1_pass 0
44
pointgroupref T_d
55
spacegroupref O_h
66
nksibzref 1
7-
totaltimeref 0.25
7+
totaltimeref 0.34

tests/integrate/219_NO_out_elf/INPUT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ orbital_dir ../../PP_ORB
1010
out_elf 1
1111

1212
#Parameters (2.Iteration)
13-
ecutwfc 5
13+
ecutwfc 20
1414
scf_thr 1e-6
1515
scf_nmax 100
1616

tests/integrate/219_NO_out_elf/refELF.cube

Lines changed: 2307 additions & 291 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
etotref -196.6254053459516
2-
etotperatomref -98.3127026730
1+
etotref -196.6219104988249
2+
etotperatomref -98.3109552494
33
ComparePot1_pass 0
44
pointgroupref T_d
55
spacegroupref O_h
66
nksibzref 1
7-
totaltimeref 1.14
7+
totaltimeref 2.58

0 commit comments

Comments
 (0)