diff --git a/source/source_io/output_log.cpp b/source/source_io/output_log.cpp index f719c6485e..e95aa69053 100644 --- a/source/source_io/output_log.cpp +++ b/source/source_io/output_log.cpp @@ -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 stress_x; @@ -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 diff --git a/source/source_io/test/outputlog_test.cpp b/source/source_io/test/outputlog_test.cpp index 92618bda66..4932596039 100644 --- a/source/source_io/test/outputlog_test.cpp +++ b/source/source_io/test/outputlog_test.cpp @@ -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("----------------------------------------------------------------")); @@ -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"); } diff --git a/source/source_md/md_base.cpp b/source/source_md/md_base.cpp index cf15aedcaf..d1e4b67292 100644 --- a/source/source_md/md_base.cpp +++ b/source/source_md/md_base.cpp @@ -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)" @@ -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; } diff --git a/source/source_md/md_func.cpp b/source/source_md/md_func.cpp index 245992401e..d6c09beafc 100644 --- a/source/source_md/md_func.cpp +++ b/source/source_md/md_func.cpp @@ -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 /* diff --git a/source/source_md/test/fire_test.cpp b/source/source_md/test/fire_test.cpp index 345f0619e4..61528b91c0 100644 --- a/source/source_md/test/fire_test.cpp +++ b/source/source_md/test/fire_test.cpp @@ -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")); diff --git a/source/source_md/test/langevin_test.cpp b/source/source_md/test/langevin_test.cpp index 9f8f4b78a4..7a3254454d 100644 --- a/source/source_md/test/langevin_test.cpp +++ b/source/source_md/test/langevin_test.cpp @@ -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, diff --git a/source/source_md/test/md_func_test.cpp b/source/source_md/test/md_func_test.cpp index 4ec77c61f9..8455823885 100644 --- a/source/source_md/test/md_func_test.cpp +++ b/source/source_md/test/md_func_test.cpp @@ -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); diff --git a/source/source_md/test/msst_test.cpp b/source/source_md/test/msst_test.cpp index ccb580538f..b59652a6fd 100644 --- a/source/source_md/test/msst_test.cpp +++ b/source/source_md/test/msst_test.cpp @@ -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, diff --git a/source/source_md/test/nhchain_test.cpp b/source/source_md/test/nhchain_test.cpp index dac231ddae..60e9525d97 100644 --- a/source/source_md/test/nhchain_test.cpp +++ b/source/source_md/test/nhchain_test.cpp @@ -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, diff --git a/source/source_md/test/verlet_test.cpp b/source/source_md/test/verlet_test.cpp index 3f070569ce..00013abf15 100644 --- a/source/source_md/test/verlet_test.cpp +++ b/source/source_md/test/verlet_test.cpp @@ -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,