Repository navigation
Expand file tree
/
Copy pathgatefield.cpp
More file actions
206 lines (181 loc) · 6.65 KB
/
Copy pathgatefield.cpp
File metadata and controls
206 lines (181 loc) · 6.65 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
#include "gatefield.h"
#include "source_io/module_parameter/parameter.h"
#include "efield.h"
#include "source_base/timer.h"
namespace elecstate
{
double Gatefield::etotgatefield = 0.0;
double Gatefield::rho_surface;
double Gatefield::zgate = 0.5;
bool Gatefield::relax = false;
bool Gatefield::block = false;
double Gatefield::block_down = 0.45;
double Gatefield::block_up = 0.55;
double Gatefield::block_height = 0.1;
void Gatefield::add_gatefield(double *vltot,
const UnitCell &cell,
const ModulePW::PW_Basis *rho_basis,
const bool &linear,
const bool &quadratic)
{
ModuleBase::TITLE("Gatefield", "add_gatefield");
ModuleBase::timer::tick("Gatefield", "add_gatefield");
//=======================================================
// preparation for constants
//=======================================================
double latvec; // latvec along the efield direction
double area; // surface area along the efield direction
Efield::prepare(cell, latvec, area);
double ion_charge = 0;
for (int it = 0; it < cell.ntype; ++it)
{
ion_charge += cell.atoms[it].na * cell.atoms[it].ncpp.zv;
}
rho_surface = -(PARAM.inp.nelec - ion_charge) / area * ModuleBase::TWO_PI;
double block_size = block_up - block_down;
//=======================================================
// correction energy for gatefield
//=======================================================
double factor = 0;
for (int it = 0; it < cell.ntype; ++it)
{
double zval = cell.atoms[it].ncpp.zv;
for (int ia = 0; ia < cell.atoms[it].na; ++ia)
{
double pos = cell.atoms[it].taud[ia][Efield::efield_dir];
factor += zval * (mopopla(zgate, pos, true) + 1.0 / 6.0); // linear part
factor += zval * mopopla(zgate, pos, false); // quadratic part
}
}
etotgatefield
= -ModuleBase::e2 * rho_surface * cell.lat0 / Efield::bmod * (factor + (PARAM.inp.nelec - ion_charge) / 12.0);
GlobalV::ofs_running << "\n\n Adding charged plate to compensate the charge of the system" << std::endl;
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "prefactor of the potential (Ry a.u.)", rho_surface);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "position of the charged plate within cell", zgate);
if (relax)
{
GlobalV::ofs_running << "Allow relaxation in specific direction" << std::endl;
}
if (block)
{
if (PARAM.inp.dip_cor_flag)
{
GlobalV::ofs_running << "Adding potential to prevent charge spilling into region of the gate" << std::endl;
}
else
{
GlobalV::ofs_running << "Adding potential to prevent interaction between lower and upper part of unit cell"
<< std::endl;
}
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "block_size in units of unit cell length", block_size);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "block_height (Ry a.u.)", block_height);
}
for (int ir = 0; ir < rho_basis->nrxx; ++ir)
{
int i = ir / (rho_basis->ny * rho_basis->nplane);
int j = ir / rho_basis->nplane - i * rho_basis->ny;
int k = ir % rho_basis->nplane + rho_basis->startz_current;
double x = (double)i / rho_basis->nx;
double y = (double)j / rho_basis->ny;
double z = (double)k / rho_basis->nz;
ModuleBase::Vector3<double> pos(x, y, z);
double gatepos = pos[Efield::efield_dir];
double value = 0;
if (linear)
{
value += rho_surface * ModuleBase::e2 * (mopopla(zgate, gatepos, true) + 1.0 / 6.0) * cell.lat0
/ Efield::bmod;
if (block && gatepos >= block_down && gatepos <= block_up && !PARAM.inp.dip_cor_flag)
{
if (gatepos - zgate <= -block_size / 2.0 * 0.9) // smooth increase within the first 10%
{
value += block_height * (gatepos - zgate + block_size / 2.0) / (0.1 * block_size / 2.0);
}
else if (gatepos - zgate >= block_size / 2.0 * 0.9) // smooth decrease within the last 10%
{
value += block_height * (gatepos - zgate - block_size / 2.0) / (-0.1 * block_size / 2.0);
}
else // block
{
value += block_height;
}
}
else if (block && gatepos >= block_down && gatepos <= block_up && PARAM.inp.dip_cor_flag)
{
if (gatepos <= block_down + Efield::efield_pos_dec)
{
value += (gatepos - block_down) / Efield::efield_pos_dec * block_height;
}
else if (gatepos >= block_up - Efield::efield_pos_dec)
{
value += (block_up - gatepos) / Efield::efield_pos_dec * block_height;
}
else
{
value += block_height;
}
}
}
if (quadratic)
{
value += rho_surface * ModuleBase::e2 * mopopla(zgate, gatepos, false) * cell.lat0 / Efield::bmod;
}
vltot[ir] += value;
}
ModuleBase::timer::tick("Gatefield", "add_gatefield");
}
double Gatefield::mopopla(double &zgate, double z, bool flag)
{
while (z > 1.0)
z -= 1.0;
while (z < 0.0)
z += 1.0;
z -= zgate;
if (z <= -0.5)
z += 1.0;
if (z >= 0.5)
z -= 1.0;
if (!flag)
{
return z * z;
}
else if (z <= 0)
{
return z;
}
else
{
return -z;
}
}
void Gatefield::compute_force(const UnitCell &cell, ModuleBase::matrix &fgate)
{
int iat = 0;
for (int it = 0; it < cell.ntype; ++it)
{
double zval = cell.atoms[it].ncpp.zv;
for (int ia = 0; ia < cell.atoms[it].na; ++ia)
{
double pos = cell.atoms[it].taud[ia][Efield::efield_dir];
while (pos > 1.0)
pos -= 1.0;
while (pos < 0.0)
pos += 1.0;
pos -= zgate;
if (pos <= -0.5)
pos += 1.0;
if (pos >= 0.5)
pos -= 1.0;
double fac = 1;
if (pos < 0)
fac = -1;
for (int jj = 0; jj < 3; ++jj)
{
fgate(iat, jj)
= -zval * ModuleBase::e2 * rho_surface * Efield::bvec[jj] / Efield::bmod * (fac - 2.0 * pos);
}
++iat;
}
}
}
} // namespace elecstate