Skip to content

Commit 91f7da2

Browse files
committed
fix a dont understand bug. and unit test fix
1 parent 1456a8c commit 91f7da2

File tree

3 files changed

+12
-45
lines changed

3 files changed

+12
-45
lines changed

source/module_cell/module_neighbor/sltk_grid.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,6 @@ void Grid::Build_Hash_Table(const UnitCell& ucell)
163163
{
164164
ModuleBase::timer::tick("Grid", "Build_Hash_Table");
165165

166-
// TODO in case expand == false, the following code is over malloc
167-
for (int i = 0; i < cell_nx; i++)
168-
{
169-
for (int j = 0; j < cell_ny; j++)
170-
{
171-
for (int k = 0; k < cell_nz; k++)
172-
{
173-
Cell[i][j][k].resize(ucell.ntype);
174-
for (int it = 0; it < ucell.ntype; ++it)
175-
{
176-
Cell[i][j][k][it].resize(ucell.atoms[it].na);
177-
}
178-
}
179-
}
180-
}
181166
ModuleBase::Vector3<double> vec1(ucell.latvec.e11, ucell.latvec.e12, ucell.latvec.e13);
182167
ModuleBase::Vector3<double> vec2(ucell.latvec.e21, ucell.latvec.e22, ucell.latvec.e23);
183168
ModuleBase::Vector3<double> vec3(ucell.latvec.e31, ucell.latvec.e32, ucell.latvec.e33);
@@ -201,7 +186,7 @@ void Grid::Build_Hash_Table(const UnitCell& ucell)
201186
b = iy + glayerY_minus;
202187
c = iz + glayerZ_minus;
203188

204-
this->Cell[a][b][c][atom.type][atom.natom] = atom;
189+
this->Cell[a][b][c].push_back(atom);
205190
}
206191
}
207192
}
@@ -214,12 +199,9 @@ void Grid::Construct_Adjacent_expand(const int true_i, const int true_j, const i
214199
{
215200
ModuleBase::timer::tick("Grid", "Construct_Adjacent_expand");
216201

217-
for (auto& atom_vector: this->Cell[true_i][true_j][true_k])
202+
for (auto& fatom: this->Cell[true_i][true_j][true_k])
218203
{
219-
for (auto& fatom: atom_vector)
220-
{
221-
Construct_Adjacent_expand_periodic(true_i, true_j, true_k, fatom);
222-
}
204+
Construct_Adjacent_expand_periodic(true_i, true_j, true_k, fatom);
223205
}
224206
ModuleBase::timer::tick("Grid", "Construct_Adjacent_expand");
225207
}
@@ -235,12 +217,9 @@ void Grid::Construct_Adjacent_expand_periodic(const int true_i, const int true_j
235217
{
236218
for (int k = 0; k < this->cell_nz; k++)
237219
{
238-
for (auto& atom_vector: this->Cell[i][j][k])
220+
for (auto& fatom2: this->Cell[i][j][k])
239221
{
240-
for (auto& fatom2: atom_vector)
241-
{
242-
Construct_Adjacent_final(true_i, true_j, true_k, fatom, i, j, k, fatom2);
243-
}
222+
Construct_Adjacent_final(true_i, true_j, true_k, fatom, i, j, k, fatom2);
244223
}
245224
}
246225
}

source/module_cell/module_neighbor/sltk_grid.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@
1010
#include <tuple>
1111
#include <unordered_map>
1212

13-
typedef std::vector<std::vector<FAtom>> AtomMap;
14-
15-
//==========================================================
16-
// CLASS NAME :
17-
// Atom_input : defined elsewhere
18-
//==========================================================
19-
20-
//==========================================================
21-
// CLASS NAME :
22-
// Grid :
23-
//==========================================================
24-
2513
class Grid
2614
{
2715
public:
@@ -61,7 +49,7 @@ void init(std::ofstream& ofs_in, const UnitCell& ucell, const double radius, boo
6149
int glayerZ;
6250
int glayerZ_minus;
6351

64-
std::vector<std::vector<std::vector<AtomMap>>> Cell; // dx , dy ,dz is cell number in each direction,respectly.
52+
std::vector<std::vector<std::vector<std::vector<FAtom>>>> Cell; // dx , dy ,dz is cell number in each direction,respectly.
6553
std::vector<std::vector<std::vector<FAtom *>>> all_adj_info;
6654
int getCellX() const
6755
{

source/module_cell/module_neighbor/test/sltk_grid_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ TEST_F(SltkGridTest, InitSmall)
108108
EXPECT_DOUBLE_EQ(LatGrid.sradius2, 0.5 * 0.5);
109109
EXPECT_DOUBLE_EQ(LatGrid.sradius, 0.5);
110110

111-
EXPECT_DOUBLE_EQ(LatGrid.true_cell_x, 2);
112-
EXPECT_DOUBLE_EQ(LatGrid.true_cell_y, 2);
113-
EXPECT_DOUBLE_EQ(LatGrid.true_cell_z, 2);
114-
EXPECT_EQ(LatGrid.cell_nx, 4);
115-
EXPECT_EQ(LatGrid.cell_ny, 4);
116-
EXPECT_EQ(LatGrid.cell_nz, 4);
111+
EXPECT_DOUBLE_EQ(LatGrid.true_cell_x, 1);
112+
EXPECT_DOUBLE_EQ(LatGrid.true_cell_y, 1);
113+
EXPECT_DOUBLE_EQ(LatGrid.true_cell_z, 1);
114+
EXPECT_EQ(LatGrid.cell_nx, 3);
115+
EXPECT_EQ(LatGrid.cell_ny, 3);
116+
EXPECT_EQ(LatGrid.cell_nz, 3);
117117
// init cell flag
118118

119119
ofs.close();

0 commit comments

Comments
 (0)