From accd6daa862fe69ac029b719dd541d3930904fcf Mon Sep 17 00:00:00 2001 From: mohanchen Date: Mon, 10 Nov 2025 22:07:35 +0800 Subject: [PATCH 1/5] remove some codes in esolver_ks_lcao and add LCAO_set.cpp --- source/source_esolver/esolver_ks_lcao.cpp | 58 ++----------------- source/source_lcao/LCAO_set.cpp | 69 +++++++++++++++++++++++ 2 files changed, 73 insertions(+), 54 deletions(-) create mode 100644 source/source_lcao/LCAO_set.cpp diff --git a/source/source_esolver/esolver_ks_lcao.cpp b/source/source_esolver/esolver_ks_lcao.cpp index d92bf2ab3b..0490a2e415 100644 --- a/source/source_esolver/esolver_ks_lcao.cpp +++ b/source/source_esolver/esolver_ks_lcao.cpp @@ -74,62 +74,14 @@ void ESolver_KS_LCAO::before_all_runners(UnitCell& ucell, const Input_pa return; } - // 5) init electronic wave function psi - Setup_Psi::allocate_psi(this->psi, this->kv, this->pv, inp); + LCAO_domain::set_psi_occ_dm_chg(); - //! read psi from file - if (inp.init_wfc == "file" && inp.esolver_type != "tddft") - { - if (!ModuleIO::read_wfc_nao(PARAM.globalv.global_readin_dir, - this->pv, *this->psi, this->pelec->ekb, this->pelec->wg, this->kv.ik2iktot, - this->kv.get_nkstot(), inp.nspin)) - { - ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "read electronic wave functions failed"); - } - } - - - // 7) init DMK, but DMR is constructed in before_scf() - this->dmat.allocate_dm(&this->kv, &this->pv, inp.nspin); - - // 8) init exact exchange calculations - this->exx_nao.before_runner(ucell, this->kv, this->orb_, this->pv, inp); - - // 9) initialize DFT+U - if (inp.dft_plus_u) - { - this->dftu.init(ucell, &this->pv, this->kv.get_nks(), &orb_); - } + LCAO_domain::set_pot(); - // 10) init local pseudopotentials - this->locpp.init_vloc(ucell, this->pw_rho); - ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL"); - - // 11) init charge density - this->chr.allocate(inp.nspin); - - // 12) init potentials - if (this->pelec->pot == nullptr) - { - this->pelec->pot = new elecstate::Potential(this->pw_rhod, this->pw_rho, - &ucell, &(this->locpp.vloc), &(this->sf), &(this->solvent), - &(this->pelec->f_en.etxc), &(this->pelec->f_en.vtxc)); - } - - // 13) init deepks - this->deepks.before_runner(ucell, this->kv.get_nks(), this->orb_, this->pv, inp); - - // 14) set occupations, tddft does not need to set occupations in the first scf - if (inp.ocp && inp.esolver_type != "tddft") - { - elecstate::fixed_weights(inp.ocp_kb, inp.nbands, inp.nelec, - this->pelec->klist, this->pelec->wg, this->pelec->skip_weights); - } - - // 15) if kpar is not divisible by nks, print a warning + //! if kpar is not divisible by nks, print a warning ModuleIO::print_kpar(this->kv.get_nks(), PARAM.globalv.kpar_lcao); - // 16) init rdmft, added by jghan + //! init rdmft, added by jghan if (inp.rdmft == true) { rdmft_solver.init(this->pv, ucell, @@ -310,8 +262,6 @@ void ESolver_KS_LCAO::after_all_runners(UnitCell& ucell) ESolver_KS::after_all_runners(ucell); - const int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1; - auto* hamilt_lcao = dynamic_cast*>(this->p_hamilt); if(!hamilt_lcao) { diff --git a/source/source_lcao/LCAO_set.cpp b/source/source_lcao/LCAO_set.cpp new file mode 100644 index 0000000000..aabd399c46 --- /dev/null +++ b/source/source_lcao/LCAO_set.cpp @@ -0,0 +1,69 @@ +#include "source_lcao/LCAO_set_pot.h" +#include "source_io/module_parameter/parameter.h" + +namespace LCAO_domain +{ + +void set_psi_occ_dm_chg(psi, kv, pv, inp, pelec, dmat, chr) +{ + //! 1) init electronic wave function psi + Setup_Psi::allocate_psi(psi, kv, pv, inp); + + //! 2) read psi from file + if (inp.init_wfc == "file" && inp.esolver_type != "tddft") + { + if (!ModuleIO::read_wfc_nao(PARAM.globalv.global_readin_dir, + pv, *psi, pelec->ekb, pelec->wg, kv.ik2iktot, + kv.get_nkstot(), inp.nspin)) + { + ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "read electronic wave functions failed"); + } + } + + // 3) set occupations, tddft does not need to set occupations in the first scf + if (inp.ocp && inp.esolver_type != "tddft") + { + elecstate::fixed_weights(inp.ocp_kb, inp.nbands, inp.nelec, + pelec->klist, pelec->wg, pelec->skip_weights); + } + + // 4) init DMK, but DMR is constructed in before_scf() + dmat.allocate_dm(&kv, &pv, inp.nspin); + + // 5) init charge density + chr.allocate(inp.nspin); +} + + +void set_pot(pelec, locpp, pw_rho, pw_rhod, sf, solvent, dftu, pv, kv, orb_, exx_nao, deepks) +{ + // 1) init local pseudopotentials + locpp.init_vloc(ucell, pw_rho); + ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL"); + + // 2) init potentials + if (pelec->pot == nullptr) + { + // where is the pot deleted? + pelec->pot = new elecstate::Potential(pw_rhod, pw_rho, + &ucell, &(locpp.vloc), &(sf), &(solvent), + &(pelec->f_en.etxc), &(pelec->f_en.vtxc)); + } + + // 3) initialize DFT+U + if (inp.dft_plus_u) + { + dftu.init(ucell, &pv, kv.get_nks(), &orb_); + } + + // 4) init exact exchange calculations + exx_nao.before_runner(ucell, kv, orb_, pv, inp); + + // 5) init deepks + deepks.before_runner(ucell, kv.get_nks(), orb_, pv, inp); + + return; +} + + +} From 98240e6773ddeac230c7eedcfc0d70638e1e8f8e Mon Sep 17 00:00:00 2001 From: mohanchen Date: Tue, 11 Nov 2025 08:32:33 +0800 Subject: [PATCH 2/5] add LCAO_set.h and LCAO_set.cpp --- source/Makefile.Objects | 1 + source/source_lcao/CMakeLists.txt | 1 + source/source_lcao/LCAO_set.cpp | 60 ++++++++++++++++++++----------- source/source_lcao/LCAO_set.h | 52 +++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 source/source_lcao/LCAO_set.h diff --git a/source/Makefile.Objects b/source/Makefile.Objects index 1aea12100a..91e4f34bea 100644 --- a/source/Makefile.Objects +++ b/source/Makefile.Objects @@ -634,6 +634,7 @@ OBJS_LCAO=evolve_elec.o\ spar_hsr.o\ spar_st.o\ spar_u.o\ + LCAO_set.o\ LCAO_set_fs.o\ LCAO_set_st.o\ LCAO_nl_mu.o\ diff --git a/source/source_lcao/CMakeLists.txt b/source/source_lcao/CMakeLists.txt index 5199625c41..7b090ab275 100644 --- a/source/source_lcao/CMakeLists.txt +++ b/source/source_lcao/CMakeLists.txt @@ -33,6 +33,7 @@ if(ENABLE_LCAO) spar_hsr.cpp spar_st.cpp spar_u.cpp + LCAO_set.cpp LCAO_set_fs.cpp LCAO_set_st.cpp LCAO_nl_mu.cpp diff --git a/source/source_lcao/LCAO_set.cpp b/source/source_lcao/LCAO_set.cpp index aabd399c46..c1390e5c8e 100644 --- a/source/source_lcao/LCAO_set.cpp +++ b/source/source_lcao/LCAO_set.cpp @@ -1,10 +1,15 @@ #include "source_lcao/LCAO_set_pot.h" #include "source_io/module_parameter/parameter.h" -namespace LCAO_domain -{ - -void set_psi_occ_dm_chg(psi, kv, pv, inp, pelec, dmat, chr) +template +void LCAO_domain::set_psi_occ_dm_chg( + const K_Vectors &kv, // k-points + psi::Psi* psi, // coefficients of NAO basis + const Parallel_Orbitals &pv, // parallel scheme of NAO basis + elecstate::ElecState* pelec, // eigen values and weights + LCAO_domain::Setup_DM &dmat, // density matrix + Charge &chr, // charge density + const Input_para &inp) // input parameters { //! 1) init electronic wave function psi Setup_Psi::allocate_psi(psi, kv, pv, inp); @@ -16,54 +21,69 @@ void set_psi_occ_dm_chg(psi, kv, pv, inp, pelec, dmat, chr) pv, *psi, pelec->ekb, pelec->wg, kv.ik2iktot, kv.get_nkstot(), inp.nspin)) { - ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "read electronic wave functions failed"); + ModuleBase::WARNING_QUIT("set_psi_occ_dm_chg", "read electronic wave functions failed"); } } - // 3) set occupations, tddft does not need to set occupations in the first scf + //! 3) set occupations, tddft does not need to set occupations in the first scf if (inp.ocp && inp.esolver_type != "tddft") { elecstate::fixed_weights(inp.ocp_kb, inp.nbands, inp.nelec, - pelec->klist, pelec->wg, pelec->skip_weights); + kv, pelec->wg, pelec->skip_weights); } - // 4) init DMK, but DMR is constructed in before_scf() + //! 4) init DMK, but DMR is constructed in before_scf() dmat.allocate_dm(&kv, &pv, inp.nspin); - // 5) init charge density + //! 5) init charge density chr.allocate(inp.nspin); + + return; } -void set_pot(pelec, locpp, pw_rho, pw_rhod, sf, solvent, dftu, pv, kv, orb_, exx_nao, deepks) + +void LCAO_domain::set_pot( + const K_Vectors &kv, + const Structure_Factor& sf, + const ModulePW::PW_Basis &pw_rho, + const ModulePW::PW_Basis &pw_rhod, + elecstate::ElecState* pelec, + const LCAO_Orbitals& orb, + const Parallel_Orbitals &pv, + pseudopot_cell_vl &locpp, + Plus_U &dftu, + surchem& solvent, + Exx_NAO &exx_nao, + Setup_DeePKS &deepks, + const Input_para &inp) { - // 1) init local pseudopotentials + //! 1) init local pseudopotentials locpp.init_vloc(ucell, pw_rho); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL"); - // 2) init potentials + //! 2) init potentials if (pelec->pot == nullptr) { // where is the pot deleted? - pelec->pot = new elecstate::Potential(pw_rhod, pw_rho, + pelec->pot = new elecstate::Potential(&pw_rhod, &pw_rho, &ucell, &(locpp.vloc), &(sf), &(solvent), &(pelec->f_en.etxc), &(pelec->f_en.vtxc)); } - // 3) initialize DFT+U + //! 3) initialize DFT+U if (inp.dft_plus_u) { - dftu.init(ucell, &pv, kv.get_nks(), &orb_); + dftu.init(ucell, &pv, kv.get_nks(), &orb); } - // 4) init exact exchange calculations - exx_nao.before_runner(ucell, kv, orb_, pv, inp); + //! 4) init exact exchange calculations + exx_nao.before_runner(ucell, kv, orb, pv, inp); - // 5) init deepks - deepks.before_runner(ucell, kv.get_nks(), orb_, pv, inp); + //! 5) init deepks + deepks.before_runner(ucell, kv.get_nks(), orb, pv, inp); return; } -} diff --git a/source/source_lcao/LCAO_set.h b/source/source_lcao/LCAO_set.h new file mode 100644 index 0000000000..1b5efa52ba --- /dev/null +++ b/source/source_lcao/LCAO_set.h @@ -0,0 +1,52 @@ +#ifndef LCAO_SET_H +#define LCAO_SET_H + +#include "source_cell/klist.h" +#include "source_psi/psi.h" +#include "source_estate/elecstate.h" +#include "source_lcao/setup_dm.h" +#include "source_pw/module_pwdft/structure_factor.h" +#include "source_basis/module_pw/pw_basis.h" +#include "source_hamilt/module_surchem/surchem.h" +#include "source_pw/module_pwdft/VL_in_pw.h" +#include "source_lcao/module_deepks/LCAO_deepks.h" +#include "source_lcao/module_dftu/dftu.h" +#include "source_lcao/setup_exx.h" +#include "source_lcao/setup_deepks.h" + +/** + * @brief set up wave functions, occupation numbers, + * density matrix and charge density + */ +template +void LCAO_domain::set_psi_occ_dm_chg( + const K_Vectors &kv, // k-points + psi::Psi* psi, // coefficients of NAO basis + const Parallel_Orbitals &pv, // parallel scheme of NAO basis + elecstate::ElecState* pelec, // eigen values and weights + LCAO_domain::Setup_DM &dmat, // density matrix + Charge &chr, // charge density + const Input_para& inp) // input parameters + +/** + * @brief set up potentials, including local pseudopotentials, + * +U potential, solvent potential, exx potential and deepks potential + */ +template +void LCAO_domain::set_pot( + const K_Vectors &kv, + const Structure_Factor& sf, + const ModulePW::PW_Basis &pw_rho, + const ModulePW::PW_Basis &pw_rhod, + elecstate::ElecState* pelec, + const LCAO_Orbitals& orb, + const Parallel_Orbitals &pv, + pseudopot_cell_vl &locpp, + Plus_U &dftu, + surchem& solvent, + Exx_NAO &exx_nao, + Setup_DeePKS &deepks, + const Input_para &inp); + + +#endif From f438e2e6c4f9efcf5cfad220ae3e90fe09a01a36 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Tue, 11 Nov 2025 10:27:44 +0800 Subject: [PATCH 3/5] finish updating esolver --- source/source_esolver/esolver_ks_lcao.cpp | 10 +-- source/source_lcao/LCAO_set.cpp | 75 ++++++++++++++++++++--- source/source_lcao/LCAO_set.h | 22 ++++--- 3 files changed, 85 insertions(+), 22 deletions(-) diff --git a/source/source_esolver/esolver_ks_lcao.cpp b/source/source_esolver/esolver_ks_lcao.cpp index 0490a2e415..0d2ef6cb11 100644 --- a/source/source_esolver/esolver_ks_lcao.cpp +++ b/source/source_esolver/esolver_ks_lcao.cpp @@ -17,10 +17,9 @@ #include "source_io/ctrl_runner_lcao.h" // use ctrl_runner_lcao() #include "source_io/ctrl_iter_lcao.h" // use ctrl_iter_lcao() #include "source_io/ctrl_scf_lcao.h" // use ctrl_scf_lcao() -#include "source_psi/setup_psi.h" // mohan add 20251019 -#include "source_io/read_wfc_nao.h" #include "source_io/print_info.h" #include "source_lcao/rho_tau_lcao.h" // mohan add 20251024 +#include "source_lcao/LCAO_set.h" // mohan add 20251111 namespace ModuleESolver { @@ -74,9 +73,12 @@ void ESolver_KS_LCAO::before_all_runners(UnitCell& ucell, const Input_pa return; } - LCAO_domain::set_psi_occ_dm_chg(); + LCAO_domain::set_psi_occ_dm_chg(this->kv, this->psi, this->pv, this->pelec, + this->dmat, this->chr, inp); - LCAO_domain::set_pot(); + LCAO_domain::set_pot(ucell, this->kv, this->sf, *this->pw_rho, *this->pw_rhod, + this->pelec, this->orb_, this->pv, this->locpp, this->dftu, + this->solvent, this->exx_nao, this->deepks, inp); //! if kpar is not divisible by nks, print a warning ModuleIO::print_kpar(this->kv.get_nks(), PARAM.globalv.kpar_lcao); diff --git a/source/source_lcao/LCAO_set.cpp b/source/source_lcao/LCAO_set.cpp index c1390e5c8e..2b4a42fcc3 100644 --- a/source/source_lcao/LCAO_set.cpp +++ b/source/source_lcao/LCAO_set.cpp @@ -1,5 +1,8 @@ -#include "source_lcao/LCAO_set_pot.h" +#include "source_lcao/LCAO_set.h" #include "source_io/module_parameter/parameter.h" +#include "source_psi/setup_psi.h" // use Setup_Psi +#include "source_io/read_wfc_nao.h" // use read_wfc_nao +#include "source_estate/elecstate_tools.h" // use fixed_weights template void LCAO_domain::set_psi_occ_dm_chg( @@ -11,6 +14,7 @@ void LCAO_domain::set_psi_occ_dm_chg( Charge &chr, // charge density const Input_para &inp) // input parameters { + //! 1) init electronic wave function psi Setup_Psi::allocate_psi(psi, kv, pv, inp); @@ -29,7 +33,7 @@ void LCAO_domain::set_psi_occ_dm_chg( if (inp.ocp && inp.esolver_type != "tddft") { elecstate::fixed_weights(inp.ocp_kb, inp.nbands, inp.nelec, - kv, pelec->wg, pelec->skip_weights); + &kv, pelec->wg, pelec->skip_weights); } //! 4) init DMK, but DMR is constructed in before_scf() @@ -42,24 +46,25 @@ void LCAO_domain::set_psi_occ_dm_chg( } - +template void LCAO_domain::set_pot( - const K_Vectors &kv, - const Structure_Factor& sf, + UnitCell &ucell, // not const because of dftu + K_Vectors &kv, // not const due to exx + Structure_Factor& sf, // will be modified in potential const ModulePW::PW_Basis &pw_rho, const ModulePW::PW_Basis &pw_rhod, elecstate::ElecState* pelec, const LCAO_Orbitals& orb, - const Parallel_Orbitals &pv, + Parallel_Orbitals &pv, // not const due to deepks pseudopot_cell_vl &locpp, Plus_U &dftu, surchem& solvent, - Exx_NAO &exx_nao, - Setup_DeePKS &deepks, + Exx_NAO &exx_nao, + Setup_DeePKS &deepks, const Input_para &inp) { //! 1) init local pseudopotentials - locpp.init_vloc(ucell, pw_rho); + locpp.init_vloc(ucell, &pw_rho); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL"); //! 2) init potentials @@ -67,7 +72,7 @@ void LCAO_domain::set_pot( { // where is the pot deleted? pelec->pot = new elecstate::Potential(&pw_rhod, &pw_rho, - &ucell, &(locpp.vloc), &(sf), &(solvent), + &ucell, &locpp.vloc, &sf, &solvent, &(pelec->f_en.etxc), &(pelec->f_en.vtxc)); } @@ -87,3 +92,53 @@ void LCAO_domain::set_pot( } + +template void LCAO_domain::set_psi_occ_dm_chg( + const K_Vectors &kv, // k-points + psi::Psi* psi, // coefficients of NAO basis + const Parallel_Orbitals &pv, // parallel scheme of NAO basis + elecstate::ElecState* pelec, // eigen values and weights + LCAO_domain::Setup_DM &dmat, // density matrix + Charge &chr, // charge density + const Input_para &inp); + +template void LCAO_domain::set_psi_occ_dm_chg>( + const K_Vectors &kv, // k-points + psi::Psi>* psi, // coefficients of NAO basis + const Parallel_Orbitals &pv, // parallel scheme of NAO basis + elecstate::ElecState* pelec, // eigen values and weights + LCAO_domain::Setup_DM> &dmat, // density matrix + Charge &chr, // charge density + const Input_para &inp); + +template void LCAO_domain::set_pot( + UnitCell &ucell, + K_Vectors &kv, + Structure_Factor& sf, + const ModulePW::PW_Basis &pw_rho, + const ModulePW::PW_Basis &pw_rhod, + elecstate::ElecState* pelec, + const LCAO_Orbitals& orb, + Parallel_Orbitals &pv, + pseudopot_cell_vl &locpp, + Plus_U &dftu, + surchem& solvent, + Exx_NAO &exx_nao, + Setup_DeePKS &deepks, + const Input_para &inp); + +template void LCAO_domain::set_pot>( + UnitCell &ucell, + K_Vectors &kv, + Structure_Factor& sf, + const ModulePW::PW_Basis &pw_rho, + const ModulePW::PW_Basis &pw_rhod, + elecstate::ElecState* pelec, + const LCAO_Orbitals& orb, + Parallel_Orbitals &pv, + pseudopot_cell_vl &locpp, + Plus_U &dftu, + surchem& solvent, + Exx_NAO> &exx_nao, + Setup_DeePKS> &deepks, + const Input_para &inp); diff --git a/source/source_lcao/LCAO_set.h b/source/source_lcao/LCAO_set.h index 1b5efa52ba..cede266522 100644 --- a/source/source_lcao/LCAO_set.h +++ b/source/source_lcao/LCAO_set.h @@ -1,6 +1,7 @@ #ifndef LCAO_SET_H #define LCAO_SET_H +#include "source_cell/unitcell.h" #include "source_cell/klist.h" #include "source_psi/psi.h" #include "source_estate/elecstate.h" @@ -14,39 +15,44 @@ #include "source_lcao/setup_exx.h" #include "source_lcao/setup_deepks.h" +namespace LCAO_domain +{ + /** * @brief set up wave functions, occupation numbers, * density matrix and charge density */ template -void LCAO_domain::set_psi_occ_dm_chg( +void set_psi_occ_dm_chg( const K_Vectors &kv, // k-points psi::Psi* psi, // coefficients of NAO basis const Parallel_Orbitals &pv, // parallel scheme of NAO basis elecstate::ElecState* pelec, // eigen values and weights LCAO_domain::Setup_DM &dmat, // density matrix Charge &chr, // charge density - const Input_para& inp) // input parameters + const Input_para& inp); // input parameters /** * @brief set up potentials, including local pseudopotentials, * +U potential, solvent potential, exx potential and deepks potential */ template -void LCAO_domain::set_pot( - const K_Vectors &kv, - const Structure_Factor& sf, +void set_pot( + UnitCell &ucell, + K_Vectors &kv, + Structure_Factor& sf, const ModulePW::PW_Basis &pw_rho, const ModulePW::PW_Basis &pw_rhod, elecstate::ElecState* pelec, const LCAO_Orbitals& orb, - const Parallel_Orbitals &pv, + Parallel_Orbitals &pv, pseudopot_cell_vl &locpp, Plus_U &dftu, surchem& solvent, - Exx_NAO &exx_nao, - Setup_DeePKS &deepks, + Exx_NAO &exx_nao, + Setup_DeePKS &deepks, const Input_para &inp); +} // end namespace #endif From 0eb5a8b8f59a68f9a3bfc21ae02e6d9ac9a4007c Mon Sep 17 00:00:00 2001 From: mohanchen Date: Tue, 11 Nov 2025 12:25:50 +0800 Subject: [PATCH 4/5] update LCAO_set, fix ref of pointer of psi --- source/source_esolver/esolver_ks_lcao.cpp | 64 ++++++++++++++++++++++- source/source_lcao/LCAO_set.cpp | 11 ++-- source/source_lcao/LCAO_set.h | 2 +- 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/source/source_esolver/esolver_ks_lcao.cpp b/source/source_esolver/esolver_ks_lcao.cpp index 0d2ef6cb11..032cde56af 100644 --- a/source/source_esolver/esolver_ks_lcao.cpp +++ b/source/source_esolver/esolver_ks_lcao.cpp @@ -21,6 +21,13 @@ #include "source_lcao/rho_tau_lcao.h" // mohan add 20251024 #include "source_lcao/LCAO_set.h" // mohan add 20251111 + +// tmp +#include "source_psi/setup_psi.h" // use Setup_Psi +#include "source_io/read_wfc_nao.h" // use read_wfc_nao +#include "source_estate/elecstate_tools.h" // use fixed_weights + + namespace ModuleESolver { @@ -73,13 +80,66 @@ void ESolver_KS_LCAO::before_all_runners(UnitCell& ucell, const Input_pa return; } - LCAO_domain::set_psi_occ_dm_chg(this->kv, this->psi, this->pv, this->pelec, + LCAO_domain::set_psi_occ_dm_chg(this->kv, this->psi, this->pv, this->pelec, this->dmat, this->chr, inp); - LCAO_domain::set_pot(ucell, this->kv, this->sf, *this->pw_rho, *this->pw_rhod, + LCAO_domain::set_pot(ucell, this->kv, this->sf, *this->pw_rho, *this->pw_rhod, this->pelec, this->orb_, this->pv, this->locpp, this->dftu, this->solvent, this->exx_nao, this->deepks, inp); +/* + // 5) init electronic wave function psi + Setup_Psi::allocate_psi(this->psi, this->kv, this->pv, inp); + + //! read psi from file + if (inp.init_wfc == "file" && inp.esolver_type != "tddft") + { + if (!ModuleIO::read_wfc_nao(PARAM.globalv.global_readin_dir, + this->pv, *this->psi, this->pelec->ekb, this->pelec->wg, this->kv.ik2iktot, + this->kv.get_nkstot(), inp.nspin)) + { + ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "read electronic wave functions failed"); + } + } + + // 7) init DMK, but DMR is constructed in before_scf() + this->dmat.allocate_dm(&this->kv, &this->pv, inp.nspin); + + // 8) init exact exchange calculations + this->exx_nao.before_runner(ucell, this->kv, this->orb_, this->pv, inp); + + // 9) initialize DFT+U + if (inp.dft_plus_u) + { + this->dftu.init(ucell, &this->pv, this->kv.get_nks(), &orb_); + } + + // 10) init local pseudopotentials + this->locpp.init_vloc(ucell, this->pw_rho); + ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL"); + + // 11) init charge density + this->chr.allocate(inp.nspin); + + // 12) init potentials + if (this->pelec->pot == nullptr) + { + this->pelec->pot = new elecstate::Potential(this->pw_rhod, this->pw_rho, + &ucell, &(this->locpp.vloc), &(this->sf), &(this->solvent), + &(this->pelec->f_en.etxc), &(this->pelec->f_en.vtxc)); + } + + // 13) init deepks + this->deepks.before_runner(ucell, this->kv.get_nks(), this->orb_, this->pv, inp); + + // 14) set occupations, tddft does not need to set occupations in the first scf + if (inp.ocp && inp.esolver_type != "tddft") + { + elecstate::fixed_weights(inp.ocp_kb, inp.nbands, inp.nelec, + this->pelec->klist, this->pelec->wg, this->pelec->skip_weights); + } +*/ + //! if kpar is not divisible by nks, print a warning ModuleIO::print_kpar(this->kv.get_nks(), PARAM.globalv.kpar_lcao); diff --git a/source/source_lcao/LCAO_set.cpp b/source/source_lcao/LCAO_set.cpp index 2b4a42fcc3..2c87852fde 100644 --- a/source/source_lcao/LCAO_set.cpp +++ b/source/source_lcao/LCAO_set.cpp @@ -7,7 +7,7 @@ template void LCAO_domain::set_psi_occ_dm_chg( const K_Vectors &kv, // k-points - psi::Psi* psi, // coefficients of NAO basis + psi::Psi* &psi, // coefficients of NAO basis const Parallel_Orbitals &pv, // parallel scheme of NAO basis elecstate::ElecState* pelec, // eigen values and weights LCAO_domain::Setup_DM &dmat, // density matrix @@ -42,6 +42,8 @@ void LCAO_domain::set_psi_occ_dm_chg( //! 5) init charge density chr.allocate(inp.nspin); + ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "CHARGE"); + return; } @@ -65,7 +67,6 @@ void LCAO_domain::set_pot( { //! 1) init local pseudopotentials locpp.init_vloc(ucell, &pw_rho); - ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL"); //! 2) init potentials if (pelec->pot == nullptr) @@ -88,6 +89,8 @@ void LCAO_domain::set_pot( //! 5) init deepks deepks.before_runner(ucell, kv.get_nks(), orb, pv, inp); + ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "POTENTIALS"); + return; } @@ -95,7 +98,7 @@ void LCAO_domain::set_pot( template void LCAO_domain::set_psi_occ_dm_chg( const K_Vectors &kv, // k-points - psi::Psi* psi, // coefficients of NAO basis + psi::Psi* &psi, // coefficients of NAO basis const Parallel_Orbitals &pv, // parallel scheme of NAO basis elecstate::ElecState* pelec, // eigen values and weights LCAO_domain::Setup_DM &dmat, // density matrix @@ -104,7 +107,7 @@ template void LCAO_domain::set_psi_occ_dm_chg( template void LCAO_domain::set_psi_occ_dm_chg>( const K_Vectors &kv, // k-points - psi::Psi>* psi, // coefficients of NAO basis + psi::Psi>* &psi, // coefficients of NAO basis const Parallel_Orbitals &pv, // parallel scheme of NAO basis elecstate::ElecState* pelec, // eigen values and weights LCAO_domain::Setup_DM> &dmat, // density matrix diff --git a/source/source_lcao/LCAO_set.h b/source/source_lcao/LCAO_set.h index cede266522..f5df2df054 100644 --- a/source/source_lcao/LCAO_set.h +++ b/source/source_lcao/LCAO_set.h @@ -25,7 +25,7 @@ namespace LCAO_domain template void set_psi_occ_dm_chg( const K_Vectors &kv, // k-points - psi::Psi* psi, // coefficients of NAO basis + psi::Psi* &psi, // coefficients of NAO basis const Parallel_Orbitals &pv, // parallel scheme of NAO basis elecstate::ElecState* pelec, // eigen values and weights LCAO_domain::Setup_DM &dmat, // density matrix From 653089adff24fc7e75b2ab88c9478af2ad9cca29 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Tue, 11 Nov 2025 16:33:18 +0800 Subject: [PATCH 5/5] update esolver --- source/source_esolver/esolver_ks_lcao.cpp | 53 ----------------------- 1 file changed, 53 deletions(-) diff --git a/source/source_esolver/esolver_ks_lcao.cpp b/source/source_esolver/esolver_ks_lcao.cpp index 032cde56af..62f00adcb6 100644 --- a/source/source_esolver/esolver_ks_lcao.cpp +++ b/source/source_esolver/esolver_ks_lcao.cpp @@ -87,59 +87,6 @@ void ESolver_KS_LCAO::before_all_runners(UnitCell& ucell, const Input_pa this->pelec, this->orb_, this->pv, this->locpp, this->dftu, this->solvent, this->exx_nao, this->deepks, inp); -/* - // 5) init electronic wave function psi - Setup_Psi::allocate_psi(this->psi, this->kv, this->pv, inp); - - //! read psi from file - if (inp.init_wfc == "file" && inp.esolver_type != "tddft") - { - if (!ModuleIO::read_wfc_nao(PARAM.globalv.global_readin_dir, - this->pv, *this->psi, this->pelec->ekb, this->pelec->wg, this->kv.ik2iktot, - this->kv.get_nkstot(), inp.nspin)) - { - ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "read electronic wave functions failed"); - } - } - - // 7) init DMK, but DMR is constructed in before_scf() - this->dmat.allocate_dm(&this->kv, &this->pv, inp.nspin); - - // 8) init exact exchange calculations - this->exx_nao.before_runner(ucell, this->kv, this->orb_, this->pv, inp); - - // 9) initialize DFT+U - if (inp.dft_plus_u) - { - this->dftu.init(ucell, &this->pv, this->kv.get_nks(), &orb_); - } - - // 10) init local pseudopotentials - this->locpp.init_vloc(ucell, this->pw_rho); - ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL"); - - // 11) init charge density - this->chr.allocate(inp.nspin); - - // 12) init potentials - if (this->pelec->pot == nullptr) - { - this->pelec->pot = new elecstate::Potential(this->pw_rhod, this->pw_rho, - &ucell, &(this->locpp.vloc), &(this->sf), &(this->solvent), - &(this->pelec->f_en.etxc), &(this->pelec->f_en.vtxc)); - } - - // 13) init deepks - this->deepks.before_runner(ucell, this->kv.get_nks(), this->orb_, this->pv, inp); - - // 14) set occupations, tddft does not need to set occupations in the first scf - if (inp.ocp && inp.esolver_type != "tddft") - { - elecstate::fixed_weights(inp.ocp_kb, inp.nbands, inp.nelec, - this->pelec->klist, this->pelec->wg, this->pelec->skip_weights); - } -*/ - //! if kpar is not divisible by nks, print a warning ModuleIO::print_kpar(this->kv.get_nks(), PARAM.globalv.kpar_lcao);