Skip to content

Commit c13f16f

Browse files
YuLiu98Qianruipku
andauthored
Refactor: remove pw_init_globalc.cpp (#5559)
Co-authored-by: Qianrui Liu <[email protected]>
1 parent 203c66d commit c13f16f

File tree

6 files changed

+58
-171
lines changed

6 files changed

+58
-171
lines changed

source/Makefile.Objects

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ OBJS_ESOLVER=esolver.o\
245245
esolver_of.o\
246246
esolver_of_tool.o\
247247
esolver_of_interface.o\
248-
pw_init_globalc.o\
249248
pw_others.o\
250249

251250
OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\

source/module_esolver/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ list(APPEND objects
1010
esolver_of.cpp
1111
esolver_of_interface.cpp
1212
esolver_of_tool.cpp
13-
pw_init_globalc.cpp
1413
pw_others.cpp
1514
)
1615
if(ENABLE_LCAO)

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "module_base/memory.h"
1919
#include "module_base/module_device/device.h"
2020
#include "module_elecstate/elecstate_pw.h"
21+
#include "module_elecstate/elecstate_pw_sdft.h"
2122
#include "module_hamilt_general/module_vdw/vdw.h"
2223
#include "module_hamilt_pw/hamilt_pwdft/elecond.h"
2324
#include "module_hamilt_pw/hamilt_pwdft/hamilt_pw.h"
@@ -136,14 +137,29 @@ void ESolver_KS_PW<T, Device>::before_all_runners(const Input_para& inp, UnitCel
136137
// 3) initialize ElecState,
137138
if (this->pelec == nullptr)
138139
{
139-
this->pelec = new elecstate::ElecStatePW<T, Device>(this->pw_wfc,
140-
&(this->chr),
141-
&(this->kv),
142-
&ucell,
143-
&GlobalC::ppcell,
144-
this->pw_rhod,
145-
this->pw_rho,
146-
this->pw_big);
140+
if (inp.esolver_type == "sdft")
141+
{
142+
//! SDFT only supports double precision currently
143+
this->pelec = new elecstate::ElecStatePW_SDFT<std::complex<double>, Device>(this->pw_wfc,
144+
&(this->chr),
145+
&(this->kv),
146+
&ucell,
147+
&(GlobalC::ppcell),
148+
this->pw_rhod,
149+
this->pw_rho,
150+
this->pw_big);
151+
}
152+
else
153+
{
154+
this->pelec = new elecstate::ElecStatePW<T, Device>(this->pw_wfc,
155+
&(this->chr),
156+
&(this->kv),
157+
&ucell,
158+
&GlobalC::ppcell,
159+
this->pw_rhod,
160+
this->pw_rho,
161+
this->pw_big);
162+
}
147163
}
148164

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

183-
//! 8) setup global classes
184-
this->Init_GlobalC(inp, ucell, GlobalC::ppcell);
199+
if (this->psi != nullptr)
200+
{
201+
delete this->psi;
202+
}
203+
204+
//! init pseudopotential
205+
GlobalC::ppcell.init(ucell.ntype, &this->sf, this->pw_wfc);
206+
207+
//! initalize local pseudopotential
208+
GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, this->pw_rhod);
209+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
210+
211+
//! Initalize non-local pseudopotential
212+
GlobalC::ppcell.init_vnl(ucell, this->pw_rhod);
213+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "NON-LOCAL POTENTIAL");
214+
215+
//! Allocate psi
216+
this->p_wf_init->allocate_psi(this->psi,
217+
this->kv.get_nkstot(),
218+
this->kv.get_nks(),
219+
this->kv.ngk.data(),
220+
this->pw_wfc->npwk_max,
221+
&(this->sf));
222+
223+
this->kspw_psi = PARAM.inp.device == "gpu" || PARAM.inp.precision == "single"
224+
? new psi::Psi<T, Device>(this->psi[0])
225+
: reinterpret_cast<psi::Psi<T, Device>*>(this->psi);
226+
227+
if (PARAM.inp.precision == "single")
228+
{
229+
ModuleBase::Memory::record("Psi_single", sizeof(T) * this->psi[0].size());
230+
}
231+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT BASIS");
185232

186233
//! 9) setup occupations
187234
if (PARAM.inp.ocp)

source/module_esolver/esolver_ks_pw.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ class ESolver_KS_PW : public ESolver_KS<T, Device>
4646

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

49-
// temporary, this will be removed in the future;
50-
// Init Global class
51-
void Init_GlobalC(const Input_para& inp, UnitCell& ucell, pseudopot_cell_vnl& ppcell);
52-
5349
virtual void allocate_hamilt();
5450
virtual void deallocate_hamilt();
5551

source/module_esolver/esolver_sdft_pw.cpp

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,49 +50,7 @@ void ESolver_SDFT_PW<T, Device>::before_all_runners(const Input_para& inp, UnitC
5050
this->method_sto = inp.method_sto;
5151

5252
// 2) run "before_all_runners" in ESolver_KS
53-
ESolver_KS<T, Device>::before_all_runners(inp, ucell);
54-
55-
// 3) initialize the pointer for electronic states of SDFT
56-
this->pelec = new elecstate::ElecStatePW_SDFT<T, Device>(this->pw_wfc,
57-
&(this->chr),
58-
&(this->kv),
59-
&ucell,
60-
&(GlobalC::ppcell),
61-
this->pw_rhod,
62-
this->pw_rho,
63-
this->pw_big);
64-
65-
// 4) inititlize the charge density.
66-
this->pelec->charge->allocate(PARAM.inp.nspin);
67-
this->pelec->omega = ucell.omega;
68-
69-
// 5) initialize the potential.
70-
if (this->pelec->pot == nullptr)
71-
{
72-
this->pelec->pot = new elecstate::Potential(this->pw_rhod,
73-
this->pw_rho,
74-
&ucell,
75-
&(GlobalC::ppcell.vloc),
76-
&(this->sf),
77-
&(this->pelec->f_en.etxc),
78-
&(this->pelec->f_en.vtxc));
79-
}
80-
81-
// 6) prepare some parameters for electronic wave functions initilization
82-
this->p_wf_init = new psi::WFInit<T, Device>(PARAM.inp.init_wfc,
83-
PARAM.inp.ks_solver,
84-
PARAM.inp.basis_type,
85-
PARAM.inp.psi_initializer,
86-
&this->wf,
87-
this->pw_wfc);
88-
// 7) set occupatio, redundant?
89-
if (PARAM.inp.ocp)
90-
{
91-
this->pelec->fixed_weights(PARAM.inp.ocp_kb, PARAM.inp.nbands, PARAM.inp.nelec);
92-
}
93-
94-
// 8) initialize the global classes
95-
this->Init_GlobalC(inp, ucell, GlobalC::ppcell); // temporary
53+
ESolver_KS_PW<T, Device>::before_all_runners(inp, ucell);
9654

9755
// 9) initialize the stochastic wave functions
9856
this->stowf.init(&this->kv, this->pw_wfc->npwk_max);

source/module_esolver/pw_init_globalc.cpp

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)