forked from deepmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhsolver_pw_sup.h
More file actions
177 lines (154 loc) · 6.08 KB
/
hsolver_pw_sup.h
File metadata and controls
177 lines (154 loc) · 6.08 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 "source_basis/module_pw/pw_basis_k.h"
namespace ModulePW {
PW_Basis::PW_Basis(){};
PW_Basis::~PW_Basis(){};
void PW_Basis::initgrids(
const double lat0_in, // unit length (unit in bohr)
const ModuleBase::Matrix3
latvec_in, // Unitcell lattice vectors (unit in lat0)
const double gridecut // unit in Ry, ecut to set up grids
) {
return;
}
void PW_Basis::initgrids(
const double lat0_in,
const ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors
const int nx_in,
int ny_in,
int nz_in) {
return;
}
void PW_Basis::distribute_r() { return; }
PW_Basis_K::PW_Basis_K() {
this->nks = 1;
this->npwk_max = 3;
// used for update_precondition
this->gk2 = new double[3];
this->npwk = new int[1];
this->npwk[0] = 3;
this->tpiba2 = 1.0;
}
PW_Basis_K::~PW_Basis_K() {
delete[] this->gk2;
delete[] this->npwk;
}
double& PW_Basis_K::getgk2(const int ik, const int igl) const {
this->gk2[igl] = (ik + igl) * 1.5;
return this->gk2[igl];
}
} // namespace ModulePW
#include "source_hsolver/diago_cg.h"
#include "source_hsolver/diago_david.h"
#include "source_hsolver/diago_iter_assist.h"
namespace hsolver {
template <typename T, typename Device>
DiagoCG<T, Device>::DiagoCG(const std::string& basis_type,
const std::string& calculation) {
basis_type_ = basis_type;
calculation_ = calculation;
this->one_ = new T(static_cast<T>(1.0));
this->zero_ = new T(static_cast<T>(0.0));
this->neg_one_ = new T(static_cast<T>(-1.0));
}
template <typename T, typename Device>
DiagoCG<T, Device>::DiagoCG(const std::string& basis_type,
const std::string& calculation,
const bool& need_subspace,
const SubspaceFunc& subspace_func,
const Real& pw_diag_thr,
const int& pw_diag_nmax,
const int& nproc_in_pool) {
basis_type_ = basis_type;
calculation_ = calculation;
need_subspace_ = need_subspace;
subspace_func_ = subspace_func;
pw_diag_thr_ = pw_diag_thr;
pw_diag_nmax_ = pw_diag_nmax;
nproc_in_pool_ = nproc_in_pool;
this->one_ = new T(static_cast<T>(1.0));
this->zero_ = new T(static_cast<T>(0.0));
this->neg_one_ = new T(static_cast<T>(-1.0));
}
template <typename T, typename Device>
DiagoCG<T, Device>::~DiagoCG() {
delete this->one_;
delete this->zero_;
delete this->neg_one_;
}
template <typename T, typename Device>
double DiagoCG<T, Device>::diag(const HPsiFunc& hpsi_func,
const SPsiFunc& spsi_func,
const int ld_psi,
const int nband,
const int dim,
T* psi_in,
Real* eigenvalue_in,
const std::vector<double>& ethr_band,
const Real* prec) {
// do something
for (int ib = 0; ib < nband; ib++) {
eigenvalue_in[ib] = 0.0;
T* psi_band = psi_in + static_cast<size_t>(ib) * static_cast<size_t>(ld_psi);
for (int ig = 0; ig < ld_psi; ig++) {
psi_band[ig] += T(2.0, 0.0);
eigenvalue_in[ib] += psi_band[ig].real();
}
eigenvalue_in[ib] /= ld_psi;
}
DiagoIterAssist<T, Device>::avg_iter += 1.0;
return avg_iter_;
}
template class DiagoCG<std::complex<float>, base_device::DEVICE_CPU>;
template class DiagoCG<std::complex<double>, base_device::DEVICE_CPU>;
template <typename T, typename Device>
DiagoDavid<T, Device>::DiagoDavid(const Real* precondition_in,
const int nband_in,
const int dim_in,
const int david_ndim_in,
const diag_comm_info& diag_comm_in)
: nband(nband_in), dim(dim_in), nbase_x(david_ndim_in * nband_in), david_ndim(david_ndim_in), diag_comm(diag_comm_in) {
this->device = base_device::get_device_type(this->ctx);
this->precondition = precondition_in;
test_david = 2;
// 1: check which function is called and which step is executed
// 2: check the eigenvalues of the result of each iteration
// 3: check the eigenvalues and errors of the last result
// default: no check
}
template <typename T, typename Device>
DiagoDavid<T, Device>::~DiagoDavid() {
delmem_complex_op()(this->hpsi);
delmem_complex_op()(this->spsi);
delmem_complex_op()(this->hcc);
delmem_complex_op()(this->vcc);
delmem_complex_op()(this->lagrange_matrix);
base_device::memory::delete_memory_op<Real, base_device::DEVICE_CPU>()(this->eigenvalue);
}
template <typename T, typename Device>
int DiagoDavid<T, Device>::diag(const std::function<void(T*, T*, const int, const int)>& hpsi_func,
const std::function<void(T*, T*, const int, const int)>& spsi_func,
const int ld_psi,
T* psi_in,
Real* eigenvalue_in,
const std::vector<double>& ethr_band,
const int david_maxiter,
const int ntry_max,
const int notconv_max) {
// do nothing, we dont need it
// do something
// for (int ib = 0; ib < psi.get_nbands(); ib++) {
// eigenvalue_in[ib] = 0.0;
// for (int ig = 0; ig < psi.get_nbasis(); ig++) {
// psi(ib, ig) += T(1.0, 0.0);
// eigenvalue_in[ib] += psi(ib, ig).real();
// }
// eigenvalue_in[ib] /= psi.get_nbasis();
// }
// DiagoIterAssist<T, Device>::avg_iter += 1.0;
return 1;
}
template class DiagoDavid<std::complex<float>, base_device::DEVICE_CPU>;
template class DiagoDavid<std::complex<double>, base_device::DEVICE_CPU>;
template class DiagoIterAssist<std::complex<float>, base_device::DEVICE_CPU>;
template class DiagoIterAssist<std::complex<double>, base_device::DEVICE_CPU>;
} // namespace hsolver