@@ -91,7 +91,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
9191
9292
9393 // 7) init DMK, but DMR is constructed in before_scf()
94- dynamic_cast <elecstate::ElecStateLCAO<TK>*>( this ->pelec )-> init_DM (&this ->kv , &( this ->pv ) , inp.nspin );
94+ this ->dmat . allocate_dm (&this ->kv , &this ->pv , inp.nspin );
9595
9696 // 8) init exact exchange calculations
9797 this ->exx_nao .before_runner (ucell, this ->kv , this ->orb_ , this ->pv , inp);
@@ -153,12 +153,6 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
153153 // ! 1) call before_scf() of ESolver_KS.
154154 ESolver_KS<TK>::before_scf (ucell, istep);
155155
156- auto * estate = dynamic_cast <elecstate::ElecStateLCAO<TK>*>(this ->pelec );
157- if (!estate)
158- {
159- ModuleBase::WARNING_QUIT (" ESolver_KS_LCAO::before_scf" ," pelec does not exist" );
160- }
161-
162156 // ! 2) find search radius
163157 double search_radius = atom_arrange::set_sr_NL (GlobalV::ofs_running,
164158 PARAM.inp .out_level , orb_.get_rcutmax_Phi (), ucell.infoNL .get_rcutmax_Beta (),
@@ -193,11 +187,9 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
193187 }
194188 if (this ->p_hamilt == nullptr )
195189 {
196- elecstate::DensityMatrix<TK, double >* DM = estate->get_DM ();
197-
198190 this ->p_hamilt = new hamilt::HamiltLCAO<TK, TR>(
199191 ucell, this ->gd , &this ->pv , this ->pelec ->pot , this ->kv ,
200- two_center_bundle_, orb_, DM , this ->deepks , istep, exx_nao);
192+ two_center_bundle_, orb_, this -> dmat . dm , this ->deepks , istep, exx_nao);
201193 }
202194
203195 // 9) for each ionic step, the overlap <phi|alpha> must be rebuilt
@@ -210,7 +202,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
210202 spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance ();
211203 sc.init_sc (PARAM.inp .sc_thr , PARAM.inp .nsc , PARAM.inp .nsc_min , PARAM.inp .alpha_trial ,
212204 PARAM.inp .sccut , PARAM.inp .sc_drop_thr , ucell, &(this ->pv ),
213- PARAM.inp .nspin , this ->kv , this ->p_hamilt , this ->psi , this ->pelec );
205+ PARAM.inp .nspin , this ->kv , this ->p_hamilt , this ->psi , this ->dmat . dm , this -> pelec );
214206 }
215207
216208 // 11) set xc type before the first cal of xc in pelec->init_scf, Peize Lin add 2016-12-03
@@ -226,7 +218,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
226218 {
227219 ModuleBase::WARNING_QUIT (" ESolver_KS_LCAO::before_scf" ," p_hamilt does not exist" );
228220 }
229- estate-> get_DM () ->init_DMR (*hamilt_lcao->getHR ());
221+ this -> dmat . dm ->init_DMR (*hamilt_lcao->getHR ());
230222
231223#ifdef __MLALGO
232224 // 14) initialize DMR of DeePKS
@@ -238,7 +230,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
238230 // 2. DMK in DensityMatrix is empty (istep == 0), then DMR is initialized by zeros
239231 if (istep > 0 )
240232 {
241- estate-> get_DM () ->cal_DMR ();
233+ this -> dmat . dm ->cal_DMR ();
242234 }
243235
244236 // 16) the electron charge density should be symmetrized,
@@ -282,7 +274,7 @@ void ESolver_KS_LCAO<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& for
282274
283275 fsl.getForceStress (ucell, PARAM.inp .cal_force , PARAM.inp .cal_stress ,
284276 PARAM.inp .test_force , PARAM.inp .test_stress ,
285- this ->gd , this ->pv , this ->pelec , this ->psi ,
277+ this ->gd , this ->pv , this ->pelec , this ->dmat , this -> psi ,
286278 two_center_bundle_, orb_, force, this ->scs ,
287279 this ->locpp , this ->sf , this ->kv ,
288280 this ->pw_rho , this ->solvent , this ->deepks ,
@@ -341,7 +333,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
341333 }
342334
343335 ModuleIO::ctrl_runner_lcao<TK, TR>(ucell,
344- PARAM.inp , this ->kv , estate, this ->pv , this ->Pgrid ,
336+ PARAM.inp , this ->kv , estate, this ->dmat , this -> pv , this ->Pgrid ,
345337 this ->gd , this ->psi , this ->chr , hamilt_lcao,
346338 this ->two_center_bundle_ ,
347339 this ->orb_ , this ->pw_rho , this ->pw_rhod ,
@@ -365,9 +357,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
365357 ModuleBase::WARNING_QUIT (" ESolver_KS_LCAO::iter_init" ," pelec does not exist" );
366358 }
367359
368- elecstate::DensityMatrix<TK, double >* dm = estate->get_DM ();
369-
370- module_charge::chgmixing_ks_lcao (iter, this ->p_chgmix , dm->get_DMR_pointer (1 )->get_nnr (), PARAM.inp );
360+ module_charge::chgmixing_ks_lcao (iter, this ->p_chgmix , this ->dmat .dm ->get_DMR_pointer (1 )->get_nnr (), PARAM.inp );
371361
372362 // mohan update 2012-06-05
373363 estate->f_en .deband_harris = estate->cal_delta_eband (ucell);
@@ -384,7 +374,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
384374 this ->exx_nao .exd ->two_level_step : this ->exx_nao .exc ->two_level_step ;
385375 }
386376#endif
387- elecstate::init_dm<TK>(ucell, estate, this ->psi , this ->chr , iter, exx_two_level_step);
377+ elecstate::init_dm<TK>(ucell, estate, this ->dmat , this -> psi , this ->chr , iter, exx_two_level_step);
388378 }
389379
390380#ifdef __EXX
@@ -393,11 +383,11 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
393383 {
394384 if (GlobalC::exx_info.info_ri .real_number )
395385 {
396- this ->exx_nao .exd ->exx_eachiterinit (istep, ucell, *dm, this ->kv , iter);
386+ this ->exx_nao .exd ->exx_eachiterinit (istep, ucell, *this -> dmat . dm , this ->kv , iter);
397387 }
398388 else
399389 {
400- this ->exx_nao .exc ->exx_eachiterinit (istep, ucell, *dm, this ->kv , iter);
390+ this ->exx_nao .exc ->exx_eachiterinit (istep, ucell, *this -> dmat . dm , this ->kv , iter);
401391 }
402392 }
403393#endif
@@ -406,7 +396,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
406396 {
407397 if (istep != 0 || iter != 1 )
408398 {
409- GlobalC::dftu.set_dmr (dm);
399+ GlobalC::dftu.set_dmr (this -> dmat . dm );
410400 }
411401 // Calculate U and J if Yukawa potential is used
412402 GlobalC::dftu.cal_slater_UJ (ucell, this ->chr .rho , this ->pw_rho ->nrxx );
@@ -432,7 +422,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
432422 // save density matrix DMR for mixing
433423 if (PARAM.inp .mixing_restart > 0 && PARAM.inp .mixing_dmr && this ->p_chgmix ->mixing_restart_count > 0 )
434424 {
435- dm->save_DMR ();
425+ this -> dmat . dm ->save_DMR ();
436426 }
437427}
438428
@@ -470,7 +460,8 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2rho_single(UnitCell& ucell, int istep, int
470460 if (!skip_solve)
471461 {
472462 hsolver::HSolverLCAO<TK> hsolver_lcao_obj (&(this ->pv ), PARAM.inp .ks_solver );
473- hsolver_lcao_obj.solve (this ->p_hamilt , this ->psi [0 ], this ->pelec , this ->chr , PARAM.inp .nspin , skip_charge);
463+ hsolver_lcao_obj.solve (this ->p_hamilt , this ->psi [0 ], this ->pelec , *this ->dmat .dm ,
464+ this ->chr , PARAM.inp .nspin , skip_charge);
474465 }
475466
476467 // 4) EXX
@@ -518,7 +509,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
518509 ModuleBase::WARNING_QUIT (" ESolver_KS_LCAO::iter_finish" ," p_hamilt does not exist" );
519510 }
520511
521- const std::vector<std::vector<TK>>& dm_vec = estate-> get_DM () ->get_DMK_vector ();
512+ const std::vector<std::vector<TK>>& dm_vec = this -> dmat . dm ->get_DMK_vector ();
522513
523514 // 1) calculate the local occupation number matrix and energy correction in DFT+U
524515 if (PARAM.inp .dft_plus_u )
@@ -559,8 +550,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
559550 {
560551 if (PARAM.inp .mixing_restart > 0 && this ->p_chgmix ->mixing_restart_count > 0 && PARAM.inp .mixing_dmr )
561552 {
562- elecstate::DensityMatrix<TK, double >* dm = estate->get_DM ();
563- this ->p_chgmix ->mix_dmr (dm);
553+ this ->p_chgmix ->mix_dmr (this ->dmat .dm );
564554 }
565555 }
566556
@@ -571,7 +561,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
571561 }
572562
573563 // control the output related to the finished iteration
574- ModuleIO::ctrl_iter_lcao<TK, TR>(ucell, PARAM.inp , this ->kv , estate,
564+ ModuleIO::ctrl_iter_lcao<TK, TR>(ucell, PARAM.inp , this ->kv , estate, * this -> dmat . dm ,
575565 this ->pv , this ->gd , this ->psi , this ->chr , this ->p_chgmix ,
576566 hamilt_lcao, this ->orb_ , this ->deepks ,
577567 this ->exx_nao , iter, istep, conv_esolver, this ->scf_ene_thr );
@@ -599,16 +589,19 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
599589
600590 if (PARAM.inp .out_elf [0 ] > 0 )
601591 {
602- LCAO_domain::dm2tau (estate-> DM ->get_DMR_vector (), PARAM.inp .nspin , estate ->charge );
592+ LCAO_domain::dm2tau (this -> dmat . dm ->get_DMR_vector (), PARAM.inp .nspin , this -> pelec ->charge );
603593 }
604594
605595 // ! 1) call after_scf() of ESolver_KS
606596 ESolver_KS<TK>::after_scf (ucell, istep, conv_esolver);
607597
608598
609599 // ! 2) output of lcao every few ionic steps
600+
601+
602+
610603 ModuleIO::ctrl_scf_lcao<TK, TR>(ucell,
611- PARAM.inp , this ->kv , estate, this ->pv ,
604+ PARAM.inp , this ->kv , estate, this ->dmat . dm , this -> pv ,
612605 this ->gd , this ->psi , hamilt_lcao,
613606 this ->two_center_bundle_ ,
614607 this ->orb_ , this ->pw_wfc , this ->pw_rho ,
0 commit comments