Skip to content

Commit 1f9779d

Browse files
YuLiu98maki49
andauthored
Refactor: remove GlobalC::GridD (#5720)
* Refactor: dd TITLE and timer::tick for esolver * Refactor: remove GlobalC::GridD * convert tool_title.cpp * remove useless destructor and flag to enable the default move assignment --------- Co-authored-by: maki49 <[email protected]>
1 parent d73b1d2 commit 1f9779d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+708
-707
lines changed

source/module_base/tool_title.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void TITLE(const std::string &class_name,const std::string &function_name,const
1919
{
2020
if (disable)
2121
{
22-
return;//no output
22+
return; // no output
2323
}
2424
#ifdef __NORMAL
2525
std::cout<<" ==> "<<class_name<<"::"<<function_name<<"\t"
@@ -39,7 +39,7 @@ void TITLE(std::ofstream &ofs,const std::string &class_name,const std::string &f
3939
{
4040
if (disable)
4141
{
42-
return;//no output
42+
return; // no output
4343
}
4444
#ifdef __NORMAL
4545
std::cout<<"\n\n ==> "<<class_name<<"::"<<function_name<<"\t"

source/module_cell/module_neighbor/sltk_atom_arrange.cpp

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -162,30 +162,4 @@ void atom_arrange::search(
162162
}
163163

164164
return;
165-
}
166-
167-
168-
//2015-05-07
169-
void atom_arrange::delete_vector(
170-
std::ofstream &ofs_in,
171-
const bool pbc_flag, // GlobalV::SEARCH_PBC
172-
Grid_Driver &grid_d,
173-
const UnitCell &ucell,
174-
const double &search_radius_bohr,
175-
const int &test_atom_in)
176-
{
177-
const double radius_lat0unit2 = search_radius_bohr / ucell.lat0;
178-
179-
Atom_input at2(
180-
ofs_in,
181-
ucell,
182-
ucell.nat,
183-
ucell.ntype,
184-
pbc_flag,
185-
radius_lat0unit2,
186-
test_atom_in);
187-
188-
grid_d.delete_vector(at2.getGrid_layerX_minus(),at2.getGrid_layerY_minus(),at2.getGrid_layerZ_minus());
189-
190-
grid_d.delete_Cell();
191-
}
165+
}

source/module_cell/module_neighbor/sltk_atom_arrange.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ class atom_arrange
3030
const double& rcutmax_Beta,
3131
const bool gamma_only_local);
3232

33-
//2015-05-07
34-
static void delete_vector(
35-
std::ofstream &ofs_in,
36-
const bool pbc_flag,
37-
Grid_Driver &grid_d,
38-
const UnitCell &ucell,
39-
const double &search_radius_bohr,
40-
const int &test_atom_in);
41-
42-
private:
43-
4433
};
4534

4635
#endif

source/module_cell/module_neighbor/sltk_grid.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,9 @@ CellSet::CellSet()
1616
in_grid[2] = 0;
1717
}
1818

19-
Grid::Grid(const int& test_grid_in) : test_grid(test_grid_in)
20-
{
21-
// ModuleBase::TITLE("Grid","Grid");
22-
//----------------------------------------------------------
23-
// EXPLAIN : init_cell_flag (use this flag in case memory
24-
// leak)
25-
//----------------------------------------------------------
26-
init_cell_flag = false;
27-
}
19+
Grid::Grid(const int& test_grid_in) : test_grid(test_grid_in) {}
2820

29-
Grid::~Grid()
30-
{
31-
this->delete_Cell();
32-
}
21+
Grid::~Grid() {}
3322

3423
void Grid::init(std::ofstream& ofs_in, const UnitCell& ucell, const Atom_input& input)
3524
{
@@ -49,7 +38,6 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs
4938
{
5039
ModuleBase::TITLE("SLTK_Grid", "setMemberVariables");
5140

52-
this->delete_Cell();
5341
// mohan add 2010-09-05
5442
// AdjacentSet::call_times = 0;
5543

@@ -96,8 +84,6 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs
9684
Cell[i][j].resize(cell_nz);
9785
}
9886
}
99-
this->init_cell_flag = true;
100-
10187
this->true_cell_x = input.getGrid_layerX_minus();
10288
this->true_cell_y = input.getGrid_layerY_minus();
10389
this->true_cell_z = input.getGrid_layerZ_minus();
@@ -508,14 +494,3 @@ void Grid::Construct_Adjacent_final(const int i,
508494
fatom1.addAdjacent(fatom2);
509495
}
510496
}
511-
// 2015-05-07
512-
void Grid::delete_vector(int i, int j, int k)
513-
{
514-
if (expand_flag)
515-
{
516-
if (this->pbc)
517-
{
518-
this->Cell[i][j][k].atom_map.clear();
519-
}
520-
}
521-
}

