Skip to content

Commit 9732d79

Browse files
authored
Fix the Segmentation fault caused by zero atom case under LCAO basis. (#5821)
1 parent e25db6e commit 9732d79

File tree

7 files changed

+78
-6
lines changed

7 files changed

+78
-6
lines changed

source/module_cell/module_neighbor/sltk_grid.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,19 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs
152152
this->clear_atoms();
153153

154154
// random selection, in order to estimate again.
155-
this->x_min = ucell.atoms[0].tau[0].x;
156-
this->y_min = ucell.atoms[0].tau[0].y;
157-
this->z_min = ucell.atoms[0].tau[0].z;
158-
this->x_max = ucell.atoms[0].tau[0].x;
159-
this->y_max = ucell.atoms[0].tau[0].y;
160-
this->z_max = ucell.atoms[0].tau[0].z;
155+
for (int it = 0; it < ucell.ntype; it++)
156+
{
157+
if (ucell.atoms[it].na > 0)
158+
{
159+
this->x_min = ucell.atoms[it].tau[0].x;
160+
this->y_min = ucell.atoms[it].tau[0].y;
161+
this->z_min = ucell.atoms[it].tau[0].z;
162+
this->x_max = ucell.atoms[it].tau[0].x;
163+
this->y_max = ucell.atoms[it].tau[0].y;
164+
this->z_max = ucell.atoms[it].tau[0].z;
165+
break;
166+
}
167+
}
161168

162169
ModuleBase::Vector3<double> vec1(ucell.latvec.e11, ucell.latvec.e12, ucell.latvec.e13);
163170
ModuleBase::Vector3<double> vec2(ucell.latvec.e21, ucell.latvec.e22, ucell.latvec.e23);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
INPUT_PARAMETERS
2+
#Parameters (1.General)
3+
suffix autotest
4+
calculation scf
5+
6+
nbands 6
7+
symmetry 0
8+
pseudo_dir ../../PP_ORB/
9+
orbital_dir ../../PP_ORB/
10+
11+
#Parameters (2.Iteration)
12+
ecutwfc 20
13+
14+
#Parameters (3.Basis)
15+
basis_type lcao
16+
17+
#Parameters (4.Smearing)
18+
smearing_method gauss
19+
smearing_sigma 0.0002
20+
21+
#Parameters (5.Mixing)
22+
mixing_type broyden
23+
mixing_beta 0.7
24+
cal_force 1
25+
test_force 1
26+
cal_stress 1
27+
test_stress 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
K_POINTS
2+
0
3+
Gamma
4+
2 2 2 0 0 0
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ATOMIC_SPECIES
2+
Al 13 Al_ONCV_PBE-1.0.upf upf201
3+
Si 14 Si_ONCV_PBE-1.0.upf upf201
4+
5+
NUMERICAL_ORBITAL
6+
Al_gga_8au_100Ry_4s4p1d.orb
7+
Si_gga_8au_100Ry_2s2p1d.orb
8+
9+
LATTICE_CONSTANT
10+
10.2 // add lattice constant
11+
12+
LATTICE_VECTORS
13+
0.5 0.5 0.0
14+
0.5 0.0 0.5
15+
0.0 0.5 0.5
16+
17+
ATOMIC_POSITIONS
18+
Direct
19+
20+
Al
21+
0.0
22+
0
23+
Si // Element type
24+
0.0 // magnetism
25+
2
26+
0.00 0.00 0.00 1 1 1
27+
0.25 0.25 0.25 1 1 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test calculation when atom number is zero with LCAO.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
etotref -211.4490868003635171
2+
etotperatomref -105.7245434002
3+
totalforceref 0.000000
4+
totalstressref 366.791415
5+
totaltimeref 2.69

tests/integrate/CASES_CPU.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
#220_NO_KP_MD_MSST_level2
189189
220_NO_KP_MD_NVT
190190
220_NO_KP_MD_wfc_out
191+
223_NO_zero_atom
191192
#230_NO_KP_MD_TD
192193
240_NO_KP_15_SO
193194
240_NO_KP_15_SO_average

0 commit comments

Comments
 (0)