Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions source/source_io/output_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs,
}
else
{
title += " (KBAR)";
unit = " KBAR";
title += " (kbar)";
unit = " kbar";
unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8;
}
std::vector<double> stress_x;
Expand Down Expand Up @@ -317,7 +317,7 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs,
fmt << stress_x << stress_y << stress_z;
table = fmt.str();
ofs << table;
if (name == "TOTAL-STRESS")
if (name == "TOTAL-STRESS" && PARAM.inp.calculation != "md")
{
ofs << " #TOTAL-PRESSURE# (EXCLUDE KINETIC PART OF IONS): " << std::fixed
<< std::setprecision(6) << pressure << unit
Expand Down
4 changes: 2 additions & 2 deletions source/source_io/test/outputlog_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ TEST(PrintStress, PrintStress)
std::string output_str;
getline(ifs, output_str);
getline(ifs, output_str); // mohan add 2025-06-22
EXPECT_THAT(output_str, testing::HasSubstr(" #TOTAL-STRESS (KBAR)#"));
EXPECT_THAT(output_str, testing::HasSubstr(" #TOTAL-STRESS (kbar)#"));

getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr("----------------------------------------------------------------"));
Expand All @@ -316,7 +316,7 @@ TEST(PrintStress, PrintStress)
EXPECT_THAT(output_str, testing::HasSubstr("----------------------------------------------------------------"));

getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" #TOTAL-PRESSURE# (EXCLUDE KINETIC PART OF IONS): 49035.075992 KBAR"));
EXPECT_THAT(output_str, testing::HasSubstr(" #TOTAL-PRESSURE# (EXCLUDE KINETIC PART OF IONS): 49035.075992 kbar"));
ifs.close();
std::remove("running_stress.txt");
}
Expand Down
14 changes: 8 additions & 6 deletions source/source_md/md_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress)
// running_log output
ofs.unsetf(std::ios::fixed);
ofs << std::setprecision(8);

if (cal_stress)
{
MD_func::print_stress(ofs, virial, stress);
ofs << std::endl;
}

ofs << " ------------------------------------------------------------------------------------------------"
<< std::endl;
ofs << " " << std::left << std::setw(20) << "Energy (Ry)" << std::left << std::setw(20) << "Potential (Ry)"
Expand All @@ -209,12 +216,7 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress)
ofs << std::endl;
ofs << " ------------------------------------------------------------------------------------------------"
<< std::endl;

if (cal_stress)
{
MD_func::print_stress(ofs, virial, stress);
}

ofs << std::endl;
return;
}

Expand Down
3 changes: 2 additions & 1 deletion source/source_md/md_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,10 @@ void print_stress(std::ofstream& ofs, const ModuleBase::matrix& virial, const Mo

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

ofs << " MD PRESSURE (ELECTRONS+IONS) : " << stress_scalar * unit_transform << " kbar" << std::endl;

ofs << " ELECTRONIC PART OF STRESS: " << virial_scalar * unit_transform << " kbar" << std::endl;
ofs << " IONIC (KINETIC) PART OF STRESS: " << (stress_scalar - virial_scalar) * unit_transform << " kbar" << std::endl;
ofs << " MD PRESSURE (ELECTRONS+IONS) : " << stress_scalar * unit_transform << " kbar" << std::endl;

// one should use 'print_stress' function in ../source/source_io/output_log.cpp
/*
Expand Down
27 changes: 7 additions & 20 deletions source/source_md/test/fire_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,44 +184,31 @@ TEST_F(FIREtest, PrintMD)
std::ifstream ifs("running_fire.log");
std::string output_str;

// Line 1
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.83853919 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0846391 kbar"));
getline(ifs, output_str);
getline(ifs, output_str);
EXPECT_THAT(output_str,
testing::HasSubstr(
" ------------------------------------------------------------------------------------------------"));

// Line 2
getline(ifs, output_str);
EXPECT_THAT(output_str,
testing::HasSubstr(
" Energy (Ry) Potential (Ry) Kinetic (Ry) Temperature (K) Pressure (kbar) "));

// Line 3
getline(ifs, output_str);
EXPECT_THAT(output_str,
testing::HasSubstr(
" -0.015365236 -0.023915637 0.0085504016 300 1.0846391 "));

// Line 4
getline(ifs, output_str);
EXPECT_THAT(
output_str,
testing::HasSubstr(
" ------------------------------------------------------------------------------------------------"));

// Line 5
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0846391 kbar"));

// Line 6
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992 kbar"));

// Line 7
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.83853919 kbar"));

// Line 8
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" LARGEST FORCE (eV/A) : 0.049479926"));

Expand Down
7 changes: 7 additions & 0 deletions source/source_md/test/langevin_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ TEST_F(Langevin_test, print_md)

std::ifstream ifs("running_langevin.log");
std::string output_str;
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.83853919 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0846391 kbar"));
getline(ifs, output_str);
getline(ifs, output_str);
EXPECT_THAT(
output_str,
Expand Down
4 changes: 2 additions & 2 deletions source/source_md/test/md_func_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ TEST_F(MD_func_test, print_stress)
std::ifstream ifs("running.log");
std::string output_str;
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr("MD PRESSURE (ELECTRONS+IONS) : 0 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr("ELECTRONIC PART OF STRESS: 0 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr("IONIC (KINETIC) PART OF STRESS: 0 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr("MD PRESSURE (ELECTRONS+IONS) : 0 kbar"));
/*
getline(ifs, output_str);
getline(ifs, output_str);
Expand Down
7 changes: 7 additions & 0 deletions source/source_md/test/msst_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ TEST_F(MSST_test, print_md)

std::ifstream ifs("running_msst.log");
std::string output_str;
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.8301538 kbar")); // result different from other MD methods
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0762537 kbar")); // result different from other MD methods
getline(ifs, output_str);
getline(ifs, output_str);
EXPECT_THAT(
output_str,
Expand Down
7 changes: 7 additions & 0 deletions source/source_md/test/nhchain_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ TEST_F(NHC_test, print_md)

std::ifstream ifs("running_nhchain.log");
std::string output_str;
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.83853919 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0846391 kbar"));
getline(ifs, output_str);
getline(ifs, output_str);
EXPECT_THAT(
output_str,
Expand Down
7 changes: 7 additions & 0 deletions source/source_md/test/verlet_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ TEST_F(Verlet_test, print_md)

std::ifstream ifs("running_verlet.log");
std::string output_str;
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.83853919 kbar"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0846391 kbar"));
getline(ifs, output_str);
getline(ifs, output_str);
EXPECT_THAT(
output_str,
Expand Down
Loading