@@ -280,62 +280,105 @@ void HSolverPW<T, Device>::solve(hamilt::Hamilt<T, Device>* pHamilt,
280280 std::vector<Real> eigenvalues (this ->wfc_basis ->nks * psi.get_nbands (), 0.0 );
281281 ethr_band.resize (psi.get_nbands (), this ->diag_thr );
282282
283- // using k-point continuity
283+ // Initialize k-point continuity if enabled
284+ static int count = 0 ;
284285 if (use_k_continuity) {
285286 build_k_neighbors ();
286287 }
287288
288- static int count = 0 ;
289+ // Loop over k points for solve Hamiltonian to charge density
290+ if (use_k_continuity) {
291+ // K-point continuity case
292+ for (int i = 0 ; i < this ->wfc_basis ->nks ; ++i)
293+ {
294+ const int ik = k_order[i];
295+
296+ // update H(k) for each k point
297+ pHamilt->updateHk (ik);
289298
290- // / Loop over k points for solve Hamiltonian to charge density
291- for (int i = 0 ; i < this ->wfc_basis ->nks ; ++i)
292- {
293- const int ik = use_k_continuity ? k_order[i] : i;
294- // ModuleBase::timer::tick("HsolverPW", "k_point: " + std::to_string(ik));
295- // / update H(k) for each k point
296- pHamilt->updateHk (ik);
299+ #ifdef USE_PAW
300+ this ->paw_func_in_kloop (ik, tpiba);
301+ #endif
302+
303+ // update psi pointer for each k point
304+ psi.fix_k (ik);
305+
306+ // If using k-point continuity and not first k-point, propagate from parent
307+ if (ik > 0 && count == 0 && k_parent.find (ik) != k_parent.end ()) {
308+ propagate_psi (psi, k_parent[ik], ik);
309+ }
310+
311+ // template add precondition calculating here
312+ update_precondition (precondition, ik, this ->wfc_basis ->npwk [ik], Real (pes->pot ->get_vl_of_0 ()));
313+
314+ // use smooth threshold for all iter methods
315+ if (PARAM.inp .diago_smooth_ethr == true )
316+ {
317+ this ->cal_smooth_ethr (pes->klist ->wk [ik],
318+ &pes->wg (ik, 0 ),
319+ DiagoIterAssist<T, Device>::PW_DIAG_THR,
320+ ethr_band);
321+ }
297322
298323#ifdef USE_PAW
299- this ->paw_func_in_kloop (ik, tpiba );
324+ this ->call_paw_cell_set_currentk (ik);
300325#endif
301326
302- // / update psi pointer for each k point
303- psi. fix_k (ik );
327+ // solve eigenvector and eigenvalue for H(k)
328+ this -> hamiltSolvePsiK (pHamilt, psi, precondition, eigenvalues. data () + ik * psi. get_nbands (), this -> wfc_basis -> nks );
304329
305- // If using k-point continuity and not first k-point, propagate from parent
306- if (use_k_continuity && ik > 0 && count == 0 ) {
307- propagate_psi (psi, k_parent[ik], ik);
330+ if (skip_charge)
331+ {
332+ GlobalV::ofs_running << " Average iterative diagonalization steps for k-points " << ik
333+ << " is: " << DiagoIterAssist<T, Device>::avg_iter
334+ << " ; where current threshold is: " << this ->diag_thr << " . " << std::endl;
335+ DiagoIterAssist<T, Device>::avg_iter = 0.0 ;
336+ }
308337 }
338+ }
339+ else {
340+ // Original code without k-point continuity
341+ for (int ik = 0 ; ik < this ->wfc_basis ->nks ; ++ik)
342+ {
343+ // update H(k) for each k point
344+ pHamilt->updateHk (ik);
309345
310- // template add precondition calculating here
311- update_precondition (precondition, ik, this ->wfc_basis ->npwk [ik], Real (pes->pot ->get_vl_of_0 ()));
346+ #ifdef USE_PAW
347+ this ->paw_func_in_kloop (ik, tpiba);
348+ #endif
312349
313- // use smooth threshold for all iter methods
314- if (PARAM.inp .diago_smooth_ethr == true )
315- {
316- this ->cal_smooth_ethr (pes->klist ->wk [ik],
317- &pes->wg (ik, 0 ),
318- DiagoIterAssist<T, Device>::PW_DIAG_THR,
319- ethr_band);
320- }
350+ // update psi pointer for each k point
351+ psi.fix_k (ik);
352+
353+ // template add precondition calculating here
354+ update_precondition (precondition, ik, this ->wfc_basis ->npwk [ik], Real (pes->pot ->get_vl_of_0 ()));
355+
356+ // use smooth threshold for all iter methods
357+ if (PARAM.inp .diago_smooth_ethr == true )
358+ {
359+ this ->cal_smooth_ethr (pes->klist ->wk [ik],
360+ &pes->wg (ik, 0 ),
361+ DiagoIterAssist<T, Device>::PW_DIAG_THR,
362+ ethr_band);
363+ }
321364
322365#ifdef USE_PAW
323- this ->call_paw_cell_set_currentk (ik);
366+ this ->call_paw_cell_set_currentk (ik);
324367#endif
325368
326- / / / solve eigenvector and eigenvalue for H(k)
327- this ->hamiltSolvePsiK (pHamilt, psi, precondition, eigenvalues.data () + ik * psi.get_nbands (), this ->wfc_basis ->nks );
369+ // solve eigenvector and eigenvalue for H(k)
370+ this ->hamiltSolvePsiK (pHamilt, psi, precondition, eigenvalues.data () + ik * psi.get_nbands (), this ->wfc_basis ->nks );
328371
329- if (skip_charge)
330- {
331- GlobalV::ofs_running << " Average iterative diagonalization steps for k-points " << ik
332- << " is: " << DiagoIterAssist<T, Device>::avg_iter
333- << " ; where current threshold is: " << this ->diag_thr << " . " << std::endl;
334- DiagoIterAssist<T, Device>::avg_iter = 0.0 ;
372+ if (skip_charge)
373+ {
374+ GlobalV::ofs_running << " Average iterative diagonalization steps for k-points " << ik
375+ << " is: " << DiagoIterAssist<T, Device>::avg_iter
376+ << " ; where current threshold is: " << this ->diag_thr << " . " << std::endl;
377+ DiagoIterAssist<T, Device>::avg_iter = 0.0 ;
378+ }
335379 }
336- // ModuleBase::timer::tick("HsolverPW", "k_point: " + std::to_string(ik));
337- // / calculate the contribution of Psi for charge density rho
338380 }
381+
339382 count++;
340383 // END Loop over k points
341384
0 commit comments