Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: remove GlobalC::GridD #5720

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/module_base/tool_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void TITLE(const std::string &class_name,const std::string &function_name,const
{
if (disable)
{
return;//no output
return; // no output
}
#ifdef __NORMAL
std::cout<<" ==> "<<class_name<<"::"<<function_name<<"\t"
Expand All @@ -39,7 +39,7 @@ void TITLE(std::ofstream &ofs,const std::string &class_name,const std::string &f
{
if (disable)
{
return;//no output
return; // no output
}
#ifdef __NORMAL
std::cout<<"\n\n ==> "<<class_name<<"::"<<function_name<<"\t"
Expand Down
28 changes: 1 addition & 27 deletions source/module_cell/module_neighbor/sltk_atom_arrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,30 +162,4 @@ void atom_arrange::search(
}

return;
}


//2015-05-07
void atom_arrange::delete_vector(
std::ofstream &ofs_in,
const bool pbc_flag, // GlobalV::SEARCH_PBC
Grid_Driver &grid_d,
const UnitCell &ucell,
const double &search_radius_bohr,
const int &test_atom_in)
{
const double radius_lat0unit2 = search_radius_bohr / ucell.lat0;

Atom_input at2(
ofs_in,
ucell,
ucell.nat,
ucell.ntype,
pbc_flag,
radius_lat0unit2,
test_atom_in);

grid_d.delete_vector(at2.getGrid_layerX_minus(),at2.getGrid_layerY_minus(),at2.getGrid_layerZ_minus());

grid_d.delete_Cell();
}
}
11 changes: 0 additions & 11 deletions source/module_cell/module_neighbor/sltk_atom_arrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ class atom_arrange
const double& rcutmax_Beta,
const bool gamma_only_local);

//2015-05-07
static void delete_vector(
std::ofstream &ofs_in,
const bool pbc_flag,
Grid_Driver &grid_d,
const UnitCell &ucell,
const double &search_radius_bohr,
const int &test_atom_in);

private:

};

#endif
29 changes: 2 additions & 27 deletions source/module_cell/module_neighbor/sltk_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,9 @@ CellSet::CellSet()
in_grid[2] = 0;
}

Grid::Grid(const int& test_grid_in) : test_grid(test_grid_in)
{
// ModuleBase::TITLE("Grid","Grid");
//----------------------------------------------------------
// EXPLAIN : init_cell_flag (use this flag in case memory
// leak)
//----------------------------------------------------------
init_cell_flag = false;
}
Grid::Grid(const int& test_grid_in) : test_grid(test_grid_in) {}

Grid::~Grid()
{
this->delete_Cell();
}
Grid::~Grid() {}

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

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

Expand Down Expand Up @@ -96,8 +84,6 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs
Cell[i][j].resize(cell_nz);
}
}
this->init_cell_flag = true;

this->true_cell_x = input.getGrid_layerX_minus();
this->true_cell_y = input.getGrid_layerY_minus();
this->true_cell_z = input.getGrid_layerZ_minus();
Expand Down Expand Up @@ -508,14 +494,3 @@ void Grid::Construct_Adjacent_final(const int i,
fatom1.addAdjacent(fatom2);
}
}
// 2015-05-07
void Grid::delete_vector(int i, int j, int k)
{
if (expand_flag)
{
if (this->pbc)
{
this->Cell[i][j][k].atom_map.clear();
}
}
}
32 changes: 5 additions & 27 deletions source/module_cell/module_neighbor/sltk_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ class Grid
Grid(const int& test_grid_in);
virtual ~Grid();

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

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

// Data
bool pbc; // periodic boundary condition
Expand All @@ -64,28 +63,7 @@ class Grid
int true_cell_z;

std::vector<std::vector<std::vector<CellSet>>> Cell; // dx , dy ,dz is cell number in each direction,respectly.
void delete_Cell() // it will replace by container soon!
{
if (this->init_cell_flag)
{
for (int i = 0; i < this->cell_nx; i++)
{
for (int j = 0; j < this->cell_ny; j++)
{
this->Cell[i][j].clear();
}
}

for (int i = 0; i < this->cell_nx; i++)
{
this->Cell[i].clear();
}

this->Cell.clear();
this->init_cell_flag = false;
}
}
bool init_cell_flag = false;

// LiuXh add 2019-07-15
double getD_minX() const
{
Expand Down Expand Up @@ -125,8 +103,8 @@ class Grid
return true_cell_z;
}

private:
const int test_grid;
private:
int test_grid = 0;
//==========================================================
// MEMBER FUNCTIONS :
// Three Main Steps:
Expand Down
4 changes: 0 additions & 4 deletions source/module_cell/module_neighbor/sltk_grid_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#include <omp.h>
#endif

namespace GlobalC
{
Grid_Driver GridD;
}
Grid_Driver::Grid_Driver(
const int &test_d_in,
const int &test_grid_in)
Expand Down
9 changes: 3 additions & 6 deletions source/module_cell/module_neighbor/sltk_grid_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Grid_Driver : public Grid

~Grid_Driver();

Grid_Driver& operator=(Grid_Driver&&) = default;

//==========================================================
// EXPLAIN FOR default parameter `adjs = nullptr`
//
Expand Down Expand Up @@ -103,7 +105,7 @@ class Grid_Driver : public Grid
private:
mutable AdjacentAtomInfo adj_info;

const int test_deconstructor; // caoyu reconst 2021-05-24
int test_deconstructor = 0;

