Repository navigation
Expand file tree
/
Copy pathwrite_eig_occ_test.cpp
More file actions
128 lines (110 loc) · 3.42 KB
/
Copy pathwrite_eig_occ_test.cpp
File metadata and controls
128 lines (110 loc) · 3.42 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
#include "source_base/global_variable.h"
#define private public
#include "source_io/module_parameter/parameter.h"
#undef private
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <streambuf>
#ifdef __MPI
#include "source_base/parallel_global.h"
#include "source_cell/parallel_kpoints.h"
#include "mpi.h"
#endif
#include "../write_eig_occ.h"
#include "for_testing_klist.h"
/************************************************
* unit test of write_eig_occ
***********************************************/
/**
* - Tested Functions:
* - write_eig_occ()
* - print out electronic eigen energies and
* - occupation
*/
class IstateInfoTest : public ::testing::Test
{
protected:
K_Vectors* kv = nullptr;
ModuleBase::matrix ekb;
ModuleBase::matrix wg;
void SetUp()
{
kv = new K_Vectors;
}
void TearDown()
{
delete kv;
}
};
TEST_F(IstateInfoTest, OutIstateInfoS1)
{
// Global variables
GlobalV::KPAR = 1;
PARAM.input.nbands = 4;
PARAM.sys.nbands_l = 4;
PARAM.input.nspin = 1;
PARAM.sys.global_out_dir = "./";
// MPI setting
Parallel_Global::init_pools(GlobalV::NPROC,
GlobalV::MY_RANK,
PARAM.input.bndpar,
GlobalV::KPAR,
GlobalV::NPROC_IN_BNDGROUP,
GlobalV::RANK_IN_BPGROUP,
GlobalV::MY_BNDGROUP,
GlobalV::NPROC_IN_POOL,
GlobalV::RANK_IN_POOL,
GlobalV::MY_POOL);
const int nkstot_init = 10;
kv->set_nkstot(nkstot_init);
int nkstot = kv->get_nkstot();
kv->para_k.kinfo(nkstot, GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::RANK_IN_POOL,
GlobalV::NPROC_IN_POOL, PARAM.input.nspin);
kv->set_nks(kv->para_k.nks_pool[GlobalV::MY_POOL]);
// The number of plane waves for each k point
kv->ngk.resize(nkstot);
kv->ik2iktot.resize(nkstot);
for(int i=0; i<nkstot; ++i)
{
kv->ngk[i]=299;
kv->ik2iktot[i]=i;
}
// Initialize the number of bands
ekb.create(kv->get_nks(), PARAM.input.nbands);
wg.create(kv->get_nks(), PARAM.input.nbands);
// fill the eigenvalues
ekb.fill_out(0.15);
// fill the weights
wg.fill_out(0.0);
// setup coordinates of k-points
kv->kvec_c.resize(kv->get_nkstot());
int i = 0;
for (auto& kd: kv->kvec_c)
{
kd.set(0.01 * i, 0.01 * i, 0.01 * i);
++i;
}
// write eigenvalues and occupations
ModuleIO::write_eig_file(ekb, wg, *kv);
// check the output files
std::ifstream ifs;
ifs.open("eig.txt");
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
EXPECT_THAT(str, testing::HasSubstr("Electronic state energy (eV) and occupations"));
EXPECT_THAT(str, testing::HasSubstr("spin=1 k-point=1/10 Cartesian=0.0000000 0.0000000 0.0000000 (299 plane wave)"));
EXPECT_THAT(str, testing::HasSubstr("1 2.040854700000000 0.000000000000000"));
ifs.close();
remove("eig.txt");
}
#ifdef __MPI
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