Repository navigation
Expand file tree
/
Copy pathatom_spec_test.cpp
More file actions
215 lines (203 loc) · 4.85 KB
/
Copy pathatom_spec_test.cpp
File metadata and controls
215 lines (203 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#define private public
#include "source_io/module_parameter/parameter.h"
#undef private
#include<streambuf>
#ifdef __MPI
#include "mpi.h"
#endif
/************************************************
* unit test of Atom_pseudo
***********************************************/
/**
* - Tested Functions:
* - Atom()
* - constructor of class Atom
* - ~Atom()
* - deconstructor of class Atom
* - print_Atom()
* - print atomic info to file
* - set_index()
* - index between numerical atomic orbtials and quantum numbers L,m
* - bcast_atom()
* - bcast basic atomic info to all processes
* - bcast_atom2()
* - bcast norm-conserving pseudopotential info to all processes
*/
#define private public
#include "source_cell/read_pp.h"
#include "source_cell/pseudo.h"
#include "source_cell/atom_pseudo.h"
#include "source_cell/atom_spec.h"
#undef private
class AtomSpecTest : public testing::Test
{
protected:
Atom atom;
Pseudopot_upf upf;
std::ofstream ofs;
std::ifstream ifs;
};
TEST_F(AtomSpecTest, PrintAtom)
{
#ifdef __MPI
if(GlobalV::MY_RANK==0)
{
#endif
ofs.open("tmp_atom_info");
atom.label = "C";
atom.type = 1;
atom.na = 2;
atom.nwl = 2;
atom.Rcut = 1.1;
atom.nw = 14;
atom.stapos_wf = 0;
atom.mass = 12.0;
atom.tau.resize(atom.na);
atom.tau[0].x = 0.2;
atom.tau[0].y = 0.2;
atom.tau[0].z = 0.2;
atom.tau[1].x = 0.4;
atom.tau[1].y = 0.4;
atom.tau[1].z = 0.4;
atom.print_Atom(ofs);
ofs.close();
ifs.open("tmp_atom_info");
std::string str((std::istreambuf_iterator<char>(ifs)),std::istreambuf_iterator<char>());
EXPECT_THAT(str, testing::HasSubstr("label = C"));
EXPECT_THAT(str, testing::HasSubstr("type = 1"));
EXPECT_THAT(str, testing::HasSubstr("na = 2"));
EXPECT_THAT(str, testing::HasSubstr("nwl = 2"));
EXPECT_THAT(str, testing::HasSubstr("Rcut = 1.1"));
EXPECT_THAT(str, testing::HasSubstr("nw = 14"));
EXPECT_THAT(str, testing::HasSubstr("stapos_wf = 0"));
EXPECT_THAT(str, testing::HasSubstr("mass = 12"));
EXPECT_THAT(str, testing::HasSubstr("atom_position(cartesian) Dimension = 2"));
ifs.close();
remove("tmp_atom_info");
#ifdef __MPI
}
#endif
}
TEST_F(AtomSpecTest, SetIndex)
{
#ifdef __MPI
if(GlobalV::MY_RANK==0)
{
#endif
atom.nw = 0;
atom.nwl = 1;
atom.l_nchi.resize(atom.nwl+1);
atom.l_nchi[0] = 2; // l:0, N:2 (arbitrary)
atom.nw += 1*atom.l_nchi[0]; // m = 2*0+1 = 1
atom.l_nchi[1] = 4; // l:1, N:4 (arbitrary)
atom.nw += 3*atom.l_nchi[1]; // m = 2*1+1 = 3
atom.set_index();
EXPECT_EQ(atom.iw2l[13],1);
EXPECT_EQ(atom.iw2n[13],3);
EXPECT_EQ(atom.iw2m[13],2);
EXPECT_EQ(atom.iw2_ylm[13],3);
EXPECT_TRUE(atom.iw2_new[11]);
// here is the table:
// nw = 2 + 3*4 = 14
// L N m L*L+m
// 0 0 0 0 0
// 1 0 1 0 0
// 2 1 0 0 1
// 3 1 0 1 2
// 4 1 0 2 3
// 5 1 1 0 1
// 6 1 1 1 2
// 7 1 1 2 3
// 8 1 2 0 1
// 9 1 2 1 2
// 10 1 2 2 3
// 11 1 3 0 1
// 12 1 3 1 2
// 13 1 3 2 3
#ifdef __MPI
}
#endif
}
#ifdef __MPI
TEST_F(AtomSpecTest, BcastAtom)
{
if(GlobalV::MY_RANK==0)
{
atom.label = "C";
atom.type = 1;
atom.na = 2;
atom.nw = 0;
atom.nwl = 1;
atom.Rcut = 1.1;
atom.l_nchi.resize(atom.nwl+1);
atom.l_nchi[0] = 2;
atom.nw += atom.l_nchi[0];
atom.l_nchi[1] = 4;
atom.nw += 3*atom.l_nchi[1];
atom.stapos_wf = 0;
atom.mass = 12.0;
atom.tau.resize(atom.na);
atom.taud.resize(atom.na);
atom.dis.resize(atom.na);
atom.vel.resize(atom.na);
atom.mag.resize(atom.na);
atom.angle1.resize(atom.na);
atom.angle2.resize(atom.na);
atom.m_loc_.resize(atom.na);
atom.mbl.resize(atom.na);
atom.lambda.resize(atom.na);
atom.constrain.resize(atom.na);
atom.tau[0].x = 0.2;
atom.tau[0].y = 0.2;
atom.tau[0].z = 0.2;
atom.tau[1].x = 0.4;
atom.tau[1].y = 0.4;
atom.tau[1].z = 0.4;
}
atom.bcast_atom();
if(GlobalV::MY_RANK!=0)
{
EXPECT_EQ(atom.label,"C");
EXPECT_EQ(atom.type,1);
EXPECT_EQ(atom.na,2);
EXPECT_EQ(atom.nwl,1);
EXPECT_DOUBLE_EQ(atom.Rcut,1.1);
EXPECT_EQ(atom.nw,14);
EXPECT_EQ(atom.stapos_wf,0);
EXPECT_DOUBLE_EQ(atom.mass,12.0);
EXPECT_DOUBLE_EQ(atom.tau[0].x,0.2);
EXPECT_DOUBLE_EQ(atom.tau[1].z,0.4);
}
}
TEST_F(AtomSpecTest, BcastAtom2)
{
if(GlobalV::MY_RANK==0)
{
ifs.open("./support/C.upf");
PARAM.input.pseudo_rcut = 15.0;
upf.read_pseudo_upf201(ifs, atom.ncpp);
upf.complete_default(atom.ncpp);
ifs.close();
EXPECT_TRUE(atom.ncpp.has_so);
}
atom.bcast_atom2();
if(GlobalV::MY_RANK!=0)
{
EXPECT_EQ(atom.ncpp.nbeta,6);
EXPECT_EQ(atom.ncpp.nchi,3);
EXPECT_DOUBLE_EQ(atom.ncpp.rho_atc[0],8.7234550809E-01);
}
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
testing::InitGoogleTest(&argc, argv);
MPI_Comm_size(MPI_COMM_WORLD,&GlobalV::NPROC);
MPI_Comm_rank(MPI_COMM_WORLD,&GlobalV::MY_RANK);
int result = RUN_ALL_TESTS();
MPI_Finalize();
return result;
}
#endif