7474namespace ModuleESolver
7575{
7676
77- // ------------------------------------------------------------------------------
78- // ! the 14th function of ESolver_KS_LCAO: after_scf
79- // ! mohan add 2024-05-11
80- // ! 1) call after_scf() of ESolver_KS
81- // ! 2) write density matrix for sparse matrix
82- // ! 4) write density matrix
83- // ! 5) write Exx matrix
84- // ! 6) write Hamiltonian and Overlap matrix
85- // ! 7) write wavefunctions
86- // ! 11) write deepks information
87- // ! 12) write rpa information
88- // ! 13) write HR in npz format
89- // ! 14) write dm in npz format
90- // ! 15) write md related
91- // ! 16) write spin constrian MW?
92- // ! 17) delete grid
93- // ! 18) write quasi-orbitals
94- // ------------------------------------------------------------------------------
9577template <typename TK, typename TR>
9678void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const bool conv_esolver)
9779{
9880 ModuleBase::TITLE (" ESolver_KS_LCAO" , " after_scf" );
9981 ModuleBase::timer::tick (" ESolver_KS_LCAO" , " after_scf" );
10082
83+ // ------------------------------------------------------------------
10184 // 1) calculate the kinetic energy density tau, sunliang 2024-09-18
85+ // ------------------------------------------------------------------
10286 if (PARAM.inp .out_elf [0 ] > 0 )
10387 {
10488 assert (this ->psi != nullptr );
10589 this ->pelec ->cal_tau (*(this ->psi ));
10690 }
10791
92+ // ------------------------------------------------------------------
10893 // ! 2) call after_scf() of ESolver_KS
94+ // ------------------------------------------------------------------
10995 ESolver_KS<TK>::after_scf (ucell, istep, conv_esolver);
11096
97+ // ------------------------------------------------------------------
11198 // ! 3) write density matrix for sparse matrix
99+ // ------------------------------------------------------------------
112100 ModuleIO::write_dmr (dynamic_cast <const elecstate::ElecStateLCAO<TK>*>(this ->pelec )->get_DM ()->get_DMR_vector (),
113101 this ->pv ,
114102 PARAM.inp .out_dm1 ,
@@ -118,7 +106,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
118106 &ucell.nat ,
119107 istep);
120108
109+ // ------------------------------------------------------------------
121110 // ! 4) write density matrix
111+ // ------------------------------------------------------------------
122112 if (PARAM.inp .out_dm )
123113 {
124114 std::vector<double > efermis (PARAM.inp .nspin == 2 ? 2 : 1 );
@@ -135,7 +125,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
135125 }
136126
137127#ifdef __EXX
128+ // ------------------------------------------------------------------
138129 // ! 5) write Hexx matrix for NSCF (see `out_chg` in docs/advanced/input_files/input-main.md)
130+ // ------------------------------------------------------------------
139131 if (PARAM.inp .calculation != " nscf" )
140132 {
141133 if (GlobalC::exx_info.info_global .cal_exx && PARAM.inp .out_chg [0 ]
@@ -154,7 +146,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
154146 }
155147#endif
156148
149+ // ------------------------------------------------------------------
157150 // 6) write Hamiltonian and Overlap matrix
151+ // ------------------------------------------------------------------
158152 for (int ik = 0 ; ik < this ->kv .get_nks (); ++ik)
159153 {
160154 if (PARAM.inp .out_mat_hs [0 ])
@@ -199,7 +193,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
199193 }
200194 }
201195
202- // 7) write wavefunctions
196+ // ------------------------------------------------------------------
197+ // 7) write electronic wavefunctions
198+ // ------------------------------------------------------------------
203199 if (elecstate::ElecStateLCAO<TK>::out_wfc_lcao && (istep % PARAM.inp .out_interval == 0 ))
204200 {
205201 ModuleIO::write_wfc_nao (elecstate::ElecStateLCAO<TK>::out_wfc_lcao,
@@ -211,15 +207,17 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
211207 istep);
212208 }
213209
214- // ! 8) Write DeePKS information
210+ // ------------------------------------------------------------------
211+ // ! 8) write DeePKS information
212+ // ------------------------------------------------------------------
215213#ifdef __DEEPKS
216214 if (this ->psi != nullptr && (istep % PARAM.inp .out_interval == 0 ))
217215 {
218216 hamilt::HamiltLCAO<TK, TR>* p_ham_deepks = dynamic_cast <hamilt::HamiltLCAO<TK, TR>*>(this ->p_hamilt );
219217 std::shared_ptr<LCAO_Deepks> ld_shared_ptr (&ld, [](LCAO_Deepks*) {});
220- LCAO_Deepks_Interface<TK, TR> LDI (ld_shared_ptr);
218+ LCAO_Deepks_Interface<TK, TR> deepks_interface (ld_shared_ptr);
221219
222- LDI .out_deepks_labels (this ->pelec ->f_en .etot ,
220+ deepks_interface .out_deepks_labels (this ->pelec ->f_en .etot ,
223221 this ->pelec ->klist ->get_nks (),
224222 ucell.nat ,
225223 PARAM.globalv .nlocal ,
@@ -235,36 +233,42 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
235233 }
236234#endif
237235
236+
237+ // ------------------------------------------------------------------
238238 // ! 9) Perform RDMFT calculations
239- /* ******* test RDMFT *********/
240- if (PARAM.inp .rdmft == true ) // rdmft, added by jghan, 2024-10-17
239+ // rdmft, added by jghan, 2024-10-17
240+ // ------------------------------------------------------------------
241+ if (PARAM.inp .rdmft == true )
241242 {
242- ModuleBase::matrix occ_number_ks (this ->pelec ->wg );
243- for (int ik = 0 ; ik < occ_number_ks .nr ; ++ik)
243+ ModuleBase::matrix occ_num (this ->pelec ->wg );
244+ for (int ik = 0 ; ik < occ_num .nr ; ++ik)
244245 {
245- for (int inb = 0 ; inb < occ_number_ks .nc ; ++inb)
246+ for (int inb = 0 ; inb < occ_num .nc ; ++inb)
246247 {
247- occ_number_ks (ik, inb) /= this ->kv .wk [ik];
248+ occ_num (ik, inb) /= this ->kv .wk [ik];
248249 }
249250 }
250- this ->rdmft_solver .update_elec (ucell, occ_number_ks , *(this ->psi ));
251+ this ->rdmft_solver .update_elec (ucell, occ_num , *(this ->psi ));
251252
252253 // ! initialize the gradients of Etotal with respect to occupation numbers and wfc,
253254 // ! and set all elements to 0.
254- ModuleBase::matrix dE_dOccNum (this ->pelec ->wg .nr , this ->pelec ->wg .nc , true );
255- psi::Psi<TK> dE_dWfc (this ->psi ->get_nk (), this ->psi ->get_nbands (), this ->psi ->get_nbasis (), this ->kv .ngk , true );
255+ // ! dedocc = d E/d Occ_Num
256+ ModuleBase::matrix dedocc (this ->pelec ->wg .nr , this ->pelec ->wg .nc , true );
257+
258+ // ! dedwfc = d E/d wfc
259+ psi::Psi<TK> dedwfc (this ->psi ->get_nk (), this ->psi ->get_nbands (), this ->psi ->get_nbasis (), this ->kv .ngk , true );
256260 dE_dWfc.zero_out ();
257261
258- double Etotal_RDMFT = this ->rdmft_solver .run (dE_dOccNum, dE_dWfc );
262+ double etot_rdmft = this ->rdmft_solver .run (dedocc, dedwfc );
259263 }
260- /* ******* test RDMFT ******** */
264+
261265
262266#ifdef __EXX
267+ // ------------------------------------------------------------------
263268 // 10) Write RPA information.
269+ // ------------------------------------------------------------------
264270 if (PARAM.inp .rpa )
265271 {
266- // ModuleRPA::DFT_RPA_interface
267- // rpa_interface(GlobalC::exx_info.info_global);
268272 RPA_LRI<TK, double > rpa_lri_double (GlobalC::exx_info.info_ri );
269273 rpa_lri_double.cal_postSCF_exx (*dynamic_cast <const elecstate::ElecStateLCAO<TK>*>(this ->pelec )->get_DM (),
270274 MPI_COMM_WORLD,
@@ -276,7 +280,10 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
276280 }
277281#endif
278282
283+
284+ // ------------------------------------------------------------------
279285 // 11) write HR in npz format.
286+ // ------------------------------------------------------------------
280287 if (PARAM.inp .out_hr_npz )
281288 {
282289 this ->p_hamilt ->updateHk (0 ); // first k point, up spin
@@ -295,7 +302,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
295302 }
296303 }
297304
305+ // ------------------------------------------------------------------
298306 // 12) write density matrix in the 'npz' format.
307+ // ------------------------------------------------------------------
299308 if (PARAM.inp .out_dm_npz )
300309 {
301310 const elecstate::DensityMatrix<TK, double >* dm
@@ -310,7 +319,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
310319 }
311320 }
312321
322+ // ------------------------------------------------------------------
313323 // ! 13) Print out information every 'out_interval' steps.
324+ // ------------------------------------------------------------------
314325 if (PARAM.inp .calculation != " md" || istep % PARAM.inp .out_interval == 0 )
315326 {
316327 // ! Print out sparse matrix
@@ -345,7 +356,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
345356 }
346357 }
347358
359+ // ------------------------------------------------------------------
348360 // ! 14) Print out atomic magnetization only when 'spin_constraint' is on.
361+ // ------------------------------------------------------------------
349362 if (PARAM.inp .sc_mag_switch )
350363 {
351364 spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance ();
@@ -354,14 +367,18 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
354367 sc.print_Mag_Force (GlobalV::ofs_running);
355368 }
356369
370+ // ------------------------------------------------------------------
357371 // ! 15) Clean up RA.
358372 // ! this should be last function and put it in the end, mohan request 2024-11-28
373+ // ------------------------------------------------------------------
359374 if (!PARAM.inp .cal_force && !PARAM.inp .cal_stress )
360375 {
361376 RA.delete_grid ();
362377 }
363378
379+ // ------------------------------------------------------------------
364380 // ! 16) Print out quasi-orbitals.
381+ // ------------------------------------------------------------------
365382 if (PARAM.inp .qo_switch )
366383 {
367384 toQO tqo (PARAM.inp .qo_basis , PARAM.inp .qo_strategy , PARAM.inp .qo_thr , PARAM.inp .qo_screening_coeff );
@@ -376,7 +393,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
376393 tqo.calculate ();
377394 }
378395
396+ // ------------------------------------------------------------------
379397 // ! 17) Print out kinetic matrix.
398+ // ------------------------------------------------------------------
380399 if (PARAM.inp .out_mat_tk [0 ])
381400 {
382401 hamilt::HS_Matrix_K<TK> hsk (&pv, true );
@@ -410,7 +429,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
410429 delete ekinetic;
411430 }
412431
413- // ! 18) Wannier 90 function, added by jingan in 2018.11.7
432+ // ------------------------------------------------------------------
433+ // ! 18) wannier90 interface, added by jingan in 2018.11.7
434+ // ------------------------------------------------------------------
414435 if (PARAM.inp .calculation == " nscf" && PARAM.inp .towannier90 )
415436 {
416437 std::cout << FmtCore::format (" \n * * * * * *\n << Start %s.\n " , " Wave function to Wannier90" );
@@ -449,7 +470,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
449470 std::cout << FmtCore::format (" >> Finish %s.\n * * * * * *\n " , " Wave function to Wannier90" );
450471 }
451472
473+ // ------------------------------------------------------------------
452474 // ! 19) berry phase calculations, added by jingan
475+ // ------------------------------------------------------------------
453476 if (PARAM.inp .calculation == " nscf" && berryphase::berry_phase_flag && ModuleSymmetry::Symmetry::symm_flag != 1 )
454477 {
455478 std::cout << FmtCore::format (" \n * * * * * *\n << Start %s.\n " , " Berry phase calculation" );
0 commit comments