6767namespace ModuleESolver
6868{
6969
70- // ------------------------------------------------------------------------------
71- // ! the 1st function of ESolver_KS_LCAO: constructor
72- // ------------------------------------------------------------------------------
7370template <typename TK, typename TR>
7471ESolver_KS_LCAO<TK, TR>::ESolver_KS_LCAO()
7572{
7673 this ->classname = " ESolver_KS_LCAO" ;
7774 this ->basisname = " LCAO" ;
75+
7876#ifdef __EXX
7977 // 1. currently this initialization must be put in constructor rather than `before_all_runners()`
8078 // because the latter is not reused by ESolver_LCAO_TDDFT,
@@ -94,47 +92,30 @@ ESolver_KS_LCAO<TK, TR>::ESolver_KS_LCAO()
9492#endif
9593}
9694
97- // ------------------------------------------------------------------------------
98- // ! the 2nd function of ESolver_KS_LCAO: deconstructor
99- // ------------------------------------------------------------------------------
10095template <typename TK, typename TR>
10196ESolver_KS_LCAO<TK, TR>::~ESolver_KS_LCAO ()
10297{
10398}
10499
105- // ------------------------------------------------------------------------------
106- // ! the 3rd function of ESolver_KS_LCAO: init
107- // ! 1) calculate overlap matrix S or initialize
108- // ! 2) init ElecState
109- // ! 3) init LCAO basis
110- // ! 4) initialize the density matrix
111- // ! 5) initialize exx
112- // ! 6) initialize DFT+U
113- // ! 7) ppcell
114- // ! 8) inititlize the charge density
115- // ! 9) initialize the potential.
116- // ! 10) initialize deepks
117- // ! 11) set occupations
118- // ! 12) print a warning if needed
119- // ------------------------------------------------------------------------------
120100template <typename TK, typename TR>
121101void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_para& inp)
122102{
123103 ModuleBase::TITLE (" ESolver_KS_LCAO" , " before_all_runners" );
124104 ModuleBase::timer::tick (" ESolver_KS_LCAO" , " before_all_runners" );
125105
106+ // 1) before_all_runners in ESolver_KS
126107 ESolver_KS<TK>::before_all_runners (ucell, inp);
127108
128109 // 2) init ElecState
129- // autoset nbands in ElecState, it should before basis_init (for Psi 2d division)
110+ // autoset nbands in ElecState before basis_init (for Psi 2d division)
130111 if (this ->pelec == nullptr )
131112 {
132113 // TK stands for double and complex<double>?
133114 this ->pelec = new elecstate::ElecStateLCAO<TK>(&(this ->chr ), // use which parameter?
134115 &(this ->kv ),
135116 this ->kv .get_nks (),
136- &(this ->GG ), // mohan add 2024-04-01
137- &(this ->GK ), // mohan add 2024-04-01
117+ &(this ->GG ),
118+ &(this ->GK ),
138119 this ->pw_rho ,
139120 this ->pw_big );
140121 }
@@ -157,9 +138,8 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
157138 // DMR is not initialized here, it will be constructed in each before_scf
158139 dynamic_cast <elecstate::ElecStateLCAO<TK>*>(this ->pelec )->init_DM (&this ->kv , &(this ->pv ), PARAM.inp .nspin );
159140
141+ // 5) initialize exact exchange calculations
160142#ifdef __EXX
161- // 5) initialize exx
162- // PLEASE simplify the Exx_Global interface
163143 if (PARAM.inp .calculation == " scf"
164144 || PARAM.inp .calculation == " relax"
165145 || PARAM.inp .calculation == " cell-relax"
@@ -190,7 +170,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
190170 dftu->init (ucell, &this ->pv , this ->kv .get_nks (), &orb_);
191171 }
192172
193- // 7) initialize ppcell
173+ // 7) initialize local pseudopotentials
194174 this ->locpp .init_vloc (ucell, this ->pw_rho );
195175 ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " LOCAL POTENTIAL" );
196176
@@ -211,8 +191,9 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
211191 &(this ->pelec ->f_en .vtxc ));
212192 }
213193
214- # ifdef __DEEPKS
194+
215195 // 10) initialize deepks
196+ #ifdef __DEEPKS
216197 LCAO_domain::DeePKS_init (ucell, pv, this ->kv .get_nks (), orb_, this ->ld , GlobalV::ofs_running);
217198 if (PARAM.inp .deepks_scf )
218199 {
@@ -279,10 +260,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
279260 return ;
280261}
281262
282- // ------------------------------------------------------------------------------
283- // ! the 5th function of ESolver_KS_LCAO: cal_energy
284- // ! mohan add 2024-05-11
285- // ------------------------------------------------------------------------------
263+
286264template <typename TK, typename TR>
287265double ESolver_KS_LCAO<TK, TR>::cal_energy()
288266{
@@ -291,10 +269,7 @@ double ESolver_KS_LCAO<TK, TR>::cal_energy()
291269 return this ->pelec ->f_en .etot ;
292270}
293271
294- // ------------------------------------------------------------------------------
295- // ! the 6th function of ESolver_KS_LCAO: cal_force
296- // ! mohan add 2024-05-11
297- // ------------------------------------------------------------------------------
272+
298273template <typename TK, typename TR>
299274void ESolver_KS_LCAO<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& force)
300275{
@@ -380,6 +355,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
380355 GlobalV::ofs_running << " !FINAL_ETOT_IS " << this ->pelec ->f_en .etot * ModuleBase::Ry_to_eV << " eV" << std::endl;
381356 GlobalV::ofs_running << " --------------------------------------------\n\n " << std::endl;
382357
358+ // 1) write information
383359 if (PARAM.inp .out_dos != 0 || PARAM.inp .out_band [0 ] != 0 || PARAM.inp .out_proj_band != 0 )
384360 {
385361 GlobalV::ofs_running << " \n\n\n\n " ;
@@ -412,14 +388,16 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
412388 << std::endl;
413389 GlobalV::ofs_running << " \n\n\n\n " ;
414390 }
415- // qianrui modify 2020-10-18
391+
392+ // 2) write information
416393 if (PARAM.inp .calculation == " scf" || PARAM.inp .calculation == " md" || PARAM.inp .calculation == " relax" )
417394 {
418395 ModuleIO::write_istate_info (this ->pelec ->ekb , this ->pelec ->wg , this ->kv );
419396 }
420397
421398 const int nspin0 = (PARAM.inp .nspin == 2 ) ? 2 : 1 ;
422399
400+ // 3) print out band information
423401 if (PARAM.inp .out_band [0 ])
424402 {
425403 for (int is = 0 ; is < nspin0; is++)
@@ -435,13 +413,15 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
435413 this ->pelec ->ekb ,
436414 this ->kv );
437415 }
438- } // out_band
416+ }
439417
440- if (PARAM.inp .out_proj_band ) // Projeced band structure added by jiyy-2022-4-20
418+ // 4) write projected band structure by jiyy-2022-4-20
419+ if (PARAM.inp .out_proj_band )
441420 {
442421 ModuleIO::write_proj_band_lcao (this ->psi , this ->pv , this ->pelec , this ->kv , ucell, this ->p_hamilt );
443422 }
444423
424+ // 5) print out density of states (DOS)
445425 if (PARAM.inp .out_dos )
446426 {
447427 ModuleIO::out_dos_nao (this ->psi ,
@@ -458,6 +438,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
458438 this ->p_hamilt );
459439 }
460440
441+ // 6) print out exchange-correlation potential
461442 if (PARAM.inp .out_mat_xc )
462443 {
463444 ModuleIO::write_Vxc<TK, TR>(PARAM.inp .nspin ,
@@ -486,6 +467,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
486467 );
487468 }
488469
470+ // 7) write eband terms
489471 if (PARAM.inp .out_eband_terms )
490472 {
491473 ModuleIO::write_eband_terms<TK, TR>(PARAM.inp .nspin ,
@@ -518,10 +500,7 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
518500 ModuleBase::timer::tick (" ESolver_KS_LCAO" , " after_all_runners" );
519501}
520502
521- // ------------------------------------------------------------------------------
522- // ! the 10th function of ESolver_KS_LCAO: iter_init
523- // ! mohan add 2024-05-11
524- // ------------------------------------------------------------------------------
503+
525504template <typename TK, typename TR>
526505void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const int iter)
527506{
@@ -546,6 +525,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
546525 std::cout << " eV " << std::endl;
547526 }
548527 }
528+
549529 // for mixing restart
550530 if (iter == this ->p_chgmix ->mixing_restart_step && PARAM.inp .mixing_restart > 0.0 )
551531 {
@@ -581,7 +561,6 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
581561 // mohan update 2012-06-05
582562 this ->pelec ->f_en .deband_harris = this ->pelec ->cal_delta_eband (ucell);
583563
584- // mohan move it outside 2011-01-13
585564 // first need to calculate the weight according to
586565 // electrons number.
587566 if (istep == 0 && PARAM.inp .init_wfc == " file" )
@@ -591,7 +570,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
591570 std::cout << " WAVEFUN -> CHARGE " << std::endl;
592571
593572 // calculate the density matrix using read in wave functions
594- // and the ncalculate the charge density on grid.
573+ // and then calculate the charge density on grid.
595574
596575 this ->pelec ->skip_weights = true ;
597576 this ->pelec ->calculate_weights ();
@@ -695,33 +674,18 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
695674 }
696675}
697676
698- // ------------------------------------------------------------------------------
699- // ! the 11th function of ESolver_KS_LCAO: hamilt2density_single
700- // ! mohan add 2024-05-11
701- // ! 1) save input rho
702- // ! 2) save density matrix DMR for mixing
703- // ! 3) solve the Hamiltonian and output band gap
704- // ! 4) print bands for each k-point and each band
705- // ! 5) EXX:
706- // ! 6) DFT+U: compute local occupation number matrix and energy correction
707- // ! 7) DeePKS: compute delta_e
708- // ! 8) DeltaSpin:
709- // ! 9) use new charge density to calculate energy
710- // ! 10) symmetrize the charge density
711- // ! 11) compute magnetization, only for spin==2
712- // ! 12) calculate delta energy
713- // ------------------------------------------------------------------------------
677+
714678template <typename TK, typename TR>
715679void ESolver_KS_LCAO<TK, TR>::hamilt2density_single(UnitCell& ucell, int istep, int iter, double ethr)
716680{
717681 ModuleBase::TITLE (" ESolver_KS_LCAO" , " hamilt2density_single" );
718682
719- // reset energy
683+ // i1) reset energy
720684 this ->pelec ->f_en .eband = 0.0 ;
721685 this ->pelec ->f_en .demet = 0.0 ;
722686 bool skip_charge = PARAM.inp .calculation == " nscf" ? true : false ;
723687
724- // run the inner lambda loop to contrain atomic moments with the DeltaSpin method
688+ // 2) run the inner lambda loop to contrain atomic moments with the DeltaSpin method
725689 bool skip_solve = false ;
726690 if (PARAM.inp .sc_mag_switch )
727691 {
@@ -740,13 +704,15 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2density_single(UnitCell& ucell, int istep,
740704 skip_solve = true ;
741705 }
742706 }
707+
708+ // 3) run Hsolver
743709 if (!skip_solve)
744710 {
745711 hsolver::HSolverLCAO<TK> hsolver_lcao_obj (&(this ->pv ), PARAM.inp .ks_solver );
746712 hsolver_lcao_obj.solve (this ->p_hamilt , this ->psi [0 ], this ->pelec , skip_charge);
747713 }
748714
749- // 5) what's the exd used for?
715+ // 4) EXX
750716#ifdef __EXX
751717 if (PARAM.inp .calculation != " nscf" )
752718 {
@@ -761,22 +727,18 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2density_single(UnitCell& ucell, int istep,
761727 }
762728#endif
763729
764- // 10 ) symmetrize the charge density
730+ // 5 ) symmetrize the charge density
765731 Symmetry_rho srho;
766732 for (int is = 0 ; is < PARAM.inp .nspin ; is++)
767733 {
768734 srho.begin (is, this ->chr , this ->pw_rho , ucell.symm );
769735 }
770736
771- // 12 ) calculate delta energy
737+ // 6 ) calculate delta energy
772738 this ->pelec ->f_en .deband = this ->pelec ->cal_delta_eband (ucell);
773739}
774740
775- // ------------------------------------------------------------------------------
776- // ! the 12th function of ESolver_KS_LCAO: update_pot
777- // ! mohan add 2024-05-11
778- // ! 1) print potential
779- // ------------------------------------------------------------------------------
741+
780742template <typename TK, typename TR>
781743void ESolver_KS_LCAO<TK, TR>::update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver)
782744{
@@ -794,21 +756,14 @@ void ESolver_KS_LCAO<TK, TR>::update_pot(UnitCell& ucell, const int istep, const
794756 }
795757}
796758
797- // ------------------------------------------------------------------------------
798- // ! the 13th function of ESolver_KS_LCAO: iter_finish
799- // ! mohan add 2024-05-11
800- // ! 1) mix density matrix
801- // ! 2) output charge density
802- // ! 3) output exx matrix
803- // ! 4) output charge density and density matrix
804- // ------------------------------------------------------------------------------
759+
805760template <typename TK, typename TR>
806761void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int & iter, bool & conv_esolver)
807762{
808763 ModuleBase::TITLE (" ESolver_KS_LCAO" , " iter_finish" );
809764
810- // 6 ) calculate the local occupation number matrix and energy correction in
811- // DFT+U
765+ // 1 ) calculate the local occupation number matrix and energy correction
766+ // in DFT+U
812767 if (PARAM.inp .dft_plus_u )
813768 {
814769 // only old DFT+U method should calculated energy correction in esolver,
@@ -831,7 +786,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
831786 GlobalC::dftu.output (ucell);
832787 }
833788
834- // (7 ) for deepks, calculate delta_e
789+ // 2 ) for deepks, calculate delta_e
835790#ifdef __DEEPKS
836791 if (PARAM.inp .deepks_scf )
837792 {
@@ -844,25 +799,25 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
844799 }
845800#endif
846801
847- // 8 ) for delta spin
802+ // 3 ) for delta spin
848803 if (PARAM.inp .sc_mag_switch )
849804 {
850805 spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance ();
851806 sc.cal_mi_lcao (iter);
852807 }
853808
854- // call iter_finish() of ESolver_KS
809+ // 4) call iter_finish() of ESolver_KS
855810 ESolver_KS<TK>::iter_finish (ucell, istep, iter, conv_esolver);
856811
857- // 1 ) mix density matrix if mixing_restart + mixing_dmr + not first
812+ // 5 ) mix density matrix if mixing_restart + mixing_dmr + not first
858813 // mixing_restart at every iter
859814 if (PARAM.inp .mixing_restart > 0 && this ->p_chgmix ->mixing_restart_count > 0 && PARAM.inp .mixing_dmr )
860815 {
861816 elecstate::DensityMatrix<TK, double >* dm = dynamic_cast <elecstate::ElecStateLCAO<TK>*>(this ->pelec )->get_DM ();
862817 this ->p_chgmix ->mix_dmr (dm);
863818 }
864819
865- // 2 ) save charge density
820+ // 6 ) save charge density
866821 // Peize Lin add 2020.04.04
867822 if (GlobalC::restart.info_save .save_charge )
868823 {
@@ -873,7 +828,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
873828 }
874829
875830#ifdef __EXX
876- // 3 ) save exx matrix
831+ // 7 ) save exx matrix
877832 if (PARAM.inp .calculation != " nscf" )
878833 {
879834 if (GlobalC::exx_info.info_global .cal_exx )
@@ -900,7 +855,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
900855 }
901856#endif
902857
903- // 6 ) use the converged occupation matrix for next MD/Relax SCF calculation
858+ // 8 ) use the converged occupation matrix for next MD/Relax SCF calculation
904859 if (PARAM.inp .dft_plus_u && conv_esolver)
905860 {
906861 GlobalC::dftu.initialed_locale = true ;
0 commit comments