Skip to content

Commit 68248c6

Browse files
authored
Refactor: remove GlobalC::Pgrid (#5740)
* Refactor: remove GlobalC::Pgrid * fix compile without mpi
1 parent c611100 commit 68248c6

37 files changed

+142
-105
lines changed

source/module_elecstate/elecstate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ void ElecState::calEBand()
208208

209209
void ElecState::init_scf(const int istep,
210210
const UnitCell& ucell,
211+
const Parallel_Grid& pgrid,
211212
const ModuleBase::ComplexMatrix& strucfac,
212213
const bool* numeric,
213214
ModuleSymmetry::Symmetry& symm,
@@ -227,7 +228,7 @@ void ElecState::init_scf(const int istep,
227228
// choose charge density from ionic step 0.
228229
if (istep == 0)
229230
{
230-
this->charge->init_rho(this->eferm,ucell, strucfac, symm, (const void*)this->klist, wfcpw);
231+
this->charge->init_rho(this->eferm,ucell, pgrid, strucfac, symm, (const void*)this->klist, wfcpw);
231232
this->charge->check_rho(); // check the rho
232233
}
233234

source/module_elecstate/elecstate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class ElecState
111111
*/
112112
void init_scf(const int istep,
113113
const UnitCell& ucell,
114+
const Parallel_Grid& pgrid,
114115
const ModuleBase::ComplexMatrix& strucfac,
115116
const bool* numeric,
116117
ModuleSymmetry::Symmetry& symm,

source/module_elecstate/module_charge/charge.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "module_base/global_variable.h"
77
#include "module_base/parallel_global.h"
88
#include "module_basis/module_pw/pw_basis.h"
9-
#include "module_elecstate/fp_energy.h"
109
#include "module_cell/module_symmetry/symmetry.h"
10+
#include "module_elecstate/fp_energy.h"
11+
#include "module_hamilt_pw/hamilt_pwdft/parallel_grid.h"
1112

1213
//a forward declaration of UnitCell
1314
class UnitCell;
@@ -43,6 +44,7 @@ class Charge
4344
double **kin_r = nullptr; // kinetic energy density in real space, for meta-GGA
4445
double **kin_r_save = nullptr; // kinetic energy density in real space, for meta-GGA
4546
// wenfei 2021-07-28
47+
const Parallel_Grid* pgrid = nullptr;
4648
private:
4749
//temporary
4850
double *_space_rho = nullptr, *_space_rho_save = nullptr;
@@ -73,6 +75,7 @@ class Charge
7375
*/
7476
void init_rho(elecstate::efermi& eferm_iout,
7577
const UnitCell& ucell,
78+
const Parallel_Grid& pgrid,
7679
const ModuleBase::ComplexMatrix& strucFac,
7780
ModuleSymmetry::Symmetry& symm,
7881
const void* klist = nullptr,

source/module_elecstate/module_charge/charge_extra.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ void Charge_Extra::Init_CE(const int& nspin, const int& natom, const int& nrxx,
7575
}
7676

7777
void Charge_Extra::extrapolate_charge(
78-
#ifdef __MPI
7978
Parallel_Grid* Pgrid,
80-
#endif
8179
UnitCell& ucell,
8280
Charge* chr,
8381
Structure_Factor* sf,
@@ -109,7 +107,7 @@ void Charge_Extra::extrapolate_charge(
109107
rho_extr = std::min(istep, pot_order);
110108
if(rho_extr == 0)
111109
{
112-
sf->setup_structure_factor(&ucell, chr->rhopw);
110+
sf->setup_structure_factor(&ucell, *Pgrid, chr->rhopw);
113111
ofs_running << " charge density from previous step !" << std::endl;
114112
return;
115113
}
@@ -171,7 +169,7 @@ void Charge_Extra::extrapolate_charge(
171169
}
172170
}
173171

174-
sf->setup_structure_factor(&ucell, chr->rhopw);
172+
sf->setup_structure_factor(&ucell, *Pgrid, chr->rhopw);
175173
double** rho_atom = new double*[this->nspin];
176174
for (int is = 0; is < this->nspin; is++)
177175
{

source/module_elecstate/module_charge/charge_extra.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ class Charge_Extra
6363
* @param ofs_warning the output stream
6464
*/
6565
void extrapolate_charge(
66-
#ifdef __MPI
6766
Parallel_Grid* Pgrid,
68-
#endif
6967
UnitCell& ucell,
7068
Charge* chr,
7169
Structure_Factor* sf,

source/module_elecstate/module_charge/charge_init.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
void Charge::init_rho(elecstate::efermi& eferm_iout,
2525
const UnitCell& ucell,
26+
const Parallel_Grid& pgrid,
2627
const ModuleBase::ComplexMatrix& strucFac,
2728
ModuleSymmetry::Symmetry& symm,
2829
const void* klist,
@@ -33,7 +34,8 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
3334
std::cout << " START CHARGE : " << PARAM.inp.init_chg << std::endl;
3435
//here we need to set the omega for the charge density
3536
set_omega(&ucell.omega);
36-
37+
this->pgrid = &pgrid;
38+
3739
bool read_error = false;
3840
if (PARAM.inp.init_chg == "file" || PARAM.inp.init_chg == "auto")
3941
{
@@ -57,7 +59,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
5759
{
5860
std::stringstream ssc;
5961
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube";
60-
if (ModuleIO::read_vdata_palgrid(GlobalC::Pgrid,
62+
if (ModuleIO::read_vdata_palgrid(pgrid,
6163
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
6264
GlobalV::ofs_running,
6365
ssc.str(),
@@ -107,7 +109,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
107109
GlobalV::ofs_running << " try to read kinetic energy density from file : " << ssc.str()
108110
<< std::endl;
109111
// mohan update 2012-02-10, sunliang update 2023-03-09
110-
if (ModuleIO::read_vdata_palgrid(GlobalC::Pgrid,
112+
if (ModuleIO::read_vdata_palgrid(pgrid,
111113
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
112114
GlobalV::ofs_running,
113115
ssc.str(),
@@ -170,7 +172,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
170172
// try to load from the output of `out_chg`
171173
std::stringstream ssc;
172174
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube";
173-
if (ModuleIO::read_vdata_palgrid(GlobalC::Pgrid,
175+
if (ModuleIO::read_vdata_palgrid(pgrid,
174176
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
175177
GlobalV::ofs_running,
176178
ssc.str(),

source/module_elecstate/potentials/pot_surchem.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class PotSurChem : public PotBase
4040
}
4141

4242
v_eff += this->surchem_->v_correction(*ucell,
43+
*chg->pgrid,
4344
const_cast<ModulePW::PW_Basis*>(this->rho_basis_),
4445
v_eff.nr,
4546
chg->rho,

source/module_elecstate/test/charge_extra_test.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Magnetism::~Magnetism()
2424
{
2525
delete[] this->start_magnetization;
2626
}
27+
Parallel_Grid::~Parallel_Grid(){};
28+
2729

2830
// mock functions for Charge
2931
Charge::Charge()
@@ -87,7 +89,7 @@ Structure_Factor::Structure_Factor()
8789
Structure_Factor::~Structure_Factor()
8890
{
8991
}
90-
void Structure_Factor::setup_structure_factor(const UnitCell* Ucell, const ModulePW::PW_Basis* rho_basis)
92+
void Structure_Factor::setup_structure_factor(const UnitCell*, const Parallel_Grid&, const ModulePW::PW_Basis*)
9193
{
9294
}
9395

@@ -113,6 +115,7 @@ class ChargeExtraTest : public ::testing::Test
113115
Charge_Extra CE;
114116
UcellTestPrepare utp = UcellTestLib["Si"];
115117
std::unique_ptr<UnitCell> ucell;
118+
Parallel_Grid* pgrid = nullptr;
116119
Charge charge;
117120
Structure_Factor sf;
118121
void SetUp() override
@@ -183,7 +186,7 @@ TEST_F(ChargeExtraTest, ExtrapolateChargeCase1)
183186
CE.pot_order = 3;
184187

185188
GlobalV::ofs_running.open("log");
186-
CE.extrapolate_charge(*ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
189+
CE.extrapolate_charge(pgrid, *ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
187190
GlobalV::ofs_running.close();
188191

189192
// Check the results
@@ -205,7 +208,7 @@ TEST_F(ChargeExtraTest, ExtrapolateChargeCase2)
205208
CE.pot_order = 3;
206209

207210
GlobalV::ofs_running.open("log");
208-
CE.extrapolate_charge(*ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
211+
CE.extrapolate_charge(pgrid, *ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
209212
GlobalV::ofs_running.close();
210213

211214
// Check the results
@@ -227,7 +230,7 @@ TEST_F(ChargeExtraTest, ExtrapolateChargeCase3)
227230
CE.pot_order = 3;
228231

229232
GlobalV::ofs_running.open("log");
230-
CE.extrapolate_charge(*ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
233+
CE.extrapolate_charge(pgrid, *ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
231234
GlobalV::ofs_running.close();
232235

233236
// Check the results
@@ -248,7 +251,7 @@ TEST_F(ChargeExtraTest, ExtrapolateChargeCase4)
248251
CE.istep = 3;
249252

250253
GlobalV::ofs_running.open("log");
251-
CE.extrapolate_charge(*ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
254+
CE.extrapolate_charge(pgrid, *ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
252255
GlobalV::ofs_running.close();
253256

254257
// Check the results

source/module_elecstate/test/elecstate_base_test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Charge::~Charge()
3434
}
3535
UnitCell::UnitCell(){}
3636
UnitCell::~UnitCell(){}
37+
Parallel_Grid::Parallel_Grid(){};
38+
Parallel_Grid::~Parallel_Grid(){};
3739
Magnetism::Magnetism(){}
3840
Magnetism::~Magnetism(){}
3941
InfoNonlocal::InfoNonlocal(){}
@@ -73,6 +75,7 @@ void Charge::set_rho_core_paw()
7375
}
7476
void Charge::init_rho(elecstate::efermi&,
7577
const UnitCell&,
78+
const Parallel_Grid&,
7679
ModuleBase::ComplexMatrix const&,
7780
ModuleSymmetry::Symmetry& symm,
7881
const void*,
@@ -146,6 +149,7 @@ class ElecStateTest : public ::testing::Test
146149
protected:
147150
elecstate::MockElecState* elecstate;
148151
UnitCell ucell;
152+
Parallel_Grid pgrid;
149153
std::string output;
150154
void SetUp()
151155
{
@@ -256,7 +260,7 @@ TEST_F(ElecStateTest, InitSCF)
256260
ModuleBase::ComplexMatrix strucfac;
257261
elecstate->eferm = efermi;
258262
ModuleSymmetry::Symmetry symm;
259-
EXPECT_NO_THROW(elecstate->init_scf(istep, ucell,strucfac, nullptr, symm));
263+
EXPECT_NO_THROW(elecstate->init_scf(istep, ucell, pgrid, strucfac, nullptr, symm));
260264
// delete elecstate->pot is done in the destructor of elecstate
261265
delete charge;
262266
}

source/module_elecstate/test/elecstate_pw_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void Charge::set_rho_core_paw()
141141
}
142142
void Charge::init_rho(elecstate::efermi&,
143143
const UnitCell&,
144+
const Parallel_Grid&,
144145
ModuleBase::ComplexMatrix const&,
145146
ModuleSymmetry::Symmetry& symm,
146147
const void*,

0 commit comments

Comments
 (0)