Skip to content

Commit

Permalink
Refactor: remove pw_init_globalc.cpp (#5559)
Browse files Browse the repository at this point in the history
Co-authored-by: Qianrui Liu <[email protected]>
  • Loading branch information
YuLiu98 and Qianruipku authored Nov 22, 2024
1 parent 203c66d commit c13f16f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 171 deletions.
1 change: 0 additions & 1 deletion source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ OBJS_ESOLVER=esolver.o\
esolver_of.o\
esolver_of_tool.o\
esolver_of_interface.o\
pw_init_globalc.o\
pw_others.o\

OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\
Expand Down
1 change: 0 additions & 1 deletion source/module_esolver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ list(APPEND objects
esolver_of.cpp
esolver_of_interface.cpp
esolver_of_tool.cpp
pw_init_globalc.cpp
pw_others.cpp
)
if(ENABLE_LCAO)
Expand Down
67 changes: 57 additions & 10 deletions source/module_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "module_base/memory.h"
#include "module_base/module_device/device.h"
#include "module_elecstate/elecstate_pw.h"
#include "module_elecstate/elecstate_pw_sdft.h"
#include "module_hamilt_general/module_vdw/vdw.h"
#include "module_hamilt_pw/hamilt_pwdft/elecond.h"
#include "module_hamilt_pw/hamilt_pwdft/hamilt_pw.h"
Expand Down Expand Up @@ -136,14 +137,29 @@ void ESolver_KS_PW<T, Device>::before_all_runners(const Input_para& inp, UnitCel
// 3) initialize ElecState,
if (this->pelec == nullptr)
{
this->pelec = new elecstate::ElecStatePW<T, Device>(this->pw_wfc,
&(this->chr),
&(this->kv),
&ucell,
&GlobalC::ppcell,
this->pw_rhod,
this->pw_rho,
this->pw_big);
if (inp.esolver_type == "sdft")
{
//! SDFT only supports double precision currently
this->pelec = new elecstate::ElecStatePW_SDFT<std::complex<double>, Device>(this->pw_wfc,
&(this->chr),
&(this->kv),
&ucell,
&(GlobalC::ppcell),
this->pw_rhod,
this->pw_rho,
this->pw_big);
}
else
{
this->pelec = new elecstate::ElecStatePW<T, Device>(this->pw_wfc,
&(this->chr),
&(this->kv),
&ucell,
&GlobalC::ppcell,
this->pw_rhod,
this->pw_rho,
this->pw_big);
}
}

//! 4) inititlize the charge density.
Expand Down Expand Up @@ -180,8 +196,39 @@ void ESolver_KS_PW<T, Device>::before_all_runners(const Input_para& inp, UnitCel
#endif
&GlobalC::ppcell);

//! 8) setup global classes
this->Init_GlobalC(inp, ucell, GlobalC::ppcell);
if (this->psi != nullptr)
{
delete this->psi;
}

//! init pseudopotential
GlobalC::ppcell.init(ucell.ntype, &this->sf, this->pw_wfc);

//! initalize local pseudopotential
GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, this->pw_rhod);
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");

//! Initalize non-local pseudopotential
GlobalC::ppcell.init_vnl(ucell, this->pw_rhod);
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "NON-LOCAL POTENTIAL");

//! Allocate psi
this->p_wf_init->allocate_psi(this->psi,
this->kv.get_nkstot(),
this->kv.get_nks(),
this->kv.ngk.data(),
this->pw_wfc->npwk_max,
&(this->sf));

this->kspw_psi = PARAM.inp.device == "gpu" || PARAM.inp.precision == "single"
? new psi::Psi<T, Device>(this->psi[0])
: reinterpret_cast<psi::Psi<T, Device>*>(this->psi);

if (PARAM.inp.precision == "single")
{
ModuleBase::Memory::record("Psi_single", sizeof(T) * this->psi[0].size());
}
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT BASIS");

//! 9) setup occupations
if (PARAM.inp.ocp)
Expand Down
4 changes: 0 additions & 4 deletions source/module_esolver/esolver_ks_pw.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ class ESolver_KS_PW : public ESolver_KS<T, Device>

virtual void hamilt2density_single(const int istep, const int iter, const double ethr) override;

// temporary, this will be removed in the future;
// Init Global class
void Init_GlobalC(const Input_para& inp, UnitCell& ucell, pseudopot_cell_vnl& ppcell);

virtual void allocate_hamilt();
virtual void deallocate_hamilt();

Expand Down
44 changes: 1 addition & 43 deletions source/module_esolver/esolver_sdft_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,49 +50,7 @@ void ESolver_SDFT_PW<T, Device>::before_all_runners(const Input_para& inp, UnitC
this->method_sto = inp.method_sto;

// 2) run "before_all_runners" in ESolver_KS
ESolver_KS<T, Device>::before_all_runners(inp, ucell);

// 3) initialize the pointer for electronic states of SDFT
this->pelec = new elecstate::ElecStatePW_SDFT<T, Device>(this->pw_wfc,
&(this->chr),
&(this->kv),
&ucell,
&(GlobalC::ppcell),
this->pw_rhod,
this->pw_rho,
this->pw_big);

// 4) inititlize the charge density.
this->pelec->charge->allocate(PARAM.inp.nspin);
this->pelec->omega = ucell.omega;

// 5) initialize the potential.
if (this->pelec->pot == nullptr)
{
this->pelec->pot = new elecstate::Potential(this->pw_rhod,
this->pw_rho,
&ucell,
&(GlobalC::ppcell.vloc),
&(this->sf),
&(this->pelec->f_en.etxc),
&(this->pelec->f_en.vtxc));
}

// 6) prepare some parameters for electronic wave functions initilization
this->p_wf_init = new psi::WFInit<T, Device>(PARAM.inp.init_wfc,
PARAM.inp.ks_solver,
PARAM.inp.basis_type,
PARAM.inp.psi_initializer,
&this->wf,
this->pw_wfc);
// 7) set occupatio, redundant?
if (PARAM.inp.ocp)
{
this->pelec->fixed_weights(PARAM.inp.ocp_kb, PARAM.inp.nbands, PARAM.inp.nelec);
}

// 8) initialize the global classes
this->Init_GlobalC(inp, ucell, GlobalC::ppcell); // temporary
ESolver_KS_PW<T, Device>::before_all_runners(inp, ucell);

// 9) initialize the stochastic wave functions
this->stowf.init(&this->kv, this->pw_wfc->npwk_max);
Expand Down
112 changes: 0 additions & 112 deletions source/module_esolver/pw_init_globalc.cpp

This file was deleted.

0 comments on commit c13f16f

Please sign in to comment.