Repository navigation
Expand file tree
/
Copy pathcal_wfc.cpp
More file actions
177 lines (164 loc) · 5.4 KB
/
Copy pathcal_wfc.cpp
File metadata and controls
177 lines (164 loc) · 5.4 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
#include "read_pseudo.h"
namespace elecstate
{
void cal_nwfc(std::ofstream& log,UnitCell& ucell,Atom* atoms)
{
ModuleBase::TITLE("UnitCell", "cal_nwfc");
const int ntype = ucell.ntype;
const int nat = ucell.nat;
assert(ntype > 0);
assert(nat > 0);
//===========================
// (1) set iw2l, iw2n, iw2m
//===========================
for (int it = 0; it < ntype; it++)
{
ucell.atoms[it].set_index();
}
//===========================
// (2) set namax and nwmax
//===========================
ucell.namax = 0;
ucell.nwmax = 0;
for (int it = 0; it < ntype; it++) {
ucell.namax = std::max(atoms[it].na, ucell.namax);
ucell.nwmax = std::max(atoms[it].nw, ucell.nwmax);
}
//===========================
// (3) set nwfc and stapos_wf
//===========================
int nlocal_tmp = 0;
for (int it = 0; it < ntype; it++) {
atoms[it].stapos_wf = nlocal_tmp;
const int nlocal_it = atoms[it].nw * atoms[it].na;
if (PARAM.inp.nspin != 4) {
nlocal_tmp += nlocal_it;
} else {
nlocal_tmp += nlocal_it * 2; // zhengdy-soc
}
}
// log << " " << std::setw(40) << "NLOCAL"
// << " = " << nlocal_tmp << std::endl;
//========================================================
// (4) set index for itia2iat, itiaiw2iwt
//========================================================
// mohan add 2010-09-26
assert(nlocal_tmp > 0);
assert(nlocal_tmp == PARAM.globalv.nlocal);
delete[] ucell.iwt2iat;
delete[] ucell.iwt2iw;
ucell.iwt2iat = new int[nlocal_tmp];
ucell.iwt2iw = new int[nlocal_tmp];
ucell.itia2iat.create(ntype, ucell.namax);
ucell.set_iat2iwt(PARAM.globalv.npol);
int iat = 0;
int iwt = 0;
for (int it = 0; it < ntype; it++) {
for (int ia = 0; ia < atoms[it].na; ia++) {
ucell.itia2iat(it, ia) = iat;
for (int iw = 0; iw < atoms[it].nw * PARAM.globalv.npol; iw++) {
ucell.iwt2iat[iwt] = iat;
ucell.iwt2iw[iwt] = iw;
++iwt;
}
++iat;
}
}
//========================
// (5) set lmax and nmax
//========================
ucell.lmax = 0;
ucell.nmax = 0;
ucell.nmax_total = 0;
for (int it = 0; it < ntype; it++) {
ucell.lmax = std::max(ucell.lmax, atoms[it].nwl);
for (int l = 0; l < atoms[it].nwl + 1; l++) {
ucell.nmax = std::max(ucell.nmax, atoms[it].l_nchi[l]);
}
int nchi = 0;
for (int l = 0; l < atoms[it].nwl + 1; l++) {
nchi += atoms[it].l_nchi[l];
}
ucell.nmax_total = std::max(ucell.nmax_total, nchi);
}
//=======================
// (6) set lmax_ppwf
//=======================
ucell.lmax_ppwf = 0;
for (int it = 0; it < ntype; it++) {
for (int ic = 0; ic < atoms[it].ncpp.nchi; ic++) {
if (ucell.lmax_ppwf < atoms[it].ncpp.lchi[ic]) {
ucell.lmax_ppwf = atoms[it].ncpp.lchi[ic];
}
}
}
//=====================
// Use localized basis
//=====================
if ((PARAM.inp.basis_type == "lcao") || (PARAM.inp.basis_type == "lcao_in_pw")
|| ((PARAM.inp.basis_type == "pw") && (PARAM.inp.init_wfc.substr(0, 3) == "nao")
&& (PARAM.inp.esolver_type == "ksdft"))) // xiaohui add 2013-09-02
{
ModuleBase::GlobalFunc::AUTO_SET("NBANDS", PARAM.inp.nbands);
} else // plane wave basis
{
// if(winput::after_iter && winput::sph_proj)
//{
// if(PARAM.inp.nbands < PARAM.globalv.nlocal)
// {
// ModuleBase::WARNING_QUIT("cal_nwfc","NBANDS must > PARAM.globalv.nlocal
//!");
// }
// }
}
return;
}
void cal_meshx(int& meshx,const Atom* atoms, const int ntype)
{
meshx = 0;
for (int it = 0; it < ntype; it++) {
const int mesh = atoms[it].ncpp.msh;
if (mesh > meshx)
{
meshx = mesh;
}
}
}
void cal_natomwfc(std::ofstream& log,int& natomwfc,const int ntype,const Atom* atoms)
{
natomwfc = 0;
for (int it = 0; it < ntype; it++)
{
//============================
// Use pseudo-atomic orbitals
//============================
int tmp = 0;
for (int l = 0; l < atoms[it].ncpp.nchi; l++)
{
if (atoms[it].ncpp.oc[l] >= 0)
{
if (PARAM.inp.nspin == 4)
{
if (atoms[it].ncpp.has_so)
{
tmp += 2 * atoms[it].ncpp.lchi[l];
if (fabs(atoms[it].ncpp.jchi[l] - atoms[it].ncpp.lchi[l] - 0.5)< 1e-6)
{
tmp += 2;
}
} else
{
tmp += 2 * (2 * atoms[it].ncpp.lchi[l] + 1);
}
} else
{
tmp += 2 * atoms[it].ncpp.lchi[l] + 1;
}
}
}
natomwfc += tmp * atoms[it].na;
}
ModuleBase::GlobalFunc::OUT(log, "Number of pseudo atomic orbitals", natomwfc);
return;
}
}