Skip to content

Commit 4ec8064

Browse files
committed
fix a adj set clear bug and add self to adj list
1 parent 63a686c commit 4ec8064

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

source/module_cell/module_neighbor/sltk_grid_driver.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void Grid_Driver::Find_atom(
3838

3939
// store result in member adj_info when parameter adjs is NULL
4040
AdjacentAtomInfo* local_adjs = adjs == nullptr ? &this->adj_info : adjs;
41+
local_adjs->clear();
4142
const std::list<FAtom *> & all_atom = Cell[this->true_cell_x][this->true_cell_y][this->true_cell_z].atom_map[std::make_tuple(cartesian_pos.x, cartesian_pos.y, cartesian_pos.z)].getAdjacent();
4243
//std::cout << "ntype = "<< ntype << " atom size = " << all_atom.size() << std::endl;
4344
for(const FAtom * atom : all_atom)
@@ -53,30 +54,34 @@ void Grid_Driver::Find_atom(
5354
}
5455
else
5556
{
56-
local_adjs->adjacent_tau.push_back(Calculate_adjacent_site(*atom,
57+
local_adjs->adjacent_tau.push_back(Calculate_adjacent_site(atom->x(), atom->y(), atom->z(),
5758
vec1[0], vec2[0], vec3[0],
5859
vec1[1], vec2[1], vec3[1],
5960
vec1[2], vec2[2], vec3[2],
6061
atom->getCellX(), atom->getCellY(), atom->getCellZ()));
6162
}//end if expand_flag
6263
local_adjs->adj_num++;
6364
}
64-
local_adjs->adj_num--;
65+
local_adjs->ntype.push_back(ntype);
66+
local_adjs->natom.push_back(nnumber);
67+
local_adjs->box.push_back(ModuleBase::Vector3<int>(0, 0, 0));
68+
local_adjs->adjacent_tau.push_back(ModuleBase::Vector3<double>(cartesian_pos.x, cartesian_pos.y, cartesian_pos.z));
69+
6570

6671
ModuleBase::timer::tick("Grid_Driver","Find_atom");
6772
return;
6873
}
6974

70-
ModuleBase::Vector3<double> Grid_Driver::Calculate_adjacent_site(const FAtom &atom,
75+
ModuleBase::Vector3<double> Grid_Driver::Calculate_adjacent_site(const double x, const double y, const double z,
7176
const double &box11, const double &box12, const double &box13,
7277
const double &box21, const double &box22, const double &box23,
7378
const double &box31, const double &box32, const double &box33,
7479
const short box_x, const short box_y, const short box_z) const
7580
{
7681
ModuleBase::Vector3<double> adjacent_site(0, 0, 0);
77-
adjacent_site.x = atom.x() + box_x * box11 + box_y * box12 + box_z * box13;
78-
adjacent_site.y = atom.y() + box_x * box21 + box_y * box22 + box_z * box23;
79-
adjacent_site.z = atom.z() + box_x * box31 + box_y * box32 + box_z * box33;
82+
adjacent_site.x = x + box_x * box11 + box_y * box12 + box_z * box13;
83+
adjacent_site.y = y + box_x * box21 + box_y * box22 + box_z * box23;
84+
adjacent_site.z = z + box_x * box31 + box_y * box32 + box_z * box33;
8085

8186
return adjacent_site;
8287
}

source/module_cell/module_neighbor/sltk_grid_driver.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ class AdjacentAtomInfo
2525
std::vector<int> natom;
2626
std::vector<ModuleBase::Vector3<double>> adjacent_tau;
2727
std::vector<ModuleBase::Vector3<int>> box;
28+
void clear()
29+
{
30+
adj_num = 0;
31+
ntype.clear();
32+
natom.clear();
33+
adjacent_tau.clear();
34+
box.clear();
35+
}
2836
};
2937

3038
void filter_adjs(const std::vector<bool>& is_adj, AdjacentAtomInfo& adjs);
@@ -88,7 +96,7 @@ class Grid_Driver : public Grid
8896
// MEMBER FUNCTIONS :
8997
// NAME : Calculate_adjacent_site
9098
//==========================================================
91-
ModuleBase::Vector3<double> Calculate_adjacent_site(const FAtom &atom,
99+
ModuleBase::Vector3<double> Calculate_adjacent_site(const double x, const double y, const double z,
92100
const double &box11, const double &box12, const double &box13,
93101
const double &box21, const double &box22, const double &box23,
94102
const double &box31, const double &box32, const double &box33,

0 commit comments

Comments
 (0)