Skip to content

Commit 7d29c43

Browse files
committed
fix dm bug in PEXSI
1 parent 639fc03 commit 7d29c43

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

source/source_estate/elecstate_lcao.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#include "elecstate_lcao.h"
2-
3-
#include "cal_dm.h"
1+
#include "source_estate/elecstate_lcao.h"
2+
#include "source_estate/cal_dm.h"
43
#include "source_base/timer.h"
54
#include "source_estate/module_dm/cal_dm_psi.h"
65
#include "source_hamilt/module_xc/xc_functional.h"
@@ -31,9 +30,10 @@ double ElecStateLCAO<std::complex<double>>::get_spin_constrain_energy()
3130
return sc.cal_escon();
3231
}
3332

34-
#ifdef __PEXSI
3533
template <>
36-
void ElecStateLCAO<double>::dm2Rho(std::vector<double*> pexsi_DM, std::vector<double*> pexsi_EDM)
34+
void ElecStateLCAO<double>::dm2Rho(std::vector<double*> pexsi_DM,
35+
std::vector<double*> pexsi_EDM,
36+
DensityMatrix<double, double>* dm)
3737
{
3838
ModuleBase::timer::tick("ElecStateLCAO", "dm2Rho");
3939

@@ -43,13 +43,15 @@ void ElecStateLCAO<double>::dm2Rho(std::vector<double*> pexsi_DM, std::vector<do
4343
nspin = 1;
4444
}
4545

46-
this->get_DM()->pexsi_EDM = pexsi_EDM;
46+
#ifdef __PEXSI
47+
dm->pexsi_EDM = pexsi_EDM;
48+
#endif
4749

4850
for (int is = 0; is < nspin; is++)
4951
{
50-
this->DM->set_DMK_pointer(is, pexsi_DM[is]);
52+
dm->set_DMK_pointer(is, pexsi_DM[is]);
5153
}
52-
DM->cal_DMR();
54+
dm->cal_DMR();
5355

5456
for (int is = 0; is < PARAM.inp.nspin; is++)
5557
{
@@ -58,14 +60,14 @@ void ElecStateLCAO<double>::dm2Rho(std::vector<double*> pexsi_DM, std::vector<do
5860
}
5961

6062
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
61-
ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho);
63+
ModuleGint::cal_gint_rho(dm->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho);
6264
if (XC_Functional::get_ked_flag())
6365
{
6466
for (int is = 0; is < PARAM.inp.nspin; is++)
6567
{
6668
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[0], this->charge->nrxx);
6769
}
68-
ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);
70+
ModuleGint::cal_gint_tau(dm->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);
6971
}
7072

7173
this->charge->renormalize_rho();
@@ -75,13 +77,13 @@ void ElecStateLCAO<double>::dm2Rho(std::vector<double*> pexsi_DM, std::vector<do
7577
}
7678

7779
template <>
78-
void ElecStateLCAO<std::complex<double>>::dm2rho(std::vector<std::complex<double>*> pexsi_DM,
79-
std::vector<std::complex<double>*> pexsi_EDM)
80+
void ElecStateLCAO<std::complex<double>>::dm2Rho(std::vector<std::complex<double>*> pexsi_DM,
81+
std::vector<std::complex<double>*> pexsi_EDM,
82+
DensityMatrix<std::complex<double>, double>* dm)
8083
{
8184
ModuleBase::WARNING_QUIT("ElecStateLCAO", "pexsi is not completed for multi-k case");
8285
}
8386

84-
#endif
8587

8688
template class ElecStateLCAO<double>; // Gamma_only case
8789
template class ElecStateLCAO<std::complex<double>>; // multi-k case

source/source_estate/elecstate_lcao.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class ElecStateLCAO : public ElecState
3737

3838
double get_spin_constrain_energy() override;
3939

40-
#ifdef __PEXSI
4140
// use for pexsi
4241

4342
/**
@@ -46,8 +45,9 @@ class ElecStateLCAO : public ElecState
4645
* @param pexsi_EDM: pointers of energy-weighed density matrix (EDMK) calculated by pexsi, needed by MD, will be
4746
* stored in DensityMatrix::pexsi_EDM
4847
*/
49-
void dm2rho(std::vector<TK*> pexsi_DM, std::vector<TK*> pexsi_EDM);
50-
#endif
48+
void dm2Rho(std::vector<TK*> pexsi_DM,
49+
std::vector<TK*> pexsi_EDM,
50+
DensityMatrix<TK, double>* dm);
5151

5252
};
5353

0 commit comments

Comments
 (0)