11#include " esolver_ks.h"
22
3- #include < ctime>
4- #include < iostream>
5- #ifdef __MPI
6- #include < mpi.h>
7- #else
8- #include < chrono>
9- #endif
103#include " module_base/timer.h"
114#include " module_cell/cal_atoms_info.h"
125#include " module_io/json_output/init_info.h"
158#include " module_io/print_info.h"
169#include " module_io/write_istate_info.h"
1710#include " module_parameter/parameter.h"
11+
12+ #include < ctime>
13+ #include < iostream>
1814// --------------Temporary----------------
1915#include " module_base/global_variable.h"
2016#include " module_hamilt_lcao/module_dftu/dftu.h"
@@ -427,49 +423,11 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
427423 this ->niter = this ->maxniter ;
428424
429425 // 4) SCF iterations
430- double diag_ethr = PARAM.inp .pw_diag_thr ;
426+ this -> diag_ethr = PARAM.inp .pw_diag_thr ;
431427
432428 std::cout << " * * * * * *\n << Start SCF iteration." << std::endl;
433429 for (int iter = 1 ; iter <= this ->maxniter ; ++iter)
434430 {
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-
473431 // 6) initialization of SCF iterations
474432 this ->iter_init (istep, iter);
475433
@@ -615,33 +573,6 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
615573
616574 // 10) finish scf iterations
617575 this ->iter_finish (istep, iter);
618- #ifdef __MPI
619- double duration = (double )(MPI_Wtime () - iterstart);
620- #else
621- double duration
622- = (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now () - iterstart))
623- .count ()
624- / static_cast <double >(1e6 );
625- #endif
626-
627- // 11) get mtaGGA related parameters
628- double dkin = 0.0 ; // for meta-GGA
629- if (XC_Functional::get_func_type () == 3 || XC_Functional::get_func_type () == 5 )
630- {
631- dkin = p_chgmix->get_dkin (pelec->charge , PARAM.inp .nelec );
632- }
633- this ->pelec ->print_etot (this ->conv_esolver , iter, drho, dkin, duration, PARAM.inp .printe , diag_ethr);
634-
635- // 12) Json, need to be moved to somewhere else
636- #ifdef __RAPIDJSON
637- // add Json of scf mag
638- Json::add_output_scf_mag (GlobalC::ucell.magnet .tot_magnetization ,
639- GlobalC::ucell.magnet .abs_magnetization ,
640- this ->pelec ->f_en .etot * ModuleBase::Ry_to_eV,
641- this ->pelec ->f_en .etot_delta * ModuleBase::Ry_to_eV,
642- drho,
643- duration);
644- #endif // __RAPIDJSON
645576
646577 // 13) check convergence
647578 if (this ->conv_esolver || this ->oscillate_esolver )
@@ -653,12 +584,6 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
653584 }
654585 break ;
655586 }
656-
657- // notice for restart
658- if (PARAM.inp .mixing_restart > 0 && iter == this ->p_chgmix ->mixing_restart_step - 1 && iter != PARAM.inp .scf_nmax )
659- {
660- std::cout << " SCF restart after this step!" << std::endl;
661- }
662587 } // end scf iterations
663588 std::cout << " >> Leave SCF iteration.\n * * * * * *" << std::endl;
664589
@@ -671,6 +596,47 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
671596 return ;
672597};
673598
599+ template <typename T, typename Device>
600+ void ESolver_KS<T, Device>::iter_init(const int istep, const int iter)
601+ {
602+ ModuleIO::write_head (GlobalV::ofs_running, istep, iter, this ->basisname );
603+
604+ #ifdef __MPI
605+ iter_time = MPI_Wtime ();
606+ #else
607+ iter_time = std::chrono::system_clock::now ();
608+ #endif
609+
610+ if (PARAM.inp .esolver_type == " ksdft" )
611+ {
612+ diag_ethr = hsolver::set_diagethr_ks (PARAM.inp .basis_type ,
613+ PARAM.inp .esolver_type ,
614+ PARAM.inp .calculation ,
615+ PARAM.inp .init_chg ,
616+ PARAM.inp .precision ,
617+ istep,
618+ iter,
619+ drho,
620+ PARAM.inp .pw_diag_thr ,
621+ diag_ethr,
622+ PARAM.inp .nelec );
623+ }
624+ else if (PARAM.inp .esolver_type == " sdft" )
625+ {
626+ diag_ethr = hsolver::set_diagethr_sdft (PARAM.inp .basis_type ,
627+ PARAM.inp .esolver_type ,
628+ PARAM.inp .calculation ,
629+ PARAM.inp .init_chg ,
630+ istep,
631+ iter,
632+ drho,
633+ PARAM.inp .pw_diag_thr ,
634+ diag_ethr,
635+ PARAM.inp .nbands ,
636+ esolver_KS_ne);
637+ }
638+ }
639+
674640template <typename T, typename Device>
675641void ESolver_KS<T, Device>::iter_finish(const int istep, int & iter)
676642{
@@ -684,6 +650,39 @@ void ESolver_KS<T, Device>::iter_finish(const int istep, int& iter)
684650 }
685651 this ->pelec ->f_en .etot_delta = this ->pelec ->f_en .etot - this ->pelec ->f_en .etot_old ;
686652 this ->pelec ->f_en .etot_old = this ->pelec ->f_en .etot ;
653+
654+ #ifdef __MPI
655+ double duration = (double )(MPI_Wtime () - iter_time);
656+ #else
657+ double duration
658+ = (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now () - iter_time)).count ()
659+ / static_cast <double >(1e6 );
660+ #endif
661+
662+ // get mtaGGA related parameters
663+ double dkin = 0.0 ; // for meta-GGA
664+ if (XC_Functional::get_func_type () == 3 || XC_Functional::get_func_type () == 5 )
665+ {
666+ dkin = p_chgmix->get_dkin (pelec->charge , PARAM.inp .nelec );
667+ }
668+ this ->pelec ->print_etot (this ->conv_esolver , iter, drho, dkin, duration, PARAM.inp .printe , diag_ethr);
669+
670+ // Json, need to be moved to somewhere else
671+ #ifdef __RAPIDJSON
672+ // add Json of scf mag
673+ Json::add_output_scf_mag (GlobalC::ucell.magnet .tot_magnetization ,
674+ GlobalC::ucell.magnet .abs_magnetization ,
675+ this ->pelec ->f_en .etot * ModuleBase::Ry_to_eV,
676+ this ->pelec ->f_en .etot_delta * ModuleBase::Ry_to_eV,
677+ drho,
678+ duration);
679+ #endif // __RAPIDJSON
680+
681+ // notice for restart
682+ if (PARAM.inp .mixing_restart > 0 && iter == this ->p_chgmix ->mixing_restart_step - 1 && iter != PARAM.inp .scf_nmax )
683+ {
684+ std::cout << " SCF restart after this step!" << std::endl;
685+ }
687686}
688687
689688// ! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
@@ -698,13 +697,6 @@ void ESolver_KS<T, Device>::after_scf(const int istep)
698697 {
699698 this ->pelec ->print_eigenvalue (GlobalV::ofs_running);
700699 }
701- // #ifdef __RAPIDJSON
702- // // add Json of efermi energy converge
703- // Json::add_output_efermi_converge(this->pelec->eferm.ef * ModuleBase::Ry_to_eV, this->conv_esolver);
704- // // add nkstot,nkstot_ibz to output json
705- // int Jnkstot = this->pelec->klist->get_nkstot();
706- // Json::add_nkstot(Jnkstot);
707- // #endif //__RAPIDJSON
708700}
709701
710702// ------------------------------------------------------------------------------
0 commit comments