Skip to content

Commit ed2fecf

Browse files
authored
Refactor: remove wf from esolver (#5567)
* repalce wf.npwx * change the file name `wfinit` * remove wf from esolver * fix build bug
1 parent e0202e0 commit ed2fecf

File tree

9 files changed

+23
-26
lines changed

9 files changed

+23
-26
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ OBJS_SRCPW=H_Ewald_pw.o\
666666
symmetry_rhog.o\
667667
wavefunc.o\
668668
wf_atomic.o\
669-
wfinit.o\
669+
psiinit.o\
670670
elecond.o\
671671
sto_tool.o\
672672
sto_elecond.o\

source/module_esolver/esolver_ks.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ class ESolver_KS : public ESolver_FP
6565
//! Charge mixing method, only used in KDSFT, not in OFDFT
6666
Charge_Mixing* p_chgmix = nullptr;
6767

68-
//! wave functions, this one may be deleted in near future
69-
//! mohan note 2024-11-14
70-
wavefunc wf;
71-
7268
//! Electronic wavefunctions
7369
psi::Psi<T>* psi = nullptr;
7470

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ void ESolver_KS_PW<T, Device>::before_all_runners(const Input_para& inp, UnitCel
185185
PARAM.inp.ks_solver,
186186
PARAM.inp.basis_type,
187187
PARAM.inp.psi_initializer,
188-
&this->wf,
189188
this->pw_wfc);
190189
this->p_wf_init->prepare_init(&(this->sf),
191190
&ucell,

source/module_esolver/esolver_ks_pw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define ESOLVER_KS_PW_H
33
#include "./esolver_ks.h"
44
#include "module_hamilt_pw/hamilt_pwdft/operator_pw/velocity_pw.h"
5-
#include "module_hamilt_pw/hamilt_pwdft/wfinit.h"
5+
#include "module_hamilt_pw/hamilt_pwdft/psiinit.h"
66

77
#include <memory>
88
#include <module_base/macros.h>

source/module_esolver/esolver_sdft_pw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ void ESolver_SDFT_PW<T, Device>::before_all_runners(const Input_para& inp, UnitC
7878
// 4) allocate spaces for \sqrt(f(H))|chi> and |\tilde{chi}>
7979
size_t size = stowf.chi0->size();
8080
this->stowf.shchi
81-
= new psi::Psi<T, Device>(this->kv.get_nks(), this->stowf.nchip_max, this->wf.npwx, this->kv.ngk.data());
81+
= new psi::Psi<T, Device>(this->kv.get_nks(), this->stowf.nchip_max, this->pw_wfc->npwk_max, this->kv.ngk.data());
8282
ModuleBase::Memory::record("SDFT::shchi", size * sizeof(T));
8383

8484
if (PARAM.inp.nbands > 0)
8585
{
8686
this->stowf.chiortho
87-
= new psi::Psi<T, Device>(this->kv.get_nks(), this->stowf.nchip_max, this->wf.npwx, this->kv.ngk.data());
87+
= new psi::Psi<T, Device>(this->kv.get_nks(), this->stowf.nchip_max, this->pw_wfc->npwk_max, this->kv.ngk.data());
8888
ModuleBase::Memory::record("SDFT::chiortho", size * sizeof(T));
8989
}
9090

source/module_hamilt_pw/hamilt_pwdft/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ list(APPEND objects
2828
VNL_grad_pw.cpp
2929
wavefunc.cpp
3030
wf_atomic.cpp
31-
wfinit.cpp
31+
psiinit.cpp
3232
structure_factor.cpp
3333
structure_factor_k.cpp
3434
soc.cpp

source/module_hamilt_pw/hamilt_pwdft/wfinit.cpp renamed to source/module_hamilt_pw/hamilt_pwdft/psiinit.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "wfinit.h"
1+
#include "psiinit.h"
22

33
#include "module_base/macros.h"
44
#include "module_base/timer.h"
@@ -18,14 +18,12 @@ PSIInit<T, Device>::PSIInit(const std::string& init_wfc_in,
1818
const std::string& ks_solver_in,
1919
const std::string& basis_type_in,
2020
const bool& use_psiinitializer_in,
21-
wavefunc* p_wf_in,
2221
ModulePW::PW_Basis_K* pw_wfc_in)
2322
{
2423
this->init_wfc = init_wfc_in;
2524
this->ks_solver = ks_solver_in;
2625
this->basis_type = basis_type_in;
2726
this->use_psiinitializer = use_psiinitializer_in;
28-
this->p_wf = p_wf_in;
2927
this->pw_wfc = pw_wfc_in;
3028
}
3129

@@ -122,16 +120,16 @@ void PSIInit<T, Device>::allocate_psi(Psi<std::complex<double>>*& psi,
122120
// old method explicitly requires variables such as total number of kpoints, number
123121
// of bands, number of G-vectors, and so on. Comparatively in new method, these
124122
// variables are imported in function called initialize.
125-
psi = this->p_wf->allocate(nkstot, nks, ngk, npwx);
123+
psi = this->wf_old.allocate(nkstot, nks, ngk, npwx);
126124

127125
// however, init_at_1 does not actually initialize the psi, instead, it is a
128126
// function to calculate a interpolate table saving overlap intergral or say
129127
// Spherical Bessel Transform of atomic orbitals.
130-
this->p_wf->init_at_1(p_sf);
128+
this->wf_old.init_at_1(p_sf);
131129
// similarly, wfcinit not really initialize any wavefunction, instead, it initialize
132130
// the mapping from ixy, the 1d flattened index of point on fft grid (x, y) plane,
133131
// to the index of "stick", composed of grid points.
134-
this->p_wf->wfcinit(psi, pw_wfc);
132+
this->wf_old.wfcinit(psi, pw_wfc);
135133
}
136134
}
137135

@@ -143,8 +141,8 @@ void PSIInit<T, Device>::make_table(const int nks, Structure_Factor* p_sf)
143141
} // do not need to do anything because the interpolate table is unchanged
144142
else // old initialization method, used in EXX calculation
145143
{
146-
this->p_wf->init_after_vc(nks); // reallocate wanf2, the planewave expansion of lcao
147-
this->p_wf->init_at_1(p_sf); // re-calculate tab_at, the overlap matrix between atomic pswfc and jlq
144+
this->wf_old.init_after_vc(nks); // reallocate wanf2, the planewave expansion of lcao
145+
this->wf_old.init_at_1(p_sf); // re-calculate tab_at, the overlap matrix between atomic pswfc and jlq
148146
}
149147
}
150148

@@ -271,7 +269,7 @@ void PSIInit<T, Device>::initialize_psi(Psi<std::complex<double>>* psi,
271269
kspw_psi->fix_k(ik);
272270

273271
/// for psi init guess!!!!
274-
hamilt::diago_PAO_in_pw_k2(this->ctx, ik, *(kspw_psi), this->pw_wfc, this->p_wf, p_hamilt);
272+
hamilt::diago_PAO_in_pw_k2(this->ctx, ik, *(kspw_psi), this->pw_wfc, &this->wf_old, p_hamilt);
275273
}
276274
}
277275
else
@@ -280,7 +278,7 @@ void PSIInit<T, Device>::initialize_psi(Psi<std::complex<double>>* psi,
280278
kspw_psi->fix_k(ik);
281279

282280
/// for psi init guess!!!!
283-
hamilt::diago_PAO_in_pw_k2(this->ctx, ik, *(kspw_psi), this->pw_wfc, this->p_wf, p_hamilt);
281+
hamilt::diago_PAO_in_pw_k2(this->ctx, ik, *(kspw_psi), this->pw_wfc, &this->wf_old, p_hamilt);
284282
}
285283
}
286284
}

