-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFixedChargeProfile.cpp
101 lines (88 loc) · 2.55 KB
/
FixedChargeProfile.cpp
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
// @author Wushi Dong
// FixedChargeProfile.cpp
#include "FixedChargeProfile.h"
FixedChargeProfile::~FixedChargeProfile(){}
void FixedChargeProfile::GetFixedCharge()
{
double * charge_fixed_Gr = (double *)calloc(6, sizeof(double));
double * charge_fixed_MoS2 = (double *)calloc(6, sizeof(double));
double temp;
std::ifstream infile;
// Reads fixed charge from file
// Graphene
int n_scat_Gr = 10;
std::string filename1 = mFixedChargeFileGr;
infile.open(filename1.c_str());
if(!infile && mRank == 0)
{
std::cerr<< endl << "Error when trying to open Gr fixed charge file!" << std::endl;
}
for(int i = 0; i < 6; ++i)
{
infile >> temp;
infile >> temp;
}
for(int i = 6; i < (n_scat_Gr - 1) * 6; ++i)
{
infile >> temp;
infile >> temp;
charge_fixed_Gr[i % 6] += temp;
}
infile.close();
for(int i = 0; i < 6; ++i)
charge_fixed_Gr[i] /= (double)(n_scat_Gr - 2);
// Displays fixed charge for graphene
if(mRank == 0)
{
std::cout << "Fixed charge for Gr supercell:" << endl;
for (int i = 0; i < 6; ++i)
std::cout << i + 1 << "\t" << std::setprecision(7) << charge_fixed_Gr[i] << endl;
std::cout << endl;
}
// MoS2
int n_scat_MoS2 = 10;
std::string filename2 = mFixedChargeFileMoS2;
infile.open(filename2.c_str());
if(!infile && mRank == 0)
{
std::cerr<< endl << "Error when trying to open MoS2 fixed charge file!" << std::endl;
}
for(int i = 0; i < 6; ++i)
{
infile >> temp;
infile >> temp;
}
for(int i = 6; i < (n_scat_MoS2 - 1) * 6; ++i)
{
infile >> temp;
infile >> temp;
charge_fixed_MoS2[i % 6] += temp;
}
infile.close();
for(int i = 0; i < 6; ++i)
charge_fixed_MoS2[i] /= (double)(n_scat_MoS2 - 2);
// Displays fixed charge for MoS2
if(mRank == 0)
{
std::cout << "Fixed charge for MoS2 supercell:" << endl;
for (int i = 0; i < 6; ++i)
std::cout << i + 1 << "\t" << std::setprecision(7) << charge_fixed_MoS2[i] << endl;
std::cout << endl;
}
// Sets fixed charge for the device
// Graphene
for(int i = 0; i < mNumPrincipalLayerGraphene * 6 - 1; ++i)
mpCharge[i] = charge_fixed_Gr[i % 6];
// S2
mpCharge[mNumPrincipalLayerGraphene * 6] = charge_fixed_MoS2[4];
// Gr
for(int i = 0; i < mNumPrincipalLayerMoS2 * 6 - 1; ++i)
mpCharge[i + mNumPrincipalLayerGraphene * 6 + 1] = charge_fixed_MoS2[i % 6];
}
//void FixedChargeProfile::Print() const
//{
// std::cout << "Fixed Charge: " << endl;
// for(int i = 0; i < mNGrid; ++i)
// std::cout << i << '\t' << mpCharge[i] << endl;
// std::cout << endl;
//}