Skip to content

Commit 18a05d1

Browse files
committed
use vector to refactor Cellset varible
1 parent 84859e8 commit 18a05d1

File tree

5 files changed

+12
-41
lines changed

5 files changed

+12
-41
lines changed

source/module_cell/module_neighbor/sltk_atom.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
#include "sltk_atom.h"
22
#include <iostream>
33

4-
class AdjacentSet;
5-
6-
//int FAtom::count1 = 0;
7-
//int FAtom::count2 = 0;
8-
94
/*** Constructors and destructor ***/
105
FAtom::FAtom()
116
{

source/module_cell/module_neighbor/sltk_atom.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "sltk_adjacent_set.h"
77
#include "module_base/timer.h"
88
#include <list>
9-
class AdjacentSet;
109

1110
// a class contains the atom position,
1211
// the type and the index,

source/module_cell/module_neighbor/sltk_atom_arrange.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,5 @@ void atom_arrange::delete_vector(
169169

170170
grid_d.delete_vector(at2);
171171

172-
if (grid_d.init_cell_flag)
173-
{
174-
for (int i = 0;i < grid_d.dx;i++)
175-
{
176-
for (int j = 0;j < grid_d.dy;j++)
177-
{
178-
delete[] grid_d.Cell[i][j];
179-
}
180-
}
181-
182-
for (int i = 0;i < grid_d.dx;i++)
183-
{
184-
delete[] grid_d.Cell[i];
185-
}
186-
187-
delete[] grid_d.Cell;
188-
grid_d.init_cell_flag = false;
189-
}
190-
return;
172+
grid_d.delete_Cell();
191173
}

source/module_cell/module_neighbor/sltk_grid.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void Grid::setMemberVariables(
6767

6868
this->delete_Cell();
6969
// mohan add 2010-09-05
70-
AdjacentSet::call_times = 0;
70+
// AdjacentSet::call_times = 0;
7171

7272
this->natom = input.getAmount();
7373
if(test_grid)ModuleBase::GlobalFunc::OUT(ofs_in, "natom", natom);
@@ -126,14 +126,14 @@ void Grid::setMemberVariables(
126126
if(test_grid)ModuleBase::GlobalFunc::OUT(ofs_in,"CellNumber",dx,dy,dz);
127127

128128

129-
Cell = new CellSet**[dx];
129+
Cell.resize(dx);
130130
for (int i = 0;i < dx;i++)
131131
{
132-
Cell[i] = new CellSet*[dy];
132+
Cell[i].resize(dy);
133133

134134
for (int j = 0;j < dy;j++)
135135
{
136-
Cell[i][j] = new CellSet[dz];
136+
Cell[i][j].resize(dz);
137137
}
138138
}
139139
this->init_cell_flag = true;
@@ -163,7 +163,7 @@ void Grid::setBoundaryAdjacent(
163163
this->Construct_Adjacent_begin();
164164
}
165165

166-
if(test_grid)ModuleBase::GlobalFunc::OUT(ofs_in,"Adjacent_set call times",AdjacentSet::call_times);
166+
//if(test_grid)ModuleBase::GlobalFunc::OUT(ofs_in,"Adjacent_set call times",AdjacentSet::call_times);
167167

168168
//if (test_grid)ModuleBase::GlobalFunc::DONE(ofs_in, "Construct_Adjacent");
169169

@@ -220,7 +220,6 @@ void Grid::Build_Hash_Table(const UnitCell &ucell, const Atom_input &input)
220220
for (int i = 0; i < input.getAmount(); ++i)
221221
{
222222
const FAtom &atom = input.getFakeAtom(i);
223-
all_atom_map[{atom.x(), atom.y(), atom.z()}] = atom;
224223

225224
int a, b, c;
226225
this->In_Which_Cell(ucell, a, b, c, atom);
@@ -247,7 +246,7 @@ void Grid::Construct_Adjacent_expand(
247246
//----------------------------------------------------------
248247
ModuleBase::timer::tick("Grid", "Construct_Adjacent_expand");
249248

250-
AdjacentSet::setExpandFlag(this->expand_flag);
249+
/* AdjacentSet::setExpandFlag(this->expand_flag);
251250
252251
AdjacentSet::setDx(this->dx);
253252
@@ -265,7 +264,7 @@ void Grid::Construct_Adjacent_expand(
265264
266265
AdjacentSet::setCenter(true_i * dy * dz + true_j * dz + true_k);
267266
268-
267+
*/
269268
// if(test_grid)OUT(ofs_running,"GridCenter",true_i,true_j,true_k);
270269
// if(test_grid)OUT(ofs_running,"GridDim",dx,dy,dz);
271270

source/module_cell/module_neighbor/sltk_grid.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Grid
9090
int true_cell_y;
9191
int true_cell_z;
9292

93-
CellSet ***Cell; //dx , dy ,dz is cell number in each direction,respectly.
93+
std::vector<std::vector<std::vector<CellSet>>> Cell; //dx , dy ,dz is cell number in each direction,respectly.
9494
void delete_Cell() //it will replace by container soon!
9595
{
9696
if (this->init_cell_flag)
@@ -99,16 +99,16 @@ class Grid
9999
{
100100
for (int j = 0;j < this->dy;j++)
101101
{
102-
delete[] this->Cell[i][j];
102+
this->Cell[i][j].clear();
103103
}
104104
}
105105

106106
for (int i = 0;i < this->dx;i++)
107107
{
108-
delete[] this->Cell[i];
108+
this->Cell[i].clear();
109109
}
110110

111-
delete[] this->Cell;
111+
this->Cell.clear();
112112
this->init_cell_flag = false;
113113
}
114114
}
@@ -128,10 +128,6 @@ class Grid
128128
const int& getCellY(void) const {return dy;}
129129
const int& getCellZ(void) const {return dz;}
130130

131-
// Inner Function
132-
protected:
133-
AtomMap all_atom_map;
134-
135131
private:
136132

137133
const int test_grid;

0 commit comments

Comments
 (0)