//==========================================================
// MEMBER FUNCTIONS :
Expand All @@ -125,9 +127,4 @@ class Grid_Driver : public Grid
const short box_y,
const short box_z) const;
};

namespace GlobalC
{
extern Grid_Driver GridD;
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Magnetism::~Magnetism()
void SetGlobalV()
{
PARAM.input.test_grid = false;
PARAM.input.test_deconstructor = false;
}

class SltkAtomArrangeTest : public testing::Test
Expand Down
4 changes: 0 additions & 4 deletions source/module_cell/module_neighbor/test/sltk_grid_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ TEST_F(SltkGridTest, Init)
Atom_input Atom_inp(ofs, *ucell, ucell->nat, ucell->ntype, pbc, radius, test_atom_in);
Grid LatGrid(PARAM.input.test_grid);
LatGrid.init(ofs, *ucell, Atom_inp);
EXPECT_TRUE(LatGrid.init_cell_flag);
EXPECT_EQ(LatGrid.getCellX(), 11);
EXPECT_EQ(LatGrid.getCellY(), 11);
EXPECT_EQ(LatGrid.getCellZ(), 11);
Expand Down Expand Up @@ -126,9 +125,6 @@ TEST_F(SltkGridTest, InitSmall)
EXPECT_EQ(LatGrid.cell_nx, 4);
EXPECT_EQ(LatGrid.cell_ny, 4);
EXPECT_EQ(LatGrid.cell_nz, 4);
// init cell flag
EXPECT_TRUE(LatGrid.init_cell_flag);

ofs.close();
remove("test.out");
}
Expand Down
2 changes: 1 addition & 1 deletion source/module_elecstate/module_dm/test/test_dm_R_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class DMTest : public testing::Test
#endif
};

// test for construct DMR from GlobalC::GridD and UnitCell
// test for construct DMR from GridD and UnitCell
TEST_F(DMTest, DMInit1)
{
// initalize a kvectors
Expand Down
2 changes: 2 additions & 0 deletions source/module_esolver/esolver_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ void ESolver_FP::before_all_runners(UnitCell& ucell, const Input_para& inp)
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
void ESolver_FP::after_scf(UnitCell& ucell, const int istep)
{
ModuleBase::TITLE("ESolver_FP", "after_scf");

// 0) output convergence information
ModuleIO::output_convergence_after_scf(this->conv_esolver, this->pelec->f_en.etot);

Expand Down
14 changes: 8 additions & 6 deletions source/module_esolver/esolver_gets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,25 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)
ucell.infoNL.get_rcutmax_Beta(),
PARAM.globalv.gamma_only_local);

Grid_Driver gd;

atom_arrange::search(PARAM.inp.search_pbc,
GlobalV::ofs_running,
GlobalC::GridD,
gd,
ucell,
search_radius,
PARAM.inp.test_atom_input);

Record_adj RA;
RA.for_2d(ucell, GlobalC::GridD, this->pv, PARAM.globalv.gamma_only_local, orb_.cutoffs());
RA.for_2d(ucell, gd, this->pv, PARAM.globalv.gamma_only_local, orb_.cutoffs());

if (this->p_hamilt == nullptr)
{
if (PARAM.inp.nspin == 4)
{
this->p_hamilt
= new hamilt::HamiltLCAO<std::complex<double>, std::complex<double>>(ucell,
GlobalC::GridD,
gd,
&this->pv,
this->kv,
*(two_center_bundle_.overlap_orb),
Expand All @@ -121,7 +123,7 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)
else
{
this->p_hamilt = new hamilt::HamiltLCAO<std::complex<double>, double>(ucell,
GlobalC::GridD,
gd,
&this->pv,
this->kv,
*(two_center_bundle_.overlap_orb),
Expand All @@ -132,13 +134,13 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)

const std::string fn = PARAM.globalv.global_out_dir + "SR.csr";
std::cout << " The file is saved in " << fn << std::endl;
ModuleIO::output_SR(pv, GlobalC::GridD, this->p_hamilt, fn);
ModuleIO::output_SR(pv, gd, this->p_hamilt, fn);

if (PARAM.inp.out_mat_r)
{
cal_r_overlap_R r_matrix;
r_matrix.init(ucell,pv, orb_);
r_matrix.out_rR(ucell,istep);
r_matrix.out_rR(ucell, gd, istep);
}

ModuleBase::timer::tick("ESolver_GetS", "runner");
Expand Down
6 changes: 2 additions & 4 deletions source/module_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,7 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
ModuleBase::timer::tick(this->classname, "runner");

// 2) before_scf (electronic iteration loops)
ModuleBase::timer::tick(this->classname, "before_scf");
this->before_scf(ucell, istep);
ModuleBase::timer::tick(this->classname, "before_scf");

// 3) write charge density
if (PARAM.inp.dm_to_rho)
Expand Down Expand Up @@ -468,9 +466,7 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
} // end scf iterations

// 9) after scf
ModuleBase::timer::tick(this->classname, "after_scf");
this->after_scf(ucell, istep);
ModuleBase::timer::tick(this->classname, "after_scf");

ModuleBase::timer::tick(this->classname, "runner");
return;
Expand Down Expand Up @@ -740,6 +736,8 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
template <typename T, typename Device>
void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep)
{
ModuleBase::TITLE("ESolver_KS", "after_scf");

// 1) call after_scf() of ESolver_FP
ESolver_FP::after_scf(ucell, istep);

Expand Down
Loading
Loading