Skip to content

Commit 0ab60f3

Browse files
committed
change ucell in module_ri/exx_lir.hpp/cal_exx_elec
1 parent 0d95907 commit 0ab60f3

File tree

9 files changed

+47
-28
lines changed

9 files changed

+47
-28
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,15 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
623623
if (GlobalC::exx_info.info_ri.real_number)
624624
{
625625
this->exd->exx_eachiterinit(istep,
626+
ucell,
626627
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
627628
this->kv,
628629
iter);
629630
}
630631
else
631632
{
632633
this->exc->exx_eachiterinit(istep,
634+
ucell,
633635
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
634636
this->kv,
635637
iter);
@@ -1052,7 +1054,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
10521054
occ_number_ks(ik, inb) /= this->kv.wk[ik];
10531055
}
10541056
}
1055-
this->rdmft_solver.update_elec(occ_number_ks, *(this->psi));
1057+
this->rdmft_solver.update_elec(ucell,occ_number_ks, *(this->psi));
10561058

10571059
//! initialize the gradients of Etotal with respect to occupation numbers and wfc,
10581060
//! and set all elements to 0.

source/module_rdmft/rdmft.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class RDMFT
9090

9191
//! update in elec-step
9292
// Or we can use rdmft_solver.wfc/occ_number directly when optimizing, so that the update_elec() function does not require parameters.
93-
void update_elec(const ModuleBase::matrix& occ_number_in, const psi::Psi<TK>& wfc_in, const Charge* charge_in = nullptr);
93+
void update_elec(const UnitCell& ucell, const ModuleBase::matrix& occ_number_in, const psi::Psi<TK>& wfc_in, const Charge* charge_in = nullptr);
9494

9595
//! obtain the gradient of total energy with respect to occupation number and wfc
9696
double cal_E_grad_wfc_occ_num();
@@ -117,7 +117,7 @@ class RDMFT
117117
void cal_V_hartree();
118118

119119
//! construct V_XC based on different XC_functional( i.e. RDMFT class member XC_func_rdmft)
120-
void cal_V_XC();
120+
void cal_V_XC(const UnitCell& ucell);
121121

122122
//! get the total Hamilton in k-space
123123
void cal_Hk_Hpsi();

source/module_rdmft/rdmft_pot.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void RDMFT<TK, TR>::cal_V_hartree()
175175

176176

