Skip to content
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
3 changes: 2 additions & 1 deletion source/module_elecstate/elecstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void ElecState::calEBand()

void ElecState::init_scf(const int istep,
const UnitCell& ucell,
const Parallel_Grid& pgrid,
const ModuleBase::ComplexMatrix& strucfac,
const bool* numeric,
ModuleSymmetry::Symmetry& symm,
Expand All @@ -227,7 +228,7 @@ void ElecState::init_scf(const int istep,
// choose charge density from ionic step 0.
if (istep == 0)
{
this->charge->init_rho(this->eferm,ucell, strucfac, symm, (const void*)this->klist, wfcpw);
this->charge->init_rho(this->eferm,ucell, pgrid, strucfac, symm, (const void*)this->klist, wfcpw);
this->charge->check_rho(); // check the rho
}

Expand Down
1 change: 1 addition & 0 deletions source/module_elecstate/elecstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class ElecState
*/
void init_scf(const int istep,
const UnitCell& ucell,
const Parallel_Grid& pgrid,
const ModuleBase::ComplexMatrix& strucfac,
const bool* numeric,
ModuleSymmetry::Symmetry& symm,
Expand Down
5 changes: 4 additions & 1 deletion source/module_elecstate/module_charge/charge.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#include "module_base/global_variable.h"
#include "module_base/parallel_global.h"
#include "module_basis/module_pw/pw_basis.h"
#include "module_elecstate/fp_energy.h"
#include "module_cell/module_symmetry/symmetry.h"
#include "module_elecstate/fp_energy.h"
#include "module_hamilt_pw/hamilt_pwdft/parallel_grid.h"

//a forward declaration of UnitCell
class UnitCell;
Expand Down Expand Up @@ -43,6 +44,7 @@ class Charge
double **kin_r = nullptr; // kinetic energy density in real space, for meta-GGA
double **kin_r_save = nullptr; // kinetic energy density in real space, for meta-GGA
// wenfei 2021-07-28
const Parallel_Grid* pgrid = nullptr;
private:
//temporary
double *_space_rho = nullptr, *_space_rho_save = nullptr;
Expand Down Expand Up @@ -73,6 +75,7 @@ class Charge
*/
void init_rho(elecstate::efermi& eferm_iout,
const UnitCell& ucell,
const Parallel_Grid& pgrid,
const ModuleBase::ComplexMatrix& strucFac,
ModuleSymmetry::Symmetry& symm,
const void* klist = nullptr,
Expand Down
6 changes: 2 additions & 4 deletions source/module_elecstate/module_charge/charge_extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ void Charge_Extra::Init_CE(const int& nspin, const int& natom, const int& nrxx,
}

void Charge_Extra::extrapolate_charge(
#ifdef __MPI
Parallel_Grid* Pgrid,
#endif
UnitCell& ucell,
Charge* chr,
Structure_Factor* sf,
Expand Down Expand Up @@ -109,7 +107,7 @@ void Charge_Extra::extrapolate_charge(
rho_extr = std::min(istep, pot_order);
if(rho_extr == 0)
{
sf->setup_structure_factor(&ucell, chr->rhopw);
sf->setup_structure_factor(&ucell, *Pgrid, chr->rhopw);
ofs_running << " charge density from previous step !" << std::endl;
return;
}
Expand Down Expand Up @@ -171,7 +169,7 @@ void Charge_Extra::extrapolate_charge(
}
}

sf->setup_structure_factor(&ucell, chr->rhopw);
sf->setup_structure_factor(&ucell, *Pgrid, chr->rhopw);
double** rho_atom = new double*[this->nspin];
for (int is = 0; is < this->nspin; is++)
{
Expand Down
2 changes: 0 additions & 2 deletions source/module_elecstate/module_charge/charge_extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class Charge_Extra
* @param ofs_warning the output stream
*/
void extrapolate_charge(
#ifdef __MPI
Parallel_Grid* Pgrid,
#endif
UnitCell& ucell,
Charge* chr,
Structure_Factor* sf,
Expand Down
10 changes: 6 additions & 4 deletions source/module_elecstate/module_charge/charge_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

void Charge::init_rho(elecstate::efermi& eferm_iout,
const UnitCell& ucell,
const Parallel_Grid& pgrid,
const ModuleBase::ComplexMatrix& strucFac,
ModuleSymmetry::Symmetry& symm,
const void* klist,
Expand All @@ -33,7 +34,8 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
std::cout << " START CHARGE : " << PARAM.inp.init_chg << std::endl;
//here we need to set the omega for the charge density
set_omega(&ucell.omega);

this->pgrid = &pgrid;

bool read_error = false;
if (PARAM.inp.init_chg == "file" || PARAM.inp.init_chg == "auto")
{
Expand All @@ -57,7 +59,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
{
std::stringstream ssc;
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube";
if (ModuleIO::read_vdata_palgrid(GlobalC::Pgrid,
if (ModuleIO::read_vdata_palgrid(pgrid,
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
GlobalV::ofs_running,
ssc.str(),
Expand Down Expand Up @@ -107,7 +109,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
GlobalV::ofs_running << " try to read kinetic energy density from file : " << ssc.str()
<< std::endl;
// mohan update 2012-02-10, sunliang update 2023-03-09
if (ModuleIO::read_vdata_palgrid(GlobalC::Pgrid,
if (ModuleIO::read_vdata_palgrid(pgrid,
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
GlobalV::ofs_running,
ssc.str(),
Expand Down Expand Up @@ -170,7 +172,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
// try to load from the output of `out_chg`
std::stringstream ssc;
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube";
if (ModuleIO::read_vdata_palgrid(GlobalC::Pgrid,
if (ModuleIO::read_vdata_palgrid(pgrid,
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
GlobalV::ofs_running,
ssc.str(),
Expand Down
1 change: 1 addition & 0 deletions source/module_elecstate/potentials/pot_surchem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class PotSurChem : public PotBase
}

v_eff += this->surchem_->v_correction(*ucell,
*chg->pgrid,
const_cast<ModulePW::PW_Basis*>(this->rho_basis_),
v_eff.nr,
chg->rho,
Expand Down
13 changes: 8 additions & 5 deletions source/module_elecstate/test/charge_extra_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Magnetism::~Magnetism()
{
delete[] this->start_magnetization;
}
Parallel_Grid::~Parallel_Grid(){};


// mock functions for Charge
Charge::Charge()
Expand Down Expand Up @@ -87,7 +89,7 @@ Structure_Factor::Structure_Factor()
Structure_Factor::~Structure_Factor()
{
}
void Structure_Factor::setup_structure_factor(const UnitCell* Ucell, const ModulePW::PW_Basis* rho_basis)
void Structure_Factor::setup_structure_factor(const UnitCell*, const Parallel_Grid&, const ModulePW::PW_Basis*)
{
}

Expand All @@ -113,6 +115,7 @@ class ChargeExtraTest : public ::testing::Test
Charge_Extra CE;
UcellTestPrepare utp = UcellTestLib["Si"];
std::unique_ptr<UnitCell> ucell;
Parallel_Grid* pgrid = nullptr;
Charge charge;
Structure_Factor sf;
void SetUp() override
Expand Down Expand Up @@ -183,7 +186,7 @@ TEST_F(ChargeExtraTest, ExtrapolateChargeCase1)
CE.pot_order = 3;

GlobalV::ofs_running.open("log");
CE.extrapolate_charge(*ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
CE.extrapolate_charge(pgrid, *ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
GlobalV::ofs_running.close();

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

GlobalV::ofs_running.open("log");
CE.extrapolate_charge(*ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
CE.extrapolate_charge(pgrid, *ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
GlobalV::ofs_running.close();

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

GlobalV::ofs_running.open("log");
CE.extrapolate_charge(*ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
CE.extrapolate_charge(pgrid, *ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
GlobalV::ofs_running.close();

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

GlobalV::ofs_running.open("log");
CE.extrapolate_charge(*ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
CE.extrapolate_charge(pgrid, *ucell.get(), &charge, &sf, GlobalV::ofs_running, GlobalV::ofs_warning);
GlobalV::ofs_running.close();

// Check the results
Expand Down
6 changes: 5 additions & 1 deletion source/module_elecstate/test/elecstate_base_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Charge::~Charge()
}
UnitCell::UnitCell(){}
UnitCell::~UnitCell(){}
Parallel_Grid::Parallel_Grid(){};
Parallel_Grid::~Parallel_Grid(){};
Magnetism::Magnetism(){}
Magnetism::~Magnetism(){}
InfoNonlocal::InfoNonlocal(){}
Expand Down Expand Up @@ -73,6 +75,7 @@ void Charge::set_rho_core_paw()
}
void Charge::init_rho(elecstate::efermi&,
const UnitCell&,
const Parallel_Grid&,
ModuleBase::ComplexMatrix const&,
ModuleSymmetry::Symmetry& symm,
const void*,
Expand Down Expand Up @@ -146,6 +149,7 @@ class ElecStateTest : public ::testing::Test
protected:
elecstate::MockElecState* elecstate;
UnitCell ucell;
Parallel_Grid pgrid;
std::string output;
void SetUp()
{
Expand Down Expand Up @@ -256,7 +260,7 @@ TEST_F(ElecStateTest, InitSCF)
ModuleBase::ComplexMatrix strucfac;
elecstate->eferm = efermi;
ModuleSymmetry::Symmetry symm;
EXPECT_NO_THROW(elecstate->init_scf(istep, ucell,strucfac, nullptr, symm));
EXPECT_NO_THROW(elecstate->init_scf(istep, ucell, pgrid, strucfac, nullptr, symm));
// delete elecstate->pot is done in the destructor of elecstate
delete charge;
}
Expand Down
1 change: 1 addition & 0 deletions source/module_elecstate/test/elecstate_pw_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void Charge::set_rho_core_paw()
}
void Charge::init_rho(elecstate::efermi&,
const UnitCell&,
const Parallel_Grid&,
ModuleBase::ComplexMatrix const&,
ModuleSymmetry::Symmetry& symm,
const void*,
Expand Down
7 changes: 4 additions & 3 deletions source/module_esolver/esolver_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep)
this->pw_rhod->real2recip(this->pelec->charge->rho_save[is], this->pelec->charge->rhog_save[is]);
}
std::string fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_CHG.cube";
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
ModuleIO::write_vdata_palgrid(Pgrid,
data,
is,
PARAM.inp.nspin,
Expand All @@ -172,7 +172,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep)
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
{
fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_TAU.cube";
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
ModuleIO::write_vdata_palgrid(Pgrid,
this->pelec->charge->kin_r_save[is],
is,
PARAM.inp.nspin,
Expand Down Expand Up @@ -209,7 +209,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep)
{
std::string fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_POT.cube";

ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
ModuleIO::write_vdata_palgrid(Pgrid,
this->pelec->pot->get_effective_v(is),
is,
PARAM.inp.nspin,
Expand Down Expand Up @@ -260,6 +260,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep)
this->pelec->charge->rho,
this->pelec->charge->kin_r,
this->pw_rhod,
this->Pgrid,
&(ucell),
PARAM.inp.out_elf[1]);
}
Expand Down
4 changes: 4 additions & 0 deletions source/module_esolver/esolver_fp.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ namespace ModuleESolver
//! K points in Brillouin zone
K_Vectors kv;

//! Plane-wave basis set for charge density
ModulePW::PW_Basis* pw_rho;

//! parallel for rho grid
Parallel_Grid Pgrid;

//! pointer to pseudopotential
pseudopot_cell_vl* p_locpp = nullptr;

Expand Down
8 changes: 4 additions & 4 deletions source/module_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para

//! 10) initialize the real-space uniform grid for FFT and parallel
//! distribution of plane waves
GlobalC::Pgrid.init(this->pw_rhod->nx,
Pgrid.init(this->pw_rhod->nx,
this->pw_rhod->ny,
this->pw_rhod->nz,
this->pw_rhod->nplane,
Expand All @@ -269,7 +269,7 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
pw_big->bz);

//! 11) calculate the structure factor
this->sf.setup_structure_factor(&ucell, this->pw_rhod);
this->sf.setup_structure_factor(&ucell, Pgrid, this->pw_rhod);

#ifdef USE_PAW
if (PARAM.inp.use_paw)
Expand Down Expand Up @@ -709,7 +709,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
data = this->pelec->charge->rho_save[is];
}
std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube";
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
ModuleIO::write_vdata_palgrid(Pgrid,
data,
is,
PARAM.inp.nspin,
Expand All @@ -722,7 +722,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
{
fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube";
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
ModuleIO::write_vdata_palgrid(Pgrid,
this->pelec->charge->kin_r_save[is],
is,
PARAM.inp.nspin,
Expand Down
23 changes: 10 additions & 13 deletions source/module_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,12 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)
if (ucell.ionic_position_updated)
{
this->CE.update_all_dis(ucell);
this->CE.extrapolate_charge(
#ifdef __MPI
&(GlobalC::Pgrid),
#endif
ucell,
this->pelec->charge,
&this->sf,
GlobalV::ofs_running,
GlobalV::ofs_warning);
this->CE.extrapolate_charge(&this->Pgrid,
ucell,
this->pelec->charge,
&this->sf,
GlobalV::ofs_running,
GlobalV::ofs_warning);
}

// init Hamilt, this should be allocated before each scf loop
Expand Down Expand Up @@ -308,7 +305,7 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)
elecstate::cal_ux(ucell);

//! calculate the total local pseudopotential in real space
this->pelec->init_scf(istep, ucell,this->sf.strucFac, this->ppcell.numeric, ucell.symm, (void*)this->pw_wfc);
this->pelec->init_scf(istep, ucell, this->Pgrid, this->sf.strucFac, this->ppcell.numeric, ucell.symm, (void*)this->pw_wfc);

//! output the initial charge density
if (PARAM.inp.out_chg[0] == 2)
Expand All @@ -317,7 +314,7 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)
{
std::stringstream ss;
ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_CHG_INI.cube";
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
ModuleIO::write_vdata_palgrid(this->Pgrid,
this->pelec->charge->rho[is],
is,
PARAM.inp.nspin,
Expand All @@ -335,7 +332,7 @@ void ESolver_KS_PW<T, Device>::before_scf(UnitCell& ucell, const int istep)
{
std::stringstream ss;
ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_POT_INI.cube";
ModuleIO::write_vdata_palgrid(GlobalC::Pgrid,
ModuleIO::write_vdata_palgrid(this->Pgrid,
this->pelec->pot->get_effective_v(is),
is,
PARAM.inp.nspin,
Expand Down Expand Up @@ -703,7 +700,7 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep)
this->pw_rhod,
this->pw_wfc,
this->ctx,
GlobalC::Pgrid,
this->Pgrid,
PARAM.globalv.global_out_dir,
PARAM.inp.if_separate_k);
}
Expand Down
Loading
Loading