Skip to content

Commit 555bec6

Browse files
committed
add unittest for the update_pos_tau
1 parent 89a9ba0 commit 555bec6

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

source/module_cell/test/unitcell_test_para.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ TEST_F(UcellTest, UpdatePosTau)
153153
}
154154
delete[] pos_in;
155155
}
156-
TEST_F(UcellTest, UpdatePosTaud)
156+
TEST_F(UcellTest, UpdatePosTaud_pointer)
157157
{
158158
double* pos_in = new double[ucell->nat * 3];
159159
ModuleBase::Vector3<double>* tmp = new ModuleBase::Vector3<double>[ucell->nat];
@@ -181,6 +181,37 @@ TEST_F(UcellTest, UpdatePosTaud)
181181
delete[] pos_in;
182182
}
183183

184+
//test update_pos_taud with ModuleBase::Vector3<double> version
185+
TEST_F(UcellTest, UpdatePosTaud_Vector3)
186+
{
187+
ModuleBase::Vector3<double>* pos_in = new ModuleBase::Vector3<double>[ucell->nat];
188+
ModuleBase::Vector3<double>* tmp = new ModuleBase::Vector3<double>[ucell->nat];
189+
ucell->set_iat2itia();
190+
for (int iat = 0; iat < ucell->nat; ++iat)
191+
{
192+
for (int ik = 0; ik < 3; ++ik)
193+
{
194+
pos_in[iat][ik] = 0.01;
195+
}
196+
int it=0;
197+
int ia=0;
198+
ucell->iat2iait(iat, &ia, &it);
199+
tmp[iat] = ucell->atoms[it].taud[ia];
200+
}
201+
unitcell::update_pos_taud(ucell->lat,pos_in,ucell->ntype,
202+
ucell->nat,ucell->atoms);
203+
for (int iat = 0; iat < ucell->nat; ++iat)
204+
{
205+
int it, ia;
206+
ucell->iat2iait(iat, &ia, &it);
207+
for (int ik = 0; ik < 3; ++ik)
208+
{
209+
EXPECT_DOUBLE_EQ(ucell->atoms[it].taud[ia][ik], tmp[iat][ik] + 0.01);
210+
}
211+
}
212+
delete[] tmp;
213+
delete[] pos_in;
214+
}
184215
TEST_F(UcellTest, ReadPseudo)
185216
{
186217
PARAM.input.pseudo_dir = pp_dir;

source/module_cell/update_cell.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,8 @@ void update_pos_tau(const Lattice& lat,
374374
bcast_atoms_tau(atoms, ntype);
375375
}
376376

377-
template <typename T>
378377
void update_pos_taud(const Lattice& lat,
379-
const T* posd_in,
378+
const double* posd_in,
380379
const int ntype,
381380
const int nat,
382381
Atom* atoms)
@@ -408,9 +407,9 @@ void update_pos_taud(const Lattice& lat,
408407
Atom* atoms)
409408
{
410409
int iat = 0;
411-
for (int it = 0; it < this->ntype; it++)
410+
for (int it = 0; it < ntype; it++)
412411
{
413-
Atom* atom = &this->atoms[it];
412+
Atom* atom = &atoms[it];
414413
for (int ia = 0; ia < atom->na; ia++)
415414
{
416415
for (int ik = 0; ik < 3; ++ik)
@@ -421,9 +420,9 @@ void update_pos_taud(const Lattice& lat,
421420
iat++;
422421
}
423422
}
424-
assert(iat == this->nat);
425-
unitcell::periodic_boundary_adjustment(this->atoms,this->latvec, this->ntype);
426-
this->bcast_atoms_tau();
423+
assert(iat == nat);
424+
periodic_boundary_adjustment(atoms,lat.latvec,ntype);
425+
bcast_atoms_tau(atoms, ntype);
427426
}
428427

429428
void periodic_boundary_adjustment(Atom* atoms,

0 commit comments

Comments
 (0)