Skip to content

Commit a6d0ba1

Browse files
authored
Refactor: remove init_after_vc (#5547)
1 parent c650aa8 commit a6d0ba1

15 files changed

+81
-450
lines changed

source/Makefile.Objects

Lines changed: 0 additions & 2 deletions
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_after_vc.o\
249248
pw_init_globalc.o\
250249
pw_others.o\
251250

@@ -256,7 +255,6 @@ OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\
256255
lcao_before_scf.o\
257256
esolver_gets.o\
258257
lcao_others.o\
259-
lcao_init_after_vc.o\
260258

261259
OBJS_GINT=gint.o\
262260
gint_gamma_env.o\

source/module_esolver/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
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_after_vc.cpp
1413
pw_init_globalc.cpp
1514
pw_others.cpp
1615
)
@@ -23,7 +22,6 @@ if(ENABLE_LCAO)
2322
lcao_before_scf.cpp
2423
esolver_gets.cpp
2524
lcao_others.cpp
26-
lcao_init_after_vc.cpp
2725
)
2826
endif()
2927

source/module_esolver/esolver_fp.cpp

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -262,81 +262,44 @@ void ESolver_FP::after_scf(const int istep)
262262
PARAM.inp.out_elf[1]);
263263
}
264264
}
265-
266-
// #ifdef __RAPIDJSON
267-
// // add Json of efermi energy converge
268-
// Json::add_output_efermi_converge(this->pelec->eferm.ef * ModuleBase::Ry_to_eV, this->conv_esolver);
269-
// // add nkstot,nkstot_ibz to output json
270-
// int Jnkstot = this->pelec->klist->get_nkstot();
271-
// Json::add_nkstot(Jnkstot);
272-
// #endif //__RAPIDJSON
273265
}
274266

275-
void ESolver_FP::init_after_vc(const Input_para& inp, UnitCell& cell)
267+
void ESolver_FP::before_scf(const int istep)
276268
{
277-
ModuleBase::TITLE("ESolver_FP", "init_after_vc");
269+
ModuleBase::TITLE("ESolver_FP", "before_scf");
278270

279-
if (inp.mdp.md_prec_level == 2)
280-
{
281-
if (inp.nx * inp.ny * inp.nz == 0)
282-
{
283-
this->pw_rho->initgrids(cell.lat0, cell.latvec, 4.0 * inp.ecutwfc);
284-
}
285-
else
286-
{
287-
this->pw_rho->initgrids(cell.lat0, cell.latvec, inp.nx, inp.ny, inp.nz);
288-
}
289-
290-
this->pw_rho->initparameters(false, 4.0 * inp.ecutwfc);
291-
this->pw_rho->setuptransform();
292-
this->pw_rho->collect_local_pw();
293-
this->pw_rho->collect_uniqgg();
294-
295-
if ( PARAM.globalv.double_grid)
296-
{
297-
ModulePW::PW_Basis_Sup* pw_rhod_sup = static_cast<ModulePW::PW_Basis_Sup*>(pw_rhod);
298-
if (inp.ndx * inp.ndy * inp.ndz == 0)
299-
{
300-
this->pw_rhod->initgrids(cell.lat0, cell.latvec, inp.ecutrho);
301-
}
302-
else
303-
{
304-
this->pw_rhod->initgrids(cell.lat0, cell.latvec, inp.ndx, inp.ndy, inp.ndz);
305-
}
306-
this->pw_rhod->initparameters(false, inp.ecutrho);
307-
pw_rhod_sup->setuptransform(this->pw_rho);
308-
this->pw_rhod->collect_local_pw();
309-
this->pw_rhod->collect_uniqgg();
310-
}
311-
}
312-
else
271+
if (GlobalC::ucell.cell_parameter_updated)
313272
{
314273
// only G-vector and K-vector are changed due to the change of lattice
315274
// vector FFT grids do not change!!
316-
pw_rho->initgrids(cell.lat0, cell.latvec, pw_rho->nx, pw_rho->ny, pw_rho->nz);
275+
pw_rho->initgrids(GlobalC::ucell.lat0, GlobalC::ucell.latvec, pw_rho->nx, pw_rho->ny, pw_rho->nz);
317276
pw_rho->collect_local_pw();
318277
pw_rho->collect_uniqgg();
319278

320-
if ( PARAM.globalv.double_grid)
279+
if (PARAM.globalv.double_grid)
321280
{
322-
this->pw_rhod->initgrids(cell.lat0, cell.latvec, pw_rhod->nx, pw_rhod->ny, pw_rhod->nz);
281+
this->pw_rhod->initgrids(GlobalC::ucell.lat0, GlobalC::ucell.latvec, pw_rhod->nx, pw_rhod->ny, pw_rhod->nz);
323282
this->pw_rhod->collect_local_pw();
324283
this->pw_rhod->collect_uniqgg();
325284
}
326285

327286
GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, pw_rhod);
328287
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
329-
}
330-
this->pelec->omega = GlobalC::ucell.omega;
331288

