Skip to content

Commit e12c403

Browse files
authored
Remove DM from elecstate (#6675)
* 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
1 parent 82c3edb commit e12c403

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+649
-619
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ OBJS_LCAO=evolve_elec.o\
643643
LCAO_init_basis.o\
644644
setup_exx.o\
645645
setup_deepks.o\
646+
setup_dm.o\
646647
rho_tau_lcao.o\
647648
center2_orb.o\
648649
center2_orb-orb11.o\

source/source_esolver/esolver_dm2rho.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,22 @@ void ESolver_DM2rho<TK, TR>::runner(UnitCell& ucell, const int istep)
4646

4747
ESolver_KS_LCAO<TK, TR>::before_scf(ucell, istep);
4848

49-
auto* estate = dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec);
50-
51-
if(!estate)
52-
{
53-
ModuleBase::WARNING_QUIT("ESolver_DM2rho::after_scf","pelec does not exist");
54-
}
55-
5649
// file name of DM
5750
std::string zipname = "output_DM0.npz";
58-
elecstate::DensityMatrix<TK, double>* dm = estate->get_DM();
5951

6052
// read DM from file
61-
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(dm->get_DMR_pointer(1)));
53+
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(this->dmat.dm->get_DMR_pointer(1)));
6254

6355
// if nspin=2, need extra reading
6456
if (PARAM.inp.nspin == 2)
6557
{
6658
zipname = "output_DM1.npz";
67-
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(dm->get_DMR_pointer(2)));
59+
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(this->dmat.dm->get_DMR_pointer(2)));
6860
}
6961

7062
// it's dangerous to design psiToRho function like this, mohan note 20251024
7163
// this->pelec->psiToRho(*this->psi);
72-
LCAO_domain::dm2rho(estate->DM->get_DMR_vector(), PARAM.inp.nspin, &this->chr);
64+
LCAO_domain::dm2rho(this->dmat.dm->get_DMR_vector(), PARAM.inp.nspin, &this->chr);
7365

7466
int nspin0 = PARAM.inp.nspin == 2 ? 2 : 1;
7567

source/source_esolver/esolver_double_xc.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void ESolver_DoubleXC<TK, TR>::before_all_runners(UnitCell& ucell, const Input_p
8484
}
8585

8686
// 6) initialize the density matrix
87-
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec_base)->init_DM(&this->kv, &(this->pv), PARAM.inp.nspin);
87+
this->dmat_base.allocate_dm(&this->kv, &this->pv, PARAM.inp.nspin);
8888

8989
// 10) inititlize the charge density
9090
this->chr_base.allocate(PARAM.inp.nspin);
@@ -138,8 +138,6 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
138138
}
139139
if (this->p_hamilt_base == nullptr)
140140
{
141-
elecstate::DensityMatrix<TK, double>* DM = dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec_base)->get_DM();
142-
143141
this->p_hamilt_base = new hamilt::HamiltLCAO<TK, TR>(
144142
ucell,
145143
this->gd,
@@ -148,7 +146,7 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
148146
this->kv,
149147
this->two_center_bundle_,
150148
this->orb_,
151-
DM,
149+
this->dmat_base.dm,
152150
this->deepks,
153151
istep,
154152
this->exx_nao);
@@ -159,13 +157,11 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
159157
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
160158

161159
// DMR should be same size with Hamiltonian(R)
162-
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec_base)
163-
->get_DM()
164-
->init_DMR(*(dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(this->p_hamilt_base)->getHR()));
160+
this->dmat_base.dm->init_DMR(*(dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(this->p_hamilt_base)->getHR()));
165161

166162
if (istep > 0)
167163
{
168-
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec_base)->get_DM()->cal_DMR();
164+
this->dmat_base.dm->cal_DMR();
169165
}
170166

171167
ModuleBase::timer::tick("ESolver_DoubleXC", "before_scf");
@@ -226,23 +222,23 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
226222
std::shared_ptr<LCAO_Deepks<TK>> ld_shared_ptr(&this->deepks.ld, [](LCAO_Deepks<TK>*) {});
227223
LCAO_Deepks_Interface<TK, TR> deepks_interface(ld_shared_ptr);
228224

229-
deepks_interface.out_deepks_labels(this->pelec->f_en.etot,
230-
this->kv.get_nks(),
231-
ucell.nat,
232-
PARAM.globalv.nlocal,
233-
this->pelec->ekb,
234-
this->kv.kvec_d,
235-
ucell,
236-
this->orb_,
237-
this->gd,
238-
&(this->pv),
239-
*(this->psi),
240-
dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
241-
p_ham_deepks,
242-
iter,
243-
conv_esolver,
244-
GlobalV::MY_RANK,
245-
GlobalV::ofs_running);
225+
deepks_interface.out_deepks_labels(this->pelec->f_en.etot,
226+
this->kv.get_nks(),
227+
ucell.nat,
228+
PARAM.globalv.nlocal,
229+
this->pelec->ekb,
230+
this->kv.kvec_d,
231+
ucell,
232+
this->orb_,
233+
this->gd,
234+
&(this->pv),
235+
*(this->psi),
236+
this->dmat.dm,
237+
p_ham_deepks,
238+
iter,
239+
conv_esolver,
240+
GlobalV::MY_RANK,
241+
GlobalV::ofs_running);
246242
#endif
247243

