ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
vnl_pw.h
Go to the documentation of this file.
1#ifndef VNL_IN_PW_H
2#define VNL_IN_PW_H
3
8#include "source_cell/soc.h"
11#include "source_psi/psi.h"
12
13#include <vector>
14#ifdef __LCAO
16#endif
17
18//==========================================================
19// Calculate the non-local pseudopotential in reciprocal
20// space using plane wave as basis set.
21//==========================================================
23{
24
25 public:
28 void init(
29 const UnitCell &cell,
30 Structure_Factor *psf_in,
31 const ModulePW::PW_Basis_K *wfc_basis = nullptr,
32 const bool allocate_vkb = true);
33
34 double cell_factor = 0.0; // LiuXh add 20180619
35
36 int nkb = 0; // total number of beta functions considering all atoms
37
38 int lmaxkb = 0; // max angular momentum for non-local projectors
39
40 void init_vnl(UnitCell &cell, const ModulePW::PW_Basis *rho_basis);
41
42 void rescale_vnl(const double &omega_in);
43
45 void ensure_vnl_range(const UnitCell &cell, const double &qmax);
46
48 void check_vnl_index(const double &index, const bool &derivative) const;
49
51 double table_dq() const { return table_dq_; }
52
62 template <typename FPTYPE, typename Device>
63 void getvnl(
64 Device *ctx,
65 const UnitCell &ucell,
66 const int &ik,
67 const ModuleBase::Vector3<double> &vector_potential,
68 std::complex<FPTYPE> *vkb_in) const;
69
70 // void getvnl_alpha(const int &ik);
71
72 void init_vnl_alpha(const UnitCell &cell);
73
74 void initgradq_vnl(const UnitCell &cell);
76 size_t table_version() const { return table_version_; }
78 void ensure_grad_table(const UnitCell &cell);
79
80 //===============================================================
81 // MEMBER VARIABLES :
82 // NAME : nqx(number of interpolation points)
83 // NAME : nqxq(size of interpolation table)
84 // NAME : nhm(max number of different beta functions per atom)
85 // NAME : lmaxq
86 // NAME : dq(space between points in the pseudopotential tab)
87 //===============================================================
88 // private:
89
90 private:
91 double table_dq_ = 0.0;
92 size_t table_version_ = 1;
94
95 public:
96 int nhm = 0;
97 int nbetam = 0; // max number of beta functions
98
99 int lmaxq = 0;
100
101 ModuleBase::matrix indv; // indes linking atomic beta's to beta's in the solid
102 ModuleBase::matrix nhtol; // correspondence n <-> angular momentum l
103 ModuleBase::matrix nhtolm; // correspondence n <-> combined lm index for (l,m)
105
106 ModuleBase::realArray dvan; //(:,:,:), the D functions of the solid
107 ModuleBase::ComplexArray dvan_so; //(:,:,:), spin-orbit case, added by zhengdy-soc
108
109 ModuleBase::realArray tab; //(:,:,:), interpolation table for PPs: 4pi/sqrt(V) * \int betar(r)jl(qr)rdr
111 ModuleBase::realArray tab_at; //(:,:,:), interpolation table for atomic wfc
112 ModuleBase::realArray tab_dq; // 4pi/sqrt(V) * \int betar(r)*djl(qr)/d(qr)*r^2 dr
113
114 ModuleBase::realArray deeq; //(:,:,:,:), the integral of V_eff and Q_{nm}
115 bool multi_proj = false;
116 float *s_deeq = nullptr;
117 double *d_deeq = nullptr;
118 ModuleBase::ComplexArray deeq_nc; //(:,:,:,:), the spin-orbit case
119 std::complex<float> *c_deeq_nc = nullptr; // GPU array of deeq_nc
120 std::complex<double> *z_deeq_nc = nullptr; // GPU array of deeq_nc
121
122 // liuyu add 2023-10-03
123 // uspp
124 std::vector<int> indv_ijkb0; // first beta (index in the solid) for each atom
125 ModuleBase::IntArray ijtoh; // correspondence beta indexes ih,jh -> composite index ijh
126 ModuleBase::realArray qq_at; // the integral of q functions in the solid (ONE PER ATOM)
127 ModuleBase::realArray qq_nt; // the integral of q functions in the solid (ONE PER NTYP) used to be the qq array
128 ModuleBase::ComplexArray qq_so; // Q_{nm} for spin-orbit case
129 ModuleBase::realArray ap; // the expansion coefficients
130 ModuleBase::IntArray lpx; // for each input limi,ljmj is the number of LM in the sum
131 ModuleBase::IntArray lpl; // for each input limi,ljmj points to the allowed LM
132 ModuleBase::realArray qrad; // radial FT of Q functions
133
134 float *s_qq_nt = nullptr;
135 double *d_qq_nt = nullptr;
136 std::complex<float> *c_qq_so = nullptr; // GPU array of qq_so
137 std::complex<double> *z_qq_so = nullptr; // GPU array of qq_so
138
139 mutable ModuleBase::ComplexMatrix vkb; // all beta functions in reciprocal space
140 std::complex<double> ***vkb1_alpha;
141 std::complex<double> ***vkb_alpha;
143
144 // Column dimension of vkb matrix (= npwx), used as leading dimension in gemm/gemv.
145 // On GPU path vkb ComplexMatrix is not allocated to save CPU memory; this stores the dimension.
146 int vkbnc = 0;
147
148 // other variables
149 std::complex<double> Cal_C(
150 int alpha,
151 int lu,
152 int mu,
153 int L,
154 int M);
155
156 double CG(
157 int l1,
158 int m1,
159 int l2,
160 int m2,
161 int L,
162 int M);
163
164 void print_vnl(std::ofstream &ofs);
165
183 void radial_fft_q(
184 const int ng,
185 const int ih,
186 const int jh,
187 const int itype,
188 const double *qnorm,
189 const ModuleBase::matrix ylm,
190 std::complex<double> *qg) const;
191
197 template <typename FPTYPE, typename Device>
198 void radial_fft_q(
199 Device *ctx,
200 const int ng,
201 const int ih,
202 const int jh,
203 const int itype,
204 const FPTYPE *qnorm,
205 const FPTYPE *ylm,
206 std::complex<FPTYPE> *qg) const;
207
215 void cal_effective_D(const ModuleBase::matrix &veff, const ModulePW::PW_Basis *rho_basis, UnitCell &cell);
216#ifdef __LCAO
217 ORB_gaunt_table MGT;
218#endif
219
220 template <typename FPTYPE>
221 FPTYPE *get_nhtol_data() const;
222 template <typename FPTYPE>
223 FPTYPE *get_nhtolm_data() const;
224 template <typename FPTYPE>
225 FPTYPE *get_indv_data() const;
226 template <typename FPTYPE>
227 FPTYPE *get_tab_data() const;
228 template <typename FPTYPE>
229 FPTYPE *get_deeq_data() const;
230 template <typename FPTYPE>
231 FPTYPE *get_qq_nt_data() const;
232 template <typename FPTYPE>
233 std::complex<FPTYPE> *get_qq_so_data() const;
234 template <typename FPTYPE>
235 std::complex<FPTYPE> *get_vkb_data() const;
236 template <typename FPTYPE>
237 std::complex<FPTYPE> *get_deeq_nc_data() const;
238
239 void release_memory();
240
241 private:
242 bool memory_released = false;
243 float *s_nhtol = nullptr;
244 float *s_nhtolm = nullptr;
245 float *s_indv = nullptr;
246 float *s_tab = nullptr;
247 std::complex<float> *c_vkb = nullptr;
248
249 double *d_nhtol = nullptr;
250 double *d_nhtolm = nullptr;
251 double *d_indv = nullptr;
252 double *d_tab = nullptr;
253 std::complex<double> *z_vkb = nullptr;
254
255 const ModulePW::PW_Basis_K *wfcpw = nullptr;
256
258
259 double omega_old = 0;
260 bool use_gpu_ = false;
261
263 void fill_vnl_table(const UnitCell &cell);
264
266 void sync_vnl_table();
267
277 void compute_qrad(UnitCell &cell);
278
286 void newq(const ModuleBase::matrix &veff, const ModulePW::PW_Basis *rho_basis, UnitCell &cell);
287
294 void newd_so(const int &iat, UnitCell &cell);
295
302 void newd_nc(const int &iat, UnitCell &cell);
303};
304
305#endif // VNL_IN_PW
A basic type of data for complex array.
Definition complexarray.h:15
Definition complexmatrix.h:11
Integer array.
Definition intarray.h:17
3 elements vector
Definition vector3.h:21
Definition matrix.h:15
double float array
Definition realarray.h:21
Special pw_basis class. It includes different k-points.
Definition pw_basis_k.h:56
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:60
Definition orb_gaunt_table.h:9
Definition soc.h:49
Definition stru_fac.h:10
Provide the basic information about unitcell.
Definition unitcell.h:16
ModuleBase::matrix indv
Definition vnl_pw.h:101
double omega_old
Definition vnl_pw.h:259
double CG(int l1, int m1, int l2, int m2, int L, int M)
int nhm
Definition vnl_pw.h:96
void ensure_vnl_range(const UnitCell &cell, const double &qmax)
Ensure four-point interpolation covers qmax (inverse Bohr), without changing dq.
Definition vnl_pw_table.cpp:67
size_t gradient_version_
Definition vnl_pw.h:93
float * s_qq_nt
Definition vnl_pw.h:134
ModuleBase::matrix nhtoj
Definition vnl_pw.h:104
Structure_Factor * psf
Definition vnl_pw.h:142
std::complex< double > * z_vkb
Definition vnl_pw.h:253
void ensure_grad_table(const UnitCell &cell)
Prepare the derivative table only when the radial table changed.
Definition vnl_pw_grad.cpp:8
std::complex< float > * c_qq_so
Definition vnl_pw.h:136
int lmaxkb
Definition vnl_pw.h:38
double table_dq_
Definition vnl_pw.h:91
const ModulePW::PW_Basis_K * wfcpw
Definition vnl_pw.h:255
float * s_deeq
Definition vnl_pw.h:116
ModuleBase::realArray ap
Definition vnl_pw.h:129
FPTYPE * get_nhtol_data() const
std::complex< FPTYPE > * get_deeq_nc_data() const
std::complex< float > * c_vkb
Definition vnl_pw.h:247
std::complex< FPTYPE > * get_qq_so_data() const
std::complex< double > *** vkb_alpha
Definition vnl_pw.h:141
ModuleBase::realArray deeq
Definition vnl_pw.h:114
ModuleBase::ComplexArray deeq_nc
Definition vnl_pw.h:118
ModuleBase::ComplexArray qq_so
Definition vnl_pw.h:128
std::complex< double > Cal_C(int alpha, int lu, int mu, int L, int M)
ModuleBase::realArray dvan
Definition vnl_pw.h:106
FPTYPE * get_indv_data() const
void getvnl(Device *ctx, const UnitCell &ucell, const int &ik, const ModuleBase::Vector3< double > &vector_potential, std::complex< FPTYPE > *vkb_in) const
Build nonlocal projectors at G+k+A; pass zero A for ground-state calculations.
Definition vnl_pw_getvnl.cpp:22
double * d_qq_nt
Definition vnl_pw.h:135
double table_dq() const
Return the momentum spacing shared by the radial projector and derivative tables.
Definition vnl_pw.h:51
void fill_vnl_table(const UnitCell &cell)
Fill the allocated radial projector table using the original Bessel quadrature.
Definition vnl_pw_table.cpp:11
std::vector< int > indv_ijkb0
Definition vnl_pw.h:124
size_t table_version_
Definition vnl_pw.h:92
size_t table_version() const
Generation of radial tables, including volume rescaling.
Definition vnl_pw.h:76
ModuleBase::realArray tab_dq
Definition vnl_pw.h:112
float * s_nhtolm
Definition vnl_pw.h:244
pseudopot_cell_vnl()
Definition test_elecstate_pw.cpp:73
float * s_nhtol
Definition vnl_pw.h:243
void newd_so(const int &iat, UnitCell &cell)
calculate D functions in the soc case when tvanp is true
Definition vnl_pw_deeq.cpp:298
int nbetam
Definition vnl_pw.h:97
void compute_qrad(UnitCell &cell)
Compute interpolation table qrad.
Definition vnl_pw_qrad.cpp:33
std::complex< float > * c_deeq_nc
Definition vnl_pw.h:119
double * d_indv
Definition vnl_pw.h:251
std::complex< double > *** vkb1_alpha
Definition vnl_pw.h:140
void print_vnl(std::ofstream &ofs)
Definition vnl_pw.cpp:306
bool memory_released
Definition vnl_pw.h:242
double cell_factor
Definition vnl_pw.h:34
std::complex< double > * z_qq_so
Definition vnl_pw.h:137
FPTYPE * get_qq_nt_data() const
ModuleBase::ComplexMatrix vkb
Definition vnl_pw.h:139
void rescale_vnl(const double &omega_in)
Definition vnl_pw.cpp:310
ModuleBase::IntArray lpl
Definition vnl_pw.h:131
void check_vnl_index(const double &index, const bool &derivative) const
Reject non-finite or out-of-range dimensionless interpolation indices before reading.
Definition vnl_pw_table.cpp:111
void init_vnl_alpha(const UnitCell &cell)
double * d_nhtolm
Definition vnl_pw.h:250
ModuleBase::IntArray ijtoh
Definition vnl_pw.h:125
int nkb
Definition vnl_pw.h:36
ModuleBase::realArray qq_at
Definition vnl_pw.h:126
void init(const UnitCell &cell, Structure_Factor *psf_in, const ModulePW::PW_Basis_K *wfc_basis=nullptr, const bool allocate_vkb=true)
Definition vnl_pw.cpp:88
std::complex< FPTYPE > * get_vkb_data() const
FPTYPE * get_nhtolm_data() const
bool use_gpu_
Definition vnl_pw.h:260
int lmaxq
Definition vnl_pw.h:99
ModuleBase::realArray tab
Definition vnl_pw.h:109
bool multi_proj
Definition vnl_pw.h:115
ModuleBase::realArray qq_nt
Definition vnl_pw.h:127
ModuleBase::realArray tab_alpha
Definition vnl_pw.h:110
void init_vnl(UnitCell &cell, const ModulePW::PW_Basis *rho_basis)
Definition vnl_pw_init_vnl.cpp:27
void sync_vnl_table()
Refresh aliases and allocated precision/device copies after radial-table changes.
Definition vnl_pw_table.cpp:43
FPTYPE * get_deeq_data() const
void radial_fft_q(const int ng, const int ih, const int jh, const int itype, const double *qnorm, const ModuleBase::matrix ylm, std::complex< double > *qg) const
Compute the radial Fourier transform of the Q functions.
Definition vnl_pw_qrad.cpp:98
ModuleBase::realArray tab_at
Definition vnl_pw.h:111
FPTYPE * get_tab_data() const
ModuleBase::ComplexArray dvan_so
Definition vnl_pw.h:107
ModuleBase::matrix nhtolm
Definition vnl_pw.h:103
ModuleBase::realArray qrad
Definition vnl_pw.h:132
~pseudopot_cell_vnl()
Definition test_elecstate_pw.cpp:76
std::complex< double > * z_deeq_nc
Definition vnl_pw.h:120
void release_memory()
Definition vnl_pw.cpp:34
float * s_indv
Definition vnl_pw.h:245
void cal_effective_D(const ModuleBase::matrix &veff, const ModulePW::PW_Basis *rho_basis, UnitCell &cell)
calculate the effective coefficient matrix for non-local pseudopotential projectors
Definition vnl_pw_deeq.cpp:38
double * d_nhtol
Definition vnl_pw.h:249
ModuleBase::IntArray lpx
Definition vnl_pw.h:130
void initgradq_vnl(const UnitCell &cell)
Definition vnl_pw_grad.cpp:16
void newq(const ModuleBase::matrix &veff, const ModulePW::PW_Basis *rho_basis, UnitCell &cell)
computes the integral of the effective potential with the Q function
Definition vnl_pw_deeq.cpp:177
void newd_nc(const int &iat, UnitCell &cell)
calculate D functions in the noncolin case when tvanp is true
Definition vnl_pw_deeq.cpp:360
double * d_tab
Definition vnl_pw.h:252
float * s_tab
Definition vnl_pw.h:246
int vkbnc
Definition vnl_pw.h:146
Soc soc
Definition vnl_pw.h:257
double * d_deeq
Definition vnl_pw.h:117
ModuleBase::matrix nhtol
Definition vnl_pw.h:102