332-
if (ModuleSymmetry::Symmetry::symm_flag == 1)
333-
{
334-
cell.symm.analy_sys(cell.lat, cell.st, cell.atoms, GlobalV::ofs_running);
335-
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SYMMETRY");
336-
}
289+
this->pelec->omega = GlobalC::ucell.omega;
290+
291+
if (ModuleSymmetry::Symmetry::symm_flag == 1)
292+
{
293+
GlobalC::ucell.symm.analy_sys(GlobalC::ucell.lat,
294+
GlobalC::ucell.st,
295+
GlobalC::ucell.atoms,
296+
GlobalV::ofs_running);
297+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SYMMETRY");
298+
}
337299

338-
kv.set_after_vc(PARAM.inp.nspin, cell.G, cell.latvec);
339-
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS");
300+
kv.set_after_vc(PARAM.inp.nspin, GlobalC::ucell.G, GlobalC::ucell.latvec);
301+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS");
302+
}
340303

341304
return;
342305
}

source/module_esolver/esolver_fp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ namespace ModuleESolver
3333
virtual void before_all_runners(const Input_para& inp, UnitCell& cell) override;
3434

3535
protected:
36+
//! Something to do before SCF iterations.
37+
virtual void before_scf(const int istep);
38+
3639
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
3740
virtual void after_scf(const int istep);
3841

39-
virtual void init_after_vc(const Input_para& inp, UnitCell& cell); // liuyu add 2023-03-09
40-
4142
//! Electronic states
4243
elecstate::ElecState* pelec = nullptr;
4344

source/module_esolver/esolver_ks.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -335,34 +335,6 @@ void ESolver_KS<T, Device>::before_all_runners(const Input_para& inp, UnitCell&
335335
#endif
336336
}
337337

338-
//------------------------------------------------------------------------------
339-
//! the 4th function of ESolver_KS: init_after_vc
340-
//! mohan add 2024-05-11
341-
//------------------------------------------------------------------------------
342-
template <typename T, typename Device>
343-
void ESolver_KS<T, Device>::init_after_vc(const Input_para& inp, UnitCell& ucell)
344-
{
345-
ModuleBase::TITLE("ESolver_KS", "init_after_vc");
346-
347-
ESolver_FP::init_after_vc(inp, ucell);
348-
349-
if (inp.mdp.md_prec_level == 2)
350-
{
351-
// initialize the real-space uniform grid for FFT and parallel
352-
// distribution of plane waves
353-
GlobalC::Pgrid.init(this->pw_rhod->nx,
354-
this->pw_rhod->ny,
355-
this->pw_rhod->nz,
356-
this->pw_rhod->nplane,
357-
this->pw_rhod->nrxx,
358-
pw_big->nbz,
359-
pw_big->bz); // mohan add 2010-07-22, update 2011-05-04
360-
361-
// Calculate Structure factor
362-
this->sf.setup_structure_factor(&ucell, this->pw_rhod);
363-
}
364-
}
365-
366338
//------------------------------------------------------------------------------
367339
//! the 5th function of ESolver_KS: hamilt2density_single
368340
//! mohan add 2024-05-11

