@@ -437,7 +437,7 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
437
437
ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " INIT SCF" );
438
438
439
439
// 4) SCF iterations
440
- this -> conv_esolver = false ;
440
+ bool conv_esolver = false ;
441
441
this ->niter = this ->maxniter ;
442
442
this ->diag_ethr = PARAM.inp .pw_diag_thr ;
443
443
for (int iter = 1 ; iter <= this ->maxniter ; ++iter)
@@ -449,10 +449,10 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
449
449
this ->hamilt2density (ucell, istep, iter, diag_ethr);
450
450
451
451
// 7) finish scf iterations
452
- this ->iter_finish (ucell, istep, iter);
452
+ this ->iter_finish (ucell, istep, iter, conv_esolver );
453
453
454
454
// 8) check convergence
455
- if (this -> conv_esolver || this ->oscillate_esolver )
455
+ if (conv_esolver || this ->oscillate_esolver )
456
456
{
457
457
this ->niter = iter;
458
458
if (this ->oscillate_esolver )
@@ -464,7 +464,7 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
464
464
} // end scf iterations
465
465
466
466
// 9) after scf
467
- this ->after_scf (ucell, istep);
467
+ this ->after_scf (ucell, istep, conv_esolver );
468
468
469
469
ModuleBase::timer::tick (this ->classname , " runner" );
470
470
return ;
@@ -524,7 +524,7 @@ void ESolver_KS<T, Device>::iter_init(UnitCell& ucell, const int istep, const in
524
524
}
525
525
526
526
template <typename T, typename Device>
527
- void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int & iter)
527
+ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int & iter, bool &conv_esolver )
528
528
{
529
529
if (PARAM.inp .out_bandgap )
530
530
{
@@ -578,30 +578,30 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
578
578
}
579
579
#endif
580
580
581
- this -> conv_esolver = (drho < this ->scf_thr && not_restart_step && is_U_converged);
581
+ conv_esolver = (drho < this ->scf_thr && not_restart_step && is_U_converged);
582
582
583
583
// add energy threshold for SCF convergence
584
584
if (this ->scf_ene_thr > 0.0 )
585
585
{
586
586
// calculate energy of output charge density
587
- this ->update_pot (ucell, istep, iter);
587
+ this ->update_pot (ucell, istep, iter, conv_esolver );
588
588
this ->pelec ->cal_energies (2 ); // 2 means Kohn-Sham functional
589
589
// now, etot_old is the energy of input density, while etot is the energy of output density
590
590
this ->pelec ->f_en .etot_delta = this ->pelec ->f_en .etot - this ->pelec ->f_en .etot_old ;
591
591
// output etot_delta
592
592
GlobalV::ofs_running << " DeltaE_womix = " << this ->pelec ->f_en .etot_delta * ModuleBase::Ry_to_eV << " eV"
593
593
<< std::endl;
594
- if (iter > 1 && this -> conv_esolver == 1 ) // only check when density is converged
594
+ if (iter > 1 && conv_esolver == 1 ) // only check when density is converged
595
595
{
596
596
// update the convergence flag
597
- this -> conv_esolver
597
+ conv_esolver
598
598
= (std::abs (this ->pelec ->f_en .etot_delta * ModuleBase::Ry_to_eV) < this ->scf_ene_thr );
599
599
}
600
600
}
601
601
602
602
// If drho < hsolver_error in the first iter or drho < scf_thr, we
603
603
// do not change rho.
604
- if (drho < hsolver_error || this -> conv_esolver || PARAM.inp .calculation == " nscf" )
604
+ if (drho < hsolver_error || conv_esolver || PARAM.inp .calculation == " nscf" )
605
605
{
606
606
if (drho < hsolver_error)
607
607
{
@@ -635,14 +635,16 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
635
635
636
636
#ifdef __MPI
637
637
MPI_Bcast (&drho, 1 , MPI_DOUBLE, 0 , BP_WORLD);
638
- MPI_Bcast (&this ->conv_esolver , 1 , MPI_DOUBLE, 0 , BP_WORLD);
638
+
639
+ // be careful! conv_esolver is bool, not double !! Maybe a bug 20250302 by mohan
640
+ MPI_Bcast (&conv_esolver, 1 , MPI_DOUBLE, 0 , BP_WORLD);
639
641
MPI_Bcast (pelec->charge ->rho [0 ], this ->pw_rhod ->nrxx , MPI_DOUBLE, 0 , BP_WORLD);
640
642
#endif
641
643
642
644
// update potential
643
645
// Hamilt should be used after it is constructed.
644
646
// this->phamilt->update(conv_esolver);
645
- this ->update_pot (ucell, istep, iter);
647
+ this ->update_pot (ucell, istep, iter, conv_esolver );
646
648
647
649
// 1 means Harris-Foulkes functional
648
650
// 2 means Kohn-Sham functional
@@ -671,7 +673,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
671
673
dkin = p_chgmix->get_dkin (pelec->charge , PARAM.inp .nelec );
672
674
}
673
675
674
- this ->pelec ->print_etot (ucell.magnet ,this -> conv_esolver , iter, drho, dkin, duration, PARAM.inp .printe , diag_ethr);
676
+ this ->pelec ->print_etot (ucell.magnet ,conv_esolver, iter, drho, dkin, duration, PARAM.inp .printe , diag_ethr);
675
677
676
678
// Json, need to be moved to somewhere else
677
679
#ifdef __RAPIDJSON
@@ -691,17 +693,17 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
691
693
std::cout << " SCF restart after this step!" << std::endl;
692
694
}
693
695
694
- ESolver_FP::iter_finish (ucell, istep, iter);
696
+ ESolver_FP::iter_finish (ucell, istep, iter, conv_esolver );
695
697
}
696
698
697
699
// ! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
698
700
template <typename T, typename Device>
699
- void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep)
701
+ void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep, const bool conv_esolver )
700
702
{
701
703
ModuleBase::TITLE (" ESolver_KS" , " after_scf" );
702
704
703
705
// 1) call after_scf() of ESolver_FP
704
- ESolver_FP::after_scf (ucell, istep);
706
+ ESolver_FP::after_scf (ucell, istep, conv_esolver );
705
707
706
708
// 2) write eigenvalues
707
709
if (istep % PARAM.inp .out_interval == 0 )
0 commit comments