diff --git a/source/module_md/fire.cpp b/source/module_md/fire.cpp index 3299e05795..98f294db19 100644 --- a/source/module_md/fire.cpp +++ b/source/module_md/fire.cpp @@ -74,7 +74,8 @@ void FIRE::print_md(std::ofstream& ofs, const bool& cal_stress) { MD_base::print_md(ofs, cal_stress); - ofs << " LARGEST GRAD (eV/A) : " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << std::endl; + ofs << "\n Largest gradient in force is " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << " eV/A." << std::endl; + ofs << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A." << std::endl; std::cout << " LARGEST GRAD (eV/A) : " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << std::endl; return; diff --git a/source/module_md/test/fire_test.cpp b/source/module_md/test/fire_test.cpp index fda23e7285..2ecdf3030b 100644 --- a/source/module_md/test/fire_test.cpp +++ b/source/module_md/test/fire_test.cpp @@ -205,11 +205,13 @@ TEST_F(FIREtest, PrintMD) output_str, testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); - for (int i = 0; i < 10; ++i) + for (int i = 0; i < 11; ++i) { getline(ifs, output_str); } - EXPECT_THAT(output_str, testing::HasSubstr(" LARGEST GRAD (eV/A) : 0.049479926")); + EXPECT_THAT(output_str, testing::HasSubstr(" Largest gradient in force is 0.049479926 eV/A")); + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr(" Threshold is -1 eV/A.")); ifs.close(); remove("running.log"); } diff --git a/source/module_relax/relax_new/relax.cpp b/source/module_relax/relax_new/relax.cpp index 8507e6a2c9..41d7b28bff 100644 --- a/source/module_relax/relax_new/relax.cpp +++ b/source/module_relax/relax_new/relax.cpp @@ -140,6 +140,9 @@ bool Relax::setup_gradient(const ModuleBase::matrix& force, const ModuleBase::ma std::cout << " LARGEST GRAD (eV/A) : " << max_grad << std::endl; etot_p = etot; } + + GlobalV::ofs_running << "\n Largest gradient in force is " << max_grad << " eV/A." << std::endl; + GlobalV::ofs_running << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A." << std::endl; //========================================= //set gradient for cell degrees of freedom //========================================= @@ -223,8 +226,8 @@ bool Relax::setup_gradient(const ModuleBase::matrix& force, const ModuleBase::ma force_converged = false; } - GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << std::endl; - GlobalV::ofs_running << "\n Threshold is = " << PARAM.inp.stress_thr << std::endl; + GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << " kbar." << std::endl; + GlobalV::ofs_running << " Threshold is " << PARAM.inp.stress_thr << " kbar." << std::endl; } if(force_converged) diff --git a/source/module_relax/relax_old/ions_move_basic.cpp b/source/module_relax/relax_old/ions_move_basic.cpp index 2215b4daba..a68dbeb7e0 100644 --- a/source/module_relax/relax_old/ions_move_basic.cpp +++ b/source/module_relax/relax_old/ions_move_basic.cpp @@ -147,6 +147,10 @@ void Ions_Move_Basic::check_converged(const UnitCell &ucell, const double *grad) std::cout << " ETOT DIFF (eV) : " << Ions_Move_Basic::ediff * ModuleBase::Ry_to_eV << std::endl; std::cout << " LARGEST GRAD (eV/A) : " << Ions_Move_Basic::largest_grad * ModuleBase::Ry_to_eV / 0.529177 << std::endl; + + GlobalV::ofs_running << "\n Largest gradient in force is " << largest_grad * ModuleBase::Ry_to_eV / 0.529177 + << " eV/A." << std::endl; + GlobalV::ofs_running << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A." << std::endl; } const double etot_diff = std::abs(Ions_Move_Basic::ediff); @@ -165,8 +169,6 @@ void Ions_Move_Basic::check_converged(const UnitCell &ucell, const double *grad) { GlobalV::ofs_running << "\n Ion relaxation is converged!" << std::endl; GlobalV::ofs_running << "\n Energy difference (Ry) = " << etot_diff << std::endl; - GlobalV::ofs_running << "\n Largest gradient is (eV/A) = " << largest_grad * ModuleBase::Ry_to_eV / 0.529177 - << std::endl; Ions_Move_Basic::converged = true; ++Ions_Move_Basic::update_iter; diff --git a/source/module_relax/relax_old/lattice_change_basic.cpp b/source/module_relax/relax_old/lattice_change_basic.cpp index b506f07b7c..c145d36ee8 100644 --- a/source/module_relax/relax_old/lattice_change_basic.cpp +++ b/source/module_relax/relax_old/lattice_change_basic.cpp @@ -72,8 +72,8 @@ void Lattice_Change_Basic::change_lattice(UnitCell &ucell, double *move, double { ModuleBase::TITLE("Lattice_Change_Basic", "change_lattice"); - assert(move != NULL); - assert(lat != NULL); + assert(move != nullptr); + assert(lat != nullptr); /* std::cout<<" LATTICE CONSTANT OLD:"< 0) { ModuleBase::matrix move_mat_t(3, 3); - for (int i = 0;i < 3;++i)for (int j = 0;j < 3;++j)move_mat_t(j, i) = move[i * 3 + j] / ucell.lat0; //transpose + for (int i = 0;i < 3;++i) {for (int j = 0;j < 3;++j) {move_mat_t(j, i) = move[i * 3 + j] / ucell.lat0; //transpose +} +} ModuleBase::matrix symm_move_mat_t = (move_mat_t * ucell.G.to_matrix());//symmetrize (latvec^{-1} * move_mat)^T ucell.symm.symmetrize_mat3(symm_move_mat_t, ucell.lat); move_mat_t = symm_move_mat_t * ucell.latvec.Transpose().to_matrix();//G^{-1}=latvec^T - for (int i = 0;i < 3;++i)for (int j = 0;j < 3;++j)move[i * 3 + j] = move_mat_t(j, i) * ucell.lat0;//transpose back + for (int i = 0;i < 3;++i) {for (int j = 0;j < 3;++j) {move[i * 3 + j] = move_mat_t(j, i) * ucell.lat0;//transpose back +} +} } if (ucell.lc[0] != 0) @@ -167,8 +171,9 @@ void Lattice_Change_Basic::check_converged(const UnitCell &ucell, ModuleBase::ma { for (int i = 0; i < 3; i++) { - if (stress_ii_max < std::abs(stress(i, i))) + if (stress_ii_max < std::abs(stress(i, i))) { stress_ii_max = std::abs(stress(i, i)); +} for (int j = 0; j < 3; j++) { if (Lattice_Change_Basic::largest_grad < std::abs(stress(i, j))) @@ -207,14 +212,15 @@ void Lattice_Change_Basic::check_converged(const UnitCell &ucell, ModuleBase::ma if (Lattice_Change_Basic::largest_grad < PARAM.inp.stress_thr && stress_ii_max < PARAM.inp.stress_thr) { GlobalV::ofs_running << "\n Lattice relaxation is converged!" << std::endl; - GlobalV::ofs_running << "\n Largest gradient is = " << largest_grad << std::endl; + GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << " kbar." << std::endl; + GlobalV::ofs_running << " Threshold is " << PARAM.inp.stress_thr << " kbar." << std::endl; Lattice_Change_Basic::converged = true; ++Lattice_Change_Basic::update_iter; } else { GlobalV::ofs_running << "\n Lattice relaxation is not converged yet (threshold is " << PARAM.inp.stress_thr - << ")" << std::endl; + << " kbar)" << std::endl; Lattice_Change_Basic::converged = false; } } @@ -227,14 +233,15 @@ void Lattice_Change_Basic::check_converged(const UnitCell &ucell, ModuleBase::ma if (Lattice_Change_Basic::largest_grad < 10 * PARAM.inp.stress_thr) { GlobalV::ofs_running << "\n Lattice relaxation is converged!" << std::endl; - GlobalV::ofs_running << "\n Largest gradient is = " << largest_grad << std::endl; + GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << " kbar." << std::endl; + GlobalV::ofs_running << " Threshold is " << PARAM.inp.stress_thr << " kbar." << std::endl; Lattice_Change_Basic::converged = true; ++Lattice_Change_Basic::update_iter; } else { GlobalV::ofs_running << "\n Lattice relaxation is not converged yet (threshold is " << PARAM.inp.stress_thr - << ")" << std::endl; + << " kbar)" << std::endl; Lattice_Change_Basic::converged = false; } } @@ -242,7 +249,7 @@ void Lattice_Change_Basic::check_converged(const UnitCell &ucell, ModuleBase::ma return; } -void Lattice_Change_Basic::terminate(void) +void Lattice_Change_Basic::terminate() { ModuleBase::TITLE("Lattice_Change_Basic", "terminate"); if (Lattice_Change_Basic::converged) diff --git a/source/module_relax/relax_old/test/ions_move_basic_test.cpp b/source/module_relax/relax_old/test/ions_move_basic_test.cpp index af2595ea21..fb38d17dfc 100644 --- a/source/module_relax/relax_old/test/ions_move_basic_test.cpp +++ b/source/module_relax/relax_old/test/ions_move_basic_test.cpp @@ -132,7 +132,8 @@ TEST_F(IonsMoveBasicTest, CheckConvergedCase1) std::string expected_ofs = " old total energy (ry) = 0\n new total energy (ry) = 0\n " - " energy difference (ry) = 0\n largest gradient (ry/bohr) = 0\n largest force is 0, no " + " energy difference (ry) = 0\n largest gradient (ry/bohr) = 0\n\n" + " Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A.\n largest force is 0, no " "movement is possible.\n it may converged, otherwise no movement of atom is allowed.\n"; std::string expected_std = " ETOT DIFF (eV) : 0\n LARGEST GRAD (eV/A) : 0\n"; @@ -170,8 +171,9 @@ TEST_F(IonsMoveBasicTest, CheckConvergedCase2) std::string expected_ofs = " old total energy (ry) = 0\n new total energy (ry) = 0\n " - " energy difference (ry) = 0\n largest gradient (ry/bohr) = 0.1\n\n Ion relaxation is " - "converged!\n\n Energy difference (Ry) = 0\n\n Largest gradient is (eV/A) = 2.57111\n"; + " energy difference (ry) = 0\n largest gradient (ry/bohr) = 0.1\n\n" + " Largest gradient in force is 2.57111 eV/A.\n Threshold is -1 eV/A.\n\n Ion relaxation is " + "converged!\n\n Energy difference (Ry) = 0\n"; std::string expected_std = " ETOT DIFF (eV) : 0\n LARGEST GRAD (eV/A) : 2.57111\n"; EXPECT_EQ(expected_ofs, ofs_output); @@ -208,7 +210,8 @@ TEST_F(IonsMoveBasicTest, CheckConvergedCase3) std::string expected_ofs = " old total energy (ry) = 0\n new total energy (ry) = 0\n " - " energy difference (ry) = 1\n largest gradient (ry/bohr) = 0.1\n\n Ion relaxation is not " + " energy difference (ry) = 1\n largest gradient (ry/bohr) = 0.1\n\n" + " Largest gradient in force is 2.57111 eV/A.\n Threshold is -1 eV/A.\n\n Ion relaxation is not " "converged yet (threshold is 25.7111)\n"; std::string expected_std = " ETOT DIFF (eV) : 13.6057\n LARGEST GRAD (eV/A) : 2.57111\n"; diff --git a/source/module_relax/relax_old/test/ions_move_cg_test.cpp b/source/module_relax/relax_old/test/ions_move_cg_test.cpp index ce184b410d..40cb704849 100644 --- a/source/module_relax/relax_old/test/ions_move_cg_test.cpp +++ b/source/module_relax/relax_old/test/ions_move_cg_test.cpp @@ -89,7 +89,8 @@ TEST_F(IonsMoveCGTest, TestStartConverged) GlobalV::ofs_running.close(); // Check output - std::string expected_output = " largest force is 0, no movement is possible.\n it may converged, otherwise no " + std::string expected_output = "\n Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A.\n" + " largest force is 0, no movement is possible.\n it may converged, otherwise no " "movement of atom is allowed.\n end of geometry optimization\n " " istep = 1\n update iteration = 5\n"; std::ifstream ifs("log"); @@ -122,7 +123,8 @@ TEST_F(IonsMoveCGTest, TestStartSd) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n"; + std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A.\n\n" + " Ion relaxation is not converged yet (threshold is 0.0257111)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); ifs.close(); @@ -159,7 +161,8 @@ TEST_F(IonsMoveCGTest, TestStartTrialGoto) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n"; + std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A.\n\n" + " Ion relaxation is not converged yet (threshold is 0.0257111)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); ifs.close(); @@ -195,7 +198,8 @@ TEST_F(IonsMoveCGTest, TestStartTrial) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n"; + std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A.\n\n" + " Ion relaxation is not converged yet (threshold is 0.0257111)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); ifs.close(); @@ -233,7 +237,8 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase1) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n"; + std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A.\n\n" + " Ion relaxation is not converged yet (threshold is 0.0257111)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); ifs.close(); @@ -270,7 +275,8 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase2) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n"; + std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A.\n\n" + " Ion relaxation is not converged yet (threshold is 0.0257111)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); ifs.close(); @@ -308,7 +314,8 @@ TEST_F(IonsMoveCGTest, TestStartNoTrial) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n"; + std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A.\n\n" + " Ion relaxation is not converged yet (threshold is 0.0257111)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); ifs.close(); diff --git a/source/module_relax/relax_old/test/ions_move_sd_test.cpp b/source/module_relax/relax_old/test/ions_move_sd_test.cpp index 5292fac704..51e232094a 100644 --- a/source/module_relax/relax_old/test/ions_move_sd_test.cpp +++ b/source/module_relax/relax_old/test/ions_move_sd_test.cpp @@ -84,7 +84,8 @@ TEST_F(IonsMoveSDTest, TestStartConverged) GlobalV::ofs_running.close(); // Check output - std::string expected_output = " largest force is 0, no movement is possible.\n it may converged, otherwise no " + std::string expected_output = "\n Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A.\n" + " largest force is 0, no movement is possible.\n it may converged, otherwise no " "movement of atom is allowed.\n end of geometry optimization\n " " istep = 1\n update iteration = 5\n"; std::ifstream ifs("log"); @@ -122,7 +123,8 @@ TEST_F(IonsMoveSDTest, TestStartNotConverged) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n"; + std::string expected_output = "\n Largest gradient in force is 25.7111 eV/A.\n Threshold is -1 eV/A.\n\n" + " Ion relaxation is not converged yet (threshold is 0.0257111)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); ifs.close(); diff --git a/source/module_relax/relax_old/test/lattice_change_basic_test.cpp b/source/module_relax/relax_old/test/lattice_change_basic_test.cpp index 6049119790..61578ae68f 100644 --- a/source/module_relax/relax_old/test/lattice_change_basic_test.cpp +++ b/source/module_relax/relax_old/test/lattice_change_basic_test.cpp @@ -241,7 +241,7 @@ TEST_F(LatticeChangeBasicTest, CheckConvergedCase1) // Check the results std::ifstream ifs("log"); - std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 10)\n"; + std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 10 kbar)\n"; std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); EXPECT_EQ(output, expected_output); EXPECT_EQ(Lattice_Change_Basic::update_iter, 0); @@ -316,7 +316,7 @@ TEST_F(LatticeChangeBasicTest, CheckConvergedCase3) // Check the results std::ifstream ifs("log"); - std::string expected_output = "\n Lattice relaxation is converged!\n\n Largest gradient is = 0.147105\n"; + std::string expected_output = "\n Lattice relaxation is converged!\n\n Largest gradient in stress is 0.147105 kbar.\n Threshold is 10 kbar.\n"; std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); EXPECT_EQ(output, expected_output); EXPECT_EQ(Lattice_Change_Basic::update_iter, 1); @@ -353,7 +353,7 @@ TEST_F(LatticeChangeBasicTest, CheckConvergedCase4) // Check the results std::ifstream ifs("log"); - std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 10)\n"; + std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 10 kbar)\n"; std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); EXPECT_EQ(output, expected_output); EXPECT_EQ(Lattice_Change_Basic::update_iter, 0); @@ -428,7 +428,7 @@ TEST_F(LatticeChangeBasicTest, CheckConvergedCase6) // Check the results std::ifstream ifs("log"); - std::string expected_output = "\n Lattice relaxation is converged!\n\n Largest gradient is = 0.147105\n"; + std::string expected_output = "\n Lattice relaxation is converged!\n\n Largest gradient in stress is 0.147105 kbar.\n Threshold is 10 kbar.\n"; std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); EXPECT_EQ(output, expected_output); EXPECT_EQ(Lattice_Change_Basic::update_iter, 1); diff --git a/source/module_relax/relax_old/test/lattice_change_cg_test.cpp b/source/module_relax/relax_old/test/lattice_change_cg_test.cpp index 9eff776989..1a11148dd1 100644 --- a/source/module_relax/relax_old/test/lattice_change_cg_test.cpp +++ b/source/module_relax/relax_old/test/lattice_change_cg_test.cpp @@ -120,7 +120,7 @@ TEST_F(LatticeChangeCGTest, TestStartSd) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n"; + std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); @@ -152,7 +152,7 @@ TEST_F(LatticeChangeCGTest, TestStartTrialGoto) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n"; + std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); @@ -182,7 +182,7 @@ TEST_F(LatticeChangeCGTest, TestStartTrial) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n"; + std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); @@ -213,7 +213,7 @@ TEST_F(LatticeChangeCGTest, TestStartNoTrialGotoCase1) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n"; + std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); @@ -247,7 +247,7 @@ TEST_F(LatticeChangeCGTest, TestStartNoTrialGotoCase2) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n"; + std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); @@ -280,7 +280,7 @@ TEST_F(LatticeChangeCGTest, TestStartNoTrial) GlobalV::ofs_running.close(); // Check output - std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n"; + std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n"; std::ifstream ifs("log"); std::string output((std::istreambuf_iterator(ifs)), std::istreambuf_iterator());