Skip to content

Commit c440291

Browse files
authored
Fix: nscf for hse (#5499)
1 parent f381836 commit c440291

File tree

2 files changed

+67
-37
lines changed

2 files changed

+67
-37
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -634,19 +634,22 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(const int istep, const int iter)
634634

635635
#ifdef __EXX
636636
// calculate exact-exchange
637-
if (GlobalC::exx_info.info_ri.real_number)
638-
{
639-
this->exd->exx_eachiterinit(istep,
640-
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
641-
this->kv,
642-
iter);
643-
}
644-
else
637+
if (PARAM.inp.calculation != "nscf")
645638
{
646-
this->exc->exx_eachiterinit(istep,
647-
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
648-
this->kv,
649-
iter);
639+
if (GlobalC::exx_info.info_ri.real_number)
640+
{
641+
this->exd->exx_eachiterinit(istep,
642+
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
643+
this->kv,
644+
iter);
645+
}
646+
else
647+
{
648+
this->exc->exx_eachiterinit(istep,
649+
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
650+
this->kv,
651+
iter);
652+
}
650653
}
651654
#endif
652655

@@ -728,13 +731,16 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2density_single(int istep, int iter, double
728731

729732
// 5) what's the exd used for?
730733
#ifdef __EXX
731-
if (GlobalC::exx_info.info_ri.real_number)
734+
if (PARAM.inp.calculation != "nscf")
732735
{
733-
this->exd->exx_hamilt2density(*this->pelec, this->pv, iter);
734-
}
735-
else
736-
{
737-
this->exc->exx_hamilt2density(*this->pelec, this->pv, iter);
736+
if (GlobalC::exx_info.info_ri.real_number)
737+
{
738+
this->exd->exx_hamilt2density(*this->pelec, this->pv, iter);
739+
}
740+
else
741+
{
742+
this->exc->exx_hamilt2density(*this->pelec, this->pv, iter);
743+
}
738744
}
739745
#endif
740746

@@ -921,11 +927,29 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(const int istep, int& iter)
921927

922928
#ifdef __EXX
923929
// 3) save exx matrix
924-
if (GlobalC::exx_info.info_global.cal_exx)
930+
if (PARAM.inp.calculation != "nscf")
925931
{
926-
GlobalC::exx_info.info_ri.real_number ?
927-
this->exd->exx_iter_finish(this->kv, GlobalC::ucell, *this->p_hamilt, *this->pelec, *this->p_chgmix, this->scf_ene_thr, iter, istep, this->conv_esolver) :
928-
this->exc->exx_iter_finish(this->kv, GlobalC::ucell, *this->p_hamilt, *this->pelec, *this->p_chgmix, this->scf_ene_thr, iter, istep, this->conv_esolver);
932+
if (GlobalC::exx_info.info_global.cal_exx)
933+
{
934+
GlobalC::exx_info.info_ri.real_number ? this->exd->exx_iter_finish(this->kv,
935+
GlobalC::ucell,
936+
*this->p_hamilt,
937+
*this->pelec,
938+
*this->p_chgmix,
939+
this->scf_ene_thr,
940+
iter,
941+
istep,
942+
this->conv_esolver)
943+
: this->exc->exx_iter_finish(this->kv,
944+
GlobalC::ucell,
945+
*this->p_hamilt,
946+
*this->pelec,
947+
*this->p_chgmix,
948+
this->scf_ene_thr,
949+
iter,
950+
istep,
951+
this->conv_esolver);
952+
}
929953
}
930954
#endif
931955

@@ -1040,17 +1064,20 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
10401064

10411065
#ifdef __EXX
10421066
// 5) write Hexx matrix for NSCF (see `out_chg` in docs/advanced/input_files/input-main.md)
1043-
if (GlobalC::exx_info.info_global.cal_exx && PARAM.inp.out_chg[0]
1044-
&& istep % PARAM.inp.out_interval == 0) // Peize Lin add if 2022.11.14
1067+
if (PARAM.inp.calculation != "nscf")
10451068
{
1046-
const std::string file_name_exx = PARAM.globalv.global_out_dir + "HexxR" + std::to_string(GlobalV::MY_RANK);
1047-
if (GlobalC::exx_info.info_ri.real_number)
1069+
if (GlobalC::exx_info.info_global.cal_exx && PARAM.inp.out_chg[0]
1070+
&& istep % PARAM.inp.out_interval == 0) // Peize Lin add if 2022.11.14
10481071
{
1049-
ModuleIO::write_Hexxs_csr(file_name_exx, GlobalC::ucell, this->exd->get_Hexxs());
1050-
}
1051-
else
1052-
{
1053-
ModuleIO::write_Hexxs_csr(file_name_exx, GlobalC::ucell, this->exc->get_Hexxs());
1072+
const std::string file_name_exx = PARAM.globalv.global_out_dir + "HexxR" + std::to_string(GlobalV::MY_RANK);
1073+
if (GlobalC::exx_info.info_ri.real_number)
1074+
{
1075+
ModuleIO::write_Hexxs_csr(file_name_exx, GlobalC::ucell, this->exd->get_Hexxs());
1076+
}
1077+
else
1078+
{
1079+
ModuleIO::write_Hexxs_csr(file_name_exx, GlobalC::ucell, this->exc->get_Hexxs());
1080+
}
10541081
}
10551082
}
10561083
#endif

source/module_esolver/lcao_before_scf.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,16 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(const int istep)
210210

211211
// Peize Lin add 2016-12-03
212212
#ifdef __EXX // set xc type before the first cal of xc in pelec->init_scf
213-
if (GlobalC::exx_info.info_ri.real_number)
213+
if (PARAM.inp.calculation != "nscf")
214214
{
215-
this->exd->exx_beforescf(istep, this->kv, *this->p_chgmix, GlobalC::ucell, orb_);
216-
}
217-
else
218-
{
219-
this->exc->exx_beforescf(istep, this->kv, *this->p_chgmix, GlobalC::ucell, orb_);
215+
if (GlobalC::exx_info.info_ri.real_number)
216+
{
217+
this->exd->exx_beforescf(istep, this->kv, *this->p_chgmix, GlobalC::ucell, orb_);
218+
}
219+
else
220+
{
221+
this->exc->exx_beforescf(istep, this->kv, *this->p_chgmix, GlobalC::ucell, orb_);
222+
}
220223
}
221224
#endif // __EXX
222225

0 commit comments

Comments
 (0)