Skip to content
3 changes: 2 additions & 1 deletion source/module_md/fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions source/module_md/test/fire_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
7 changes: 5 additions & 2 deletions source/module_relax/relax_new/relax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//=========================================
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions source/module_relax/relax_old/ions_move_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
27 changes: 17 additions & 10 deletions source/module_relax/relax_old/lattice_change_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:"<<std::endl;
Expand All @@ -86,11 +86,15 @@ void Lattice_Change_Basic::change_lattice(UnitCell &ucell, double *move, double
if (ModuleSymmetry::Symmetry::symm_flag && ucell.symm.nrotk > 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)
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -227,22 +233,23 @@ 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;
}
}

return;
}

void Lattice_Change_Basic::terminate(void)
void Lattice_Change_Basic::terminate()
{
ModuleBase::TITLE("Lattice_Change_Basic", "terminate");
if (Lattice_Change_Basic::converged)
Expand Down
11 changes: 7 additions & 4 deletions source/module_relax/relax_old/test/ions_move_basic_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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";

Expand Down
21 changes: 14 additions & 7 deletions source/module_relax/relax_old/test/ions_move_cg_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
ifs.close();
Expand Down Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
ifs.close();
Expand Down Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
ifs.close();
Expand Down Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
ifs.close();
Expand Down Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
ifs.close();
Expand Down Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
ifs.close();
Expand Down
6 changes: 4 additions & 2 deletions source/module_relax/relax_old/test/ions_move_sd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
ifs.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
EXPECT_EQ(output, expected_output);
EXPECT_EQ(Lattice_Change_Basic::update_iter, 0);
Expand Down Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
EXPECT_EQ(output, expected_output);
EXPECT_EQ(Lattice_Change_Basic::update_iter, 1);
Expand Down Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
EXPECT_EQ(output, expected_output);
EXPECT_EQ(Lattice_Change_Basic::update_iter, 0);
Expand Down Expand Up @@ -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<char>(ifs)), std::istreambuf_iterator<char>());
EXPECT_EQ(output, expected_output);
EXPECT_EQ(Lattice_Change_Basic::update_iter, 1);
Expand Down
Loading
Loading