Skip to content

Commit 044abcd

Browse files
committed
remove the bug in the relax_old for it didn't run update_pos
1 parent 8655ede commit 044abcd

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

source/module_cell/update_cell.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ void periodic_boundary_adjustment(Atom* atoms,
384384
// first adjust direct coordinates,
385385
// then update them into cartesian coordinates,
386386
//----------------------------------------------
387+
for (int i=0;i<ntype;i++) {
388+
Atom* atom = &atoms[i];
389+
for (int j=0;j<atom->na;j++) {
390+
printf("the taud is %f %f %f\n",atom->taud[j].x,atom->taud[j].y,atom->taud[j].z);
391+
}
392+
}
387393
for (int it = 0; it < ntype; it++) {
388394
Atom* atom = &atoms[it];
389395
for (int ia = 0; ia < atom->na; ia++) {

source/module_relax/relax_old/ions_move_sd.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void Ions_Move_SD::start(UnitCell& ucell, const ModuleBase::matrix& force, const
5555

5656
if (istep == 1 || etot_in <= energy_saved)
5757
{
58+
printf("in cheak_converged");
59+
printf("pos[0]: %f\n", pos[0]);
5860
energy_saved = etot_in;
5961
for (int i = 0; i < dim; i++)
6062
pos_saved[i] = pos[i];

source/module_relax/relax_old/test/for_test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ Atom::Atom()
8181
{
8282
na = 2;
8383
tau.resize(na);
84+
dis.resize(na);
8485
mbl.resize(na);
86+
taud.resize(na);
8587
}
8688
Atom::~Atom()
8789
{

source/module_relax/relax_old/test/ions_move_bfgs_test.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#include "for_test.h"
2-
#include "gmock/gmock.h"
3-
#define private public
4-
#include "module_parameter/parameter.h"
5-
#undef private
62
#include "gtest/gtest.h"
3+
#include "gmock/gmock.h"
74
#define private public
85
#define protected public
6+
#include "module_parameter/parameter.h"
97
#include "module_relax/relax_old/ions_move_basic.h"
108
#include "module_relax/relax_old/ions_move_bfgs.h"
119
#undef private
@@ -109,7 +107,7 @@ TEST_F(IonsMoveBFGSTest, StartCase2)
109107
// Call the function being tested
110108
bfgs.allocate();
111109
GlobalV::ofs_running.open("log");
112-
bfgs.start(ucell, force, energy_in);
110+
EXPECT_EXIT(bfgs.start(ucell, force, energy_in) , ::testing::ExitedWithCode(1), "");
113111
GlobalV::ofs_running.close();
114112

115113
// Check the results

source/module_relax/relax_old/test/ions_move_cg_test.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,22 @@ class IonsMoveCGTest : public ::testing::Test
3838
{
3939
// Clean up after each test
4040
}
41-
41+
void setupucell(UnitCell& ucell)
42+
{
43+
for (int it = 0; it < ucell.ntype; it++)
44+
{
45+
Atom* atom = &ucell.atoms[it];
46+
for (int ia = 0; ia < atom->na; ia++)
47+
{
48+
for (int ik = 0; ik < 3; ++ik)
49+
{
50+
atom->tau[ia][ik] = 1;
51+
atom->mbl[ia][ik] = 1;
52+
}
53+
}
54+
}
55+
ucell.lat.GT.Zero();
56+
}
4257
Ions_Move_CG im_cg;
4358
};
4459

@@ -82,6 +97,7 @@ TEST_F(IonsMoveCGTest, TestStartConverged)
8297
Ions_Move_Basic::istep = 1;
8398
Ions_Move_Basic::converged = true;
8499
UnitCell ucell;
100+
setupucell(ucell);
85101
ModuleBase::matrix force(2, 3);
86102
double etot = 0.0;
87103

@@ -118,6 +134,7 @@ TEST_F(IonsMoveCGTest, TestStartSd)
118134
Ions_Move_Basic::relax_method = "cg_bfgs";
119135
Ions_Move_CG::RELAX_CG_THR = 100.0;
120136
UnitCell ucell;
137+
setupucell(ucell);
121138
ModuleBase::matrix force(2, 3);
122139
force(0, 0) = 0.01;
123140
double etot = 0.0;
@@ -151,6 +168,7 @@ TEST_F(IonsMoveCGTest, TestStartTrialGoto)
151168
Ions_Move_Basic::istep = 1;
152169
Ions_Move_Basic::converged = false;
153170
UnitCell ucell;
171+
setupucell(ucell);
154172
ModuleBase::matrix force(2, 3);
155173
force(0, 0) = 0.1;
156174
double etot = 0.0;
@@ -189,6 +207,7 @@ TEST_F(IonsMoveCGTest, TestStartTrial)
189207
Ions_Move_Basic::istep = 1;
190208
Ions_Move_Basic::converged = false;
191209
UnitCell ucell;
210+
setupucell(ucell);
192211
ModuleBase::matrix force(2, 3);
193212
force(0, 0) = 0.01;
194213
double etot = 0.0;
@@ -226,6 +245,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase1)
226245
Ions_Move_Basic::istep = 1;
227246
Ions_Move_Basic::converged = false;
228247
UnitCell ucell;
248+
setupucell(ucell);
229249
ModuleBase::matrix force(2, 3);
230250
force(0, 0) = 0.1;
231251
double etot = 0.0;
@@ -265,6 +285,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrialGotoCase2)
265285
Ions_Move_Basic::istep = 1;
266286
Ions_Move_Basic::converged = false;
267287
UnitCell ucell;
288+
setupucell(ucell);
268289
ModuleBase::matrix force(2, 3);
269290
force(0, 0) = 0.01;
270291
double etot = 0.0;
@@ -303,6 +324,7 @@ TEST_F(IonsMoveCGTest, TestStartNoTrial)
303324
Ions_Move_Basic::istep = 1;
304325
Ions_Move_Basic::converged = false;
305326
UnitCell ucell;
327+
setupucell(ucell);
306328
ModuleBase::matrix force(2, 3);
307329
force(0, 0) = 0.01;
308330
double etot = 0.0;

source/module_relax/relax_old/test/ions_move_sd_test.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ TEST_F(IonsMoveSDTest, TestStartNotConverged)
119119
ModuleBase::matrix force(2, 3);
120120
force(0, 0) = 1.0;
121121
double etot = 0.0;
122+
for (int it = 0; it < ucell.ntype; it++)
123+
{
124+
Atom* atom = &ucell.atoms[it];
125+
for (int ia = 0; ia < atom->na; ia++)
126+
{
127+
for (int ik = 0; ik < 3; ++ik)
128+
{
129+
atom->tau[ia][ik] = (ik + 1)/3;
130+
atom->mbl[ia][ik] = 1;
131+
}
132+
}
133+
}
122134

123135
// call function
124136
GlobalV::ofs_running.open("log");
@@ -139,11 +151,11 @@ TEST_F(IonsMoveSDTest, TestStartNotConverged)
139151
EXPECT_DOUBLE_EQ(Ions_Move_Basic::largest_grad, 1.0);
140152
EXPECT_DOUBLE_EQ(im_sd.energy_saved, 0.0);
141153
EXPECT_DOUBLE_EQ(im_sd.pos_saved[0], -1.0);
142-
EXPECT_DOUBLE_EQ(im_sd.pos_saved[1], 10.0);
143-
EXPECT_DOUBLE_EQ(im_sd.pos_saved[2], 20.0);
144-
EXPECT_DOUBLE_EQ(im_sd.pos_saved[3], 30.0);
145-
EXPECT_DOUBLE_EQ(im_sd.pos_saved[4], 40.0);
146-
EXPECT_DOUBLE_EQ(im_sd.pos_saved[5], 50.0);
154+
EXPECT_DOUBLE_EQ(im_sd.pos_saved[1], 0.0);
155+
EXPECT_DOUBLE_EQ(im_sd.pos_saved[2], 10.0);
156+
EXPECT_DOUBLE_EQ(im_sd.pos_saved[3], 0.0);
157+
EXPECT_DOUBLE_EQ(im_sd.pos_saved[4], 0.0);
158+
EXPECT_DOUBLE_EQ(im_sd.pos_saved[5], 10.0);
147159
EXPECT_DOUBLE_EQ(im_sd.grad_saved[0], -1.0);
148160
EXPECT_DOUBLE_EQ(im_sd.grad_saved[1], 0.0);
149161
EXPECT_DOUBLE_EQ(im_sd.grad_saved[2], 0.0);

0 commit comments

Comments
 (0)