Skip to content

Commit dad7304

Browse files
Fix DM in PEXSI (#6689)
* add update_pot in source_estate * split update_pot in rt-TDDFT into two functions, one is the original update_pot, which is replaced by update_pot function in estate, the other is save2 function used in after_iter * fix bugs * update * update esolver_ks * small updates * small bug fixed * update E_bandgap to E_gap(k) * delete rho_restart file * change setup_parameters to print_parameters * move setup_pw.cpp to setup_pwwfc.cpp in module_pwdft * update esolver, small things * delete some old_gint codes in esolver * fix bugs, update outputs * fix bug in tests * change efermi to Efermi in fp_energy.h * fix bugs * fix exd and exc in ctrl_runner_lcao * fix cmake * fix bug * delete lcao_after_scf and lcao_before_scf * modify codes including read_wfc_nao to delete pelec, add setup_psi_lcao codes * fix bugs * delete grid integral in FORCE_STRESS * move read psi to esolver, not in psi * fix system bug * fix bug in read_wfc_nao.h * change PARAM.inp to inp * fix bugs * delete omega in pelec, remove some deepks codes to setup_deepks.cpp * remove exx redundant parameters in Hamilt_LCAO * Fix circular dependencies of header files. * fix bugs in MLALGO * refactor exx lcao * add rho_tau_lcao files * fix bug in setup_deepks * move rho_tau_lcao to source_lcao * remove old psiToRho function in elecstate_lcao and replace with new rho_tau_lcao * update estate * fix bug in ELF * fix bug * move DM outside of pelec * deal with init_dm functions * remove pelec in dftu, replace with dmk_d(ouble) and dmk_c(omplex) * fix cal_ldos with DM * update delta_spin * update delta spin run_lambda_loop * the big issue to remove dm may be caused by cal_mw_from_lambda * remove some DM * keep updating DM * refactor some DM in double_xc * now all functions can be compiled * fix it * update again * add and compile setup_dm * update fix bugs * simplify dm * one more fix * now I can compile the code * fix some bugs in EXX version * fix FORCE_STRESS * fix 2 * fix 3 * fix 4 * fix 5 * improve esolver_ks_lcao * improve again * comment out psi2rho in init_dm * clean esolver_ks_lcao * update structure_factor * update sf * update * fix sf * fix * fix structure factor * fix dm bug in PEXSI * fix PEXSI * Update edm.cpp * fix edm * Update hsolver_lcao.cpp * Update hsolver_lcao.cpp --------- Co-authored-by: Levi Zhou <[email protected]>
1 parent efbf84e commit dad7304

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

source/source_estate/elecstate_lcao.cpp

Lines changed: 16 additions & 14 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,25 +30,28 @@ 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
{
38-
ModuleBase::timer::tick("ElecStateLCAO", "dm2Rho");
38+
ModuleBase::timer::tick("ElecStateLCAO", "dm2rho");
3939

4040
int nspin = PARAM.inp.nspin;
4141
if (PARAM.inp.nspin == 4)
4242
{
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,30 +60,30 @@ 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();
7274

73-
ModuleBase::timer::tick("ElecStateLCAO", "dm2Rho");
75+
ModuleBase::timer::tick("ElecStateLCAO", "dm2rho");
7476
return;
7577
}
7678

7779
template <>
7880
void ElecStateLCAO<std::complex<double>>::dm2rho(std::vector<std::complex<double>*> pexsi_DM,
79-
std::vector<std::complex<double>*> pexsi_EDM)
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

source/source_hsolver/hsolver_lcao.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void HSolverLCAO<TK, Device>::solve(hamilt::Hamilt<TK>* pHamilt,
112112
else if (this->method == "pexsi")
113113
{
114114
#ifdef __PEXSI // other purification methods should follow this routine
115-
DiagoPexsi<T> pe(ParaV);
115+
DiagoPexsi<TK> pe(ParaV);
116116
for (int ik = 0; ik < psi.get_nk(); ++ik)
117117
{
118118
/// update H(k) for each k point
@@ -121,10 +121,10 @@ void HSolverLCAO<TK, Device>::solve(hamilt::Hamilt<TK>* pHamilt,
121121
// solve eigenvector and eigenvalue for H(k)
122122
pe.diag(pHamilt, psi, nullptr);
123123
}
124-
auto _pes = dynamic_cast<elecstate::ElecStateLCAO<T>*>(pes);
124+
auto _pes = dynamic_cast<elecstate::ElecStateLCAO<TK>*>(pes);
125125
pes->f_en.eband = pe.totalFreeEnergy;
126126
// maybe eferm could be dealt with in the future
127-
_pes->dm2rho(dm, pe.EDM);
127+
_pes->dm2rho(pe.DM, pe.EDM, &dm);
128128
#endif
129129
}
130130

source/source_lcao/edm.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ elecstate::DensityMatrix<double, double> Force_LCAO<double>::cal_edm(const elecs
3131
#ifdef __PEXSI
3232
if (PARAM.inp.ks_solver == "pexsi")
3333
{
34-
auto pes = dynamic_cast<const elecstate::ElecStateLCAO<double>*>(pelec);
34+
// auto pes = dynamic_cast<const elecstate::ElecStateLCAO<double>*>(pelec);
3535
for (int ik = 0; ik < nspin; ik++)
3636
{
37-
edm.set_DMK_pointer(ik, pes->get_DM()->pexsi_EDM[ik]);
37+
edm.set_DMK_pointer(ik, dm.pexsi_EDM[ik]);
3838
}
3939

4040
}
@@ -47,7 +47,8 @@ elecstate::DensityMatrix<double, double> Force_LCAO<double>::cal_edm(const elecs
4747
}
4848

4949
template<>
50-
elecstate::DensityMatrix<std::complex<double>, double> Force_LCAO<std::complex<double>>::cal_edm(const elecstate::ElecState* pelec,
50+
elecstate::DensityMatrix<std::complex<double>, double> Force_LCAO<std::complex<double>>::cal_edm(
51+
const elecstate::ElecState* pelec,
5152
const psi::Psi<std::complex<double>>& psi,
5253
const elecstate::DensityMatrix<std::complex<double>, double>& dm,
5354
const K_Vectors& kv,

0 commit comments

Comments
 (0)