forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathpseudo_nc_test.cpp
More file actions
131 lines (121 loc) · 2.91 KB
/
pseudo_nc_test.cpp
File metadata and controls
131 lines (121 loc) · 2.91 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
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#define private public
#include "source_io/module_parameter/parameter.h"
#undef private
#include<streambuf>
/************************************************
* unit test of pseudo
***********************************************/
/**
* - Tested Functions:
* - pseudo
* - ~pseudo
* - complete_default_h
* - complete_default_atom
* - complete_default_vl
* - complete_default
* - print_pseudo_h
* - print_pseudo_atom
* - print_pseudo_vl
* - print_pseudo
*/
#define private public
#include "source_cell/read_pp.h"
#include "source_cell/atom_pseudo.h"
#undef private
class NCPPTest : public testing::Test
{
protected:
std::unique_ptr<Pseudopot_upf> upf{new Pseudopot_upf};
std::unique_ptr<Atom_pseudo> ncpp{new Atom_pseudo};
};
TEST_F(NCPPTest, SetPseudoH)
{
std::ifstream ifs;
//set
ifs.open("./support/C.upf");
PARAM.input.pseudo_rcut = 15.0;
upf->read_pseudo_upf201(ifs, *ncpp);
//set_pseudo_h
upf->complete_default_h(*ncpp);
if(!ncpp->has_so)
{
for (int i=0;i<ncpp->nchi;i++)
{
EXPECT_EQ(ncpp->nn[i],0);
EXPECT_EQ(ncpp->jchi[i],0);
}
for (int i=0;i<ncpp->nbeta;i++)
{
EXPECT_EQ(ncpp->jjj[i],0);
}
}
ifs.close();
}
TEST_F(NCPPTest, SetPseudoAtom)
{
std::ifstream ifs;
//set
ifs.open("./support/C.upf");
PARAM.input.pseudo_rcut = 15.0;
upf->read_pseudo_upf201(ifs, *ncpp);
//set_pseudo_atom
upf->complete_default_h(*ncpp);
upf->complete_default_atom(*ncpp);
EXPECT_EQ(ncpp->rcut,PARAM.input.pseudo_rcut);
if(!ncpp->nlcc)
{
for(int i=0;i<ncpp->mesh;i++)
{
EXPECT_EQ(ncpp->rho_atc[i],0.0);
}
}
EXPECT_EQ(ncpp->msh,ncpp->mesh);
ifs.close();
}
TEST_F(NCPPTest, SetPseudoNC)
{
std::ifstream ifs;
//set
ifs.open("./support/C.upf");
PARAM.input.pseudo_rcut = 15.0;
// set pseudo nbeta = 0
upf->read_pseudo_upf201(ifs, *ncpp);
ncpp->nbeta = 0;
upf->complete_default(*ncpp);
EXPECT_EQ(ncpp->nh,0);
// set pseudo nbeta > 0
upf->read_pseudo_upf201(ifs, *ncpp);
upf->complete_default(*ncpp);
EXPECT_EQ(ncpp->nh,14);
EXPECT_EQ(ncpp->kkbeta,132);
ifs.close();
}
TEST_F(NCPPTest, PrintNC)
{
std::ifstream ifs;
//set
ifs.open("./support/C.upf");
PARAM.input.pseudo_rcut = 15.0;
upf->read_pseudo_upf201(ifs, *ncpp);
upf->complete_default(*ncpp);
ifs.close();
//print
std::ofstream ofs;
ofs.open("./tmp_log");
ncpp->print_pseudo(ofs);
ofs.close();
ifs.open("./tmp_log");
std::string str((std::istreambuf_iterator<char>(ifs)),std::istreambuf_iterator<char>());
EXPECT_THAT(str,testing::HasSubstr("psd C"));
EXPECT_THAT(str,testing::HasSubstr("pp_type NC"));
EXPECT_THAT(str,testing::HasSubstr("dft PBE"));
EXPECT_THAT(str,testing::HasSubstr("zv 4"));
EXPECT_THAT(str,testing::HasSubstr("nchi 3"));
EXPECT_THAT(str,testing::HasSubstr("nbeta 6"));
EXPECT_THAT(str,testing::HasSubstr("dion : nr=6 nc=6"));
EXPECT_THAT(str,testing::HasSubstr("msh\t1247"));
ifs.close();
remove("./tmp_log");
}