Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 4 additions & 69 deletions source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,76 +941,11 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)

#ifdef __EXX
// 3) save exx matrix
int two_level_step = GlobalC::exx_info.info_ri.real_number ? this->exd->two_level_step : this->exc->two_level_step;

if (GlobalC::restart.info_save.save_H && two_level_step > 0
&& (!GlobalC::exx_info.info_global.separate_loop || iter == 1)) // to avoid saving the same value repeatedly
{
////////// for Add_Hexx_Type::k
/*
hamilt::HS_Matrix_K<TK> Hexxk_save(&this->pv, 1);
for (int ik = 0; ik < this->kv.get_nks(); ++ik) {
Hexxk_save.set_zero_hk();

hamilt::OperatorEXX<hamilt::OperatorLCAO<TK, TR>> opexx_save(&Hexxk_save,
nullptr,
this->kv);

opexx_save.contributeHk(ik);

GlobalC::restart.save_disk("Hexx",
ik,
this->pv.get_local_size(),
Hexxk_save.get_hk());
}*/
////////// for Add_Hexx_Type:R
const std::string& restart_HR_path = GlobalC::restart.folder + "HexxR" + std::to_string(GlobalV::MY_RANK);
if (GlobalC::exx_info.info_ri.real_number)
{
ModuleIO::write_Hexxs_csr(restart_HR_path, GlobalC::ucell, this->exd->get_Hexxs());
}
else
{
ModuleIO::write_Hexxs_csr(restart_HR_path, GlobalC::ucell, this->exc->get_Hexxs());
}
if (GlobalV::MY_RANK == 0)
{
GlobalC::restart.save_disk("Eexx", 0, 1, &this->pelec->f_en.exx);
}
}

if (GlobalC::exx_info.info_global.cal_exx && this->conv_esolver)
if (GlobalC::exx_info.info_global.cal_exx)
{
// Kerker mixing does not work for the density matrix.
// In the separate loop case, it can still work in the subsequent inner loops where Hexx(DM) is fixed.
// In the non-separate loop case where Hexx(DM) is updated in every iteration of the 2nd loop, it should be
// closed.
if (!GlobalC::exx_info.info_global.separate_loop)
{
this->p_chgmix->close_kerker_gg0();
}
if (GlobalC::exx_info.info_ri.real_number)
{
this->conv_esolver = this->exd->exx_after_converge(
*this->p_hamilt,
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
this->kv,
PARAM.inp.nspin,
iter,
this->pelec->f_en.etot,
this->scf_ene_thr);
}
else
{
this->conv_esolver = this->exc->exx_after_converge(
*this->p_hamilt,
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
this->kv,
PARAM.inp.nspin,
iter,
this->pelec->f_en.etot,
this->scf_ene_thr);
}
GlobalC::exx_info.info_ri.real_number ?
this->exd->exx_iter_finish(this->kv, GlobalC::ucell, *this->p_hamilt, *this->pelec, *this->p_chgmix, this->scf_ene_thr, iter, this->conv_esolver) :
this->exc->exx_iter_finish(this->kv, GlobalC::ucell, *this->p_hamilt, *this->pelec, *this->p_chgmix, this->scf_ene_thr, iter, this->conv_esolver);
}
#endif

Expand Down
4 changes: 4 additions & 0 deletions source/module_ri/Exx_LRI_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class Exx_LRI_Interface
/// @brief in hamilt2density: calculate Hexx and Eexx
void exx_hamilt2density(elecstate::ElecState& elec, const Parallel_Orbitals& pv, const int iter);

/// @brief in iter_finish: write Hexx, do something according to whether SCF is converged
void exx_iter_finish(const K_Vectors& kv, const UnitCell& ucell,
hamilt::Hamilt<T>& hamilt, elecstate::ElecState& elec, Charge_Mixing& chgmix,
const double& scf_ene_thr, int& iter, bool& conv_esolver);
/// @brief: in do_after_converge: add exx operators; do DM mixing if seperate loop
bool exx_after_converge(
hamilt::Hamilt<T>& hamilt,
Expand Down
58 changes: 58 additions & 0 deletions source/module_ri/Exx_LRI_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sys/time.h>
#include "module_io/csr_reader.h"
#include "module_io/write_HS_sparse.h"
#include "module_elecstate/elecstate_lcao.h"

template<typename T, typename Tdata>
void Exx_LRI_Interface<T, Tdata>::write_Hexxs_cereal(const std::string& file_name) const
Expand Down Expand Up @@ -143,6 +144,63 @@ void Exx_LRI_Interface<T, Tdata>::exx_hamilt2density(elecstate::ElecState& elec,
}
}

template<typename T, typename Tdata>
void Exx_LRI_Interface<T, Tdata>::exx_iter_finish(const K_Vectors& kv, const UnitCell& ucell,
hamilt::Hamilt<T>& hamilt, elecstate::ElecState& elec, Charge_Mixing& chgmix,
const double& scf_ene_thr, int& iter, bool& conv_esolver)
{
if (GlobalC::restart.info_save.save_H && this->two_level_step > 0
&& (!GlobalC::exx_info.info_global.separate_loop || iter == 1)) // to avoid saving the same value repeatedly
{
////////// for Add_Hexx_Type::k
/*
hamilt::HS_Matrix_K<TK> Hexxk_save(&this->pv, 1);
for (int ik = 0; ik < this->kv.get_nks(); ++ik) {
Hexxk_save.set_zero_hk();

hamilt::OperatorEXX<hamilt::OperatorLCAO<TK, TR>> opexx_save(&Hexxk_save,
nullptr,
this->kv);

opexx_save.contributeHk(ik);

GlobalC::restart.save_disk("Hexx",
ik,
this->pv.get_local_size(),
Hexxk_save.get_hk());
}*/
////////// for Add_Hexx_Type:R
const std::string& restart_HR_path = GlobalC::restart.folder + "HexxR" + std::to_string(GlobalV::MY_RANK);
ModuleIO::write_Hexxs_csr(restart_HR_path, GlobalC::ucell, this->get_Hexxs());

if (GlobalV::MY_RANK == 0)
{
GlobalC::restart.save_disk("Eexx", 0, 1, &elec.f_en.exx);
}
}

if (GlobalC::exx_info.info_global.cal_exx && conv_esolver)
{
// Kerker mixing does not work for the density matrix.
// In the separate loop case, it can still work in the subsequent inner loops where Hexx(DM) is fixed.
// In the non-separate loop case where Hexx(DM) is updated in every iteration of the 2nd loop, it should be
// closed.
if (!GlobalC::exx_info.info_global.separate_loop)
{
chgmix.close_kerker_gg0();
}
conv_esolver = this->exx_after_converge(
hamilt,
*dynamic_cast<const elecstate::ElecStateLCAO<T>*>(&elec)->get_DM(),
kv,
PARAM.inp.nspin,
iter,
elec.f_en.etot,
scf_ene_thr);
}
//else if ( PARAM.inp.rdmft && two_level_step ) { conv_esolver = true; } // for RDMFT in the future to quit after the first iter of the exx-loop
}

template<typename T, typename Tdata>
bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
hamilt::Hamilt<T>& hamilt,
Expand Down
Loading