Skip to content

Commit 6e6d09d

Browse files
committed
add unittest for update_pos_tau
1 parent 038364e commit 6e6d09d

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

source/module_cell/test/unitcell_test_para.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
#include "mpi.h"
1515
#endif
1616
#include "prepare_unitcell.h"
17-
17+
#include "../update_cell.h"
18+
#include "../bcast_cell.h"
1819
#ifdef __LCAO
1920
InfoNonlocal::InfoNonlocal()
2021
{
@@ -44,6 +45,7 @@ Magnetism::~Magnetism()
4445
/**
4546
* - Tested Functions:
4647
* - UpdatePosTaud
48+
* - update_pos_tau(double* pos)
4749
* - update_pos_taud(const double* pos)
4850
* - bcast_atoms_tau() is also called in the above function, which calls Atom::bcast_atom with many
4951
* atomic info in addition to tau
@@ -123,7 +125,34 @@ TEST_F(UcellTest, BcastUnitcell)
123125
EXPECT_EQ(atom_labels[1], atom_type2_expected);
124126
}
125127
}
126-
128+
TEST_F(UcellTest, UpdatePosTau)
129+
{
130+
double* pos_in = new double[ucell->nat * 3];
131+
ucell->set_iat2itia();
132+
std::fill(pos_in, pos_in + ucell->nat * 3, 0);
133+
for (int iat = 0; iat < ucell->nat; ++iat)
134+
{
135+
int it, ia;
136+
ucell->iat2iait(iat, &ia, &it);
137+
for (int ik = 0; ik < 3; ++ik)
138+
{
139+
ucell->atoms[it].mbl[ia][ik] = true;
140+
pos_in[iat * 3 + ik] = (iat * 3 + ik) / (ucell->nat * 3.0) * (ucell->lat.lat0);
141+
}
142+
}
143+
unitcell::update_pos_tau(ucell->lat,pos_in,ucell->ntype,ucell->nat,ucell->atoms);
144+
for (int iat = 0; iat < ucell->nat; ++iat)
145+
{
146+
int it, ia;
147+
ucell->iat2iait(iat, &ia, &it);
148+
for (int ik = 0; ik < 3; ++ik)
149+
{
150+
EXPECT_DOUBLE_EQ(ucell->atoms[it].tau[ia][ik],
151+
(iat*3+ik)/(ucell->nat*3.0));
152+
}
153+
}
154+
delete[] pos_in;
155+
}
127156
TEST_F(UcellTest, UpdatePosTaud)
128157
{
129158
double* pos_in = new double[ucell->nat * 3];
@@ -147,6 +176,7 @@ TEST_F(UcellTest, UpdatePosTaud)
147176
EXPECT_DOUBLE_EQ(ucell->atoms[it].taud[ia].y, tmp[iat].y + 0.01);
148177
EXPECT_DOUBLE_EQ(ucell->atoms[it].taud[ia].z, tmp[iat].z + 0.01);
149178
}
179+
delete[] tmp;
150180
delete[] pos_in;
151181
}
152182

source/module_cell/update_cell.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,13 @@ void periodic_boundary_adjustment(Atom* atoms,
413413
atom->taud[ia].z -= 1.0;
414414
}
415415

416-
if (atom->taud[ia].x < 0 || atom->taud[ia].y < 0
417-
|| atom->taud[ia].z < 0 || atom->taud[ia].x >= 1.0
418-
|| atom->taud[ia].y >= 1.0 || atom->taud[ia].z >= 1.0) {
416+
if (atom->taud[ia].x < 0
417+
|| atom->taud[ia].y < 0
418+
|| atom->taud[ia].z < 0
419+
|| atom->taud[ia].x >= 1.0
420+
|| atom->taud[ia].y >= 1.0
421+
|| atom->taud[ia].z >= 1.0)
422+
{
419423
GlobalV::ofs_warning << " it=" << it + 1 << " ia=" << ia + 1 << std::endl;
420424
GlobalV::ofs_warning << "d=" << atom->taud[ia].x << " "
421425
<< atom->taud[ia].y << " "

source/module_cell/update_cell.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ the functions are defined in the namespace UnitCell,
1313
Accually, the functions are focused on the cell-relax part functions
1414
of the UnitCell class.
1515
3. periodic_boundary_adjustment: adjust the boundary of the cell
16+
4. update_pos_tau: update the Cartesian coordinate postion of the atoms
1617
*/
1718
namespace unitcell
1819
{
@@ -21,13 +22,20 @@ namespace unitcell
2122
void remake_cell(Lattice& lat);
2223

2324
void setup_cell_after_vc(UnitCell& ucell, std::ofstream& log);
24-
25+
26+
/**
27+
* @brief check the boundary of the cell, for each atom,the taud
28+
* in three directions should be in the range of [-1,1)
29+
* @param atoms: the atoms to be adjusted [in]
30+
* @param latvec: the lattice of the atoms [in]
31+
* @param ntype: the number of types of the atoms [in]
32+
*/
2533
void periodic_boundary_adjustment(Atom* atoms,
2634
const ModuleBase::Matrix3& latvec,
2735
const int ntype);
2836

2937
/**
30-
* update the position and tau of the atoms
38+
* @brief update the position and tau of the atoms
3139
*
3240
* @param lat: the lattice of the atoms [in]
3341
* @param pos: the position of the atoms [in]

0 commit comments

Comments
 (0)