Skip to content

Commit cc9d759

Browse files
1041176461jiyuangQianruipkumaki49
authored
Refactor: modify EXX realx/md calculation framework (#5403)
* Use template to reconstruct parse_expression * Feature: output R matrix at each MD step * Modify'matrix_HS' to 'matrix' for R matrix output * Merge branches 'develop' and 'develop' of https://github.com/1041176461/abacus-develop into develop * Fix: modify index in parse_expression * Fix: add regfree for parse_expression * Doc: update phonopy doc * Doc: update phonopy doc * fix tdos plot for nspin=2 * optimize dosplot for nspin=2 * fix legend for dosplot * Refactor: modify exx loop for relax/md * add exx when istep>0 * Update dos.py * Update esolver_sdft_pw.cpp * Update lcao_before_scf.cpp * Update Exx_LRI_interface.h * Update Exx_LRI_interface.hpp * Fix: compile error * Fix: compile error * Fix: change HSE relax/md result.ref for new framework * Fix: compile error * compatible with exx_iter_finish --------- Co-authored-by: jiyuang <[email protected]> Co-authored-by: Qianrui <[email protected]> Co-authored-by: maki49 <[email protected]>
1 parent d533ad5 commit cc9d759

File tree

21 files changed

+78
-50
lines changed

21 files changed

+78
-50
lines changed

source/module_esolver/esolver_ks.cpp

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

611611
// 10) finish scf iterations
612-
this->iter_finish(iter);
612+
this->iter_finish(istep, iter);
613613
#ifdef __MPI
614614
double duration = (double)(MPI_Wtime() - iterstart);
615615
#else
@@ -663,7 +663,7 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
663663
};
664664

665665
template <typename T, typename Device>
666-
void ESolver_KS<T, Device>::iter_finish(int& iter)
666+
void ESolver_KS<T, Device>::iter_finish(const int istep, int& iter)
667667
{
668668
// 1 means Harris-Foulkes functional
669669
// 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
@@ -58,7 +58,7 @@ class ESolver_KS : public ESolver_FP
5858
virtual void iter_init(const int istep, const int iter) {};
5959

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

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

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,15 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(const int istep, const int iter)
625625
// calculate exact-exchange
626626
if (GlobalC::exx_info.info_ri.real_number)
627627
{
628-
this->exd->exx_eachiterinit(*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
628+
this->exd->exx_eachiterinit(istep,
629+
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
629630
this->kv,
630631
iter);
631632
}
632633
else
633634
{
634-
this->exc->exx_eachiterinit(*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
635+
this->exc->exx_eachiterinit(istep,
636+
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
635637
this->kv,
636638
iter);
637639
}
@@ -914,12 +916,12 @@ void ESolver_KS_LCAO<TK, TR>::update_pot(const int istep, const int iter)
914916
//! 5) cal_MW? (why put it here?)
915917
//------------------------------------------------------------------------------
916918
template <typename TK, typename TR>
917-
void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)
919+
void ESolver_KS_LCAO<TK, TR>::iter_finish(const int istep, int& iter)
918920
{
919921
ModuleBase::TITLE("ESolver_KS_LCAO", "iter_finish");
920922

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

924926
// 1) mix density matrix if mixing_restart + mixing_dmr + not first
925927
// mixing_restart at every iter
@@ -944,8 +946,8 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)
944946
if (GlobalC::exx_info.info_global.cal_exx)
945947
{
946948
GlobalC::exx_info.info_ri.real_number ?
947-
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) :
948-
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);
949+
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) :
950+
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);
949951
}
950952
#endif
951953

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
@@ -191,9 +191,9 @@ namespace ModuleESolver
191191
}
192192

193193
template <typename T>
194-
void ESolver_KS_LIP<T>::iter_finish(int& iter)
194+
void ESolver_KS_LIP<T>::iter_finish(const int istep, int& iter)
195195
{
196-
ESolver_KS_PW<T>::iter_finish(iter);
196+
ESolver_KS_PW<T>::iter_finish(istep, iter);
197197

198198
#ifdef __EXX
199199
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
@@ -434,10 +434,10 @@ void ESolver_KS_PW<T, Device>::update_pot(const int istep, const int iter)
434434
}
435435

436436
template <typename T, typename Device>
437-
void ESolver_KS_PW<T, Device>::iter_finish(int& iter)
437+
void ESolver_KS_PW<T, Device>::iter_finish(const int istep, int& iter)
438438
{
439439
// call iter_finish() of ESolver_KS
440-
ESolver_KS<T, Device>::iter_finish(iter);
440+
ESolver_KS<T, Device>::iter_finish(istep, iter);
441441

442442
// liuyu 2023-10-24
443443
// 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
@@ -153,10 +153,10 @@ void ESolver_SDFT_PW<T, Device>::before_scf(const int istep)
153153
}
154154

155155
template <typename T, typename Device>
156-
void ESolver_SDFT_PW<T, Device>::iter_finish(int& iter)
156+
void ESolver_SDFT_PW<T, Device>::iter_finish(const int istep, int& iter)
157157
{
158158
// call iter_finish() of ESolver_KS
159-
ESolver_KS<T, Device>::iter_finish(iter);
159+
ESolver_KS<T, Device>::iter_finish(istep, iter);
160160
}
161161

162162
template <typename T, typename Device>

source/module_esolver/esolver_sdft_pw.h

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

4040
virtual void others(const int istep) override;
4141

42-
virtual void iter_finish(int& iter) override;
42+
virtual void iter_finish(const int istep, int& iter) override;
4343

4444
virtual void after_scf(const int istep) override;
4545

0 commit comments

Comments
 (0)