Skip to content

Commit e4044a4

Browse files
authored
fix exxsym (#5348)
1 parent 5a774bf commit e4044a4

File tree

8 files changed

+38
-28
lines changed

8 files changed

+38
-28
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,12 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
203203
if (GlobalC::exx_info.info_ri.real_number)
204204
{
205205
this->exx_lri_double->init(MPI_COMM_WORLD, this->kv, orb_);
206+
this->exd->exx_before_all_runners(this->kv, GlobalC::ucell, this->pv);
206207
}
207208
else
208209
{
209210
this->exx_lri_complex->init(MPI_COMM_WORLD, this->kv, orb_);
211+
this->exc->exx_before_all_runners(this->kv, GlobalC::ucell, this->pv);
210212
}
211213
}
212214
}

source/module_esolver/lcao_before_scf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(const int istep)
210210
#ifdef __EXX // set xc type before the first cal of xc in pelec->init_scf
211211
if (GlobalC::exx_info.info_ri.real_number)
212212
{
213-
this->exd->exx_beforescf(this->kv, *this->p_chgmix, GlobalC::ucell, this->pv, orb_);
213+
this->exd->exx_beforescf(this->kv, *this->p_chgmix, GlobalC::ucell, orb_);
214214
}
215215
else
216216
{
217-
this->exc->exx_beforescf(this->kv, *this->p_chgmix, GlobalC::ucell, this->pv, orb_);
217+
this->exc->exx_beforescf(this->kv, *this->p_chgmix, GlobalC::ucell, orb_);
218218
}
219219
#endif // __EXX
220220

source/module_ri/Exx_LRI_interface.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ class Exx_LRI_Interface
4848
double& get_Eexx() const { return this->exx_ptr->Eexx; }
4949

5050
// Processes in ESolver_KS_LCAO
51+
/// @brief in before_all_runners: set symmetry according to irreducible k-points
52+
/// since k-points are not reduced again after the variation of the cell and exx-symmetry must be consistent with k-points.
53+
/// In the future, we will reduce k-points again during cell-relax, then this setting can be moved to `exx_beforescf`.
54+
void exx_before_all_runners(const K_Vectors& kv, const UnitCell& ucell, const Parallel_2D& pv);
55+
5156
/// @brief in beforescf: set xc type, opt_orb, do DM mixing
52-
void exx_beforescf(const K_Vectors& kv, const Charge_Mixing& chgmix, const UnitCell& ucell, const Parallel_2D& pv, const LCAO_Orbitals& orb);
57+
void exx_beforescf(const K_Vectors& kv, const Charge_Mixing& chgmix, const UnitCell& ucell, const LCAO_Orbitals& orb);
5358

5459
/// @brief in eachiterinit: do DM mixing and calculate Hexx when entering 2nd SCF
5560
void exx_eachiterinit(const elecstate::DensityMatrix<T, double>& dm/**< double should be Tdata if complex-PBE-DM is supported*/,

source/module_ri/Exx_LRI_interface.hpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,22 @@ void Exx_LRI_Interface<T, Tdata>::read_Hexxs_cereal(const std::string& file_name
3737
}
3838

3939
template<typename T, typename Tdata>
40-
void Exx_LRI_Interface<T, Tdata>::exx_beforescf(const K_Vectors& kv, const Charge_Mixing& chgmix, const UnitCell& ucell, const Parallel_2D& pv, const LCAO_Orbitals& orb)
40+
void Exx_LRI_Interface<T, Tdata>::exx_before_all_runners(const K_Vectors& kv, const UnitCell& ucell, const Parallel_2D& pv)
41+
{
42+
// initialize the rotation matrix in AO representation
43+
this->exx_spacegroup_symmetry = (PARAM.inp.nspin < 4 && ModuleSymmetry::Symmetry::symm_flag == 1);
44+
if (this->exx_spacegroup_symmetry)
45+
{
46+
const std::array<int, 3>& period = RI_Util::get_Born_vonKarmen_period(kv);
47+
this->symrot_.find_irreducible_sector(ucell.symm, ucell.atoms, ucell.st,
48+
RI_Util::get_Born_von_Karmen_cells(period), period, ucell.lat);
49+
// this->symrot_.set_Cs_rotation(this->exx_ptr->get_abfs_nchis());
50+
this->symrot_.cal_Ms(kv, ucell, pv);
51+
}
52+
}
53+
54+
template<typename T, typename Tdata>
55+
void Exx_LRI_Interface<T, Tdata>::exx_beforescf(const K_Vectors& kv, const Charge_Mixing& chgmix, const UnitCell& ucell, const LCAO_Orbitals& orb)
4156
{
4257
#ifdef __MPI
4358
if (GlobalC::exx_info.info_global.cal_exx)
@@ -54,17 +69,6 @@ void Exx_LRI_Interface<T, Tdata>::exx_beforescf(const K_Vectors& kv, const Charg
5469
XC_Functional::set_xc_type("scan");
5570
}
5671
}
57-
// initialize the rotation matrix in AO representation
58-
this->exx_spacegroup_symmetry = (PARAM.inp.nspin < 4 && ModuleSymmetry::Symmetry::symm_flag == 1);
59-
if (this->exx_spacegroup_symmetry)
60-
{
61-
const std::array<int, 3>& period = RI_Util::get_Born_vonKarmen_period(kv);
62-
this->symrot_.find_irreducible_sector(ucell.symm, ucell.atoms, ucell.st,
63-
RI_Util::get_Born_von_Karmen_cells(period), period, ucell.lat);
64-
// this->symrot_.set_Cs_rotation(this->exx_ptr->get_abfs_nchis());
65-
this->symrot_.cal_Ms(kv, ucell, pv);
66-
}
67-
6872
this->exx_ptr->cal_exx_ions(PARAM.inp.out_ri_cv);
6973
}
7074

