Skip to content

Commit b57beea

Browse files
committed
add unit test
1 parent 0affe0e commit b57beea

File tree

4 files changed

+156
-2
lines changed

4 files changed

+156
-2
lines changed

source/module_hamilt_pw/hamilt_pwdft/structure_factor.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ void Structure_Factor::setup_structure_factor(const UnitCell* Ucell, const Paral
164164
syncmem_z2z_h2d_op()(this->z_eigts3, this->eigts3.c, Ucell->nat * (2 * rho_basis->nz + 1));
165165
}
166166
else {
167-
std::cout<<"the test is "<<std::endl;
168167
if (PARAM.globalv.has_float_data) {
169-
std::cout<<"here set the float data"<<std::endl;
170168
resmem_ch_op()(this->c_eigts1, Ucell->nat * (2 * rho_basis->nx + 1));
171169
resmem_ch_op()(this->c_eigts2, Ucell->nat * (2 * rho_basis->ny + 1));
172170
resmem_ch_op()(this->c_eigts3, Ucell->nat * (2 * rho_basis->nz + 1));

source/module_hamilt_pw/hamilt_pwdft/test/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,31 @@ AddTest(
2626
TARGET radial_proj_test
2727
LIBS parameter base device ${math_libs}
2828
SOURCES radial_proj_test.cpp ../radial_proj.cpp
29+
)
30+
31+
AddTest(
32+
TARGET structure_factor_test
33+
LIBS parameter ${math_libs} base device planewave
34+
SOURCES structure_factor_test.cpp ../structure_factor.cpp ../parallel_grid.cpp
35+
../../../module_cell/unitcell.cpp
36+
../../../module_io/output.cpp
37+
../../../module_cell/update_cell.cpp
38+
../../../module_cell/bcast_cell.cpp
39+
../../../module_cell/print_cell.cpp
40+
../../../module_cell/atom_spec.cpp
41+
../../../module_cell/atom_pseudo.cpp
42+
../../../module_cell/pseudo.cpp
43+
../../../module_cell/read_stru.cpp
44+
../../../module_cell/read_atom_species.cpp
45+
../../../module_cell/read_atoms.cpp
46+
../../../module_cell/read_pp.cpp
47+
../../../module_cell/read_pp_complete.cpp
48+
../../../module_cell/read_pp_upf100.cpp
49+
../../../module_cell/read_pp_upf201.cpp
50+
../../../module_cell/read_pp_vwr.cpp
51+
../../../module_cell/read_pp_blps.cpp
52+
../../../module_elecstate/read_pseudo.cpp
53+
../../../module_elecstate/cal_wfc.cpp
54+
../../../module_elecstate/cal_nelec_nband.cpp
55+
../../../module_elecstate/read_orb.cpp
2956
)
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include "gtest/gtest.h"
2+
#include "gmock/gmock.h"
3+
#include <string>
4+
#include <cmath>
5+
#include <complex>
6+
#include "module_cell/unitcell.h"
7+
#include "module_elecstate/module_dm/test/prepare_unitcell.h"
8+
#define private public
9+
#include "module_parameter/parameter.h"
10+
#include "module_hamilt_pw/hamilt_pwdft/structure_factor.h"
11+
#undef private
12+
/************************************************
13+
* unit test of class Structure_factor and
14+
***********************************************/
15+
16+
/**
17+
* - Tested Functions:
18+
* - Fcoef::create to create a 5 dimensional array of complex numbers
19+
* - Soc::set_fcoef to set the fcoef array
20+
* - Soc::spinor to calculate the spinor
21+
* - Soc::rot_ylm to calculate the rotation matrix
22+
* - Soc::sph_ind to calculate the m index of the spherical harmonics
23+
*/
24+
25+
//compare two complex by using EXPECT_DOUBLE_EQ()
26+
InfoNonlocal::InfoNonlocal()
27+
{
28+
}
29+
InfoNonlocal::~InfoNonlocal()
30+
{
31+
}
32+
33+
Magnetism::Magnetism()
34+
{
35+
}
36+
Magnetism::~Magnetism()
37+
{
38+
}
39+
40+
class StructureFactorTest : public testing::Test
41+
{
42+
protected:
43+
Structure_Factor SF;
44+
std::string output;
45+
ModulePW::PW_Basis* rho_basis;
46+
UnitCell* ucell;
47+
UcellTestPrepare utp = UcellTestLib["Si"];
48+
Parallel_Grid* pgrid;
49+
std::vector<int> nw = {13};
50+
int nlocal = 0;
51+
void SetUp()
52+
{
53+
rho_basis=new ModulePW::PW_Basis;
54+
ucell = utp.SetUcellInfo(nw, nlocal);
55+
ucell->set_iat2iwt(1);
56+
pgrid = new Parallel_Grid;
57+
rho_basis->npw=10;
58+
rho_basis->gcar=new ModuleBase::Vector3<double>[10];
59+
// for (int ig=0;ig<rho_basis->npw;ig++)
60+
// {
61+
// rho_basis->gcar[ig]=1.0;
62+
// }
63+
}
64+
};
65+
66+
TEST_F(StructureFactorTest, set)
67+
{
68+
const ModulePW::PW_Basis* rho_basis_in;
69+
const int nbspline_in =10;
70+
SF.set(rho_basis_in,nbspline_in);
71+
EXPECT_EQ(nbspline_in, 10);
72+
}
73+
74+
75+
TEST_F(StructureFactorTest, setup_structure_factor_double)
76+
{
77+
rho_basis->npw = 10;
78+
SF.setup_structure_factor(ucell,*pgrid,rho_basis);
79+
80+
for (int i=0;i< ucell->nat * (2 * rho_basis->nx + 1);i++)
81+
{
82+
EXPECT_EQ(SF.z_eigts1[i].real(),1);
83+
EXPECT_EQ(SF.z_eigts1[i].imag(),0);
84+
}
85+
86+
for (int i=0;i< ucell->nat * (2 * rho_basis->ny + 1);i++)
87+
{
88+
EXPECT_EQ(SF.z_eigts2[i].real(),1);
89+
EXPECT_EQ(SF.z_eigts2[i].imag(),0);
90+
}
91+
92+
for (int i=0;i< ucell->nat * (2 * rho_basis->nz + 1);i++)
93+
{
94+
EXPECT_EQ(SF.z_eigts3[i].real(),1);
95+
EXPECT_EQ(SF.z_eigts3[i].imag(),0);
96+
}
97+
}
98+
99+
TEST_F(StructureFactorTest, setup_structure_factor_float)
100+
{
101+
PARAM.sys.has_float_data = true;
102+
rho_basis->npw = 10;
103+
SF.setup_structure_factor(ucell,*pgrid,rho_basis);
104+
105+
for (int i=0;i< ucell->nat * (2 * rho_basis->nx + 1);i++)
106+
{
107+
EXPECT_EQ(SF.c_eigts1[i].real(),1);
108+
EXPECT_EQ(SF.c_eigts1[i].imag(),0);
109+
}
110+
111+
for (int i=0;i< ucell->nat * (2 * rho_basis->ny + 1);i++)
112+
{
113+
EXPECT_EQ(SF.c_eigts2[i].real(),1);
114+
EXPECT_EQ(SF.c_eigts2[i].imag(),0);
115+
}
116+
117+
for (int i=0;i< ucell->nat * (2 * rho_basis->nz + 1);i++)
118+
{
119+
EXPECT_EQ(SF.c_eigts3[i].real(),1);
120+
EXPECT_EQ(SF.c_eigts3[i].imag(),0);
121+
}
122+
}
123+
124+
int main()
125+
{
126+
testing::InitGoogleTest();
127+
return RUN_ALL_TESTS();
128+
}

tests/integrate/CASES_CPU.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
102_PW_DA_davidson
2828
102_PW_DA_davidson_float
2929
102_PW_DS_davsubspace
30+
102_PW_DS_davsubspace_float
3031
102_PW_DS_davsubspace_sca
3132
102_PW_PINT_RKS
3233
102_PW_PINT_UKS

0 commit comments

Comments
 (0)