From b0503e45c9b37e61657994038dc28e11815cc3a3 Mon Sep 17 00:00:00 2001 From: Yu Liu <77716030+YuLiu98@users.noreply.github.com> Date: Thu, 14 Nov 2024 23:18:40 +0800 Subject: [PATCH] Refactor: remove lcao_fun.cpp (#5481) * Refactor: remove lcao_fun.cpp * use original format --- source/Makefile.Objects | 1 - source/module_esolver/CMakeLists.txt | 1 - source/module_esolver/esolver_ks_lcao.cpp | 22 +++- source/module_esolver/esolver_ks_lcao.h | 11 +- source/module_esolver/lcao_fun.cpp | 129 ---------------------- source/module_io/output_mat_sparse.cpp | 100 ++++++++--------- source/module_io/output_mat_sparse.h | 70 +++--------- source/module_io/output_mulliken.h | 32 ++++++ 8 files changed, 115 insertions(+), 251 deletions(-) delete mode 100644 source/module_esolver/lcao_fun.cpp diff --git a/source/Makefile.Objects b/source/Makefile.Objects index 504349de48..78e3080356 100644 --- a/source/Makefile.Objects +++ b/source/Makefile.Objects @@ -259,7 +259,6 @@ OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\ lcao_gets.o\ lcao_others.o\ lcao_init_after_vc.o\ - lcao_fun.o\ OBJS_GINT=gint.o\ gint_gamma_env.o\ diff --git a/source/module_esolver/CMakeLists.txt b/source/module_esolver/CMakeLists.txt index 0a818e1464..77795d82c0 100644 --- a/source/module_esolver/CMakeLists.txt +++ b/source/module_esolver/CMakeLists.txt @@ -25,7 +25,6 @@ if(ENABLE_LCAO) lcao_gets.cpp lcao_others.cpp lcao_init_after_vc.cpp - lcao_fun.cpp ) endif() diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index 069ec0e8c7..630420ed5a 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -13,6 +13,7 @@ #include "module_io/nscf_band.h" #include "module_io/output_dmk.h" #include "module_io/output_log.h" +#include "module_io/output_mat_sparse.h" #include "module_io/output_mulliken.h" #include "module_io/output_sk.h" #include "module_io/to_qo.h" @@ -1132,14 +1133,27 @@ void ESolver_KS_LCAO::after_scf(const int istep) } } - // 14) write md related - if (!md_skip_out(PARAM.inp.calculation, istep, PARAM.inp.out_interval)) + // 14) output sparse matrix + if (PARAM.inp.calculation != "md" || istep % PARAM.inp.out_interval == 0) { - this->create_Output_Mat_Sparse(istep).write(); + ModuleIO::output_mat_sparse(PARAM.inp.out_mat_hs2, + PARAM.inp.out_mat_dh, + PARAM.inp.out_mat_t, + PARAM.inp.out_mat_r, + istep, + this->pelec->pot->get_effective_v(), + this->pv, + this->GK, // mohan add 2024-04-01 + two_center_bundle_, + orb_, + GlobalC::ucell, + GlobalC::GridD, // mohan add 2024-04-06 + this->kv, + this->p_hamilt); // mulliken charge analysis if (PARAM.inp.out_mul) { - this->cal_mag(istep, true); + ModuleIO::cal_mag(&(this->pv), this->p_hamilt, this->kv, this->pelec, GlobalC::ucell, istep, true); } } diff --git a/source/module_esolver/esolver_ks_lcao.h b/source/module_esolver/esolver_ks_lcao.h index 761d660fe5..4acb416e63 100644 --- a/source/module_esolver/esolver_ks_lcao.h +++ b/source/module_esolver/esolver_ks_lcao.h @@ -41,8 +41,6 @@ class ESolver_KS_LCAO : public ESolver_KS { void get_S(); - void cal_mag(const int istep, const bool print = false); - protected: virtual void before_scf(const int istep) override; @@ -89,14 +87,7 @@ class ESolver_KS_LCAO : public ESolver_KS { void set_matrix_grid(Record_adj& ra); void beforesolver(const int istep); - //---------------------------------------------------------------------- - - /// @brief create ModuleIO::Output_Mat_Sparse object to output sparse - /// density matrix of H, S, T, r - ModuleIO::Output_Mat_Sparse create_Output_Mat_Sparse(int istep); - - /// @brief check if skip the corresponding output in md calculation - bool md_skip_out(std::string calculation, int istep, int interval); + //--------------------------------------------------------------------- #ifdef __EXX std::shared_ptr> exd = nullptr; diff --git a/source/module_esolver/lcao_fun.cpp b/source/module_esolver/lcao_fun.cpp deleted file mode 100644 index 10e2ac1374..0000000000 --- a/source/module_esolver/lcao_fun.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "esolver_ks_lcao.h" - -#include "module_base/global_variable.h" -#include "module_base/tool_title.h" -#include "module_io/dos_nao.h" -#include "module_io/nscf_band.h" -#include "module_io/output_dmk.h" -#include "module_io/output_log.h" -#include "module_io/output_mulliken.h" -#include "module_io/output_sk.h" -#include "module_io/to_qo.h" -#include "module_io/write_HS.h" -#include "module_io/write_istate_info.h" -#include "module_io/write_proj_band_lcao.h" -#include "module_parameter/parameter.h" - -//--------------temporary---------------------------- -#include - -#include "module_base/global_function.h" -#include "module_cell/module_neighbor/sltk_grid_driver.h" -#include "module_elecstate/module_charge/symmetry_rho.h" -#include "module_elecstate/occupy.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h" // need divide_HS_in_frag -#include "module_hamilt_lcao/module_dftu/dftu.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" -#include "module_io/print_info.h" - -//-----force& stress------------------- -#include "module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h" - -//-----HSolver ElecState Hamilt-------- -#include "module_elecstate/elecstate_lcao.h" -#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" -#include "module_hsolver/hsolver_lcao.h" -// function used by deepks -#include "module_elecstate/cal_dm.h" -//--------------------------------------------------- - -#include "module_hamilt_lcao/module_deltaspin/spin_constrain.h" -#include "module_io/io_dmk.h" -#include "module_io/write_dmr.h" -#include "module_io/write_wfc_nao.h" - -namespace ModuleESolver -{ - -//------------------------------------------------------------------------------ -//! the 18th function of ESolver_KS_LCAO: create_Output_Mat_Sparse -//! mohan add 2024-05-11 -//------------------------------------------------------------------------------ -template -ModuleIO::Output_Mat_Sparse ESolver_KS_LCAO::create_Output_Mat_Sparse(int istep) -{ - return ModuleIO::Output_Mat_Sparse(PARAM.inp.out_mat_hs2, - PARAM.inp.out_mat_dh, - PARAM.inp.out_mat_t, - PARAM.inp.out_mat_r, - istep, - this->pelec->pot->get_effective_v(), - this->pv, - this->GK, // mohan add 2024-04-01 - two_center_bundle_, - orb_, - GlobalC::GridD, // mohan add 2024-04-06 - this->kv, - this->p_hamilt); -} - -//------------------------------------------------------------------------------ -//! the 19th function of ESolver_KS_LCAO: md_skip_out -//! mohan add 2024-05-11 -//------------------------------------------------------------------------------ -template -bool ESolver_KS_LCAO::md_skip_out(std::string calculation, int istep, int interval) -{ - if (calculation == "md") - { - if (istep % interval != 0) - { - return true; - } - } - return false; -} - -template -void ESolver_KS_LCAO::cal_mag(const int istep, const bool print) -{ - auto cell_index = CellIndex(GlobalC::ucell.get_atomLabels(), - GlobalC::ucell.get_atomCounts(), - GlobalC::ucell.get_lnchiCounts(), - PARAM.inp.nspin); - auto out_sk = ModuleIO::Output_Sk(this->p_hamilt, - &(this->pv), - PARAM.inp.nspin, - this->kv.get_nks()); - auto out_dmk = ModuleIO::Output_DMK(dynamic_cast*>(this->pelec)->get_DM(), - &(this->pv), - PARAM.inp.nspin, - this->kv.get_nks()); - auto mulp = ModuleIO::Output_Mulliken(&(out_sk), - &(out_dmk), - &(this->pv), - &cell_index, - this->kv.isk, - PARAM.inp.nspin); - auto atom_chg = mulp.get_atom_chg(); - /// used in updating mag info in STRU file - GlobalC::ucell.atom_mulliken = mulp.get_atom_mulliken(atom_chg); - if (print && GlobalV::MY_RANK == 0) - { - /// write the Orbital file - cell_index.write_orb_info(PARAM.globalv.global_out_dir); - /// write mulliken.txt - mulp.write(istep, PARAM.globalv.global_out_dir); - /// write atomic mag info in running log file - mulp.print_atom_mag(atom_chg, GlobalV::ofs_running); - } -} - -//------------------------------------------------------------------------------ -//! the 20th,21th,22th functions of ESolver_KS_LCAO -//! mohan add 2024-05-11 -//------------------------------------------------------------------------------ -template class ESolver_KS_LCAO; -template class ESolver_KS_LCAO, double>; -template class ESolver_KS_LCAO, std::complex>; -} // namespace ModuleESolver diff --git a/source/module_io/output_mat_sparse.cpp b/source/module_io/output_mat_sparse.cpp index f6b690c809..9891e06836 100644 --- a/source/module_io/output_mat_sparse.cpp +++ b/source/module_io/output_mat_sparse.cpp @@ -1,93 +1,89 @@ #include "output_mat_sparse.h" -#include "cal_r_overlap_R.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" // for ucell -#include "write_HS_R.h" +#include "module_io/cal_r_overlap_R.h" +#include "module_io/write_HS_R.h" namespace ModuleIO { -template -Output_Mat_Sparse::Output_Mat_Sparse(int out_mat_hsR, - int out_mat_dh, - int out_mat_t, - int out_mat_r, - int istep, - const ModuleBase::matrix& v_eff, - const Parallel_Orbitals& pv, - Gint_k& gint_k, // mohan add 2024-04-01 - const TwoCenterBundle& two_center_bundle, - const LCAO_Orbitals& orb, - Grid_Driver& grid, // mohan add 2024-04-06 - const K_Vectors& kv, - hamilt::Hamilt* p_ham) - : _out_mat_hsR(out_mat_hsR), _out_mat_dh(out_mat_dh), _out_mat_t(out_mat_t), _out_mat_r(out_mat_r), _istep(istep), - _v_eff(v_eff), _pv(pv), orb_(orb), _gint_k(gint_k), // mohan add 2024-04-01 - two_center_bundle_(two_center_bundle), _grid(grid), // mohan add 2024-04-06 - _kv(kv), _p_ham(p_ham) {} - template <> -void Output_Mat_Sparse::write() +void output_mat_sparse(const bool& out_mat_hsR, + const bool& out_mat_dh, + const bool& out_mat_t, + const bool& out_mat_r, + const int& istep, + const ModuleBase::matrix& v_eff, + const Parallel_Orbitals& pv, + Gint_k& gint_k, + const TwoCenterBundle& two_center_bundle, + const LCAO_Orbitals& orb, + UnitCell& ucell, + Grid_Driver& grid, + const K_Vectors& kv, + hamilt::Hamilt* p_ham) { } template <> -void Output_Mat_Sparse>::write() +void output_mat_sparse(const bool& out_mat_hsR, + const bool& out_mat_dh, + const bool& out_mat_t, + const bool& out_mat_r, + const int& istep, + const ModuleBase::matrix& v_eff, + const Parallel_Orbitals& pv, + Gint_k& gint_k, + const TwoCenterBundle& two_center_bundle, + const LCAO_Orbitals& orb, + UnitCell& ucell, + Grid_Driver& grid, + const K_Vectors& kv, + hamilt::Hamilt>* p_ham) { LCAO_HS_Arrays HS_Arrays; // store sparse arrays //! generate a file containing the Hamiltonian and S(overlap) matrices - if (_out_mat_hsR) + if (out_mat_hsR) { - output_HSR(_istep, this->_v_eff, this->_pv, HS_Arrays, this->_grid, _kv, _p_ham); + output_HSR(istep, v_eff, pv, HS_Arrays, grid, kv, p_ham); } //! generate a file containing the kinetic energy matrix - if (_out_mat_t) + if (out_mat_t) { - output_TR(_istep, - GlobalC::ucell, - this->_pv, - HS_Arrays, - this->_grid, - two_center_bundle_, - orb_ - ); // LiuXh add 2019-07-15 + output_TR(istep, ucell, pv, HS_Arrays, grid, two_center_bundle, orb); } //! generate a file containing the derivatives of the Hamiltonian matrix (in Ry/Bohr) - if (_out_mat_dh) + if (out_mat_dh) { - output_dHR(_istep, - this->_v_eff, - this->_gint_k, // mohan add 2024-04-01 - this->_pv, + output_dHR(istep, + v_eff, + gint_k, // mohan add 2024-04-01 + pv, HS_Arrays, - this->_grid, // mohan add 2024-04-06 - two_center_bundle_, - orb_, - _kv); // LiuXh add 2019-07-15 + grid, // mohan add 2024-04-06 + two_center_bundle, + orb, + kv); // LiuXh add 2019-07-15 } // add by jingan for out r_R matrix 2019.8.14 - if (_out_mat_r) + if (out_mat_r) { cal_r_overlap_R r_matrix; - r_matrix.init(this->_pv, orb_); - if (_out_mat_hsR) + r_matrix.init(pv, orb); + if (out_mat_hsR) { - r_matrix.out_rR_other(_istep, HS_Arrays.output_R_coor); + r_matrix.out_rR_other(istep, HS_Arrays.output_R_coor); } else { - r_matrix.out_rR(_istep); + r_matrix.out_rR(istep); } } return; } -template class Output_Mat_Sparse; -template class Output_Mat_Sparse>; - } // namespace ModuleIO diff --git a/source/module_io/output_mat_sparse.h b/source/module_io/output_mat_sparse.h index dc0e7b3d0e..2adf7448a1 100644 --- a/source/module_io/output_mat_sparse.h +++ b/source/module_io/output_mat_sparse.h @@ -3,66 +3,28 @@ #include "module_basis/module_ao/parallel_orbitals.h" #include "module_basis/module_nao/two_center_bundle.h" +#include "module_cell/klist.h" +#include "module_hamilt_general/hamilt.h" #include "module_hamilt_lcao/module_gint/gint_k.h" -#include "module_hsolver/hsolver_lcao.h" namespace ModuleIO { /// @brief the output interface to write the sparse matrix of H, S, T, and r template -class Output_Mat_Sparse -{ - public: - Output_Mat_Sparse(int out_mat_hsR, - int out_mat_dh, - int out_mat_t, - int out_mat_r, - int istep, - const ModuleBase::matrix& v_eff, - const Parallel_Orbitals& pv, - Gint_k& gint_k, // mohan add 2024-04-01 - const TwoCenterBundle& two_center_bundle, - const LCAO_Orbitals& orb, - Grid_Driver& grid, // mohan add 2024-04-06 - const K_Vectors& kv, - hamilt::Hamilt* p_ham); - - void write(); - - private: - //! generate a file containing the Hamiltonian and S(overlap) matrices - int _out_mat_hsR; - - //! generate a file containing the derivatives of the Hamiltonian matrix (in Ry/Bohr) - int _out_mat_dh; - - //! generate a file containing the kinetic energy matrix - int _out_mat_t; - - //! generate a file containing the matrix representation of the position matrix (in Bohr) - int _out_mat_r; - - int _istep; - - const ModuleBase::matrix& _v_eff; - - const Parallel_Orbitals& _pv; - - const LCAO_Orbitals& orb_; - - Gint_k& _gint_k; // mohan add 2024-04-01 - - // introduced temporarily for LCAO refactoring - const TwoCenterBundle& two_center_bundle_; - - // mohan fix bug 2024-04-07, a typical bug!!! - Grid_Driver& _grid; // mohan add 2024-04-06 - - const K_Vectors& _kv; - - hamilt::Hamilt* _p_ham; -}; - +void output_mat_sparse(const bool& out_mat_hsR, + const bool& out_mat_dh, + const bool& out_mat_t, + const bool& out_mat_r, + const int& istep, + const ModuleBase::matrix& v_eff, + const Parallel_Orbitals& pv, + Gint_k& gint_k, // mohan add 2024-04-01 + const TwoCenterBundle& two_center_bundle, + const LCAO_Orbitals& orb, + UnitCell& ucell, + Grid_Driver& grid, // mohan add 2024-04-06 + const K_Vectors& kv, + hamilt::Hamilt* p_ham); } // namespace ModuleIO #endif // OUTPUT_MAT_SPARSE_H diff --git a/source/module_io/output_mulliken.h b/source/module_io/output_mulliken.h index 5a4336ce94..560dedfeaa 100644 --- a/source/module_io/output_mulliken.h +++ b/source/module_io/output_mulliken.h @@ -4,6 +4,7 @@ #include "module_base/matrix.h" #include "module_basis/module_ao/parallel_orbitals.h" #include "module_cell/cell_index.h" +#include "module_elecstate/elecstate_lcao.h" #include "module_io/output_dmk.h" #include "module_io/output_sk.h" @@ -82,6 +83,37 @@ class Output_Mulliken ModuleBase::matrix orbMulP_; }; +template +void cal_mag(Parallel_Orbitals* pv, + hamilt::Hamilt* p_ham, + K_Vectors& kv, + elecstate::ElecState* pelec, + UnitCell& ucell, + const int istep, + const bool print) +{ + auto cell_index + = CellIndex(ucell.get_atomLabels(), ucell.get_atomCounts(), ucell.get_lnchiCounts(), PARAM.inp.nspin); + auto out_sk = ModuleIO::Output_Sk(p_ham, pv, PARAM.inp.nspin, kv.get_nks()); + auto out_dmk = ModuleIO::Output_DMK(dynamic_cast*>(pelec)->get_DM(), + pv, + PARAM.inp.nspin, + kv.get_nks()); + auto mulp = ModuleIO::Output_Mulliken(&(out_sk), &(out_dmk), pv, &cell_index, kv.isk, PARAM.inp.nspin); + auto atom_chg = mulp.get_atom_chg(); + /// used in updating mag info in STRU file + ucell.atom_mulliken = mulp.get_atom_mulliken(atom_chg); + if (print && GlobalV::MY_RANK == 0) + { + /// write the Orbital file + cell_index.write_orb_info(PARAM.globalv.global_out_dir); + /// write mulliken.txt + mulp.write(istep, PARAM.globalv.global_out_dir); + /// write atomic mag info in running log file + mulp.print_atom_mag(atom_chg, GlobalV::ofs_running); + } +} + } // namespace ModuleIO #endif // OUTPUT_MULLIKEN_H