Skip to content

Commit d15217c

Browse files
authored
Merge pull request #7 from 1041176461/new_loop
Refactor: modify exx loop for relax/md
2 parents 90e4750 + 7740356 commit d15217c

File tree

17 files changed

+68
-38
lines changed

17 files changed

+68
-38
lines changed

source/module_esolver/esolver_ks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
594594
this->update_pot(istep, iter);
595595

596596
// 10) finish scf iterations
597-
this->iter_finish(iter);
597+
this->iter_finish(istep, iter);
598598
#ifdef __MPI
599599
double duration = (double)(MPI_Wtime() - iterstart);
600600
#else
@@ -659,7 +659,7 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
659659
};
660660

661661
template <typename T, typename Device>
662-
void ESolver_KS<T, Device>::iter_finish(int& iter)
662+
void ESolver_KS<T, Device>::iter_finish(const int istep, int& iter)
663663
{
664664
// 1 means Harris-Foulkes functional
665665
// 2 means Kohn-Sham functional

source/module_esolver/esolver_ks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ESolver_KS : public ESolver_FP
6464
virtual void iter_init(const int istep, const int iter) {};
6565

6666
//! Something to do after hamilt2density function in each iter loop.
67-
virtual void iter_finish(int& iter);
67+
virtual void iter_finish(const int istep, int& iter);
6868

6969
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
7070
virtual void after_scf(const int istep) override;

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,15 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(const int istep, const int iter)
623623
// calculate exact-exchange
624624
if (GlobalC::exx_info.info_ri.real_number)
625625
{
626-
this->exd->exx_eachiterinit(*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
626+
this->exd->exx_eachiterinit(istep,
627+
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
627628
this->kv,
628629
iter);
629630
}
630631
else
631632
{
632-
this->exc->exx_eachiterinit(*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
633+
this->exc->exx_eachiterinit(istep,
634+
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
633635
this->kv,
634636
iter);
635637
}
@@ -912,12 +914,12 @@ void ESolver_KS_LCAO<TK, TR>::update_pot(const int istep, const int iter)
912914
//! 5) cal_MW? (why put it here?)
913915
//------------------------------------------------------------------------------
914916
template <typename TK, typename TR>
915-
void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)
917+
void ESolver_KS_LCAO<TK, TR>::iter_finish(const int istep, int& iter)
916918
{
917919
ModuleBase::TITLE("ESolver_KS_LCAO", "iter_finish");
918920

919921
// call iter_finish() of ESolver_KS
920-
ESolver_KS<TK>::iter_finish(iter);
922+
ESolver_KS<TK>::iter_finish(istep, iter);
921923

922924
// 1) mix density matrix if mixing_restart + mixing_dmr + not first
923925
// mixing_restart at every iter
@@ -941,7 +943,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)
941943
// 3) save exx matrix
942944
int two_level_step = GlobalC::exx_info.info_ri.real_number ? this->exd->two_level_step : this->exc->two_level_step;
943945

944-
if (GlobalC::restart.info_save.save_H && two_level_step > 0
946+
if (GlobalC::restart.info_save.save_H && (two_level_step > 0 || istep > 0)
945947
&& (!GlobalC::exx_info.info_global.separate_loop || iter == 1)) // to avoid saving the same value repeatedly
946948
{
947949
////////// for Add_Hexx_Type::k
@@ -989,23 +991,27 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)
989991
}
990992
if (GlobalC::exx_info.info_ri.real_number)
991993
{
994+
this->exd->dm_last_step = dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM();
992995
this->conv_esolver = this->exd->exx_after_converge(
993996
*this->p_hamilt,
994997
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
995998
this->kv,
996999
PARAM.inp.nspin,
9971000
iter,
1001+
istep,
9981002
this->pelec->f_en.etot,
9991003
this->scf_ene_thr);
10001004
}
10011005
else
10021006
{
1007+
this->exc->dm_last_step = dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM();
10031008
this->conv_esolver = this->exc->exx_after_converge(
10041009
*this->p_hamilt,
10051010
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
10061011
this->kv,
10071012
PARAM.inp.nspin,
10081013
iter,
1014+
istep,
10091015
this->pelec->f_en.etot,
10101016
this->scf_ene_thr);
10111017
}

source/module_esolver/esolver_ks_lcao.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ESolver_KS_LCAO : public ESolver_KS<TK> {
5656

5757
virtual void update_pot(const int istep, const int iter) override;
5858

59-
virtual void iter_finish(int& iter) override;
59+
virtual void iter_finish(const int istep, int& iter) override;
6060

6161
virtual void after_scf(const int istep) override;
6262

source/module_esolver/esolver_ks_lcaopw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ namespace ModuleESolver
192192
}
193193

194194
template <typename T>
195-
void ESolver_KS_LIP<T>::iter_finish(int& iter)
195+
void ESolver_KS_LIP<T>::iter_finish(const int istep, int& iter)
196196
{
197-
ESolver_KS_PW<T>::iter_finish(iter);
197+
ESolver_KS_PW<T>::iter_finish(istep, iter);
198198

199199
#ifdef __EXX
200200
if (GlobalC::exx_info.info_global.cal_exx && this->conv_esolver)

source/module_esolver/esolver_ks_lcaopw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace ModuleESolver
2828

2929
protected:
3030
virtual void iter_init(const int istep, const int iter) override;
31-
virtual void iter_finish(int& iter) override;
31+
virtual void iter_finish(const int istep, int& iter) override;
3232

3333
virtual void allocate_hamilt() override;
3434
virtual void deallocate_hamilt() override;

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,10 @@ void ESolver_KS_PW<T, Device>::update_pot(const int istep, const int iter)
438438
}
439439

440440
template <typename T, typename Device>
441-
void ESolver_KS_PW<T, Device>::iter_finish(int& iter)
441+
void ESolver_KS_PW<T, Device>::iter_finish(const int istep, int& iter)
442442
{
443443
// call iter_finish() of ESolver_KS
444-
ESolver_KS<T, Device>::iter_finish(iter);
444+
ESolver_KS<T, Device>::iter_finish(istep, iter);
445445

446446
// liuyu 2023-10-24
447447
// D in uspp need vloc, thus needs update when veff updated

source/module_esolver/esolver_ks_pw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ESolver_KS_PW : public ESolver_KS<T, Device>
4646

4747
virtual void update_pot(const int istep, const int iter) override;
4848

49-
virtual void iter_finish(int& iter) override;
49+
virtual void iter_finish(const int istep, int& iter) override;
5050

5151
virtual void after_scf(const int istep) override;
5252

source/module_esolver/esolver_sdft_pw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ void ESolver_SDFT_PW::before_scf(const int istep)
139139
}
140140
}
141141

142-
void ESolver_SDFT_PW::iter_finish(int& iter)
142+
void ESolver_SDFT_PW::iter_finish(const int istep, int& iter)
143143
{
144144
// call iter_finish() of ESolver_KS
145-
ESolver_KS<std::complex<double>>::iter_finish(iter);
145+
ESolver_KS<std::complex<double>>::iter_finish(istep, iter);
146146
}
147147

148148
void ESolver_SDFT_PW::after_scf(const int istep)

source/module_esolver/esolver_sdft_pw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ESolver_SDFT_PW : public ESolver_KS_PW<std::complex<double>>
3737

3838
virtual void others(const int istep) override;
3939

40-
virtual void iter_finish(int& iter) override;
40+
virtual void iter_finish(const int istep, int& iter) override;
4141

4242
virtual void after_scf(const int istep) override;
4343

0 commit comments

Comments
 (0)