source/module_esolver/esolver_ks.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ class ESolver_KS : public ESolver_FP
3838
//! Something to do before SCF iterations.
3939
virtual void before_scf(const int istep) {};
4040

41-
virtual void init_after_vc(const Input_para& inp, UnitCell& cell) override; // liuyu add 2023-03-09
42-
4341
//! Something to do before hamilt2density function in each iter loop.
4442
virtual void iter_init(const int istep, const int iter);
4543

source/module_esolver/esolver_ks_lcao.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class ESolver_KS_LCAO : public ESolver_KS<TK> {
2929

3030
void before_all_runners(const Input_para& inp, UnitCell& cell) override;
3131

32-
void init_after_vc(const Input_para& inp, UnitCell& cell) override;
33-
3432
double cal_energy() override;
3533

3634
void cal_force(ModuleBase::matrix& force) override;

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,25 @@ void ESolver_KS_PW<T, Device>::before_scf(const int istep)
195195
{
196196
ModuleBase::TITLE("ESolver_KS_PW", "before_scf");
197197

198+
//! 1) call before_scf() of ESolver_FP
199+
ESolver_FP::before_scf(istep);
200+
198201
if (GlobalC::ucell.cell_parameter_updated)
199202
{
200-
this->init_after_vc(PARAM.inp, GlobalC::ucell);
203+
GlobalC::ppcell.init_vnl(GlobalC::ucell, this->pw_rhod);
204+
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "NON-LOCAL POTENTIAL");
205+
206+
this->pw_wfc->initgrids(GlobalC::ucell.lat0,
207+
GlobalC::ucell.latvec,
208+
this->pw_wfc->nx,
209+
this->pw_wfc->ny,
210+
this->pw_wfc->nz);
211+
212+
this->pw_wfc->initparameters(false, PARAM.inp.ecutwfc, this->kv.get_nks(), this->kv.kvec_d.data());
213+
214+
this->pw_wfc->collect_local_pw(PARAM.inp.erf_ecut, PARAM.inp.erf_height, PARAM.inp.erf_sigma);
215+
216+
this->p_wf_init->make_table(this->kv.get_nks(), &this->sf);
201217
}
202218
if (GlobalC::ucell.ionic_position_updated)
203219
{

source/module_esolver/esolver_ks_pw.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +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-
void init_after_vc(const Input_para& inp, UnitCell& cell) override;
50-
5149
// temporary, this will be removed in the future;
5250
// Init Global class
5351
void Init_GlobalC(const Input_para& inp, UnitCell& ucell, pseudopot_cell_vnl& ppcell);

source/module_esolver/esolver_of.cpp

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -153,66 +153,6 @@ void ESolver_OF::before_all_runners(const Input_para& inp, UnitCell& ucell)
153153
this->allocate_array();
154154
}
155155

156-
void ESolver_OF::init_after_vc(const Input_para& inp, UnitCell& ucell)
157-
{
158-
ModuleBase::timer::tick("ESolver_OF", "init_after_vc");
159-
160-
ESolver_FP::init_after_vc(inp, ucell);
161-
162-
this->dV_ = ucell.omega / this->pw_rho->nxyz;
163-
164-
if (inp.mdp.md_prec_level == 2)
165-
{
166-
// initialize the real-space uniform grid for FFT and parallel
167-
// distribution of plane waves
168-
GlobalC::Pgrid.init(this->pw_rho->nx,
169-
this->pw_rho->ny,
170-
this->pw_rho->nz,
171-
this->pw_rho->nplane,
172-
this->pw_rho->nrxx,
173-
pw_big->nbz,
174-
pw_big->bz); // mohan add 2010-07-22, update 2011-05-04
175-
176-
// Calculate Structure factor
177-
this->sf.setup_structure_factor(&ucell, this->pw_rho);
178-
}
179-
180-
// initialize elecstate, including potential
181-
this->init_elecstate(ucell);
182-
GlobalC::ppcell.init_vnl(ucell, pw_rho);
183-
184-
// Initialize KEDF
185-
this->init_kedf(inp);
186-
187-
// Initialize optimization methods
188-
this->init_opt();
189-
190-
// Refresh the arrays
191-
delete this->psi_;
192-
this->psi_ = new psi::Psi<double>(1, PARAM.inp.nspin, this->pw_rho->nrxx);
193-
for (int is = 0; is < PARAM.inp.nspin; ++is)
194-
{
195-
this->pphi_[is] = this->psi_->get_pointer(is);
196-
}
197-
198-
delete this->ptemp_rho_;
199-
this->ptemp_rho_ = new Charge();
200-
this->ptemp_rho_->set_rhopw(this->pw_rho);
201-
this->ptemp_rho_->allocate(PARAM.inp.nspin);
202-
203-
for (int is = 0; is < PARAM.inp.nspin; ++is)
204-
{
205-
delete[] this->pdLdphi_[is];
206-
delete[] this->pdEdphi_[is];
207-
delete[] this->pdirect_[is];
208-
delete[] this->precip_dir_[is];
209-
this->pdLdphi_[is] = new double[this->pw_rho->nrxx];
210-
this->pdEdphi_[is] = new double[this->pw_rho->nrxx];
211-
this->pdirect_[is] = new double[this->pw_rho->nrxx];
212-
this->precip_dir_[is] = new std::complex<double>[pw_rho->npw];
213-
}
214-
}
215-
216156
void ESolver_OF::runner(int istep, UnitCell& ucell)
217157
{
218158
ModuleBase::timer::tick("ESolver_OF", "runner");
@@ -260,9 +200,47 @@ void ESolver_OF::runner(int istep, UnitCell& ucell)
260200
*/
261201
void ESolver_OF::before_opt(const int istep, UnitCell& ucell)
262202
{
203+
//! 1) call before_scf() of ESolver_FP
204+
ESolver_FP::before_scf(istep);
205+
263206
if (ucell.cell_parameter_updated)
264207
{
265-
this->init_after_vc(PARAM.inp, ucell);
208+
this->dV_ = ucell.omega / this->pw_rho->nxyz;
209+
210+
// initialize elecstate, including potential
211+
this->init_elecstate(ucell);
212+
GlobalC::ppcell.init_vnl(ucell, pw_rho);
213+
214+
// Initialize KEDF
215+
this->init_kedf(PARAM.inp);
216+
217+
// Initialize optimization methods
218+
this->init_opt();
219+
220+
// Refresh the arrays
221+
delete this->psi_;
222+
this->psi_ = new psi::Psi<double>(1, PARAM.inp.nspin, this->pw_rho->nrxx);
223+
for (int is = 0; is < PARAM.inp.nspin; ++is)
224+
{
225+
this->pphi_[is] = this->psi_->get_pointer(is);
226+
}
227+
228+
delete this->ptemp_rho_;
229+
this->ptemp_rho_ = new Charge();
230+
this->ptemp_rho_->set_rhopw(this->pw_rho);
231+
this->ptemp_rho_->allocate(PARAM.inp.nspin);
232+
233+
for (int is = 0; is < PARAM.inp.nspin; ++is)
234+
{
235+
delete[] this->pdLdphi_[is];
236+
delete[] this->pdEdphi_[is];
237+
delete[] this->pdirect_[is];
238+
delete[] this->precip_dir_[is];
239+
this->pdLdphi_[is] = new double[this->pw_rho->nrxx];
240+
this->pdEdphi_[is] = new double[this->pw_rho->nrxx];
241+
this->pdirect_[is] = new double[this->pw_rho->nrxx];
242+
this->precip_dir_[is] = new std::complex<double>[pw_rho->npw];
243+
}
266244
}
267245
if (ucell.ionic_position_updated)
268246
{

0 commit comments

Comments
 (0)