@@ -673,7 +673,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(const int istep, const int iter)
673673 // method
674674 if (PARAM.inp .sc_mag_switch && iter > PARAM.inp .sc_scf_nmin )
675675 {
676- SpinConstrain<TK, base_device::DEVICE_CPU >& sc = SpinConstrain<TK, base_device::DEVICE_CPU >::getScInstance ();
676+ SpinConstrain<TK>& sc = SpinConstrain<TK>::getScInstance ();
677677 sc.run_lambda_loop (iter - 1 );
678678 }
679679}
@@ -779,30 +779,23 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2density(int istep, int iter, double ethr)
779779 }
780780#endif
781781
782- // 8) for delta spin
783- if (PARAM.inp .sc_mag_switch )
784- {
785- SpinConstrain<TK, base_device::DEVICE_CPU>& sc = SpinConstrain<TK, base_device::DEVICE_CPU>::getScInstance ();
786- sc.cal_MW (iter, this ->p_hamilt );
787- }
788-
789- // 9) use new charge density to calculate energy
782+ // 8) use new charge density to calculate energy
790783 this ->pelec ->cal_energies (1 );
791784
792- // 10 ) symmetrize the charge density
785+ // 9 ) symmetrize the charge density
793786 Symmetry_rho srho;
794787 for (int is = 0 ; is < PARAM.inp .nspin ; is++)
795788 {
796789 srho.begin (is, *(this ->pelec ->charge ), this ->pw_rho , GlobalC::ucell.symm );
797790 }
798791
799- // 11 ) compute magnetization, only for spin==2
792+ // 10 ) compute magnetization, only for nspin != 1
800793 GlobalC::ucell.magnet .compute_magnetization (this ->pelec ->charge ->nrxx ,
801794 this ->pelec ->charge ->nxyz ,
802795 this ->pelec ->charge ->rho ,
803796 this ->pelec ->nelec_spin .data ());
804797
805- // 12 ) calculate delta energy
798+ // 11 ) calculate delta energy for hartree and exchange-correlation double countings
806799 this ->pelec ->f_en .deband = this ->pelec ->cal_delta_eband ();
807800}
808801
@@ -911,7 +904,6 @@ void ESolver_KS_LCAO<TK, TR>::update_pot(const int istep, const int iter)
911904// ! 2) output charge density
912905// ! 3) output exx matrix
913906// ! 4) output charge density and density matrix
914- // ! 5) cal_MW? (why put it here?)
915907// ------------------------------------------------------------------------------
916908template <typename TK, typename TR>
917909void ESolver_KS_LCAO<TK, TR>::iter_finish(int & iter)
@@ -1054,15 +1046,6 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)
10541046 }
10551047 }
10561048
1057- // 5) cal_MW?
1058- // escon: energy of spin constraint depends on Mi, so cal_energies should be
1059- // called after cal_MW
1060- if (PARAM.inp .sc_mag_switch )
1061- {
1062- SpinConstrain<TK, base_device::DEVICE_CPU>& sc = SpinConstrain<TK, base_device::DEVICE_CPU>::getScInstance ();
1063- sc.cal_MW (iter, this ->p_hamilt );
1064- }
1065-
10661049 // 6) use the converged occupation matrix for next MD/Relax SCF calculation
10671050 if (PARAM.inp .dft_plus_u && this ->conv_esolver )
10681051 {
@@ -1223,13 +1206,14 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
12231206 }
12241207 }
12251208
1226- // 15) write spin constrian MW?
1227- // spin constrain calculations, added by Tianqi Zhao .
1228- if (PARAM.inp .sc_mag_switch )
1209+ // 15) write atomic magnetization only when spin_constraint is on
1210+ // spin constrain calculations.
1211+ if (PARAM.inp .sc_mag_switch )
12291212 {
1230- SpinConstrain<TK, base_device::DEVICE_CPU>& sc = SpinConstrain<TK, base_device::DEVICE_CPU>::getScInstance ();
1231- sc.cal_MW (istep, true );
1232- sc.print_Mag_Force ();
1213+ SpinConstrain<TK>& sc = SpinConstrain<TK>::getScInstance ();
1214+ sc.cal_mi_lcao (istep);
1215+ sc.print_Mi (GlobalV::ofs_running);
1216+ sc.print_Mag_Force (GlobalV::ofs_running);
12331217 }
12341218
12351219 // 16) delete grid
0 commit comments