Skip to content

Commit 9a8552d

Browse files
committed
update md outputs
1 parent 959fe8b commit 9a8552d

File tree

4 files changed

+45
-24
lines changed

4 files changed

+45
-24
lines changed

source/module_base/memory.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,9 @@ void Memory::print_all(std::ofstream &ofs)
385385
Parallel_Reduce::reduce_all(Memory::total_gpu);
386386
#endif
387387
#endif
388-
ofs <<"\n NAME-------------------------|MEMORY(MB)--------" << std::endl;
389-
ofs <<std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total << std::endl;
388+
ofs <<"\n NAME-------------------------|MEMORY(MB)------------------" << std::endl;
389+
ofs << std::right;
390+
ofs << std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total << std::endl;
390391

391392
assert(n_memory>0);
392393

@@ -440,7 +441,7 @@ void Memory::print_all(std::ofstream &ofs)
440441
return;
441442
}
442443

443-
ofs <<"\n NAME-------------------------|GPU MEMORY(MB)----" << std::endl;
444+
ofs <<"\n NAME-------------------------|GPU MEMORY(MB)--------------" << std::endl;
444445
ofs <<std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total_gpu << std::endl;
445446

446447
assert(n_memory>0);

source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -733,19 +733,14 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
733733
GlobalV::ofs_running << std::setiosflags(std::ios::showpos);
734734
GlobalV::ofs_running << std::setiosflags(std::ios::fixed) << std::setprecision(10) << std::endl;
735735
ModuleIO::print_stress("OVERLAP STRESS", soverlap, PARAM.inp.test_stress, ry);
736-
// test
737736
ModuleIO::print_stress("T STRESS", stvnl_dphi, PARAM.inp.test_stress, ry);
738737
ModuleIO::print_stress("VNL STRESS", svnl_dbeta, PARAM.inp.test_stress, ry);
739-
740738
ModuleIO::print_stress("T_VNL STRESS", stvnl, PARAM.inp.test_stress, ry);
741-
742739
ModuleIO::print_stress("VL_dPHI STRESS", svl_dphi, PARAM.inp.test_stress, ry);
743740
ModuleIO::print_stress("VL_dVL STRESS", sigmadvl, PARAM.inp.test_stress, ry);
744741
ModuleIO::print_stress("HAR STRESS", sigmahar, PARAM.inp.test_stress, ry);
745-
746742
ModuleIO::print_stress("EWALD STRESS", sigmaewa, PARAM.inp.test_stress, ry);
747743
ModuleIO::print_stress("cc STRESS", sigmacc, PARAM.inp.test_stress, ry);
748-
// ModuleIO::print_stress("NLCC STRESS",sigmacc,PARAM.inp.test_stress,ry);
749744
ModuleIO::print_stress("XC STRESS", sigmaxc, PARAM.inp.test_stress, ry);
750745
if (vdw_solver != nullptr)
751746
{
@@ -760,11 +755,13 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
760755
ModuleIO::print_stress("DeltaSpin STRESS", stress_dspin, PARAM.inp.test_stress, ry);
761756
}
762757
ModuleIO::print_stress("TOTAL STRESS", scs, PARAM.inp.test_stress, ry);
763-
764758
} // end of test
759+
765760
GlobalV::ofs_running << std::setiosflags(std::ios::left);
761+
766762
// print total stress
767-
ModuleIO::print_stress("TOTAL-STRESS", scs, true, ry);
763+
bool screen = false;
764+
ModuleIO::print_stress("TOTAL-STRESS", scs, screen, ry);
768765

769766
double unit_transform = 0.0;
770767
unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8;