177177
template <typename TK, typename TR>
178-
void RDMFT<TK, TR>::cal_V_XC()
178+
void RDMFT<TK, TR>::cal_V_XC(const UnitCell& ucell)
179179
{
180180
// // //test
181181
// DM_XC_pass = DM_XC;
@@ -280,11 +280,11 @@ void RDMFT<TK, TR>::cal_V_XC()
280280
// provide the Ds_XC to Vxc_fromRI(V_exx_XC)
281281
if (this->exx_spacegroup_symmetry && GlobalC::exx_info.info_global.exx_symmetry_realspace)
282282
{
283-
Vxc_fromRI_d->cal_exx_elec(Ds_XC_d, *ParaV, &this->symrot_exx);
283+
Vxc_fromRI_d->cal_exx_elec(Ds_XC_d, ucell,*ParaV, &this->symrot_exx);
284284
}
285285
else
286286
{
287-
Vxc_fromRI_d->cal_exx_elec(Ds_XC_d, *ParaV);
287+
Vxc_fromRI_d->cal_exx_elec(Ds_XC_d, ucell,*ParaV);
288288
}
289289

290290
// when we doing V_exx_XC.contributeHk(ik), we get HK_XC constructed by the special DM_XC
@@ -308,11 +308,11 @@ void RDMFT<TK, TR>::cal_V_XC()
308308
// // provide the Ds_XC to Vxc_fromRI(V_exx_XC)
309309
if (this->exx_spacegroup_symmetry && GlobalC::exx_info.info_global.exx_symmetry_realspace)
310310
{
311-
Vxc_fromRI_c->cal_exx_elec(Ds_XC_c, *ParaV, &this->symrot_exx);
311+
Vxc_fromRI_c->cal_exx_elec(Ds_XC_c, ucell,*ParaV, &this->symrot_exx);
312312
}
313313
else
314314
{
315-
Vxc_fromRI_c->cal_exx_elec(Ds_XC_c, *ParaV);
315+
Vxc_fromRI_c->cal_exx_elec(Ds_XC_c, ucell,*ParaV);
316316
}
317317

318318
// when we doing V_exx_XC.contributeHk(ik), we get HK_XC constructed by the special DM_XC

source/module_rdmft/update_state_rdmft.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ void RDMFT<TK, TR>::update_ion(UnitCell& ucell_in,
4747

4848

4949
template <typename TK, typename TR>
50-
void RDMFT<TK, TR>::update_elec(const ModuleBase::matrix& occ_number_in, const psi::Psi<TK>& wfc_in, const Charge* charge_in)
50+
void RDMFT<TK, TR>::update_elec(const UnitCell& ucell,
51+
const ModuleBase::matrix& occ_number_in,
52+
const psi::Psi<TK>& wfc_in, const Charge* charge_in)
5153
{
5254
// update occ_number, wg, wk_fun_occNum
5355
occ_number = (occ_number_in);
@@ -76,11 +78,11 @@ void RDMFT<TK, TR>::update_elec(const ModuleBase::matrix& occ_number_in, const p
7678
if( this->cal_E_type != 1 )
7779
{
7880
// the second cal_E_type need the complete pot to get effctive_V to calEband and so on.
79-
this->pelec->pot->update_from_charge(charge, ucell);
81+
this->pelec->pot->update_from_charge(charge, &ucell);
8082
}
8183

8284
this->cal_V_hartree();
83-
this->cal_V_XC();
85+
this->cal_V_XC(ucell);
8486
// this->cal_Hk_Hpsi();
8587

8688
std::cout << "\n******\n" << "update elec in rdmft successfully" << "\n******\n" << std::endl;

source/module_ri/Exx_LRI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Exx_LRI
6464
void cal_exx_stress();
6565
void cal_exx_ions(const UnitCell& ucell, const bool write_cv = false);
6666
void cal_exx_elec(const std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>>& Ds,
67+
const UnitCell& ucell,
6768
const Parallel_Orbitals& pv,
6869
const ModuleSymmetry::Symmetry_rotation* p_symrot = nullptr);
6970
std::vector<std::vector<int>> get_abfs_nchis() const;

source/module_ri/Exx_LRI.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,18 @@ void Exx_LRI<Tdata>::cal_exx_ions(const UnitCell& ucell,
116116
// this->m_abfsabfs.init_radial_table(Rradial);
117117
// this->m_abfslcaos_lcaos.init_radial_table(Rradial);
118118

119-
std::vector<TA> atoms(GlobalC::ucell.nat);
120-
for(int iat=0; iat<GlobalC::ucell.nat; ++iat) {
119+
std::vector<TA> atoms(ucell.nat);
120+
for(int iat=0; iat<ucell.nat; ++iat) {
121121
atoms[iat] = iat;
122122
}
123123
std::map<TA,TatomR> atoms_pos;
124-
for(int iat=0; iat<GlobalC::ucell.nat; ++iat) {
125-
atoms_pos[iat] = RI_Util::Vector3_to_array3( GlobalC::ucell.atoms[ GlobalC::ucell.iat2it[iat] ].tau[ GlobalC::ucell.iat2ia[iat] ] );
124+
for(int iat=0; iat<ucell.nat; ++iat) {
125+
atoms_pos[iat] = RI_Util::Vector3_to_array3( ucell.atoms[ ucell.iat2it[iat] ].tau[ ucell.iat2ia[iat] ] );
126126
}
127127
const std::array<TatomR,Ndim> latvec
128-
= {RI_Util::Vector3_to_array3(GlobalC::ucell.a1),
129-
RI_Util::Vector3_to_array3(GlobalC::ucell.a2),
130-
RI_Util::Vector3_to_array3(GlobalC::ucell.a3)};
128+
= {RI_Util::Vector3_to_array3(ucell.a1),
129+
RI_Util::Vector3_to_array3(ucell.a2),
130+
RI_Util::Vector3_to_array3(ucell.a3)};
131131
const std::array<Tcell,Ndim> period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]};
132132

133133
this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period);
@@ -190,6 +190,7 @@ void Exx_LRI<Tdata>::cal_exx_ions(const UnitCell& ucell,
190190

191191
template<typename Tdata>
192192
void Exx_LRI<Tdata>::cal_exx_elec(const std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>>& Ds,
193+
const UnitCell& ucell,
193194
const Parallel_Orbitals& pv,
194195
const ModuleSymmetry::Symmetry_rotation* p_symrot)
195196
{

source/module_ri/Exx_LRI_interface.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ class Exx_LRI_Interface
5757
void exx_beforescf(const int istep, const K_Vectors& kv, const Charge_Mixing& chgmix, const UnitCell& ucell, const LCAO_Orbitals& orb);
5858

5959
/// @brief in eachiterinit: do DM mixing and calculate Hexx when entering 2nd SCF
60-
void exx_eachiterinit(const int istep, const elecstate::DensityMatrix<T, double>& dm/**< double should be Tdata if complex-PBE-DM is supported*/,
61-
const K_Vectors& kv, const int& iter);
60+
void exx_eachiterinit(const int istep,
61+
const UnitCell& ucell,
62+
const elecstate::DensityMatrix<T, double>& dm/**< double should be Tdata if complex-PBE-DM is supported*/,
63+
const K_Vectors& kv,
64+
const int& iter);
6265

6366
/// @brief in hamilt2density: calculate Hexx and Eexx
6467
void exx_hamilt2density(elecstate::ElecState& elec, const Parallel_Orbitals& pv, const int iter);

source/module_ri/Exx_LRI_interface.hpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,33 @@ void Exx_LRI_Interface<T, Tdata>::exx_beforescf(const int istep,
114114
}
115115

116116
template<typename T, typename Tdata>
117-
void Exx_LRI_Interface<T, Tdata>::exx_eachiterinit(const int istep, const elecstate::DensityMatrix<T, double>& dm, const K_Vectors& kv, const int& iter)
117+
void Exx_LRI_Interface<T, Tdata>::exx_eachiterinit(const int istep,
118+
const UnitCell& ucell,
119+
const elecstate::DensityMatrix<T, double>& dm,
120+
const K_Vectors& kv,
121+
const int& iter)
118122
{
119123
if (GlobalC::exx_info.info_global.cal_exx)
120124
{
121125
if (!GlobalC::exx_info.info_global.separate_loop && (this->two_level_step || istep > 0))
122126
{
123127
const bool flag_restart = (iter == 1) ? true : false;
124-
auto cal = [this, &kv, &flag_restart](const elecstate::DensityMatrix<T, double>& dm_in)
128+
auto cal = [this, &ucell,&kv, &flag_restart](const elecstate::DensityMatrix<T, double>& dm_in)
125129
{
126130
if (this->exx_spacegroup_symmetry) { this->mix_DMk_2D.mix(symrot_.restore_dm(kv,dm_in.get_DMK_vector(), *dm_in.get_paraV_pointer()), flag_restart); }
127131
else { this->mix_DMk_2D.mix(dm_in.get_DMK_vector(), flag_restart); }
128132
const std::vector<std::map<int,std::map<std::pair<int, std::array<int, 3>>,RI::Tensor<Tdata>>>>
129133
Ds = PARAM.globalv.gamma_only_local
130134
? RI_2D_Comm::split_m2D_ktoR<Tdata>(*this->exx_ptr->p_kv, this->mix_DMk_2D.get_DMk_gamma_out(), *dm_in.get_paraV_pointer(), PARAM.inp.nspin)
131135
: RI_2D_Comm::split_m2D_ktoR<Tdata>(*this->exx_ptr->p_kv, this->mix_DMk_2D.get_DMk_k_out(), *dm_in.get_paraV_pointer(), PARAM.inp.nspin, this->exx_spacegroup_symmetry);
132-
if (this->exx_spacegroup_symmetry && GlobalC::exx_info.info_global.exx_symmetry_realspace) { this->exx_ptr->cal_exx_elec(Ds, *dm_in.get_paraV_pointer(), &this->symrot_); }
133-
else { this->exx_ptr->cal_exx_elec(Ds, *dm_in.get_paraV_pointer()); }
136+
if (this->exx_spacegroup_symmetry && GlobalC::exx_info.info_global.exx_symmetry_realspace)
137+
{
138+
this->exx_ptr->cal_exx_elec(Ds, ucell,*dm_in.get_paraV_pointer(), &this->symrot_);
139+
}
140+
else
141+
{
142+
this->exx_ptr->cal_exx_elec(Ds, ucell,*dm_in.get_paraV_pointer());
143+
}
134144
};
135145
if(istep > 0 && flag_restart) {
136146
cal(*dm_last_step);
@@ -326,13 +336,13 @@ bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
326336

327337
if (this->exx_spacegroup_symmetry && GlobalC::exx_info.info_global.exx_symmetry_realspace)
328338
{
329-
this->exx_ptr->cal_exx_elec(Ds, *dm.get_paraV_pointer(), &this->symrot_);
339+
this->exx_ptr->cal_exx_elec(Ds, ucell, *dm.get_paraV_pointer(), &this->symrot_);
330340
// this->symrot_.print_HR(this->exx_ptr->Hexxs[0], "Hexxs_irreducible"); // test
331341
// this->symrot_.print_HR(this->exx_ptr->Hexxs[0], "Hexxs_restored", 1e-10); // test
332342
}
333343
else
334344
{
335-
this->exx_ptr->cal_exx_elec(Ds, *dm.get_paraV_pointer()); // restore DM but not Hexx
345+
this->exx_ptr->cal_exx_elec(Ds, ucell, *dm.get_paraV_pointer()); // restore DM but not Hexx
336346
// this->symrot_.print_HR(this->exx_ptr->Hexxs[0], "Hexxs_restore-DM-only"); // test
337347
// this->symrot_.print_HR(this->exx_ptr->Hexxs[0], "Hexxs_ref"); // test
338348
}

source/module_ri/RPA_LRI.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ void RPA_LRI<T, Tdata>::cal_postSCF_exx(const elecstate::DensityMatrix<T, Tdata>
110110
exx_lri_rpa.cal_exx_ions(ucell,PARAM.inp.out_ri_cv);
111111

112112
if (exx_spacegroup_symmetry && PARAM.inp.exx_symmetry_realspace) {
113-
exx_lri_rpa.cal_exx_elec(Ds, *dm.get_paraV_pointer(), &symrot);
113+
exx_lri_rpa.cal_exx_elec(Ds, ucell,*dm.get_paraV_pointer(), &symrot);
114114
} else {
115-
exx_lri_rpa.cal_exx_elec(Ds, *dm.get_paraV_pointer());
115+
exx_lri_rpa.cal_exx_elec(Ds, ucell,*dm.get_paraV_pointer());
116116
}
117117
// cout<<"postSCF_Eexx: "<<exx_lri_rpa.Eexx<<endl;
118118
}

0 commit comments

Comments
 (0)