source/module_ri/module_exx_symmetry/irreducible_sector.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ namespace ModuleSymmetry
8686
return TCdouble(std::round(return_lattice_double.x), std::round(return_lattice_double.y), std::round(return_lattice_double.z));
8787
}
8888

89-
void Irreducible_Sector::get_return_lattice_all(const Symmetry& symm, const Atom* atoms, const Statistics& st)
89+
void Irreducible_Sector::cal_return_lattice_all(const Symmetry& symm, const Atom* atoms, const Statistics& st)
9090
{
91-
ModuleBase::TITLE("Symmetry_rotation", "get_return_lattice_all");
91+
ModuleBase::TITLE("Symmetry_rotation", "cal_return_lattice_all");
9292
this->return_lattice_.resize(st.nat, std::vector<TCdouble>(symm.nrotk));
9393
for (int iat1 = 0;iat1 < st.nat;++iat1)
9494
{
@@ -163,7 +163,7 @@ namespace ModuleSymmetry
163163
this->irreducible_sector_.clear();
164164
this->sector_stars_.clear();
165165

166-
if (this->return_lattice_.empty()) this->get_return_lattice_all(symm, atoms, st);
166+
if (this->return_lattice_.empty()) this->cal_return_lattice_all(symm, atoms, st);
167167
// if (this->atompair_stars_.empty()) this->find_irreducible_atom_pairs(symm);
168168

169169
// contruct {atom pair, R} set

source/module_ri/module_exx_symmetry/irreducible_sector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ namespace ModuleSymmetry
6767
TCdouble get_return_lattice(const Symmetry& symm,
6868
const ModuleBase::Matrix3& gmatd, const TCdouble gtransd,
6969
const TCdouble& posd_a1, const TCdouble& posd_a2)const;
70-
void get_return_lattice_all(const Symmetry& symm, const Atom* atoms, const Statistics& st);
7170

7271
protected:
72+
void cal_return_lattice_all(const Symmetry& symm, const Atom* atoms, const Statistics& st);
73+
7374
//--------------------------------------------------------------------------------
7475
/// The sub functions to find irreducible sector: {abR}
7576

source/module_ri/module_exx_symmetry/symmetry_rotation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ namespace ModuleSymmetry
9595
auto vec_conj = [](const std::vector<std::complex<double>>& z, const double scal = 1.0) -> std::vector<std::complex<double>>
9696
{
9797
std::vector<std::complex<double>> z_conj(z.size());
98-
for (int i = 0;i < z.size();++i) { z_conj[i] = std::conj(z[i]) * scal;
99-
}
98+
for (int i = 0;i < z.size();++i) { z_conj[i] = std::conj(z[i]) * scal; }
10099
return z_conj;
101100
};
102101
std::vector<std::vector<std::complex<double>>> dm_k_full;
@@ -110,8 +109,7 @@ namespace ModuleSymmetry
110109
{
111110
double factor = 1.0 / static_cast<double>(kv.kstars[ik_ibz].size());
112111
std::vector<std::complex<double>> dm_scaled(pv.get_local_size());
113-
for (int i = 0;i < pv.get_local_size();++i) { dm_scaled[i] = factor * dm_k_ibz[ik_ibz + is * nk][i];
114-
}
112+
for (int i = 0;i < pv.get_local_size();++i) { dm_scaled[i] = factor * dm_k_ibz[ik_ibz + is * nk][i]; }
115113
dm_k_full.push_back(dm_scaled);
116114
}
117115
else if (vec3_eq(isym_kvd.second, -kv.kvec_d[ik_ibz], this->eps_) && this->TRS_first_) {

source/module_ri/module_exx_symmetry/symmetry_rotation.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ namespace ModuleSymmetry
2121
//--------------------------------------------------------------------------------
2222
// getters
2323
const std::map<Tap, std::set<TC>>& get_irreducible_sector()const { return this->irs_.get_irreducible_sector(); }
24-
void find_irreducible_sector(const Symmetry& symm, const Atom* atoms, const Statistics& st,
25-
const std::vector<TC>& Rs, const TC& period, const Lattice& lat)
26-
{
27-
this->irs_.find_irreducible_sector(symm, atoms, st, Rs, period, lat);
28-
}
2924
TCdouble get_return_lattice(const Symmetry& symm,
3025
const ModuleBase::Matrix3& gmatd, const TCdouble gtransd,
3126
const TCdouble& posd_a1, const TCdouble& posd_a2)const
@@ -34,6 +29,11 @@ namespace ModuleSymmetry
3429
}
3530
//--------------------------------------------------------------------------------
3631
// setters
32+
void find_irreducible_sector(const Symmetry& symm, const Atom* atoms, const Statistics& st,
33+
const std::vector<TC>& Rs, const TC& period, const Lattice& lat)
34+
{
35+
this->irs_.find_irreducible_sector(symm, atoms, st, Rs, period, lat);
36+
}
3737
void set_Cs_rotation(const std::vector<std::vector<int>>& abfs_l_nchi);
3838
//--------------------------------------------------------------------------------
3939
/// functions to contruct rotation matrix in AO-representation

0 commit comments

Comments
 (0)