Skip to content

Commit 6a6fa6d

Browse files
committed
Test: Update Unit tests.
1 parent 88b052e commit 6a6fa6d

File tree

9 files changed

+24
-22
lines changed

9 files changed

+24
-22
lines changed

source/module_md/fire.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ void FIRE::print_md(std::ofstream& ofs, const bool& cal_stress)
7474
{
7575
MD_base::print_md(ofs, cal_stress);
7676

77-
GlobalV::ofs_running << "\n Largest gradient in force is " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << " eV/A." << std::endl;
78-
GlobalV::ofs_running << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A" << std::endl;
77+
ofs << "\n Largest gradient in force is " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << " eV/A." << std::endl;
78+
ofs << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A." << std::endl;
7979
std::cout << " LARGEST GRAD (eV/A) : " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << std::endl;
8080

8181
return;

source/module_md/test/fire_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,13 @@ TEST_F(FIREtest, PrintMD)
205205
output_str,
206206
testing::HasSubstr(
207207
" ------------------------------------------------------------------------------------------------"));
208-
for (int i = 0; i < 10; ++i)
208+
for (int i = 0; i < 11; ++i)
209209
{
210210
getline(ifs, output_str);
211211
}
212212
EXPECT_THAT(output_str, testing::HasSubstr(" Largest gradient in force is 0.049479926 eV/A"));
213+
getline(ifs, output_str);
214+
EXPECT_THAT(output_str, testing::HasSubstr(" Threshold is -1 eV/A."));
213215
ifs.close();
214216
remove("running.log");
215217
}

source/module_relax/relax_new/relax.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ bool Relax::setup_gradient(const ModuleBase::matrix& force, const ModuleBase::ma
142142
}
143143

144144
GlobalV::ofs_running << "\n Largest gradient in force is " << max_grad << " eV/A." << std::endl;
145-
GlobalV::ofs_running << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A" << std::endl;
145+
GlobalV::ofs_running << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A." << std::endl;
146146
//=========================================
147147
//set gradient for cell degrees of freedom
148148
//=========================================
@@ -227,7 +227,7 @@ bool Relax::setup_gradient(const ModuleBase::matrix& force, const ModuleBase::ma
227227
}
228228

229229
GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << " kbar." << std::endl;
230-
GlobalV::ofs_running << " Threshold is = " << PARAM.inp.stress_thr << " kbar." << std::endl;
230+
GlobalV::ofs_running << " Threshold is " << PARAM.inp.stress_thr << " kbar." << std::endl;
231231
}
232232

233233
if(force_converged)

source/module_relax/relax_old/ions_move_basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void Ions_Move_Basic::check_converged(const UnitCell &ucell, const double *grad)
150150

151151
GlobalV::ofs_running << "\n Largest gradient in force is " << largest_grad * ModuleBase::Ry_to_eV / 0.529177
152152
<< " eV/A." << std::endl;
153-
GlobalV::ofs_running << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A" << std::endl;
153+
GlobalV::ofs_running << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A." << std::endl;
154154
}
155155

156156
const double etot_diff = std::abs(Ions_Move_Basic::ediff);

