From f05a55acbd9b7b2c94c570f0fca693f15797055a Mon Sep 17 00:00:00 2001 From: AsTonyshment Date: Fri, 23 Jan 2026 18:10:34 +0800 Subject: [PATCH] Refactor wavefunction initialization in lcao_others --- source/source_esolver/lcao_others.cpp | 129 +++++++++----------------- 1 file changed, 42 insertions(+), 87 deletions(-) diff --git a/source/source_esolver/lcao_others.cpp b/source/source_esolver/lcao_others.cpp index 32934463b8..337b8feacd 100644 --- a/source/source_esolver/lcao_others.cpp +++ b/source/source_esolver/lcao_others.cpp @@ -1,27 +1,27 @@ -#include "source_lcao/hamilt_lcao.h" -#include "source_lcao/module_dftu/dftu.h" #include "source_esolver/esolver_ks_lcao.h" #include "source_estate/cal_ux.h" #include "source_estate/module_charge/symmetry_rho.h" +#include "source_lcao/hamilt_lcao.h" +#include "source_lcao/module_dftu/dftu.h" #include "source_pw/module_pwdft/global.h" // +#include "source_base/formatter.h" +#include "source_base/timer.h" +#include "source_cell/module_neighbor/sltk_atom_arrange.h" +#include "source_cell/module_neighbor/sltk_grid_driver.h" +#include "source_estate/elecstate_lcao.h" +#include "source_estate/module_dm/cal_dm_psi.h" #include "source_io/berryphase.h" #include "source_io/get_pchg_lcao.h" #include "source_io/get_wf_lcao.h" -#include "source_io/write_HS_R.h" #include "source_io/module_parameter/parameter.h" -#include "source_base/timer.h" -#include "source_cell/module_neighbor/sltk_atom_arrange.h" -#include "source_cell/module_neighbor/sltk_grid_driver.h" +#include "source_io/read_wfc_nao.h" +#include "source_io/write_HS_R.h" +#include "source_io/write_elecstat_pot.h" #include "source_lcao/LCAO_domain.h" +#include "source_lcao/module_deltaspin/spin_constrain.h" #include "source_lcao/module_operator_lcao/op_exx_lcao.h" #include "source_lcao/module_operator_lcao/operator_lcao.h" -#include "source_lcao/module_deltaspin/spin_constrain.h" -#include "source_io/read_wfc_nao.h" -#include "source_io/write_elecstat_pot.h" -#include "source_base/formatter.h" -#include "source_estate/elecstate_lcao.h" -#include "source_estate/module_dm/cal_dm_psi.h" #ifdef __EXX #include "source_io/restart_exx_csr.h" @@ -90,23 +90,21 @@ void ESolver_KS_LCAO::others(UnitCell& ucell, const int istep) PARAM.inp.test_atom_input); // (3) Periodic condition search for each grid. - gint_info_.reset( - new ModuleGint::GintInfo( - this->pw_big->nbx, - this->pw_big->nby, - this->pw_big->nbz, - this->pw_rho->nx, - this->pw_rho->ny, - this->pw_rho->nz, - 0, - 0, - this->pw_big->nbzp_start, - this->pw_big->nbx, - this->pw_big->nby, - this->pw_big->nbzp, - orb_.Phi, - ucell, - this->gd)); + gint_info_.reset(new ModuleGint::GintInfo(this->pw_big->nbx, + this->pw_big->nby, + this->pw_big->nbz, + this->pw_rho->nx, + this->pw_rho->ny, + this->pw_rho->nz, + 0, + 0, + this->pw_big->nbzp_start, + this->pw_big->nbx, + this->pw_big->nby, + this->pw_big->nbzp, + orb_.Phi, + ucell, + this->gd)); ModuleGint::Gint::set_gint_info(gint_info_.get()); // (2)For each atom, calculate the adjacent atoms in different cells @@ -121,49 +119,8 @@ void ESolver_KS_LCAO::others(UnitCell& ucell, const int istep) // this information is used to calculate // the force. - // init psi - if (this->psi == nullptr) - { - int nsk = 0; - int ncol = 0; - if (PARAM.globalv.gamma_only_local) - { - nsk = PARAM.inp.nspin; - ncol = this->pv.ncol_bands; - if (PARAM.inp.ks_solver == "genelpa" || PARAM.inp.ks_solver == "elpa" || PARAM.inp.ks_solver == "lapack" - || PARAM.inp.ks_solver == "pexsi" || PARAM.inp.ks_solver == "cusolver" - || PARAM.inp.ks_solver == "cusolvermp") - { - ncol = this->pv.ncol; - } - } - else - { - nsk = this->kv.get_nks(); -#ifdef __MPI - ncol = this->pv.ncol_bands; -#else - ncol = PARAM.inp.nbands; -#endif - } - this->psi = new psi::Psi(nsk, ncol, this->pv.nrow, this->kv.ngk, true); - } - - // init wfc from file - if (istep == 0 && PARAM.inp.init_wfc == "file") - { - if (!ModuleIO::read_wfc_nao(PARAM.globalv.global_readin_dir, - this->pv, - *(this->psi), - this->pelec->ekb, - this->pelec->wg, - this->pelec->klist->ik2iktot, - this->pelec->klist->get_nkstot(), - PARAM.inp.nspin)) - { - ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::others", "read wfc nao failed"); - } - } + // init psi deleted by taoni 2026-01-23 + // don't need to since initialized in LCAO_domain::set_psi_occ_dm_chg in before_all_runners // init Hamiltonian if (this->p_hamilt != nullptr) @@ -173,21 +130,19 @@ void ESolver_KS_LCAO::others(UnitCell& ucell, const int istep) } if (this->p_hamilt == nullptr) { - this->p_hamilt = new hamilt::HamiltLCAO( - ucell, - this->gd, - &this->pv, - this->pelec->pot, - this->kv, - two_center_bundle_, - orb_, - this->dmat.dm, - &this->dftu, - this->deepks, - istep, - this->exx_nao); - } - + this->p_hamilt = new hamilt::HamiltLCAO(ucell, + this->gd, + &this->pv, + this->pelec->pot, + this->kv, + two_center_bundle_, + orb_, + this->dmat.dm, + &this->dftu, + this->deepks, + istep, + this->exx_nao); + } // for each ionic step, the overlap must be rebuilt // since it depends on ionic positions