3131#include " module_hamilt/hamilt_pw.h"
3232#include " module_hsolver/diago_iter_assist.h"
3333
34+ #include " src_io/write_wfc_realspace.h"
35+ #include " src_io/winput.h"
36+ #include " src_io/numerical_descriptor.h"
37+ #include " src_io/numerical_basis.h"
38+ #include " src_io/to_wannier90.h"
39+ #include " src_io/berryphase.h"
40+
3441namespace ModuleESolver
3542{
3643
@@ -107,7 +114,7 @@ namespace ModuleESolver
107114 GlobalC::CHR.allocate (GlobalV::NSPIN, GlobalC::pw.nrxx , GlobalC::pw.ngmc );
108115 GlobalC::pot.allocate (GlobalC::pw.nrxx );
109116
110- GlobalC::wf.allocate (GlobalC::kv.nks );
117+ this -> psi = GlobalC::wf.allocate (GlobalC::kv.nks );
111118
112119 // cout<<GlobalC::pw.nrxx<<endl;
113120 // cout<<"before ufft allocate"<<endl;
@@ -158,7 +165,7 @@ namespace ModuleESolver
158165 if (GlobalV::NBANDS != 0 || GlobalV::CALCULATION.substr (0 ,3 ) != " sto" )
159166 // qianrui add temporarily. In the future, wfcinit() should be compatible with cases when NBANDS=0
160167 {
161- GlobalC::wf.wfcinit ();
168+ GlobalC::wf.wfcinit (this -> psi );
162169 }
163170
164171#ifdef __LCAO
@@ -286,7 +293,7 @@ namespace ModuleESolver
286293 }
287294
288295 hsolver::DiagoIterAssist::PW_DIAG_THR = ethr;
289- this ->phsol ->solve (this ->phami , GlobalC::wf. psi [0 ], this ->pelec );
296+ this ->phsol ->solve (this ->phami , this -> psi [0 ], this ->pelec );
290297
291298 // transform energy for print
292299 GlobalC::en.eband = this ->pelec ->eband ;
@@ -402,7 +409,7 @@ namespace ModuleESolver
402409 // WF_io::write_wfc( ssw.str(), GlobalC::wf.evc );
403410 // mohan update 2011-02-21
404411 // qianrui update 2020-10-17
405- WF_io::write_wfc2 (ssw.str (), GlobalC::wf. psi [0 ], GlobalC::pw.gcar );
412+ WF_io::write_wfc2 (ssw.str (), this -> psi [0 ], GlobalC::pw.gcar );
406413 // ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running,"write wave functions into file WAVEFUNC.dat");
407414 }
408415
@@ -414,9 +421,6 @@ namespace ModuleESolver
414421
415422 void ESolver_KS_PW::afterscf ()
416423 {
417- // temporary transform psi to evc
418- // psi back to evc
419- // GlobalC::wf.psi_transform_evc();
420424 for (int ik=0 ; ik<this ->pelec ->ekb .nr ; ++ik)
421425 {
422426 for (int ib=0 ; ib<this ->pelec ->ekb .nc ; ++ib)
@@ -595,17 +599,153 @@ namespace ModuleESolver
595599 void ESolver_KS_PW::cal_Force (ModuleBase::matrix& force)
596600 {
597601 Forces ff;
598- ff.init (force);
602+ ff.init (force, this -> psi );
599603 }
604+
600605 void ESolver_KS_PW::cal_Stress (ModuleBase::matrix& stress)
601606 {
602607 Stress_PW ss;
603- ss.cal_stress (stress);
608+ ss.cal_stress (stress, this -> psi );
604609 }
610+
605611 void ESolver_KS_PW::postprocess ()
606612 {
607613 // compute density of states
608614 GlobalC::en.perform_dos_pw ();
615+
616+ // caoyu add 2020-11-24, mohan updat 2021-01-03
617+ if (GlobalV::BASIS_TYPE==" pw" && GlobalV::deepks_out_labels)
618+ {
619+ Numerical_Descriptor nc;
620+ nc.output_descriptor (this ->psi [0 ], INPUT.deepks_descriptor_lmax );
621+ ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running," GENERATE DESCRIPTOR FOR DEEPKS" );
622+ }
623+
624+ if (GlobalV::BASIS_TYPE==" pw" && winput::out_spillage) // xiaohui add 2013-09-01
625+ {
626+ // std::cout << "\n Output Spillage Information : " << std::endl;
627+ // calculate spillage value.
628+ #ifdef __LCAO
629+ if ( winput::out_spillage == 3 )
630+ {
631+ GlobalV::BASIS_TYPE=" pw" ;
632+ std::cout << " NLOCAL = " << GlobalV::NLOCAL << std::endl;
633+
634+ for (int ik=0 ; ik<GlobalC::kv.nks ; ik++)
635+ {
636+ GlobalC::wf.wanf2 [ik].create (GlobalV::NLOCAL, GlobalC::wf.npwx );
637+ if (GlobalV::BASIS_TYPE==" pw" )
638+ {
639+ std::cout << " ik=" << ik + 1 << std::endl;
640+
641+ GlobalV::BASIS_TYPE=" lcao_in_pw" ;
642+ GlobalC::wf.LCAO_in_pw_k (ik, GlobalC::wf.wanf2 [ik]);
643+ GlobalV::BASIS_TYPE=" pw" ;
644+ }
645+ }
646+
647+ // Spillage sp;
648+ // sp.get_both(GlobalV::NBANDS, GlobalV::NLOCAL, GlobalC::wf.wanf2, GlobalC::wf.evc);
649+ }
650+ #endif
651+
652+ // output overlap
653+ if ( winput::out_spillage <= 2 )
654+ {
655+ Numerical_Basis numerical_basis;
656+ numerical_basis.output_overlap (this ->psi [0 ]);
657+ ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running," BASIS OVERLAP (Q and S) GENERATION." );
658+ }
659+ }
660+
661+ if (GlobalC::wf.out_wfc_r == 1 ) // Peize Lin add 2021.11.21
662+ {
663+ Write_Wfc_Realspace::write_wfc_realspace_1 (this ->psi [0 ], " wfc_realspace" , true );
664+ }
665+ }
666+
667+ void ESolver_KS_PW::hamilt2estates (const double ethr)
668+ {
669+ if (this ->phsol != nullptr )
670+ {
671+ hsolver::DiagoIterAssist::need_subspace = false ;
672+ hsolver::DiagoIterAssist::PW_DIAG_THR = ethr;
673+ this ->phsol ->solve (this ->phami , this ->psi [0 ], this ->pelec , true );
674+ }
675+ else
676+ {
677+ ModuleBase::WARNING_QUIT (" ESolver_KS_PW" , " HSolver has not been initialed!" );
678+ }
679+ }
680+
681+ void ESolver_KS_PW::nscf ()
682+ {
683+ ModuleBase::TITLE (" ESolver_KS_PW" ," nscf" );
684+ ModuleBase::timer::tick (" ESolver_KS_PW" ," nscf" );
685+
686+ this ->beforescf (1 );
687+ // ========================================
688+ // diagonalization of the KS hamiltonian
689+ // =======================================
690+ set_ethr (1 , 1 );
691+
692+ this ->hamilt2estates (this ->diag_ethr );
693+
694+ for (int ik=0 ; ik<this ->pelec ->ekb .nr ; ++ik)
695+ {
696+ for (int ib=0 ; ib<this ->pelec ->ekb .nc ; ++ib)
697+ {
698+ GlobalC::wf.ekb [ik][ib] = this ->pelec ->ekb (ik, ib);
699+ }
700+ }
701+
702+ GlobalV::ofs_running << " \n End of Band Structure Calculation \n " << std::endl;
703+
704+
705+ for (int ik = 0 ; ik < GlobalC::kv.nks ; ik++)
706+ {
707+ if (GlobalV::NSPIN==2 )
708+ {
709+ if (ik == 0 ) GlobalV::ofs_running << " spin up :" << std::endl;
710+ if (ik == ( GlobalC::kv.nks / 2 )) GlobalV::ofs_running << " spin down :" << std::endl;
711+ }
712+ // out.printV3(GlobalV::ofs_running, GlobalC::kv.kvec_c[ik]);
713+
714+ GlobalV::ofs_running << " k-points" << ik+1
715+ << " (" << GlobalC::kv.nkstot << " ): "
716+ << GlobalC::kv.kvec_c [ik].x
717+ << " " << GlobalC::kv.kvec_c [ik].y
718+ << " " << GlobalC::kv.kvec_c [ik].z << std::endl;
719+
720+ for (int ib = 0 ; ib < GlobalV::NBANDS; ib++)
721+ {
722+ GlobalV::ofs_running << " spin" << GlobalC::kv.isk [ik]+1
723+ << " _final_band " << ib+1
724+ << " " << this ->pelec ->ekb (ik, ib) * ModuleBase::Ry_to_eV
725+ << " " << GlobalC::wf.wg (ik, ib)*GlobalC::kv.nks << std::endl;
726+ }
727+ GlobalV::ofs_running << std::endl;
728+ }
729+
730+ // add by jingan in 2018.11.7
731+ if (INPUT.towannier90 )
732+ {
733+ toWannier90 myWannier (GlobalC::kv.nkstot ,GlobalC::ucell.G );
734+ myWannier.init_wannier (this ->psi );
735+ }
736+
737+ // =======================================================
738+ // Do a Berry phase polarization calculation if required
739+ // =======================================================
740+
741+ if (berryphase::berry_phase_flag && ModuleSymmetry::Symmetry::symm_flag == 0 )
742+ {
743+ berryphase bp;
744+ bp.Macroscopic_polarization (this ->psi );
745+ }
746+
747+ ModuleBase::timer::tick (" ESolver_KS_PW" ," nscf" );
748+ return ;
609749 }
610750
611751}
0 commit comments