source/module_hamilt_pw/hamilt_pwdft/wfinit.h renamed to source/module_hamilt_pw/hamilt_pwdft/psiinit.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class PSIInit
1616
const std::string& ks_solver_in,
1717
const std::string& basis_type_in,
1818
const bool& use_psiinitializer_in,
19-
wavefunc* p_wf_in,
2019
ModulePW::PW_Basis_K* pw_wfc_in);
2120
~PSIInit(){};
2221

@@ -47,7 +46,7 @@ class PSIInit
4746
*
4847
* @param psi store the wavefunction
4948
* @param p_hamilt Hamiltonian operator
50-
* @param ofs_running output stream for running information
49+
* @param ofs_running output stream for running information
5150
* @param is_already_initpsi whether psi has been initialized
5251
*/
5352
void initialize_psi(Psi<std::complex<double>>* psi,
@@ -73,17 +72,22 @@ class PSIInit
7372
// while the std::make_unique() is not supported till C++14,
7473
// so use the new and std::unique_ptr to manage the memory, but this makes new-delete not symmetric
7574
std::unique_ptr<psi_initializer<T, Device>> psi_init;
76-
// temporary
77-
// wavefunc pointer
78-
wavefunc* p_wf = nullptr;
75+
76+
//! temporary: wave functions, this one may be deleted in future
77+
wavefunc wf_old;
78+
7979
// whether to use psi_initializer
8080
bool use_psiinitializer = false;
81+
8182
// wavefunction initialization type
8283
std::string init_wfc = "none";
84+
8385
// Kohn-Sham solver type
8486
std::string ks_solver = "none";
87+
8588
// basis type
8689
std::string basis_type = "none";
90+
8791
// pw basis
8892
ModulePW::PW_Basis_K* pw_wfc = nullptr;
8993

source/module_ri/exx_lip.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "module_elecstate/elecstate.h"
2222
#include "module_basis/module_pw/pw_basis_k.h"
2323
#include "module_cell/module_symmetry/symmetry.h"
24-
#include "module_hamilt_pw/hamilt_pwdft/wfinit.h"
24+
#include "module_hamilt_pw/hamilt_pwdft/psiinit.h"
2525
#include "module_hamilt_pw/hamilt_pwdft/structure_factor.h"
2626
#include "module_base/tool_title.h"
2727
#include "module_base/timer.h"

0 commit comments

Comments
 (0)