Skip to content

Commit 88b052e

Browse files
committed
Test: Update corresponding Unit tests.
1 parent cf15085 commit 88b052e

File tree

8 files changed

+41
-28
lines changed

8 files changed

+41
-28
lines changed

source/module_md/test/fire_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ TEST_F(FIREtest, PrintMD)
209209
{
210210
getline(ifs, output_str);
211211
}
212-
EXPECT_THAT(output_str, testing::HasSubstr(" LARGEST GRAD (eV/A) : 0.049479926"));
212+
EXPECT_THAT(output_str, testing::HasSubstr(" Largest gradient in force is 0.049479926 eV/A"));
213213
ifs.close();
214214
remove("running.log");
215215
}

source/module_relax/relax_new/relax.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ bool Relax::setup_gradient(const ModuleBase::matrix& force, const ModuleBase::ma
138138
{
139139
std::cout << " ETOT DIFF (eV) : " << etot - etot_p << std::endl;
140140
std::cout << " LARGEST GRAD (eV/A) : " << max_grad << std::endl;
141-
GlobalV::ofs_running << "\n Largest gradient in force is " << max_grad << " eV/A." << std::endl;
142-
GlobalV::ofs_running << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A" << std::endl;
143141
etot_p = etot;
144142
}
143+
144+
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;
145146
//=========================================
146147
//set gradient for cell degrees of freedom
147148
//=========================================

source/module_relax/relax_old/lattice_change_basic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void Lattice_Change_Basic::check_converged(const UnitCell &ucell, ModuleBase::ma
215215
else
216216
{
217217
GlobalV::ofs_running << "\n Lattice relaxation is not converged yet (threshold is " << PARAM.inp.stress_thr
218-
<< ")" << std::endl;
218+
<< " kbar)" << std::endl;
219219
Lattice_Change_Basic::converged = false;
220220
}
221221
}
@@ -236,7 +236,7 @@ void Lattice_Change_Basic::check_converged(const UnitCell &ucell, ModuleBase::ma
236236
else
237237
{
238238
GlobalV::ofs_running << "\n Lattice relaxation is not converged yet (threshold is " << PARAM.inp.stress_thr
239-
<< ")" << std::endl;
239+
<< " kbar)" << std::endl;
240240
Lattice_Change_Basic::converged = false;
241241
}
242242
}

source/module_relax/relax_old/test/ions_move_basic_test.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ TEST_F(IonsMoveBasicTest, CheckConvergedCase1)
132132

133133
std::string expected_ofs
134134
= " old total energy (ry) = 0\n new total energy (ry) = 0\n "
135-
" energy difference (ry) = 0\n largest gradient (ry/bohr) = 0\n largest force is 0, no "
135+
" 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 "
136137
"movement is possible.\n it may converged, otherwise no movement of atom is allowed.\n";
137138
std::string expected_std = " ETOT DIFF (eV) : 0\n LARGEST GRAD (eV/A) : 0\n";
138139

@@ -170,8 +171,9 @@ TEST_F(IonsMoveBasicTest, CheckConvergedCase2)
170171

171172
std::string expected_ofs
172173
= " old total energy (ry) = 0\n new total energy (ry) = 0\n "
173-
" energy difference (ry) = 0\n largest gradient (ry/bohr) = 0.1\n\n Ion relaxation is "
174-
"converged!\n\n Energy difference (Ry) = 0\n\n Largest gradient is (eV/A) = 2.57111\n";
174+
" 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 "
176+
"converged!\n\n Energy difference (Ry) = 0\n";
175177
std::string expected_std = " ETOT DIFF (eV) : 0\n LARGEST GRAD (eV/A) : 2.57111\n";
176178

177179
EXPECT_EQ(expected_ofs, ofs_output);
@@ -208,7 +210,8 @@ TEST_F(IonsMoveBasicTest, CheckConvergedCase3)
208210

209211
std::string expected_ofs
210212
= " old total energy (ry) = 0\n new total energy (ry) = 0\n "
211-
" energy difference (ry) = 1\n largest gradient (ry/bohr) = 0.1\n\n Ion relaxation is not "
213+
" 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 "
212215
"converged yet (threshold is 25.7111)\n";
213216
std::string expected_std = " ETOT DIFF (eV) : 13.6057\n LARGEST GRAD (eV/A) : 2.57111\n";
214217

source/module_relax/relax_old/test/ions_move_cg_test.cpp

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

9191
// Check output
92-
std::string expected_output = " largest force is 0, no movement is possible.\n it may converged, otherwise no "
92+
std::string expected_output = "\n Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A\n"
93+
" largest force is 0, no movement is possible.\n it may converged, otherwise no "
9394
"movement of atom is allowed.\n end of geometry optimization\n "
9495
" istep = 1\n update iteration = 5\n";
9596
std::ifstream ifs("log");
@@ -122,7 +123,8 @@ TEST_F(IonsMoveCGTest, TestStartSd)
122123
GlobalV::ofs_running.close();
123124

124125
// Check output
125-
std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n";
126+
std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A\n\n"
127+
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
126128
std::ifstream ifs("log");
127129
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
128130
ifs.close();
@@ -159,7 +161,8 @@ TEST_F(IonsMoveCGTest, TestStartTrialGoto)
159161
GlobalV::ofs_running.close();
160162

161163
// Check output
162-
std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n";
164+
std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A\n\n"
165+
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
163166
std::ifstream ifs("log");
164167
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
165168
ifs.close();
@@ -195,7 +198,8 @@ TEST_F(IonsMoveCGTest, TestStartTrial)
195198
GlobalV::ofs_running.close();
196199

197200
// Check output
198-
std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n";
201+
std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A\n\n"
202+
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
199203
std::ifstream ifs("log");
200204
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
201205
ifs.close();
@@ -233,7 +237,8 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase1)
233237
GlobalV::ofs_running.close();
234238