source/module_cell/module_neighbor/sltk_grid.h

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ class Grid
4141
Grid(const int& test_grid_in);
4242
virtual ~Grid();
4343

44-
void init(std::ofstream& ofs, const UnitCell& ucell, const Atom_input& input);
44+
Grid& operator=(Grid&&) = default;
4545

46-
// 2015-05-07
47-
void delete_vector(int i, int j, int k);
46+
void init(std::ofstream& ofs, const UnitCell& ucell, const Atom_input& input);
4847

4948
// Data
5049
bool pbc; // periodic boundary condition
@@ -64,28 +63,7 @@ class Grid
6463
int true_cell_z;
6564

6665
std::vector<std::vector<std::vector<CellSet>>> Cell; // dx , dy ,dz is cell number in each direction,respectly.
67-
void delete_Cell() // it will replace by container soon!
68-
{
69-
if (this->init_cell_flag)
70-
{
71-
for (int i = 0; i < this->cell_nx; i++)
72-
{
73-
for (int j = 0; j < this->cell_ny; j++)
74-
{
75-
this->Cell[i][j].clear();
76-
}
77-
}
78-
79-
for (int i = 0; i < this->cell_nx; i++)
80-
{
81-
this->Cell[i].clear();
82-
}
83-
84-
this->Cell.clear();
85-
this->init_cell_flag = false;
86-
}
87-
}
88-
bool init_cell_flag = false;
66+
8967
// LiuXh add 2019-07-15
9068
double getD_minX() const
9169
{
@@ -125,8 +103,8 @@ class Grid
125103
return true_cell_z;
126104
}
127105

128-
private:
129-
const int test_grid;
106+
private:
107+
int test_grid = 0;
130108
//==========================================================
131109
// MEMBER FUNCTIONS :
132110
// Three Main Steps:

source/module_cell/module_neighbor/sltk_grid_driver.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
#include <omp.h>
99
#endif
1010

11-
namespace GlobalC
12-
{
13-
Grid_Driver GridD;
14-
}
1511
Grid_Driver::Grid_Driver(
1612
const int &test_d_in,
1713
const int &test_grid_in)

source/module_cell/module_neighbor/sltk_grid_driver.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class Grid_Driver : public Grid
5555

5656
~Grid_Driver();
5757

58+
Grid_Driver& operator=(Grid_Driver&&) = default;
59+
5860
//==========================================================
5961
// EXPLAIN FOR default parameter `adjs = nullptr`
6062
//
@@ -103,7 +105,7 @@ class Grid_Driver : public Grid
103105
private:
104106
mutable AdjacentAtomInfo adj_info;
105107

106-
const int test_deconstructor; // caoyu reconst 2021-05-24
108+
int test_deconstructor = 0;
107109

108110
//==========================================================
109111
// MEMBER FUNCTIONS :
@@ -125,9 +127,4 @@ class Grid_Driver : public Grid
125127
const short box_y,
126128
const short box_z) const;
127129
};
128-
129-
namespace GlobalC
130-
{
131-
extern Grid_Driver GridD;
132-
}
133130
#endif

source/module_cell/module_neighbor/test/sltk_atom_arrange_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ Magnetism::~Magnetism()
5252
void SetGlobalV()
5353
{
5454
PARAM.input.test_grid = false;
55-
PARAM.input.test_deconstructor = false;
5655
}
5756

5857
class SltkAtomArrangeTest : public testing::Test

source/module_cell/module_neighbor/test/sltk_grid_test.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ TEST_F(SltkGridTest, Init)
8484
Atom_input Atom_inp(ofs, *ucell, ucell->nat, ucell->ntype, pbc, radius, test_atom_in);
8585
Grid LatGrid(PARAM.input.test_grid);
8686
LatGrid.init(ofs, *ucell, Atom_inp);
87-
EXPECT_TRUE(LatGrid.init_cell_flag);
8887
EXPECT_EQ(LatGrid.getCellX(), 11);
8988
EXPECT_EQ(LatGrid.getCellY(), 11);
9089
EXPECT_EQ(LatGrid.getCellZ(), 11);
@@ -126,9 +125,6 @@ TEST_F(SltkGridTest, InitSmall)
126125
EXPECT_EQ(LatGrid.cell_nx, 4);
127126
EXPECT_EQ(LatGrid.cell_ny, 4);
128127
EXPECT_EQ(LatGrid.cell_nz, 4);
129-
// init cell flag
130-
EXPECT_TRUE(LatGrid.init_cell_flag);
131-
132128
ofs.close();
133129
remove("test.out");
134130
}

source/module_elecstate/module_dm/test/test_dm_R_init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class DMTest : public testing::Test
100100
#endif
101101
};
102102

103-
// test for construct DMR from GlobalC::GridD and UnitCell
103+
// test for construct DMR from GridD and UnitCell
104104
TEST_F(DMTest, DMInit1)
105105
{
106106
// initalize a kvectors

0 commit comments

Comments
 (0)