source/module_relax/relax_old/lattice_change_basic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void Lattice_Change_Basic::check_converged(const UnitCell &ucell, ModuleBase::ma
208208
{
209209
GlobalV::ofs_running << "\n Lattice relaxation is converged!" << std::endl;
210210
GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << " kbar." << std::endl;
211-
GlobalV::ofs_running << " Threshold is = " << PARAM.inp.stress_thr << " kbar." << std::endl;
211+
GlobalV::ofs_running << " Threshold is " << PARAM.inp.stress_thr << " kbar." << std::endl;
212212
Lattice_Change_Basic::converged = true;
213213
++Lattice_Change_Basic::update_iter;
214214
}
@@ -229,7 +229,7 @@ void Lattice_Change_Basic::check_converged(const UnitCell &ucell, ModuleBase::ma
229229
{
230230
GlobalV::ofs_running << "\n Lattice relaxation is converged!" << std::endl;
231231
GlobalV::ofs_running << "\n Largest gradient in stress is " << largest_grad << " kbar." << std::endl;
232-
GlobalV::ofs_running << " Threshold is = " << PARAM.inp.stress_thr << " kbar." << std::endl;
232+
GlobalV::ofs_running << " Threshold is " << PARAM.inp.stress_thr << " kbar." << std::endl;
233233
Lattice_Change_Basic::converged = true;
234234
++Lattice_Change_Basic::update_iter;
235235
}

source/module_relax/relax_old/test/ions_move_basic_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ TEST_F(IonsMoveBasicTest, CheckConvergedCase1)
133133
std::string expected_ofs
134134
= " old total energy (ry) = 0\n new total energy (ry) = 0\n "
135135
" energy difference (ry) = 0\n largest gradient (ry/bohr) = 0\n\n"
136-
" Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A\n largest force is 0, no "
136+
" Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A.\n largest force is 0, no "
137137
"movement is possible.\n it may converged, otherwise no movement of atom is allowed.\n";
138138
std::string expected_std = " ETOT DIFF (eV) : 0\n LARGEST GRAD (eV/A) : 0\n";
139139

@@ -172,7 +172,7 @@ TEST_F(IonsMoveBasicTest, CheckConvergedCase2)
172172
std::string expected_ofs
173173
= " old total energy (ry) = 0\n new total energy (ry) = 0\n "
174174
" energy difference (ry) = 0\n largest gradient (ry/bohr) = 0.1\n\n"
175-
" Largest gradient in force is 2.57111 eV/A.\n Threshold is -1 eV/A\n\n Ion relaxation is "
175+
" Largest gradient in force is 2.57111 eV/A.\n Threshold is -1 eV/A.\n\n Ion relaxation is "
176176
"converged!\n\n Energy difference (Ry) = 0\n";
177177
std::string expected_std = " ETOT DIFF (eV) : 0\n LARGEST GRAD (eV/A) : 2.57111\n";
178178

@@ -211,7 +211,7 @@ TEST_F(IonsMoveBasicTest, CheckConvergedCase3)
211211
std::string expected_ofs
212212
= " old total energy (ry) = 0\n new total energy (ry) = 0\n "
213213
" energy difference (ry) = 1\n largest gradient (ry/bohr) = 0.1\n\n"
214-
" Largest gradient in force is 2.57111 eV/A.\n Threshold is -1 eV/A\n\n Ion relaxation is not "
214+
" Largest gradient in force is 2.57111 eV/A.\n Threshold is -1 eV/A.\n\n Ion relaxation is not "
215215
"converged yet (threshold is 25.7111)\n";
216216
std::string expected_std = " ETOT DIFF (eV) : 13.6057\n LARGEST GRAD (eV/A) : 2.57111\n";
217217

source/module_relax/relax_old/test/ions_move_cg_test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ TEST_F(IonsMoveCGTest, TestStartConverged)
8989
GlobalV::ofs_running.close();
9090

9191
// Check output
92-
std::string expected_output = "\n Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A\n"
92+
std::string expected_output = "\n Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A.\n"
9393
" largest force is 0, no movement is possible.\n it may converged, otherwise no "
9494
"movement of atom is allowed.\n end of geometry optimization\n "
9595
" istep = 1\n update iteration = 5\n";
@@ -123,7 +123,7 @@ TEST_F(IonsMoveCGTest, TestStartSd)
123123
GlobalV::ofs_running.close();
124124

125125
// Check output
126-
std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A\n\n"
126+
std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A.\n\n"
127127
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
128128
std::ifstream ifs("log");
129129
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
@@ -161,7 +161,7 @@ TEST_F(IonsMoveCGTest, TestStartTrialGoto)
161161
GlobalV::ofs_running.close();
162162

163163
// Check output
164-
std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A\n\n"
164+
std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A.\n\n"
165165
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
166166
std::ifstream ifs("log");
167167
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
@@ -198,7 +198,7 @@ TEST_F(IonsMoveCGTest, TestStartTrial)
198198
GlobalV::ofs_running.close();
199199

200200
// Check output
201-
std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A\n\n"
201+
std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A.\n\n"
202202
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
203203
std::ifstream ifs("log");
204204
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
@@ -237,7 +237,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase1)
237237
GlobalV::ofs_running.close();
238238

239239
// Check output
240-
std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A\n\n"
240+
std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A.\n\n"
241241
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
242242
std::ifstream ifs("log");
243243
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
@@ -275,7 +275,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase2)
275275
GlobalV::ofs_running.close();
276276

277277
// Check output
278-
std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A\n\n"
278+
std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A.\n\n"
279279
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
280280
std::ifstream ifs("log");
281281
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
@@ -314,7 +314,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrial)
314314
GlobalV::ofs_running.close();
315315

316316
// Check output
317-
std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A\n\n"
317+
std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A.\n\n"
318318
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
319319
std::ifstream ifs("log");
320320
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());

source/module_relax/relax_old/test/ions_move_sd_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ TEST_F(IonsMoveSDTest, TestStartConverged)
8484
GlobalV::ofs_running.close();
8585

8686
// Check output
87-
std::string expected_output = "\n Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A\n"
87+
std::string expected_output = "\n Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A.\n"
8888
" largest force is 0, no movement is possible.\n it may converged, otherwise no "
8989
"movement of atom is allowed.\n end of geometry optimization\n "
9090
" istep = 1\n update iteration = 5\n";
@@ -123,7 +123,7 @@ TEST_F(IonsMoveSDTest, TestStartNotConverged)
123123
GlobalV::ofs_running.close();
124124

125125
// Check output
126-
std::string expected_output = "\n Largest gradient in force is 25.7111 eV/A.\n Threshold is -1 eV/A\n\n"
126+
std::string expected_output = "\n Largest gradient in force is 25.7111 eV/A.\n Threshold is -1 eV/A.\n\n"
127127
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
128128
std::ifstream ifs("log");
129129
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());

source/module_relax/relax_old/test/lattice_change_basic_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ TEST_F(LatticeChangeBasicTest, CheckConvergedCase3)
316316

317317
// Check the results
318318
std::ifstream ifs("log");
319-
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";
319+
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";
320320
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
321321
EXPECT_EQ(output, expected_output);
322322
EXPECT_EQ(Lattice_Change_Basic::update_iter, 1);
@@ -428,7 +428,7 @@ TEST_F(LatticeChangeBasicTest, CheckConvergedCase6)
428428

429429
// Check the results
430430
std::ifstream ifs("log");
431-
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";
431+
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";
432432
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
433433
EXPECT_EQ(output, expected_output);
434434
EXPECT_EQ(Lattice_Change_Basic::update_iter, 1);

0 commit comments

Comments
 (0)