source/module_io/output_log.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ void print_force(std::ofstream& ofs_running,
223223
std::vector<double> force_y;
224224
std::vector<double> force_z;
225225
std::string table;
226-
std::vector<std::string> titles({name, "", "", ""});
226+
227+
ofs_running << " " << name << std::endl;
228+
229+
std::vector<std::string> titles({"Atoms", "Force_x", "Force_y", "Force_z"});
227230
int iat = 0;
228231
for (int it = 0; it < cell.ntype; it++)
229232
{
@@ -242,13 +245,24 @@ void print_force(std::ofstream& ofs_running,
242245
}
243246
}
244247

245-
FmtTable fmt(titles, atom_label.size(), {"%10s", "%20.10f", "%20.10f", "%20.10f"});
248+
// titles: titles for each column
249+
// atom_label.size(): number of lines in this table
250+
// format for each value in the column
251+
FmtTable fmt(titles,
252+
atom_label.size(),
253+
{"%8s", "%20.10f", "%20.10f", "%20.10f"},
254+
{FmtTable::Align::RIGHT,FmtTable::Align::RIGHT});
255+
246256
fmt << atom_label << force_x << force_y << force_z;
247257
table = fmt.str();
248258
ofs_running << table << std::endl;
249-
if (PARAM.inp.test_force) { std::cout << table << std::endl;
250-
}
259+
260+
if (PARAM.inp.test_force)
261+
{
262+
std::cout << table << std::endl;
263+
}
251264
}
265+
252266
void print_stress(const std::string& name, const ModuleBase::matrix& scs, const bool screen, const bool ry)
253267
{
254268
const double output_acc = 1.0e-8;
@@ -270,7 +284,10 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const
270284
std::vector<double> stress_y;
271285
std::vector<double> stress_z;
272286
std::string table;
273-
std::vector<std::string> titles({title, "", ""});
287+
288+
GlobalV::ofs_running << " " << title << std::endl;
289+
290+
std::vector<std::string> titles({"Stress_x", "Stress_y", "Stress_z"});
274291
for (int i = 0; i < 3; i++)
275292
{
276293
double sx = scs(i, 0) * unit_transform;
@@ -283,22 +300,25 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const
283300

284301
double pressure = (scs(0, 0) + scs(1, 1) + scs(2, 2)) / 3.0 * unit_transform;
285302

286-
FmtTable fmt(titles, 3, {"%20.10f", "%20.10f", "%20.10f"});
303+
FmtTable fmt(titles, 3, {"%20.10f", "%20.10f", "%20.10f"},
304+
{FmtTable::Align::RIGHT,FmtTable::Align::RIGHT});
305+
287306
fmt << stress_x << stress_y << stress_z;
288307
table = fmt.str();
289308
GlobalV::ofs_running << table;
290309
if (name == "TOTAL-STRESS")
291310
{
292-
GlobalV::ofs_running << " TOTAL-PRESSURE: " << std::fixed << std::setprecision(6) << pressure << unit
293-
<< std::endl
311+
GlobalV::ofs_running << " TOTAL-PRESSURE (DO NOT INCLUDE KINETIC PART OF IONS): " << std::fixed
312+
<< std::setprecision(6) << pressure << unit
294313
<< std::endl;
295314
}
296315
if (screen)
297316
{
298317
std::cout << table;
299318
if (name == "TOTAL-STRESS")
300319
{
301-
std::cout << " TOTAL-PRESSURE: " << std::fixed << std::setprecision(6) << pressure << unit << std::endl
320+
std::cout << " TOTAL-PRESSURE (DO NOT INCLUDE KINETIC PART OF IONS): " << std::fixed
321+
<< std::setprecision(6) << pressure << unit
302322
<< std::endl;
303323
}
304324
}

source/module_md/md_func.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,18 @@ void print_stress(std::ofstream& ofs, const ModuleBase::matrix& virial, const Mo
293293

294294
for (int i = 0; i < 3; i++)
295295
{
296-
stress_scalar += stress(i, i) / 3;
297-
virial_scalar += virial(i, i) / 3;
296+
stress_scalar += stress(i, i) / 3.0;
297+
virial_scalar += virial(i, i) / 3.0;
298298
}
299299

300300
const double unit_transform = ModuleBase::HARTREE_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8;
301301

302-
ofs << "Virtual Pressure is " << stress_scalar * unit_transform << " kbar " << std::endl;
303-
ofs << "Virial Term is " << virial_scalar * unit_transform << " kbar " << std::endl;
304-
ofs << "Kinetic Term is " << (stress_scalar - virial_scalar) * unit_transform << " kbar " << std::endl;
302+
ofs << " MD PRESSURE (ELECTRONS+IONS) : " << stress_scalar * unit_transform << " KBAR" << std::endl;
303+
ofs << " ELECTRONIC PART OF STRESS: " << virial_scalar * unit_transform << " KBAR" << std::endl;
304+
ofs << " IONIC (KINETIC) PART OF STRESS: " << (stress_scalar - virial_scalar) * unit_transform << " KBAR" << std::endl;
305305

306+
// one should use 'print_stress' function in ../source/module_io/output_log.cpp
307+
/*
306308
ofs.unsetf(std::ios::fixed);
307309
ofs << std::setprecision(8) << std::endl;
308310
ModuleBase::GlobalFunc::NEW_PART("MD STRESS (kbar)");
@@ -312,6 +314,7 @@ void print_stress(std::ofstream& ofs, const ModuleBase::matrix& virial, const Mo
312314
<< std::setw(15) << stress(i, 2) * unit_transform << std::endl;
313315
}
314316
ofs << std::setiosflags(std::ios::left);
317+
*/
315318

316319
return;
317320
}

0 commit comments

Comments
 (0)