@@ -427,49 +427,11 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
427427 this ->niter = this ->maxniter ;
428428
429429 // 4) SCF iterations
430- double diag_ethr = PARAM.inp .pw_diag_thr ;
430+ this -> diag_ethr = PARAM.inp .pw_diag_thr ;
431431
432432 std::cout << " * * * * * *\n << Start SCF iteration." << std::endl;
433433 for (int iter = 1 ; iter <= this ->maxniter ; ++iter)
434434 {
435- // 5) write head
436- ModuleIO::write_head (GlobalV::ofs_running, istep, iter, this ->basisname );
437-
438- #ifdef __MPI
439- auto iterstart = MPI_Wtime ();
440- #else
441- auto iterstart = std::chrono::system_clock::now ();
442- #endif
443-
444- if (PARAM.inp .esolver_type == " ksdft" )
445- {
446- diag_ethr = hsolver::set_diagethr_ks (PARAM.inp .basis_type ,
447- PARAM.inp .esolver_type ,
448- PARAM.inp .calculation ,
449- PARAM.inp .init_chg ,
450- PARAM.inp .precision ,
451- istep,
452- iter,
453- drho,
454- PARAM.inp .pw_diag_thr ,
455- diag_ethr,
456- PARAM.inp .nelec );
457- }
458- else if (PARAM.inp .esolver_type == " sdft" )
459- {
460- diag_ethr = hsolver::set_diagethr_sdft (PARAM.inp .basis_type ,
461- PARAM.inp .esolver_type ,
462- PARAM.inp .calculation ,
463- PARAM.inp .init_chg ,
464- istep,
465- iter,
466- drho,
467- PARAM.inp .pw_diag_thr ,
468- diag_ethr,
469- PARAM.inp .nbands ,
470- esolver_KS_ne);
471- }
472-
473435 // 6) initialization of SCF iterations
474436 this ->iter_init (istep, iter);
475437
@@ -610,46 +572,13 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
610572
611573 // 10) finish scf iterations
612574 this ->iter_finish (istep, iter);
613- #ifdef __MPI
614- double duration = (double )(MPI_Wtime () - iterstart);
615- #else
616- double duration
617- = (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now () - iterstart))
618- .count ()
619- / static_cast <double >(1e6 );
620- #endif
621-
622- // 11) get mtaGGA related parameters
623- double dkin = 0.0 ; // for meta-GGA
624- if (XC_Functional::get_func_type () == 3 || XC_Functional::get_func_type () == 5 )
625- {
626- dkin = p_chgmix->get_dkin (pelec->charge , PARAM.inp .nelec );
627- }
628- this ->pelec ->print_etot (this ->conv_esolver , iter, drho, dkin, duration, PARAM.inp .printe , diag_ethr);
629-
630- // 12) Json, need to be moved to somewhere else
631- #ifdef __RAPIDJSON
632- // add Json of scf mag
633- Json::add_output_scf_mag (GlobalC::ucell.magnet .tot_magnetization ,
634- GlobalC::ucell.magnet .abs_magnetization ,
635- this ->pelec ->f_en .etot * ModuleBase::Ry_to_eV,
636- this ->pelec ->f_en .etot_delta * ModuleBase::Ry_to_eV,
637- drho,
638- duration);
639- #endif // __RAPIDJSON
640575
641576 // 13) check convergence
642577 if (this ->conv_esolver )
643578 {
644579 this ->niter = iter;
645580 break ;
646581 }
647-
648- // notice for restart
649- if (PARAM.inp .mixing_restart > 0 && iter == this ->p_chgmix ->mixing_restart_step - 1 && iter != PARAM.inp .scf_nmax )
650- {
651- std::cout << " SCF restart after this step!" << std::endl;
652- }
653582 } // end scf iterations
654583 std::cout << " >> Leave SCF iteration.\n * * * * * *" << std::endl;
655584
@@ -662,6 +591,47 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
662591 return ;
663592};
664593
594+ template <typename T, typename Device>
595+ void ESolver_KS<T, Device>::iter_init(const int istep, const int iter)
596+ {
597+ ModuleIO::write_head (GlobalV::ofs_running, istep, iter, this ->basisname );
598+
599+ #ifdef __MPI
600+ iter_time = MPI_Wtime ();
601+ #else
602+ iter_time = std::chrono::system_clock::now ();
603+ #endif
604+
605+ if (PARAM.inp .esolver_type == " ksdft" )
606+ {
607+ diag_ethr = hsolver::set_diagethr_ks (PARAM.inp .basis_type ,
608+ PARAM.inp .esolver_type ,
609+ PARAM.inp .calculation ,
610+ PARAM.inp .init_chg ,
611+ PARAM.inp .precision ,
612+ istep,
613+ iter,
614+ drho,
615+ PARAM.inp .pw_diag_thr ,
616+ diag_ethr,
617+ PARAM.inp .nelec );
618+ }
619+ else if (PARAM.inp .esolver_type == " sdft" )
620+ {
621+ diag_ethr = hsolver::set_diagethr_sdft (PARAM.inp .basis_type ,
622+ PARAM.inp .esolver_type ,
623+ PARAM.inp .calculation ,
624+ PARAM.inp .init_chg ,
625+ istep,
626+ iter,
627+ drho,
628+ PARAM.inp .pw_diag_thr ,
629+ diag_ethr,
630+ PARAM.inp .nbands ,
631+ esolver_KS_ne);
632+ }
633+ }
634+
665635template <typename T, typename Device>
666636void ESolver_KS<T, Device>::iter_finish(const int istep, int & iter)
667637{
@@ -675,6 +645,39 @@ void ESolver_KS<T, Device>::iter_finish(const int istep, int& iter)
675645 }
676646 this ->pelec ->f_en .etot_delta = this ->pelec ->f_en .etot - this ->pelec ->f_en .etot_old ;
677647 this ->pelec ->f_en .etot_old = this ->pelec ->f_en .etot ;
648+
649+ #ifdef __MPI
650+ double duration = (double )(MPI_Wtime () - iter_time);
651+ #else
652+ double duration
653+ = (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now () - iter_time)).count ()
654+ / static_cast <double >(1e6 );
655+ #endif
656+
657+ // get mtaGGA related parameters
658+ double dkin = 0.0 ; // for meta-GGA
659+ if (XC_Functional::get_func_type () == 3 || XC_Functional::get_func_type () == 5 )
660+ {
661+ dkin = p_chgmix->get_dkin (pelec->charge , PARAM.inp .nelec );
662+ }
663+ this ->pelec ->print_etot (this ->conv_esolver , iter, drho, dkin, duration, PARAM.inp .printe , diag_ethr);
664+
665+ // Json, need to be moved to somewhere else
666+ #ifdef __RAPIDJSON
667+ // add Json of scf mag
668+ Json::add_output_scf_mag (GlobalC::ucell.magnet .tot_magnetization ,
669+ GlobalC::ucell.magnet .abs_magnetization ,
670+ this ->pelec ->f_en .etot * ModuleBase::Ry_to_eV,
671+ this ->pelec ->f_en .etot_delta * ModuleBase::Ry_to_eV,
672+ drho,
673+ duration);
674+ #endif // __RAPIDJSON
675+
676+ // notice for restart
677+ if (PARAM.inp .mixing_restart > 0 && iter == this ->p_chgmix ->mixing_restart_step - 1 && iter != PARAM.inp .scf_nmax )
678+ {
679+ std::cout << " SCF restart after this step!" << std::endl;
680+ }
678681}
679682
680683// ! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
@@ -689,13 +692,6 @@ void ESolver_KS<T, Device>::after_scf(const int istep)
689692 {
690693 this ->pelec ->print_eigenvalue (GlobalV::ofs_running);
691694 }
692- // #ifdef __RAPIDJSON
693- // // add Json of efermi energy converge
694- // Json::add_output_efermi_converge(this->pelec->eferm.ef * ModuleBase::Ry_to_eV, this->conv_esolver);
695- // // add nkstot,nkstot_ibz to output json
696- // int Jnkstot = this->pelec->klist->get_nkstot();
697- // Json::add_nkstot(Jnkstot);
698- // #endif //__RAPIDJSON
699695}
700696
701697// ------------------------------------------------------------------------------
0 commit comments