Skip to content

Commit 414446a

Browse files
authored
Refactor:remove cal_tau from ElecStateLCAO (#5802)
* modify the cal_tau in lcao * add template for cal_tau * updatea func for cal_tau
1 parent 028e91d commit 414446a

File tree

6 files changed

+58
-20
lines changed

6 files changed

+58
-20
lines changed

source/module_elecstate/elecstate_lcao.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "module_hamilt_lcao/module_gint/grid_technique.h"
99
#include "module_hamilt_pw/hamilt_pwdft/global.h"
1010
#include "module_parameter/parameter.h"
11+
#include "elecstate_lcao_cal_tau.h"
1112

1213
#include <vector>
1314

@@ -64,7 +65,7 @@ void ElecStateLCAO<std::complex<double>>::psiToRho(const psi::Psi<std::complex<d
6465

6566
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
6667
{
67-
this->cal_tau(psi);
68+
elecstate::lcao_cal_tau_k(gint_k, this->charge);
6869
}
6970

7071
this->charge->renormalize_rho();
@@ -99,7 +100,7 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)
99100

100101
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
101102
{
102-
this->cal_tau(psi);
103+
elecstate::lcao_cal_tau_gamma(gint_gamma, this->charge);
103104
}
104105

105106
this->charge->renormalize_rho();

source/module_elecstate/elecstate_lcao.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class ElecStateLCAO : public ElecState
4646
// virtual void psiToRho(const psi::Psi<double>& psi) override;
4747
// return current electronic density rho, as a input for constructing Hamiltonian
4848
// const double* getRho(int spin) const override;
49-
virtual void cal_tau(const psi::Psi<TK>& psi) override;
5049

5150
// update charge density for next scf step
5251
// void getNewRho() override;
Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,56 @@
11
#include "elecstate_lcao.h"
2-
2+
#include "elecstate_lcao_cal_tau.h"
33
#include "module_base/timer.h"
44

55
namespace elecstate
66
{
77

88
// calculate the kinetic energy density tau, multi-k case
9-
template <>
10-
void ElecStateLCAO<std::complex<double>>::cal_tau(const psi::Psi<std::complex<double>>& psi)
9+
void lcao_cal_tau_k(Gint_k* gint_k,
10+
Charge* charge)
1111
{
1212
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
1313

1414
for (int is = 0; is < PARAM.inp.nspin; is++)
1515
{
16-
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
16+
ModuleBase::GlobalFunc::ZEROS(charge->kin_r[is], charge->nrxx);
1717
}
18-
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
19-
this->gint_k->cal_gint(&inout1);
18+
Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
19+
gint_k->cal_gint(&inout1);
2020

2121
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
2222
return;
2323
}
2424

2525
// calculate the kinetic energy density tau, gamma-only case
26-
template <>
27-
void ElecStateLCAO<double>::cal_tau(const psi::Psi<double>& psi)
26+
void lcao_cal_tau_gamma(Gint_Gamma* gint_gamma,
27+
Charge* charge)
2828
{
2929
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
3030

3131
for (int is = 0; is < PARAM.inp.nspin; is++)
3232
{
33-
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
33+
ModuleBase::GlobalFunc::ZEROS(charge->kin_r[is], charge->nrxx);
3434
}
35-
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
36-
this->gint_gamma->cal_gint(&inout1);
35+
Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
36+
gint_gamma->cal_gint(&inout1);
3737

3838
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
3939
return;
4040
}
41-
}
41+
template <>
42+
void lcao_cal_tau<double>(Gint_Gamma* gint_gamma,
43+
Gint_k* gint_k,
44+
Charge* charge)
45+
{
46+
lcao_cal_tau_gamma(gint_gamma, charge);
47+
}
48+
template <>
49+
void lcao_cal_tau<complex<double>>(Gint_Gamma* gint_gamma,
50+
Gint_k* gint_k,
51+
Charge* charge)
52+
{
53+
lcao_cal_tau_k(gint_k, charge);
54+
}
55+
56+
} // namespace elecstate
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef ELECSTATE_LCAO_CAL_TAU_H
2+
#define ELECSTATE_LCAO_CAL_TAU_H
3+
#include "module_elecstate/module_charge/charge.h"
4+
#include "module_hamilt_lcao/module_gint/gint_gamma.h"
5+
#include "module_hamilt_lcao/module_gint/gint_k.h"
6+
namespace elecstate
7+
{
8+
9+
void lcao_cal_tau_k(Gint_k* gint_k,
10+
Charge* charge);
11+
12+
void lcao_cal_tau_gamma(Gint_Gamma* gint_gamma,
13+
Charge* charge);
14+
15+
template <typename T>
16+
void lcao_cal_tau(Gint_Gamma* gint_gamma,
17+
Gint_k* gint_k,
18+
Charge* charge);
19+
20+
}
21+
#endif

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "module_base/global_function.h"
3535
#include "module_cell/module_neighbor/sltk_grid_driver.h"
3636
#include "module_elecstate/cal_ux.h"
37+
#include "module_elecstate/elecstate_lcao_cal_tau.h"
3738
#include "module_elecstate/module_charge/symmetry_rho.h"
3839
#include "module_elecstate/occupy.h"
3940
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h" // need divide_HS_in_frag
@@ -927,8 +928,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
927928
// 1) calculate the kinetic energy density tau, sunliang 2024-09-18
928929
if (PARAM.inp.out_elf[0] > 0)
929930
{
930-
assert(this->psi != nullptr);
931-
this->pelec->cal_tau(*(this->psi));
931+
elecstate::lcao_cal_tau<TK>(&(this->GG),
932+
&(this->GK),
933+
this->pelec->charge);
932934
}
933935

934936
//! 2) call after_scf() of ESolver_KS

source/module_rdmft/update_state_rdmft.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "module_elecstate/module_dm/cal_dm_psi.h"
99
#include "module_elecstate/module_dm/density_matrix.h"
1010
#include "module_elecstate/module_charge/symmetry_rho.h"
11-
11+
#include "module_elecstate/elecstate_lcao_cal_tau.h"
1212

1313
namespace rdmft
1414
{
@@ -118,7 +118,7 @@ void RDMFT<TK, TR>::update_charge(UnitCell& ucell)
118118
// }
119119
// Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau);
120120
// GG->cal_gint(&inout1);
121-
this->pelec->cal_tau(wfc);
121+
elecstate::lcao_cal_tau_gamma(GG, charge);
122122
}
123123

124124
charge->renormalize_rho();
@@ -148,7 +148,7 @@ void RDMFT<TK, TR>::update_charge(UnitCell& ucell)
148148
// }
149149
// Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau);
150150
// GK->cal_gint(&inout1);
151-
this->pelec->cal_tau(wfc);
151+
elecstate::lcao_cal_tau_k(GK, charge);
152152
}
153153

154154
charge->renormalize_rho();

0 commit comments

Comments
 (0)