-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPotentialProfile.cpp
117 lines (97 loc) · 2.74 KB
/
PotentialProfile.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
#include "PotentialProfile.h"
PotentialProfile::~PotentialProfile(){}
void PotentialProfile::Init()
{
// Use linear drop as trial potential
if(mPotentialInitializationMethod == "linear")
{
for(int i = 0; i < mNumGrid; ++i)
mpPotential[i] = -0.5 * mVoltageBias + (mVoltageBias / (double)(mNumGrid + 1)) * (double)(i + 1);
}
// Mannually set trial potential due to screening of interface charge potential
else if(mPotentialInitializationMethod == "mannual")
{
mpPotential[mNumGridGraphene] += -1.0;
mpPotential[mNumGridGraphene - 1] += -0.5;
mpPotential[mNumGridGraphene + 1] += -0.5;
mpPotential[mNumGridGraphene - 2] += -0.05;
mpPotential[mNumGridGraphene + 2] += -0.05;
}
// Use potential from last run as input for the current calculation
else if(mPotentialInitializationMethod == "last")
{
std::ifstream infile;
double temp;
infile.open("last/potential.txt");
if(!infile)
{
std::cerr<< "[ERROR] Cannot find last potential file!" << std::endl;
}
for(int i = 0; i < mNumGrid; ++i)
{
infile >> temp;
infile >> mpPotential[i];
}
infile.close();
}
// Use converged potential as input for the current calculation
else if(mPotentialInitializationMethod == "converged")
{
std::ifstream infile;
double temp;
infile.open("potential_conv.txt");
if(!infile)
{
std::cerr<< "[ERROR] Cannot find converged potential file!" << std::endl;
}
for(int i = 0; i < mNumGrid; ++i)
{
infile >> temp;
infile >> mpPotential[i];
}
infile.close();
}
else
{
{
std::cout << "[Warning] The following potential initialization method is \
not available:" << std::endl << mPotentialInitializationMethod <<
std::endl << "Initialize potential as all zeros." << std::endl;
}
}
};
void PotentialProfile::SetPotential(double *Potential)
{
for(int i = 0; i < mNumGrid; ++i)
mpPotential[i] = Potential[i];
};
void PotentialProfile::Print() const
{
// std::cout << "Potential: " << std::endl;
for(int i = 0; i < mNumGrid; ++i)
std::cout << i + 1 << '\t' << mpPotential[i] << std::endl;
std::cout << std::endl;
};
//// Testing
//int main()
//{
// Parameters parameters;
// PotentialProfile potential_profile(parameters);
// potential_profile.Print();
//
// const int n_grid2 = potential_profile.GetNumGrid();
// std::cout << n_grid2 << std::endl;
// double potential[n_grid2];
// for(int i = 0; i < n_grid2; ++i)
// potential[i] = 0.1 * double(i);
//
// potential_profile.SetPotential(potential);
// potential_profile.Print();
//
// PotentialProfile potential_profile2(parameters, "converged");
// potential_profile2.Print();
//
//
// return 0;
//}