11#include " esolver_ks_lcao.h"
22#include " source_estate/elecstate_tools.h"
33#include " source_lcao/module_deltaspin/spin_constrain.h"
4- #include " source_io/read_wfc_nao.h"
54#include " source_lcao/hs_matrix_k.hpp" // there may be multiple definitions if using hpp
6- #include " source_estate/cal_ux.h"
75#include " source_estate/module_charge/symmetry_rho.h"
86#include " source_lcao/LCAO_domain.h" // need DeePKS_init
97#include " source_lcao/module_dftu/dftu.h"
1614#endif
1715#include " source_lcao/module_rdmft/rdmft.h"
1816#include " source_estate/module_charge/chgmixing.h" // use charge mixing, mohan add 20251006
19- #include " source_estate/module_dm/setup_dm .h" // setup dm from electronic wave functions
17+ #include " source_estate/module_dm/init_dm .h" // init dm from electronic wave functions
2018#include " source_io/ctrl_runner_lcao.h" // use ctrl_runner_lcao()
2119#include " source_io/ctrl_iter_lcao.h" // use ctrl_iter_lcao()
2220#include " source_io/ctrl_scf_lcao.h" // use ctrl_scf_lcao()
2321#include " source_psi/setup_psi.h" // mohan add 20251019
2422#include " source_io/read_wfc_nao.h"
2523#include " source_io/print_info.h"
24+ #include " source_lcao/rho_tau_lcao.h" // mohan add 20251024
2625
2726namespace ModuleESolver
2827{
@@ -110,7 +109,6 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
110109
111110 // 11) init charge density
112111 this ->chr .allocate (inp.nspin );
113- this ->pelec ->omega = ucell.omega ;
114112
115113 // 12) init potentials
116114 if (this ->pelec ->pot == nullptr )
@@ -199,15 +197,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
199197
200198 this ->p_hamilt = new hamilt::HamiltLCAO<TK, TR>(
201199 ucell, this ->gd , &this ->pv , this ->pelec ->pot , this ->kv ,
202- two_center_bundle_, orb_, DM, this ->deepks
203- #ifdef __EXX
204- ,
205- istep,
206- GlobalC::exx_info.info_ri .real_number ? &this ->exx_nao .exd ->two_level_step : &this ->exx_nao .exc ->two_level_step ,
207- GlobalC::exx_info.info_ri .real_number ? &this ->exx_nao .exd ->get_Hexxs () : nullptr ,
208- GlobalC::exx_info.info_ri .real_number ? nullptr : &this ->exx_nao .exc ->get_Hexxs ()
209- #endif
210- );
200+ two_center_bundle_, orb_, DM, this ->deepks , istep, exx_nao);
211201 }
212202
213203 // 9) for each ionic step, the overlap <phi|alpha> must be rebuilt
@@ -224,19 +214,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
224214 }
225215
226216 // 11) set xc type before the first cal of xc in pelec->init_scf, Peize Lin add 2016-12-03
227- #ifdef __EXX
228- if (PARAM.inp .calculation != " nscf" )
229- {
230- if (GlobalC::exx_info.info_ri .real_number )
231- {
232- this ->exx_nao .exd ->exx_beforescf (istep, this ->kv , *this ->p_chgmix , ucell, orb_);
233- }
234- else
235- {
236- this ->exx_nao .exc ->exx_beforescf (istep, this ->kv , *this ->p_chgmix , ucell, orb_);
237- }
238- }
239- #endif
217+ this ->exx_nao .before_scf (ucell, this ->kv , orb_, this ->p_chgmix , istep, PARAM.inp );
240218
241219 // 12) init_scf, should be before_scf? mohan add 2025-03-10
242220 this ->pelec ->init_scf (istep, ucell, this ->Pgrid , this ->sf .strucFac , this ->locpp .numeric , ucell.symm );
@@ -318,10 +296,6 @@ void ESolver_KS_LCAO<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& for
318296 ModuleBase::timer::tick (" ESolver_KS_LCAO" , " cal_force" );
319297}
320298
321- // ------------------------------------------------------------------------------
322- // ! the 7th function of ESolver_KS_LCAO: cal_stress
323- // ! mohan add 2024-05-11
324- // ------------------------------------------------------------------------------
325299template <typename TK, typename TR>
326300void ESolver_KS_LCAO<TK, TR>::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress)
327301{
@@ -406,10 +380,11 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
406380 {
407381 // the following steps are only needed in the first outer exx loop
408382 exx_two_level_step
409- = GlobalC::exx_info.info_ri .real_number ? this ->exx_nao .exd ->two_level_step : this ->exx_nao .exc ->two_level_step ;
383+ = GlobalC::exx_info.info_ri .real_number ?
384+ this ->exx_nao .exd ->two_level_step : this ->exx_nao .exc ->two_level_step ;
410385 }
411386#endif
412- elecstate::setup_dm <TK>(ucell, estate, this ->psi , this ->chr , iter, exx_two_level_step);
387+ elecstate::init_dm <TK>(ucell, estate, this ->psi , this ->chr , iter, exx_two_level_step);
413388 }
414389
415390#ifdef __EXX
@@ -495,7 +470,7 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2rho_single(UnitCell& ucell, int istep, int
495470 if (!skip_solve)
496471 {
497472 hsolver::HSolverLCAO<TK> hsolver_lcao_obj (&(this ->pv ), PARAM.inp .ks_solver );
498- hsolver_lcao_obj.solve (this ->p_hamilt , this ->psi [0 ], this ->pelec , skip_charge);
473+ hsolver_lcao_obj.solve (this ->p_hamilt , this ->psi [0 ], this ->pelec , this -> chr , PARAM. inp . nspin , skip_charge);
499474 }
500475
501476 // 4) EXX
@@ -563,15 +538,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
563538 }
564539
565540 // 2) for deepks, calculate delta_e, output labels during electronic steps
566- #ifdef __MLALGO
567- if (PARAM.inp .deepks_scf )
568- {
569- this ->deepks .ld .dpks_cal_e_delta_band (dm_vec, this ->kv .get_nks ());
570- DeePKS_domain::update_dmr (this ->kv .kvec_d , dm_vec, ucell, orb_, this ->pv , this ->gd , this ->deepks .ld .dm_r );
571- estate->f_en .edeepks_scf = this ->deepks .ld .E_delta - this ->deepks .ld .e_delta_band ;
572- estate->f_en .edeepks_delta = this ->deepks .ld .E_delta ;
573- }
574- #endif
541+ this ->deepks .delta_e (ucell, this ->kv , this ->orb_ , this ->pv , this ->gd , dm_vec, this ->pelec ->f_en , PARAM.inp );
575542
576543 // 3) for delta spin
577544 if (PARAM.inp .sc_mag_switch )
@@ -617,9 +584,6 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
617584 ModuleBase::TITLE (" ESolver_KS_LCAO" , " after_scf" );
618585 ModuleBase::timer::tick (" ESolver_KS_LCAO" , " after_scf" );
619586
620- // ! 1) call after_scf() of ESolver_KS
621- ESolver_KS<TK>::after_scf (ucell, istep, conv_esolver);
622-
623587 auto * estate = dynamic_cast <elecstate::ElecStateLCAO<TK>*>(this ->pelec );
624588 auto * hamilt_lcao = dynamic_cast <hamilt::HamiltLCAO<TK, TR>*>(this ->p_hamilt );
625589
@@ -633,6 +597,15 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
633597 ModuleBase::WARNING_QUIT (" ESolver_KS_LCAO::after_scf" ," p_hamilt does not exist" );
634598 }
635599
600+ if (PARAM.inp .out_elf [0 ] > 0 )
601+ {
602+ LCAO_domain::dm2tau (estate->DM ->get_DMR_vector (), PARAM.inp .nspin , estate->charge );
603+ }
604+
605+ // ! 1) call after_scf() of ESolver_KS
606+ ESolver_KS<TK>::after_scf (ucell, istep, conv_esolver);
607+
608+
636609 // ! 2) output of lcao every few ionic steps
637610 ModuleIO::ctrl_scf_lcao<TK, TR>(ucell,
638611 PARAM.inp , this ->kv , estate, this ->pv ,
@@ -654,7 +627,6 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
654627 ModuleBase::timer::tick (" ESolver_KS_LCAO" , " after_scf" );
655628}
656629
657-
658630template class ESolver_KS_LCAO <double , double >;
659631template class ESolver_KS_LCAO <std::complex <double >, double >;
660632template class ESolver_KS_LCAO <std::complex <double >, std::complex <double >>;
0 commit comments