Skip to content

Commit

Permalink
Refactor: remove wf from esolver (#5567)
Browse files Browse the repository at this point in the history
* repalce wf.npwx

* change the file name `wfinit`

* remove wf from esolver

* fix build bug
  • Loading branch information
haozhihan authored Nov 22, 2024
1 parent e0202e0 commit ed2fecf
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ OBJS_SRCPW=H_Ewald_pw.o\
symmetry_rhog.o\
wavefunc.o\
wf_atomic.o\
wfinit.o\
psiinit.o\
elecond.o\
sto_tool.o\
sto_elecond.o\
Expand Down
4 changes: 0 additions & 4 deletions source/module_esolver/esolver_ks.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ class ESolver_KS : public ESolver_FP
//! Charge mixing method, only used in KDSFT, not in OFDFT
Charge_Mixing* p_chgmix = nullptr;

//! wave functions, this one may be deleted in near future
//! mohan note 2024-11-14
wavefunc wf;

//! Electronic wavefunctions
psi::Psi<T>* psi = nullptr;

Expand Down
1 change: 0 additions & 1 deletion source/module_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ void ESolver_KS_PW<T, Device>::before_all_runners(const Input_para& inp, UnitCel
PARAM.inp.ks_solver,
PARAM.inp.basis_type,
PARAM.inp.psi_initializer,
&this->wf,
this->pw_wfc);
this->p_wf_init->prepare_init(&(this->sf),
&ucell,
Expand Down
2 changes: 1 addition & 1 deletion source/module_esolver/esolver_ks_pw.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ESOLVER_KS_PW_H
#include "./esolver_ks.h"
#include "module_hamilt_pw/hamilt_pwdft/operator_pw/velocity_pw.h"
#include "module_hamilt_pw/hamilt_pwdft/wfinit.h"
#include "module_hamilt_pw/hamilt_pwdft/psiinit.h"

#include <memory>
#include <module_base/macros.h>
Expand Down
4 changes: 2 additions & 2 deletions source/module_esolver/esolver_sdft_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ void ESolver_SDFT_PW<T, Device>::before_all_runners(const Input_para& inp, UnitC
// 4) allocate spaces for \sqrt(f(H))|chi> and |\tilde{chi}>
size_t size = stowf.chi0->size();
this->stowf.shchi
= new psi::Psi<T, Device>(this->kv.get_nks(), this->stowf.nchip_max, this->wf.npwx, this->kv.ngk.data());
= new psi::Psi<T, Device>(this->kv.get_nks(), this->stowf.nchip_max, this->pw_wfc->npwk_max, this->kv.ngk.data());
ModuleBase::Memory::record("SDFT::shchi", size * sizeof(T));

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

Expand Down
2 changes: 1 addition & 1 deletion source/module_hamilt_pw/hamilt_pwdft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ list(APPEND objects
VNL_grad_pw.cpp
wavefunc.cpp
wf_atomic.cpp
wfinit.cpp
psiinit.cpp
structure_factor.cpp
structure_factor_k.cpp
soc.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "wfinit.h"
#include "psiinit.h"

#include "module_base/macros.h"
#include "module_base/timer.h"
Expand All @@ -18,14 +18,12 @@ PSIInit<T, Device>::PSIInit(const std::string& init_wfc_in,
const std::string& ks_solver_in,
const std::string& basis_type_in,
const bool& use_psiinitializer_in,
wavefunc* p_wf_in,
ModulePW::PW_Basis_K* pw_wfc_in)
{
this->init_wfc = init_wfc_in;
this->ks_solver = ks_solver_in;
this->basis_type = basis_type_in;
this->use_psiinitializer = use_psiinitializer_in;
this->p_wf = p_wf_in;
this->pw_wfc = pw_wfc_in;
}

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

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

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

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

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

/// for psi init guess!!!!
hamilt::diago_PAO_in_pw_k2(this->ctx, ik, *(kspw_psi), this->pw_wfc, this->p_wf, p_hamilt);
hamilt::diago_PAO_in_pw_k2(this->ctx, ik, *(kspw_psi), this->pw_wfc, &this->wf_old, p_hamilt);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class PSIInit
const std::string& ks_solver_in,
const std::string& basis_type_in,
const bool& use_psiinitializer_in,
wavefunc* p_wf_in,
ModulePW::PW_Basis_K* pw_wfc_in);
~PSIInit(){};

Expand Down Expand Up @@ -47,7 +46,7 @@ class PSIInit
*
* @param psi store the wavefunction
* @param p_hamilt Hamiltonian operator
* @param ofs_running output stream for running information
* @param ofs_running output stream for running information
* @param is_already_initpsi whether psi has been initialized
*/
void initialize_psi(Psi<std::complex<double>>* psi,
Expand All @@ -73,17 +72,22 @@ class PSIInit
// while the std::make_unique() is not supported till C++14,
// so use the new and std::unique_ptr to manage the memory, but this makes new-delete not symmetric
std::unique_ptr<psi_initializer<T, Device>> psi_init;
// temporary
// wavefunc pointer
wavefunc* p_wf = nullptr;

//! temporary: wave functions, this one may be deleted in future
wavefunc wf_old;

// whether to use psi_initializer
bool use_psiinitializer = false;

// wavefunction initialization type
std::string init_wfc = "none";

// Kohn-Sham solver type
std::string ks_solver = "none";

// basis type
std::string basis_type = "none";

// pw basis
ModulePW::PW_Basis_K* pw_wfc = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion source/module_ri/exx_lip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "module_elecstate/elecstate.h"
#include "module_basis/module_pw/pw_basis_k.h"
#include "module_cell/module_symmetry/symmetry.h"
#include "module_hamilt_pw/hamilt_pwdft/wfinit.h"
#include "module_hamilt_pw/hamilt_pwdft/psiinit.h"
#include "module_hamilt_pw/hamilt_pwdft/structure_factor.h"
#include "module_base/tool_title.h"
#include "module_base/timer.h"
Expand Down

0 comments on commit ed2fecf

Please sign in to comment.