Skip to content

Commit da68912

Browse files
committed
add unit test for the bcast
1 parent 0350677 commit da68912

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

source/module_cell/bcast_cell.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace unitcell
1313
}
1414
#endif
1515
}
16+
1617
void bcast_Lattice(Lattice& lat)
1718
{
1819
#ifdef __MPI
@@ -62,6 +63,7 @@ namespace unitcell
6263
// distribute Change the lattice vectors or not
6364
#endif
6465
}
66+
6567
void bcast_magnetism(Magnetism& magnet, const int ntype)
6668
{
6769
#ifdef __MPI

source/module_cell/test/unitcell_test_para.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,39 @@ TEST_F(UcellTest, BcastUnitcell)
113113
EXPECT_EQ(atom_labels[1], atom_type2_expected);
114114
}
115115
}
116+
TEST_F(UcellTest, BcastLattice)
117+
{
118+
unitcell::bcast_Lattice(ucell->lat);
119+
if (GlobalV::MY_RANK != 0)
120+
{
121+
EXPECT_EQ(ucell->Coordinate, "Direct");
122+
EXPECT_DOUBLE_EQ(ucell->a1.x, 10.0);
123+
EXPECT_EQ(ucell->atoms[0].na, 1);
124+
EXPECT_EQ(ucell->atoms[1].na, 2);
125+
/// this is to ensure all processes have the atom label info
126+
auto atom_labels = ucell->get_atomLabels();
127+
std::string atom_type1_expected = "C";
128+
std::string atom_type2_expected = "H";
129+
EXPECT_EQ(atom_labels[0], atom_type1_expected);
130+
EXPECT_EQ(atom_labels[1], atom_type2_expected);
131+
}
132+
}
133+
134+
TEST_F(UcellTest, BcastMagnitism)
135+
{
136+
unitcell::bcast_magnetism(ucell->magnet, ucell->ntype);
137+
PARAM.input.nspin = 4;
138+
if (GlobalV::MY_RANK != 0)
139+
{
140+
EXPECT_DOUBLE_EQ(ucell->magnet.start_magnetization[0], 0.0);
141+
EXPECT_DOUBLE_EQ(ucell->magnet.start_magnetization[1], 0.0);
142+
for (int i = 0; i < 3; ++i)
143+
{
144+
EXPECT_DOUBLE_EQ(ucell->magnet.ux_[i], 0.0);
145+
}
146+
}
147+
}
148+
116149
TEST_F(UcellTest, UpdatePosTau)
117150
{
118151
double* pos_in = new double[ucell->nat * 3];

0 commit comments

Comments
 (0)