diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index e9ea986d7e..3e8e9b1f41 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -203,10 +203,12 @@ void ESolver_KS_LCAO::before_all_runners(const Input_para& inp, UnitCell if (GlobalC::exx_info.info_ri.real_number) { this->exx_lri_double->init(MPI_COMM_WORLD, this->kv, orb_); + this->exd->exx_before_all_runners(this->kv, GlobalC::ucell, this->pv); } else { this->exx_lri_complex->init(MPI_COMM_WORLD, this->kv, orb_); + this->exc->exx_before_all_runners(this->kv, GlobalC::ucell, this->pv); } } } diff --git a/source/module_esolver/lcao_before_scf.cpp b/source/module_esolver/lcao_before_scf.cpp index 7f75907aae..127ce080d9 100644 --- a/source/module_esolver/lcao_before_scf.cpp +++ b/source/module_esolver/lcao_before_scf.cpp @@ -210,11 +210,11 @@ void ESolver_KS_LCAO::before_scf(const int istep) #ifdef __EXX // set xc type before the first cal of xc in pelec->init_scf if (GlobalC::exx_info.info_ri.real_number) { - this->exd->exx_beforescf(this->kv, *this->p_chgmix, GlobalC::ucell, this->pv, orb_); + this->exd->exx_beforescf(this->kv, *this->p_chgmix, GlobalC::ucell, orb_); } else { - this->exc->exx_beforescf(this->kv, *this->p_chgmix, GlobalC::ucell, this->pv, orb_); + this->exc->exx_beforescf(this->kv, *this->p_chgmix, GlobalC::ucell, orb_); } #endif // __EXX diff --git a/source/module_ri/Exx_LRI_interface.h b/source/module_ri/Exx_LRI_interface.h index d1b64c56df..3eb3db37d2 100644 --- a/source/module_ri/Exx_LRI_interface.h +++ b/source/module_ri/Exx_LRI_interface.h @@ -48,8 +48,13 @@ class Exx_LRI_Interface double& get_Eexx() const { return this->exx_ptr->Eexx; } // Processes in ESolver_KS_LCAO + /// @brief in before_all_runners: set symmetry according to irreducible k-points + /// since k-points are not reduced again after the variation of the cell and exx-symmetry must be consistent with k-points. + /// In the future, we will reduce k-points again during cell-relax, then this setting can be moved to `exx_beforescf`. + void exx_before_all_runners(const K_Vectors& kv, const UnitCell& ucell, const Parallel_2D& pv); + /// @brief in beforescf: set xc type, opt_orb, do DM mixing - void exx_beforescf(const K_Vectors& kv, const Charge_Mixing& chgmix, const UnitCell& ucell, const Parallel_2D& pv, const LCAO_Orbitals& orb); + void exx_beforescf(const K_Vectors& kv, const Charge_Mixing& chgmix, const UnitCell& ucell, const LCAO_Orbitals& orb); /// @brief in eachiterinit: do DM mixing and calculate Hexx when entering 2nd SCF void exx_eachiterinit(const elecstate::DensityMatrix& dm/**< double should be Tdata if complex-PBE-DM is supported*/, diff --git a/source/module_ri/Exx_LRI_interface.hpp b/source/module_ri/Exx_LRI_interface.hpp index 8fa6d8b84a..ae0c3869f8 100644 --- a/source/module_ri/Exx_LRI_interface.hpp +++ b/source/module_ri/Exx_LRI_interface.hpp @@ -37,7 +37,22 @@ void Exx_LRI_Interface::read_Hexxs_cereal(const std::string& file_name } template -void Exx_LRI_Interface::exx_beforescf(const K_Vectors& kv, const Charge_Mixing& chgmix, const UnitCell& ucell, const Parallel_2D& pv, const LCAO_Orbitals& orb) +void Exx_LRI_Interface::exx_before_all_runners(const K_Vectors& kv, const UnitCell& ucell, const Parallel_2D& pv) +{ + // initialize the rotation matrix in AO representation + this->exx_spacegroup_symmetry = (PARAM.inp.nspin < 4 && ModuleSymmetry::Symmetry::symm_flag == 1); + if (this->exx_spacegroup_symmetry) + { + const std::array& period = RI_Util::get_Born_vonKarmen_period(kv); + this->symrot_.find_irreducible_sector(ucell.symm, ucell.atoms, ucell.st, + RI_Util::get_Born_von_Karmen_cells(period), period, ucell.lat); + // this->symrot_.set_Cs_rotation(this->exx_ptr->get_abfs_nchis()); + this->symrot_.cal_Ms(kv, ucell, pv); + } +} + +template +void Exx_LRI_Interface::exx_beforescf(const K_Vectors& kv, const Charge_Mixing& chgmix, const UnitCell& ucell, const LCAO_Orbitals& orb) { #ifdef __MPI if (GlobalC::exx_info.info_global.cal_exx) @@ -54,17 +69,6 @@ void Exx_LRI_Interface::exx_beforescf(const K_Vectors& kv, const Charg XC_Functional::set_xc_type("scan"); } } - // initialize the rotation matrix in AO representation - this->exx_spacegroup_symmetry = (PARAM.inp.nspin < 4 && ModuleSymmetry::Symmetry::symm_flag == 1); - if (this->exx_spacegroup_symmetry) - { - const std::array& period = RI_Util::get_Born_vonKarmen_period(kv); - this->symrot_.find_irreducible_sector(ucell.symm, ucell.atoms, ucell.st, - RI_Util::get_Born_von_Karmen_cells(period), period, ucell.lat); - // this->symrot_.set_Cs_rotation(this->exx_ptr->get_abfs_nchis()); - this->symrot_.cal_Ms(kv, ucell, pv); - } - this->exx_ptr->cal_exx_ions(PARAM.inp.out_ri_cv); } diff --git a/source/module_ri/module_exx_symmetry/irreducible_sector.cpp b/source/module_ri/module_exx_symmetry/irreducible_sector.cpp index c9f1d4e87f..9cb889b831 100644 --- a/source/module_ri/module_exx_symmetry/irreducible_sector.cpp +++ b/source/module_ri/module_exx_symmetry/irreducible_sector.cpp @@ -86,9 +86,9 @@ namespace ModuleSymmetry return TCdouble(std::round(return_lattice_double.x), std::round(return_lattice_double.y), std::round(return_lattice_double.z)); } - void Irreducible_Sector::get_return_lattice_all(const Symmetry& symm, const Atom* atoms, const Statistics& st) + void Irreducible_Sector::cal_return_lattice_all(const Symmetry& symm, const Atom* atoms, const Statistics& st) { - ModuleBase::TITLE("Symmetry_rotation", "get_return_lattice_all"); + ModuleBase::TITLE("Symmetry_rotation", "cal_return_lattice_all"); this->return_lattice_.resize(st.nat, std::vector(symm.nrotk)); for (int iat1 = 0;iat1 < st.nat;++iat1) { @@ -163,7 +163,7 @@ namespace ModuleSymmetry this->irreducible_sector_.clear(); this->sector_stars_.clear(); - if (this->return_lattice_.empty()) this->get_return_lattice_all(symm, atoms, st); + if (this->return_lattice_.empty()) this->cal_return_lattice_all(symm, atoms, st); // if (this->atompair_stars_.empty()) this->find_irreducible_atom_pairs(symm); // contruct {atom pair, R} set diff --git a/source/module_ri/module_exx_symmetry/irreducible_sector.h b/source/module_ri/module_exx_symmetry/irreducible_sector.h index 369f5f6b31..6f9ab3cb8c 100644 --- a/source/module_ri/module_exx_symmetry/irreducible_sector.h +++ b/source/module_ri/module_exx_symmetry/irreducible_sector.h @@ -67,9 +67,10 @@ namespace ModuleSymmetry TCdouble get_return_lattice(const Symmetry& symm, const ModuleBase::Matrix3& gmatd, const TCdouble gtransd, const TCdouble& posd_a1, const TCdouble& posd_a2)const; - void get_return_lattice_all(const Symmetry& symm, const Atom* atoms, const Statistics& st); protected: + void cal_return_lattice_all(const Symmetry& symm, const Atom* atoms, const Statistics& st); + //-------------------------------------------------------------------------------- /// The sub functions to find irreducible sector: {abR} diff --git a/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp b/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp index cc01099c3a..bfdef1fab9 100644 --- a/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp +++ b/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp @@ -95,8 +95,7 @@ namespace ModuleSymmetry auto vec_conj = [](const std::vector>& z, const double scal = 1.0) -> std::vector> { std::vector> z_conj(z.size()); - for (int i = 0;i < z.size();++i) { z_conj[i] = std::conj(z[i]) * scal; -} + for (int i = 0;i < z.size();++i) { z_conj[i] = std::conj(z[i]) * scal; } return z_conj; }; std::vector>> dm_k_full; @@ -110,8 +109,7 @@ namespace ModuleSymmetry { double factor = 1.0 / static_cast(kv.kstars[ik_ibz].size()); std::vector> dm_scaled(pv.get_local_size()); - for (int i = 0;i < pv.get_local_size();++i) { dm_scaled[i] = factor * dm_k_ibz[ik_ibz + is * nk][i]; -} + for (int i = 0;i < pv.get_local_size();++i) { dm_scaled[i] = factor * dm_k_ibz[ik_ibz + is * nk][i]; } dm_k_full.push_back(dm_scaled); } else if (vec3_eq(isym_kvd.second, -kv.kvec_d[ik_ibz], this->eps_) && this->TRS_first_) { diff --git a/source/module_ri/module_exx_symmetry/symmetry_rotation.h b/source/module_ri/module_exx_symmetry/symmetry_rotation.h index 1b58fbc893..9bef3510c3 100644 --- a/source/module_ri/module_exx_symmetry/symmetry_rotation.h +++ b/source/module_ri/module_exx_symmetry/symmetry_rotation.h @@ -21,11 +21,6 @@ namespace ModuleSymmetry //-------------------------------------------------------------------------------- // getters const std::map>& get_irreducible_sector()const { return this->irs_.get_irreducible_sector(); } - void find_irreducible_sector(const Symmetry& symm, const Atom* atoms, const Statistics& st, - const std::vector& Rs, const TC& period, const Lattice& lat) - { - this->irs_.find_irreducible_sector(symm, atoms, st, Rs, period, lat); - } TCdouble get_return_lattice(const Symmetry& symm, const ModuleBase::Matrix3& gmatd, const TCdouble gtransd, const TCdouble& posd_a1, const TCdouble& posd_a2)const @@ -34,6 +29,11 @@ namespace ModuleSymmetry } //-------------------------------------------------------------------------------- // setters + void find_irreducible_sector(const Symmetry& symm, const Atom* atoms, const Statistics& st, + const std::vector& Rs, const TC& period, const Lattice& lat) + { + this->irs_.find_irreducible_sector(symm, atoms, st, Rs, period, lat); + } void set_Cs_rotation(const std::vector>& abfs_l_nchi); //-------------------------------------------------------------------------------- /// functions to contruct rotation matrix in AO-representation