Skip to content

Commit 4a69545

Browse files
authored
Refactor: move dftu_cal_occup_m to dftu (#5512)
* Refactor: move dftu_cal_occup_m to dftu * Refactor: update access permissions of variables in esolver
1 parent 593c30d commit 4a69545

File tree

11 files changed

+61
-90
lines changed

11 files changed

+61
-90
lines changed

source/Makefile.Objects

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ OBJS_ESOLVER=esolver.o\
253253
OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\
254254
esolver_ks_lcao_tddft.o\
255255
dpks_cal_e_delta_band.o\
256-
dftu_cal_occup_m.o\
257256
set_matrix_grid.o\
258257
lcao_before_scf.o\
259258
lcao_gets.o\

source/module_esolver/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ if(ENABLE_LCAO)
2020
esolver_ks_lcao_tddft.cpp
2121
dpks_cal_e_delta_band.cpp
2222
set_matrix_grid.cpp
23-
dftu_cal_occup_m.cpp
2423
lcao_before_scf.cpp
2524
lcao_gets.cpp
2625
lcao_others.cpp

source/module_esolver/dftu_cal_occup_m.cpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

source/module_esolver/esolver_fp.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,7 @@ namespace ModuleESolver
2222
{
2323
class ESolver_FP : public ESolver
2424
{
25-
public:
26-
27-
ModulePW::PW_Basis* pw_rho;
28-
29-
/**
30-
* @brief same as pw_rho for ncpp. Here 'd' stands for 'dense'
31-
* dense grid for for uspp, used for ultrasoft augmented charge density.
32-
* charge density and potential are defined on dense grids,
33-
* but effective potential needs to be interpolated on smooth grids in order to compute Veff|psi>
34-
*/
35-
ModulePW::PW_Basis* pw_rhod;
36-
ModulePW::PW_Basis_Big* pw_big; ///< [temp] pw_basis_big class
37-
25+
public:
3826
//! Constructor
3927
ESolver_FP();
4028

@@ -44,6 +32,10 @@ namespace ModuleESolver
4432
//! Initialize of the first-principels energy solver
4533
virtual void before_all_runners(const Input_para& inp, UnitCell& cell) override;
4634

35+
protected:
36+
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
37+
virtual void after_scf(const int istep);
38+
4739
virtual void init_after_vc(const Input_para& inp, UnitCell& cell); // liuyu add 2023-03-09
4840

4941
//! Electronic states
@@ -58,9 +50,16 @@ namespace ModuleESolver
5850
//! K points in Brillouin zone
5951
K_Vectors kv;
6052

61-
protected:
62-
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
63-
virtual void after_scf(const int istep);
53+
ModulePW::PW_Basis* pw_rho;
54+
55+
/**
56+
* @brief same as pw_rho for ncpp. Here 'd' stands for 'dense'
57+
* dense grid for for uspp, used for ultrasoft augmented charge density.
58+
* charge density and potential are defined on dense grids,
59+
* but effective potential needs to be interpolated on smooth grids in order to compute Veff|psi>
60+
*/
61+
ModulePW::PW_Basis* pw_rhod;
62+
ModulePW::PW_Basis_Big* pw_big; ///< [temp] pw_basis_big class
6463

6564
//! Charge extrapolation
6665
Charge_Extra CE;

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "module_base/tool_title.h"
66
#include "module_elecstate/module_dm/cal_dm_psi.h"
77
#include "module_hamilt_lcao/module_deltaspin/spin_constrain.h"
8+
#include "module_hamilt_lcao/module_dftu/dftu.h"
89
#include "module_io/berryphase.h"
910
#include "module_io/cube_io.h"
1011
#include "module_io/dos_nao.h"
@@ -879,7 +880,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(const int istep, int& iter)
879880
{
880881
const std::vector<std::vector<TK>>& tmp_dm
881882
= dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM()->get_DMK_vector();
882-
this->dftu_cal_occup_m(iter, tmp_dm);
883+
ModuleDFTU::dftu_cal_occup_m(iter, tmp_dm, this->kv, this->p_chgmix->get_mixing_beta(), this->p_hamilt);
883884
}
884885
GlobalC::dftu.cal_energy_correction(istep);
885886
}

source/module_esolver/esolver_ks_lcao.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ class ESolver_KS_LCAO : public ESolver_KS<TK> {
9797
#endif
9898

9999
private:
100-
// tmp interfaces before sub-modules are refactored
101-
void dftu_cal_occup_m(const int& iter,
102-
const std::vector<std::vector<TK>>& dm) const;
103-
104100
#ifdef __DEEPKS
105101
void dpks_cal_e_delta_band(const std::vector<std::vector<TK>>& dm) const;
106102

source/module_esolver/esolver_ks_lcao_tddft.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO<std::complex<double>, doubl
1818

1919
void before_all_runners(const Input_para& inp, UnitCell& cell) override;
2020

21+
protected:
22+
virtual void hamilt2density_single(const int istep, const int iter, const double ethr) override;
23+
24+
virtual void update_pot(const int istep, const int iter) override;
25+
26+
virtual void iter_finish(const int istep, int& iter) override;
27+
28+
virtual void after_scf(const int istep) override;
29+
2130
//! wave functions of last time step
2231
psi::Psi<std::complex<double>>* psi_laststep = nullptr;
2332

@@ -31,16 +40,6 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO<std::complex<double>, doubl
3140
elecstate::ElecStateLCAO_TDDFT* pelec_td = nullptr;
3241

3342
int td_htype = 1;
34-
35-
protected:
36-
37-
virtual void hamilt2density_single(const int istep, const int iter, const double ethr) override;
38-
39-
virtual void update_pot(const int istep, const int iter) override;
40-
41-
virtual void iter_finish(const int istep, int& iter) override;
42-
43-
virtual void after_scf(const int istep) override;
4443
};
4544

4645
} // namespace ModuleESolver

source/module_esolver/esolver_ks_lcaopw.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ namespace ModuleESolver
2020

2121
~ESolver_KS_LIP();
2222

23-
/// All the other interfaces except this one are the same as ESolver_KS_PW.
24-
virtual void hamilt2density_single(const int istep, const int iter, const double ethr) override;
25-
2623
void before_all_runners(const Input_para& inp, UnitCell& cell) override;
2724
void after_all_runners()override;
2825

2926
protected:
3027
virtual void iter_init(const int istep, const int iter) override;
3128
virtual void iter_finish(const int istep, int& iter) override;
3229

30+
/// All the other interfaces except this one are the same as ESolver_KS_PW.
31+
virtual void hamilt2density_single(const int istep, const int iter, const double ethr) override;
32+
3333
virtual void allocate_hamilt() override;
3434
virtual void deallocate_hamilt() override;
3535

source/module_esolver/esolver_ks_pw.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@ class ESolver_KS_PW : public ESolver_KS<T, Device>
2323

2424
void before_all_runners(const Input_para& inp, UnitCell& cell) override;
2525

26-
void init_after_vc(const Input_para& inp, UnitCell& cell) override;
27-
2826
double cal_energy() override;
2927

3028
void cal_force(ModuleBase::matrix& force) override;
3129

3230
void cal_stress(ModuleBase::matrix& stress) override;
3331

34-
virtual void hamilt2density_single(const int istep, const int iter, const double ethr) override;
35-
3632
void after_all_runners() override;
3733

3834
protected:
@@ -48,6 +44,10 @@ class ESolver_KS_PW : public ESolver_KS<T, Device>
4844

4945
virtual void others(const int istep) override;
5046

47+
virtual void hamilt2density_single(const int istep, const int iter, const double ethr) override;
48+
49+
void init_after_vc(const Input_para& inp, UnitCell& cell) override;
50+
5151
// temporary, this will be removed in the future;
5252
// Init Global class
5353
void Init_GlobalC(const Input_para& inp, UnitCell& ucell, pseudopot_cell_vnl& ppcell);

source/module_hamilt_lcao/module_dftu/dftu.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,25 @@ const hamilt::HContainer<double>* DFTU::get_dmr(int ispin) const
419419
}
420420
}
421421

422+
//! dftu occupation matrix for gamma only using dm(double)
423+
template <>
424+
void dftu_cal_occup_m(const int iter,
425+
const std::vector<std::vector<double>>& dm,
426+
const K_Vectors& kv,
427+
const double& mixing_beta,
428+
hamilt::Hamilt<double>* p_ham)
429+
{
430+
GlobalC::dftu.cal_occup_m_gamma(iter, dm, mixing_beta, p_ham);
431+
}
432+
433+
//! dftu occupation matrix for multiple k-points using dm(complex)
434+
template <>
435+
void dftu_cal_occup_m(const int iter,
436+
const std::vector<std::vector<std::complex<double>>>& dm,
437+
const K_Vectors& kv,
438+
const double& mixing_beta,
439+
hamilt::Hamilt<std::complex<double>>* p_ham)
440+
{
441+
GlobalC::dftu.cal_occup_m_k(iter, dm, kv, mixing_beta, p_ham);
442+
}
422443
} // namespace ModuleDFTU

0 commit comments

Comments
 (0)