Skip to content

Commit 2d59410

Browse files
committed
fix bug of stress and force
1 parent 43d33aa commit 2d59410

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

source/module_hamilt_pw/hamilt_pwdft/forces_nl.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void Forces<FPTYPE, Device>::cal_force_nl(ModuleBase::matrix& forcenl,
3333
hamilt::FS_Nonlocal_tools<FPTYPE, Device> nl_tools(nlpp_in, &ucell_in, p_kv, wfc_basis, p_sf, wg, &ekb);
3434

3535
const int nks = wfc_basis->nks;
36+
const int max_nbands = wg.nc;
3637
for (int ik = 0; ik < nks; ik++) // loop k points
3738
{
3839
// skip zero weights to speed up
@@ -46,19 +47,19 @@ void Forces<FPTYPE, Device>::cal_force_nl(ModuleBase::matrix& forcenl,
4647
}
4748
}
4849
const int npm = nbands_occ;
49-
nl_tools.cal_vkb(ik, npm);
50+
nl_tools.cal_vkb(ik, max_nbands);
5051
// calculate becp = <psi|beta> for all beta functions
5152
nl_tools.cal_becp(ik, npm, &psi_in[0](ik,0,0));
52-
nl_tools.reduce_pool_becp(npm);
53+
nl_tools.reduce_pool_becp(max_nbands);
5354
for (int ipol = 0; ipol < 3; ipol++)
5455
{
55-
nl_tools.cal_vkb_deri_f(ik, npm, ipol);
56+
nl_tools.cal_vkb_deri_f(ik, max_nbands, ipol);
5657
// calculate dbecp = <psi|\nabla beta> for all beta functions
57-
nl_tools.cal_dbecp_f(ik, npm, npm, ipol, &psi_in[0](ik,0,0));
58+
nl_tools.cal_dbecp_f(ik, max_nbands, npm, ipol, &psi_in[0](ik,0,0));
5859
nl_tools.revert_vkb(ik, ipol);
5960
}
6061
// calculate the force_i = \sum_{n,k}f_{nk}\sum_I \sum_{lm,l'm'}D_{l,l'}^{I} becp * dbecp_i
61-
nl_tools.cal_force(ik, npm, npm, true, force);
62+
nl_tools.cal_force(ik, max_nbands, npm, true, force);
6263
} // end ik
6364

6465
syncmem_var_d2h_op()(this->cpu_ctx, this->ctx, forcenl.c, force, forcenl.nr * forcenl.nc);

source/module_hamilt_pw/hamilt_pwdft/stress_func_nl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void Stress_Func<FPTYPE, Device>::stress_nl(ModuleBase::matrix& sigma,
3737
hamilt::FS_Nonlocal_tools<FPTYPE, Device> nl_tools(nlpp_in, &ucell_in, p_kv, wfc_basis, p_sf, wg, &ekb);
3838

3939
const int nks = p_kv->get_nks();
40+
const int max_nbands = wg.nc;
4041
for (int ik = 0; ik < nks; ik++) // loop k points
4142
{
4243
// skip zero weights to speed up
@@ -51,17 +52,17 @@ void Stress_Func<FPTYPE, Device>::stress_nl(ModuleBase::matrix& sigma,
5152
}
5253
const int npm = nbands_occ;
5354

54-
nl_tools.cal_vkb(ik, npm);
55+
nl_tools.cal_vkb(ik, max_nbands);
5556
// calculate becp = <psi|beta> for all beta functions
5657
nl_tools.cal_becp(ik, npm, &psi_in[0](ik,0,0));
57-
nl_tools.reduce_pool_becp(npm);
58+
nl_tools.reduce_pool_becp(max_nbands);
5859
// calculate dbecp = <psi|d(beta)/dR> for all beta functions
5960
// calculate stress = \sum <psi|d(beta_j)/dR> * <psi|beta_i> * D_{ij}
6061
for (int ipol = 0; ipol < 3; ipol++)
6162
{
6263
for (int jpol = 0; jpol <= ipol; jpol++)
6364
{
64-
nl_tools.cal_vkb_deri_s(ik, npm, ipol, jpol);
65+
nl_tools.cal_vkb_deri_s(ik, max_nbands, ipol, jpol);
6566
nl_tools.cal_dbecp_s(ik, npm, &psi_in[0](ik,0,0));
6667
nl_tools.cal_stress(ik, npm, true, ipol, jpol, stress_device);
6768
}

tests/integrate/187_PW_SDFT_ALL_GPU/INPUT

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ symmetry 0
99
pseudo_dir ../../PP_ORB
1010
device gpu
1111

12-
kpar 1
12+
kpar 2
1313
bndpar 1
1414

1515
nbands 0
@@ -21,7 +21,7 @@ cal_force 1
2121
cal_stress 1
2222

2323
#Parameters (2.Iteration)
24-
ecutwfc 30
24+
ecutwfc 20
2525
scf_thr 1e-6
2626
scf_nmax 30
2727

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -108.9478430350318803
2-
etotperatomref -54.4739215175
3-
totalforceref 187.066308
4-
totalstressref 248810.173686
5-
totaltimeref 40.81
1+
etotref -105.2612355454176907
2+
etotperatomref -52.6306177727
3+
totalforceref 197.906706
4+
totalstressref 254537.682905
5+
totaltimeref 20.82

0 commit comments

Comments
 (0)