248244
// restore to density after charge mixing
@@ -352,9 +348,12 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
352348
auto _pes_lcao = dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec);
353349
for (int ik = 0; ik < nks; ik++)
354350
{
355-
_pes_lcao_base->get_DM()->set_DMK_pointer(ik, _pes_lcao->get_DM()->get_DMK_pointer(ik));
351+
// mohan update 2025-11-03
352+
this->dmat_base.dm->set_DMK_pointer(ik, this->dmat.dm->get_DMK_pointer(ik));
353+
// _pes_lcao_base->get_DM()->set_DMK_pointer(ik, _pes_lcao->get_DM()->get_DMK_pointer(ik));
356354
}
357-
_pes_lcao_base->get_DM()->cal_DMR();
355+
this->dmat_base.dm->cal_DMR();
356+
// _pes_lcao_base->get_DM()->cal_DMR();
358357
_pes_lcao_base->ekb = _pes_lcao->ekb;
359358
_pes_lcao_base->wg = _pes_lcao->wg;
360359
}
@@ -386,6 +385,7 @@ void ESolver_DoubleXC<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& fo
386385
this->gd,
387386
this->pv,
388387
this->pelec_base,
388+
this->dmat_base, // mohan add 2025-11-03
389389
this->psi,
390390
this->two_center_bundle_,
391391
this->orb_,

source/source_esolver/esolver_double_xc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class ESolver_DoubleXC : public ESolver_KS_LCAO<TK, TR>
3232
//! Electronic states
3333
elecstate::ElecState* pelec_base = nullptr;
3434

35+
//! Density Matrix, mohan add 2025-11-03
36+
LCAO_domain::Setup_DM<TK> dmat_base;
37+
3538
//! Electorn charge density
3639
Charge chr_base;
3740
};

source/source_esolver/esolver_fp.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ void ESolver_FP::before_all_runners(UnitCell& ucell, const Input_para& inp)
5454

5555
// write geometry file
5656
ModuleIO::CifParser::write(PARAM.globalv.global_out_dir + "STRU.cif",
57-
ucell,
58-
"# Generated by ABACUS ModuleIO::CifParser",
59-
"data_?");
57+
ucell, "# Generated by ABACUS ModuleIO::CifParser", "data_?");
6058

6159
// init charge extrapolation
6260
this->CE.Init_CE(inp.nspin, ucell.nat, this->pw_rhod->nrxx, inp.chg_extrap);

source/source_esolver/esolver_ks.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
4545
{
4646
ModuleBase::TITLE("ESolver_KS", "before_all_runners");
4747

48-
//! 1) init "before_all_runniers" in ESolver_FP
48+
//! 1) setup "before_all_runniers" in ESolver_FP
4949
ESolver_FP::before_all_runners(ucell, inp);
5050

5151
//! 2) setup some parameters
@@ -67,7 +67,7 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
6767

6868
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SETUP UNITCELL");
6969

70-
//! 4) setup Exc for the first element '0', because all elements have same exc
70+
//! 4) setup Exc for the first element '0' (all elements have same exc)
7171
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
7272

7373
//! 5) setup the charge mixing parameters
@@ -84,7 +84,7 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
8484
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SYMMETRY");
8585
}
8686

87-
//! 7) Setup the k points according to symmetry.
87+
//! 7) setup k points in the Brillouin zone according to symmetry.
8888
this->kv.set(ucell,ucell.symm, inp.kpoint_file, inp.nspin, ucell.G, ucell.latvec, GlobalV::ofs_running);
8989
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS");
9090

@@ -99,19 +99,12 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
9999
this->pw_rhod->nplane, this->pw_rhod->nrxx, pw_big->nbz, pw_big->bz);
100100

101101
//! 11) calculate the structure factor
102-
this->sf.setup_structure_factor(&ucell, Pgrid, this->pw_rhod);
102+
this->sf.setup(&ucell, Pgrid, this->pw_rhod);
103103
}
104104

105105
template <typename T, typename Device>
106106
void ESolver_KS<T, Device>::hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr)
107-
{
108-
ModuleBase::timer::tick(this->classname, "hamilt2rho_single");
109-
// Temporarily, before HSolver is constructed, it should be overrided by
110-
// LCAO, PW, SDFT and TDDFT.
111-
// After HSolver is constructed, LCAO, PW, SDFT should delete their own
112-
// hamilt2rho_single() and use:
113-
ModuleBase::timer::tick(this->classname, "hamilt2rho_single");
114-
}
107+
{}
115108

116109
template <typename T, typename Device>
117110
void ESolver_KS<T, Device>::hamilt2rho(UnitCell& ucell, const int istep, const int iter, const double ethr)

0 commit comments

Comments
 (0)