@@ -250,13 +250,16 @@ void print_band(const ModuleBase::matrix& ekb,
250250 const K_Vectors* klist,
251251 const int & ik,
252252 const int & printe,
253- const int & iter)
253+ const int & iter,
254+ std::ofstream &ofs)
254255{
256+ const double largest_eig = 1.0e10 ;
257+
255258 // check the band energy.
256259 bool wrong = false ;
257260 for (int ib = 0 ; ib < PARAM.globalv .nbands_l ; ++ib)
258261 {
259- if (std::abs (ekb (ik, ib)) > 1.0e10 )
262+ if (std::abs (ekb (ik, ib)) > largest_eig )
260263 {
261264 GlobalV::ofs_warning << " ik=" << ik + 1 << " ib=" << ib + 1 << " " << ekb (ik, ib) << " Ry" << std::endl;
262265 wrong = true ;
@@ -271,18 +274,18 @@ void print_band(const ModuleBase::matrix& ekb,
271274 {
272275 if (printe > 0 && ((iter + 1 ) % printe == 0 ))
273276 {
274- GlobalV::ofs_running << std::setprecision (6 );
275- GlobalV::ofs_running << " Energy (eV) & Occupations for spin=" << klist->isk [ik] + 1
276- << " K -point=" << ik + 1 << std::endl;
277- GlobalV::ofs_running << std::setiosflags (std::ios::showpoint);
277+ ofs << std::setprecision (6 );
278+ ofs << " Energy (eV) & Occupations for spin=" << klist->isk [ik] + 1
279+ << " k -point=" << ik + 1 << std::endl;
280+ ofs << std::setiosflags (std::ios::showpoint);
278281 for (int ib = 0 ; ib < PARAM.globalv .nbands_l ; ib++)
279282 {
280- GlobalV::ofs_running << " " << std::setw (6 ) << ib + 1 << std::setw (15 )
283+ ofs << " " << std::setw (6 ) << ib + 1 << std::setw (15 )
281284 << ekb (ik, ib) * ModuleBase::Ry_to_eV;
282285 // for the first electron iteration, we don't have the energy
283286 // spectrum, so we can't get the occupations.
284- GlobalV::ofs_running << std::setw (15 ) << wg (ik, ib);
285- GlobalV::ofs_running << std::endl;
287+ ofs << std::setw (15 ) << wg (ik, ib);
288+ ofs << std::endl;
286289 }
287290 }
288291 }
@@ -317,7 +320,7 @@ void print_etot(const Magnetism& magnet,
317320
318321 GlobalV::ofs_running << std::setprecision (12 );
319322 GlobalV::ofs_running << std::setiosflags (std::ios::right);
320- GlobalV::ofs_running << " \n Density error is " << scf_thr << std::endl;
323+ GlobalV::ofs_running << " Electron density error is " << scf_thr << std::endl;
321324
322325 if (PARAM.inp .basis_type == " pw" )
323326 {
@@ -327,6 +330,7 @@ void print_etot(const Magnetism& magnet,
327330 std::vector<std::string> titles;
328331 std::vector<double > energies_Ry;
329332 std::vector<double > energies_eV;
333+
330334 if (printe > 0 && ((iter + 1 ) % printe == 0 || converged || iter == PARAM.inp .scf_nmax ))
331335 {
332336 int n_order = std::max (0 , Occupy::gaussian_type);
@@ -384,7 +388,7 @@ void print_etot(const Magnetism& magnet,
384388 }
385389
386390#ifdef __DEEPKS
387- if (PARAM.inp .deepks_scf ) // caoyu add 2021-08-10
391+ if (PARAM.inp .deepks_scf )
388392 {
389393 titles.push_back (" E_DeePKS" );
390394 energies_Ry.push_back (elec.f_en .edeepks_delta );
@@ -399,6 +403,7 @@ void print_etot(const Magnetism& magnet,
399403 energies_Ry.push_back (elec.f_en .etot_harris );
400404 }
401405
406+ // print out the Fermi energy if needed
402407 if (PARAM.globalv .two_fermi )
403408 {
404409 titles.push_back (" E_Fermi_up" );
@@ -411,6 +416,8 @@ void print_etot(const Magnetism& magnet,
411416 titles.push_back (" E_Fermi" );
412417 energies_Ry.push_back (elec.eferm .ef );
413418 }
419+
420+ // print out the band gap if needed
414421 if (PARAM.inp .out_bandgap )
415422 {
416423 if (!PARAM.globalv .two_fermi )
@@ -430,14 +437,21 @@ void print_etot(const Magnetism& magnet,
430437 std::transform (energies_Ry.begin (), energies_Ry.end (), energies_eV.begin (), [](double ener) {
431438 return ener * ModuleBase::Ry_to_eV;
432439 });
440+
441+ // for each SCF step, we print out energy
433442 FmtTable table (/* titles=*/ {" Energy" , " Rydberg" , " eV" },
434443 /* nrows=*/ titles.size (),
435444 /* formats=*/ {" %-14s" , " %20.10f" , " %20.10f" },
436445 /* indents=*/ 0 ,
437446 /* align=*/ {/* value*/ FmtTable::Align::LEFT, /* title*/ FmtTable::Align::CENTER});
447+ // print out the titles
438448 table << titles << energies_Ry << energies_eV;
449+
439450 GlobalV::ofs_running << table.str () << std::endl;
440- if (PARAM.inp .out_level == " ie" || PARAM.inp .out_level == " m" ) // xiaohui add 'm' option, 2015-09-16
451+
452+
453+
454+ if (PARAM.inp .out_level == " ie" || PARAM.inp .out_level == " m" )
441455 {
442456 std::vector<double > mag;
443457 switch (PARAM.inp .nspin )
0 commit comments