235239
// Check output
236-
std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n";
240+
std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A\n\n"
241+
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
237242
std::ifstream ifs("log");
238243
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
239244
ifs.close();
@@ -270,7 +275,8 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase2)
270275
GlobalV::ofs_running.close();
271276

272277
// Check output
273-
std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n";
278+
std::string expected_output = "\n Largest gradient in force is 0.257111 eV/A.\n Threshold is -1 eV/A\n\n"
279+
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
274280
std::ifstream ifs("log");
275281
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
276282
ifs.close();
@@ -308,7 +314,8 @@ TEST_F(IonsMoveCGTest, TestStartNoTrial)
308314
GlobalV::ofs_running.close();
309315

310316
// Check output
311-
std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n";
317+
std::string expected_output = "\n Largest gradient in force is 0.0257111 eV/A.\n Threshold is -1 eV/A\n\n"
318+
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
312319
std::ifstream ifs("log");
313320
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
314321
ifs.close();

source/module_relax/relax_old/test/ions_move_sd_test.cpp

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

8686
// Check output
87-
std::string expected_output = " largest force is 0, no movement is possible.\n it may converged, otherwise no "
87+
std::string expected_output = "\n Largest gradient in force is 0 eV/A.\n Threshold is -1 eV/A\n"
88+
" largest force is 0, no movement is possible.\n it may converged, otherwise no "
8889
"movement of atom is allowed.\n end of geometry optimization\n "
8990
" istep = 1\n update iteration = 5\n";
9091
std::ifstream ifs("log");
@@ -122,7 +123,8 @@ TEST_F(IonsMoveSDTest, TestStartNotConverged)
122123
GlobalV::ofs_running.close();
123124

124125
// Check output
125-
std::string expected_output = "\n Ion relaxation is not converged yet (threshold is 0.0257111)\n";
126+
std::string expected_output = "\n Largest gradient in force is 25.7111 eV/A.\n Threshold is -1 eV/A\n\n"
127+
" Ion relaxation is not converged yet (threshold is 0.0257111)\n";
126128
std::ifstream ifs("log");
127129
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
128130
ifs.close();

source/module_relax/relax_old/test/lattice_change_basic_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ TEST_F(LatticeChangeBasicTest, CheckConvergedCase1)
241241

242242
// Check the results
243243
std::ifstream ifs("log");
244-
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 10)\n";
244+
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 10 kbar)\n";
245245
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
246246
EXPECT_EQ(output, expected_output);
247247
EXPECT_EQ(Lattice_Change_Basic::update_iter, 0);
@@ -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 is = 0.147105\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);
@@ -353,7 +353,7 @@ TEST_F(LatticeChangeBasicTest, CheckConvergedCase4)
353353

354354
// Check the results
355355
std::ifstream ifs("log");
356-
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 10)\n";
356+
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 10 kbar)\n";
357357
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
358358
EXPECT_EQ(output, expected_output);
359359
EXPECT_EQ(Lattice_Change_Basic::update_iter, 0);
@@ -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 is = 0.147105\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);

source/module_relax/relax_old/test/lattice_change_cg_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ TEST_F(LatticeChangeCGTest, TestStartSd)
120120
GlobalV::ofs_running.close();
121121

122122
// Check output
123-
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n";
123+
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n";
124124
std::ifstream ifs("log");
125125
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
126126

@@ -152,7 +152,7 @@ TEST_F(LatticeChangeCGTest, TestStartTrialGoto)
152152
GlobalV::ofs_running.close();
153153

154154
// Check output
155-
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n";
155+
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n";
156156
std::ifstream ifs("log");
157157
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
158158

@@ -182,7 +182,7 @@ TEST_F(LatticeChangeCGTest, TestStartTrial)
182182
GlobalV::ofs_running.close();
183183

184184
// Check output
185-
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n";
185+
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n";
186186
std::ifstream ifs("log");
187187
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
188188

@@ -213,7 +213,7 @@ TEST_F(LatticeChangeCGTest, TestStartNoTrialGotoCase1)
213213
GlobalV::ofs_running.close();
214214

215215
// Check output
216-
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n";
216+
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n";
217217
std::ifstream ifs("log");
218218
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
219219

@@ -247,7 +247,7 @@ TEST_F(LatticeChangeCGTest, TestStartNoTrialGotoCase2)
247247
GlobalV::ofs_running.close();
248248

249249
// Check output
250-
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n";
250+
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n";
251251
std::ifstream ifs("log");
252252
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
253253

@@ -280,7 +280,7 @@ TEST_F(LatticeChangeCGTest, TestStartNoTrial)
280280
GlobalV::ofs_running.close();
281281

282282
// Check output
283-
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5)\n";
283+
std::string expected_output = "\n Lattice relaxation is not converged yet (threshold is 0.5 kbar)\n";
284284
std::ifstream ifs("log");
285285
std::string output((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
286286

0 commit comments

Comments
 (0)