From 9732d79f1ecbc659e629acca0d6e6866fe6f7591 Mon Sep 17 00:00:00 2001 From: Liang Sun <50293369+sunliang98@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:40:17 +0800 Subject: [PATCH] Fix the Segmentation fault caused by zero atom case under LCAO basis. (#5821) --- .../module_cell/module_neighbor/sltk_grid.cpp | 19 ++++++++----- tests/integrate/223_NO_zero_atom/INPUT | 27 +++++++++++++++++++ tests/integrate/223_NO_zero_atom/KPT | 4 +++ tests/integrate/223_NO_zero_atom/STRU | 27 +++++++++++++++++++ tests/integrate/223_NO_zero_atom/jd | 1 + tests/integrate/223_NO_zero_atom/result.ref | 5 ++++ tests/integrate/CASES_CPU.txt | 1 + 7 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 tests/integrate/223_NO_zero_atom/INPUT create mode 100644 tests/integrate/223_NO_zero_atom/KPT create mode 100644 tests/integrate/223_NO_zero_atom/STRU create mode 100644 tests/integrate/223_NO_zero_atom/jd create mode 100644 tests/integrate/223_NO_zero_atom/result.ref diff --git a/source/module_cell/module_neighbor/sltk_grid.cpp b/source/module_cell/module_neighbor/sltk_grid.cpp index d20f9bb625..6fd6575c23 100644 --- a/source/module_cell/module_neighbor/sltk_grid.cpp +++ b/source/module_cell/module_neighbor/sltk_grid.cpp @@ -152,12 +152,19 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs this->clear_atoms(); // random selection, in order to estimate again. - this->x_min = ucell.atoms[0].tau[0].x; - this->y_min = ucell.atoms[0].tau[0].y; - this->z_min = ucell.atoms[0].tau[0].z; - this->x_max = ucell.atoms[0].tau[0].x; - this->y_max = ucell.atoms[0].tau[0].y; - this->z_max = ucell.atoms[0].tau[0].z; + for (int it = 0; it < ucell.ntype; it++) + { + if (ucell.atoms[it].na > 0) + { + this->x_min = ucell.atoms[it].tau[0].x; + this->y_min = ucell.atoms[it].tau[0].y; + this->z_min = ucell.atoms[it].tau[0].z; + this->x_max = ucell.atoms[it].tau[0].x; + this->y_max = ucell.atoms[it].tau[0].y; + this->z_max = ucell.atoms[it].tau[0].z; + break; + } + } ModuleBase::Vector3 vec1(ucell.latvec.e11, ucell.latvec.e12, ucell.latvec.e13); ModuleBase::Vector3 vec2(ucell.latvec.e21, ucell.latvec.e22, ucell.latvec.e23); diff --git a/tests/integrate/223_NO_zero_atom/INPUT b/tests/integrate/223_NO_zero_atom/INPUT new file mode 100644 index 0000000000..abe15ed4a0 --- /dev/null +++ b/tests/integrate/223_NO_zero_atom/INPUT @@ -0,0 +1,27 @@ +INPUT_PARAMETERS +#Parameters (1.General) +suffix autotest +calculation scf + +nbands 6 +symmetry 0 +pseudo_dir ../../PP_ORB/ +orbital_dir ../../PP_ORB/ + +#Parameters (2.Iteration) +ecutwfc 20 + +#Parameters (3.Basis) +basis_type lcao + +#Parameters (4.Smearing) +smearing_method gauss +smearing_sigma 0.0002 + +#Parameters (5.Mixing) +mixing_type broyden +mixing_beta 0.7 +cal_force 1 +test_force 1 +cal_stress 1 +test_stress 1 diff --git a/tests/integrate/223_NO_zero_atom/KPT b/tests/integrate/223_NO_zero_atom/KPT new file mode 100644 index 0000000000..f5f7f4ec34 --- /dev/null +++ b/tests/integrate/223_NO_zero_atom/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +2 2 2 0 0 0 diff --git a/tests/integrate/223_NO_zero_atom/STRU b/tests/integrate/223_NO_zero_atom/STRU new file mode 100644 index 0000000000..a8d7fba106 --- /dev/null +++ b/tests/integrate/223_NO_zero_atom/STRU @@ -0,0 +1,27 @@ +ATOMIC_SPECIES +Al 13 Al_ONCV_PBE-1.0.upf upf201 +Si 14 Si_ONCV_PBE-1.0.upf upf201 + +NUMERICAL_ORBITAL +Al_gga_8au_100Ry_4s4p1d.orb +Si_gga_8au_100Ry_2s2p1d.orb + +LATTICE_CONSTANT +10.2 // add lattice constant + +LATTICE_VECTORS +0.5 0.5 0.0 +0.5 0.0 0.5 +0.0 0.5 0.5 + +ATOMIC_POSITIONS +Direct + +Al +0.0 +0 +Si // Element type +0.0 // magnetism +2 +0.00 0.00 0.00 1 1 1 +0.25 0.25 0.25 1 1 1 diff --git a/tests/integrate/223_NO_zero_atom/jd b/tests/integrate/223_NO_zero_atom/jd new file mode 100644 index 0000000000..e8fb4e42b6 --- /dev/null +++ b/tests/integrate/223_NO_zero_atom/jd @@ -0,0 +1 @@ +test calculation when atom number is zero with LCAO. diff --git a/tests/integrate/223_NO_zero_atom/result.ref b/tests/integrate/223_NO_zero_atom/result.ref new file mode 100644 index 0000000000..af95ced2af --- /dev/null +++ b/tests/integrate/223_NO_zero_atom/result.ref @@ -0,0 +1,5 @@ +etotref -211.4490868003635171 +etotperatomref -105.7245434002 +totalforceref 0.000000 +totalstressref 366.791415 +totaltimeref 2.69 diff --git a/tests/integrate/CASES_CPU.txt b/tests/integrate/CASES_CPU.txt index 6e6093523a..134be1fbae 100644 --- a/tests/integrate/CASES_CPU.txt +++ b/tests/integrate/CASES_CPU.txt @@ -188,6 +188,7 @@ #220_NO_KP_MD_MSST_level2 220_NO_KP_MD_NVT 220_NO_KP_MD_wfc_out +223_NO_zero_atom #230_NO_KP_MD_TD 240_NO_KP_15_SO 240_NO_KP_15_SO_average