ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
stress_func.h
Go to the documentation of this file.
1#ifndef STRESS_FUNC_H
2#define STRESS_FUNC_H
3
11#include "source_cell/klist.h"
14#include "source_psi/psi.h"
18
20
21//-------------------------------------------------------------------
22// mohan reconstruction note: 2021-02-07
23// the stress code needs reconstructions (by Daye Zheng)
24// 1) add explanations for each function, each variable, for
25// main procedures, make the code readable
26// 2) divide the stress class into several files, each file
27// deals with only one part of the stress, it is convenient for
28// the next-step reconstruction, for example, we want to make
29// pw as an external variable instead of a global variable
30// 3) for PW and LCAO, keeps only one copy of the code, for example
31// the ewald term needs only one copy, it will reduce the
32// time to maintain both copies of stress codes.
33// 4) remain openning interfaces for others to contribute stress
34// codes, for example, molecular dynamics will have an ionic stress
35// term, +U? exx? may have other stress terms.
36// 5) delete useless comments and tests, if you have a useless code,
37// please explicitly explain why you want to keep the test
38// 6) format should be beautiful! code should be readable like a
39// note (let readers be comfortable)
40//-------------------------------------------------------------------
41
42//----------------------------------------------------------------
43// compute the stress terms in terms of the plane wave basis set
44// the stress terms include:
45// 1) the stress from the electron kinetic energy
46// 2) the stress from the local pseudopotentials
47// 3) the stress from the non-local pseudopotentials
48// 4) the stress from the Hartree term
49// 5) the stress from the non-linear core correction (if any)
50// 6) the strees from the exchange-correlation functional term
51// 7) the stress from the ewald term (ion-ion intraction under
52// periodic boundary conditions).
53// 8) the stress from ionic contributions (for molecular dynamics)
54//----------------------------------------------------------------
55
56template <typename FPTYPE, typename Device = base_device::DEVICE_CPU>
58{
59 public:
62
63 // stress functions
64 // 1) the stress from the electron kinetic energy
65 void stress_kin(
66 ModuleBase::matrix &sigma,
67 const ModuleBase::matrix &wg,
69 K_Vectors *p_kv,
70 ModulePW::PW_Basis_K *wfc_basis,
71 const UnitCell &ucell_in,
72 const psi::Psi<std::complex<FPTYPE>, Device> *psi_in = nullptr); // electron kinetic part in PW basis
73
74 // 2) the stress from the Hartree term
75 void stress_har(
76 const UnitCell &ucell,
77 ModuleBase::matrix &sigma,
78 ModulePW::PW_Basis *rho_basis,
79 const bool is_pw,
80 const Charge *const chr); // hartree part in PW or LCAO basis
81
82 // 3) the stress from the ewald term (ion-ion intraction under
83 // periodic boundary conditions).
84 // struc_fac contains unnormalized exp(-iG.tau) sums or their B-spline approximation.
85 // Its first rho_basis->npw columns must follow rho_basis's local G order.
86 // Extra columns are allowed for a PW_Basis_Sup dense SF with a matching
87 // smooth-basis prefix; only that prefix is consumed.
88 void stress_ewa(
89 const UnitCell &ucell,
90 ModuleBase::matrix &sigma,
91 ModulePW::PW_Basis *rho_basis,
92 const ModuleBase::ComplexMatrix &struc_fac,
93 const bool is_pw); // ewald part in PW or LCAO basis
94
95 // 4) the stress from the local pseudopotentials
96 void stress_loc(
97 const UnitCell &ucell,
98 ModuleBase::matrix &sigma,
99 ModulePW::PW_Basis *rho_basis,
100 const ModuleBase::matrix &vloc,
101 const Structure_Factor *p_sf,
102 const bool is_pw,
103 const Charge *const chr); // local pseudopotential part in PW or LCAO
104
105 void dvloc_of_g(
106 const int &msh,
107 const FPTYPE *rab,
108 const FPTYPE *r,
109 const FPTYPE *vloc_at,
110 const FPTYPE &zp,
111 FPTYPE *dvloc,
112 ModulePW::PW_Basis *rho_basis,
113 const UnitCell &ucell_in); // used in local pseudopotential stress
114
120 void dvloc_coulomb(
121 const UnitCell &ucell,
122 const FPTYPE &zp,
123 FPTYPE *dvloc,
124 ModulePW::PW_Basis *rho_basis); // used in local pseudopotential stress
125
126 // 5) the stress from the non-linear core correction (if any)
127 void stress_cc(
128 ModuleBase::matrix &sigma,
129 ModulePW::PW_Basis *rho_basis,
131 const Structure_Factor *p_sf,
132 const bool is_pw,
133 const bool *numeric,
134 const Charge *const chr,
135 const int nspin,
136 const bool domag,
137 const bool domag_z,
138 const int gga_grad,
139 const bool gamma_only_pw); // nonlinear core correction stress in PW or LCAO basis
140
141 void deriv_drhoc(
142 const bool &numeric,
143 const double &omega,
144 const double &tpiba2,
145 const int mesh,
146 const FPTYPE *r,
147 const FPTYPE *rab,
148 const FPTYPE *rhoc,
149 FPTYPE *drhocg,
150 ModulePW::PW_Basis *rho_basis,
151 int type); // used in nonlinear core correction stress
152
153 // 6) the stress from the exchange-correlation functional term
154 void stress_gga(
155 const UnitCell &ucell,
156 ModuleBase::matrix &sigma,
157 ModulePW::PW_Basis *rho_basis,
158 const Charge *const chr,
159 const int nspin,
160 const bool domag,
161 const bool domag_z,
162 const int gga_grad); // gga part in both PW and LCAO basis
163 void stress_mgga(
164 const UnitCell &ucell,
165 ModuleBase::matrix &sigma,
166 const ModuleBase::matrix &wg,
167 const ModuleBase::matrix &v_ofk,
168 const Charge *const chr,
169 K_Vectors *p_kv,
170 ModulePW::PW_Basis_K *wfc_basis,
171 const psi::Psi<std::complex<FPTYPE>, Device> *psi_in); // gga part in PW basis
172
181 void stress_pw_terms(
183 ModuleBase::matrix &sigmadvl,
184 ModuleBase::matrix &sigmahar,
185 ModuleBase::matrix &sigmaewa,
186 ModuleBase::matrix &sigmacc,
187 ModuleBase::matrix &sigmaxc,
188 const double &etxc,
189 const Charge *const chr,
190 ModulePW::PW_Basis *rhopw,
191 const pseudopot_cell_vl &locpp,
192 const Structure_Factor &sf,
193 const int nspin,
194 const bool domag,
195 const bool domag_z,
196 const int gga_grad,
197 const bool gamma_only_pw);
198
199 // 7) the stress from the non-local pseudopotentials
209 void stress_nl(
210 ModuleBase::matrix &sigma,
211 const ModuleBase::matrix &wg,
212 const ModuleBase::matrix &ekb,
213 Structure_Factor *p_sf,
214 K_Vectors *p_kv,
216 ModulePW::PW_Basis_K *wfc_basis,
217 const psi::Psi<std::complex<FPTYPE>, Device> *psi_in,
218 const pseudopot_cell_vnl &nlpp_in,
219 const UnitCell &ucell_in); // nonlocal part in PW basis
220 // 8) the stress from the DFT+U and DeltaSpin calculations
231 void stress_onsite(
232 ModuleBase::matrix &sigma,
233 const ModuleBase::matrix &wg,
234 const ModulePW::PW_Basis_K *wfc_basis,
235 const UnitCell &ucell_in,
236 const Plus_U_Base &dftu,
237 const void *psi_in,
238 ModuleSymmetry::Symmetry *p_symm); // nonlocal part in PW basis
239
240 void get_dvnl1(
242 const int ik,
243 const int ipol,
244 Structure_Factor *p_sf,
245 ModulePW::PW_Basis_K *wfc_basis); // used in nonlocal part in PW basis
246 void get_dvnl2(
248 const int ik,
249 Structure_Factor *p_sf,
250 ModulePW::PW_Basis_K *wfc_basis); // used in nonlocal part in PW basis
251
253 const ModuleBase::realArray &table,
254 const int &dim1,
255 const int &dim2,
256 const int &dim3,
257 const FPTYPE &table_interval,
258 const FPTYPE &x);
259
283 void dqvan2(
284 const pseudopot_cell_vnl &ppcell_in,
285 const int ih,
286 const int jh,
287 const int itype,
288 const int ipol,
289 const int ng,
291 const FPTYPE *qnorm,
292 const FPTYPE &tpiba,
293 const ModuleBase::matrix &ylmk0,
294 const ModuleBase::matrix &dylmk0,
295 std::complex<FPTYPE> *dqg);
296
297 protected:
298 Device *ctx = {};
299 base_device::DEVICE_CPU *cpu_ctx = {};
301
302 private:
306
316
324
328
331
334
335 protected:
337 const UnitCell *ucell = nullptr;
338};
339
340#endif
Definition charge.h:24
Class for k-points management.
Definition klist.h:20
Definition complexmatrix.h:11
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
Symmetry analysis class.
Definition symmetry.h:24
Definition dftu_base.h:21
base_device::DEVICE_CPU * cpu_ctx
Definition stress_func.h:299
hamilt::cal_vq_deri_op< FPTYPE, Device > cal_vq_deri_op
Definition stress_func.h:330
hamilt::cal_vkb_deri_op< FPTYPE, Device > cal_vkb_deri_op
Definition stress_func.h:333
void stress_har(const UnitCell &ucell, ModuleBase::matrix &sigma, ModulePW::PW_Basis *rho_basis, const bool is_pw, const Charge *const chr)
Definition stress_har.cpp:9
Stress_Func()
Definition stress_func.h:60
base_device::memory::delete_memory_op< std::complex< FPTYPE >, Device > delmem_complex_op
Definition stress_func.h:310
void stress_kin(ModuleBase::matrix &sigma, const ModuleBase::matrix &wg, ModuleSymmetry::Symmetry *p_symm, K_Vectors *p_kv, ModulePW::PW_Basis_K *wfc_basis, const UnitCell &ucell_in, const psi::Psi< std::complex< FPTYPE >, Device > *psi_in=nullptr)
Definition stress_kin.cpp:8
base_device::memory::synchronize_memory_op< std::complex< FPTYPE >, Device, base_device::DEVICE_CPU > syncmem_complex_h2d_op
Definition stress_func.h:312
base_device::memory::delete_memory_op< FPTYPE, Device > delmem_var_op
Definition stress_func.h:320
ModuleBase::gemm_op< std::complex< FPTYPE >, Device > gemm_op
Definition stress_func.h:303
void get_dvnl1(ModuleBase::ComplexMatrix &vkb, const int ik, const int ipol, Structure_Factor *p_sf, ModulePW::PW_Basis_K *wfc_basis)
Definition stress_nl.cpp:118
base_device::memory::delete_memory_op< std::complex< FPTYPE >, base_device::DEVICE_CPU > delmem_complex_h_op
Definition stress_func.h:311
~Stress_Func()
Definition stress_func.h:61
base_device::memory::synchronize_memory_op< FPTYPE, base_device::DEVICE_CPU, Device > syncmem_var_d2h_op
Definition stress_func.h:323
void stress_pw_terms(UnitCell &ucell, ModuleBase::matrix &sigmadvl, ModuleBase::matrix &sigmahar, ModuleBase::matrix &sigmaewa, ModuleBase::matrix &sigmacc, ModuleBase::matrix &sigmaxc, const double &etxc, const Charge *const chr, ModulePW::PW_Basis *rhopw, const pseudopot_cell_vl &locpp, const Structure_Factor &sf, const int nspin, const bool domag, const bool domag_z, const int gga_grad, const bool gamma_only_pw)
Compute the plane-wave-basis stress terms shared by PW and LCAO: vlocal, hartree, ewald,...
Definition stress_loc.cpp:302
void stress_nl(ModuleBase::matrix &sigma, const ModuleBase::matrix &wg, const ModuleBase::matrix &ekb, Structure_Factor *p_sf, K_Vectors *p_kv, ModuleSymmetry::Symmetry *p_symm, ModulePW::PW_Basis_K *wfc_basis, const psi::Psi< std::complex< FPTYPE >, Device > *psi_in, const pseudopot_cell_vnl &nlpp_in, const UnitCell &ucell_in)
This routine computes the atomic force of non-local pseudopotential Stress^{NL}_{ij}...
Definition stress_nl.cpp:14
hamilt::cal_vkb_op< FPTYPE, Device > cal_vkb_op
Definition stress_func.h:332
void dvloc_of_g(const int &msh, const FPTYPE *rab, const FPTYPE *r, const FPTYPE *vloc_at, const FPTYPE &zp, FPTYPE *dvloc, ModulePW::PW_Basis *rho_basis, const UnitCell &ucell_in)
Definition stress_loc.cpp:168
void stress_gga(const UnitCell &ucell, ModuleBase::matrix &sigma, ModulePW::PW_Basis *rho_basis, const Charge *const chr, const int nspin, const bool domag, const bool domag_z, const int gga_grad)
Definition stress_gga.cpp:7
void stress_loc(const UnitCell &ucell, ModuleBase::matrix &sigma, ModulePW::PW_Basis *rho_basis, const ModuleBase::matrix &vloc, const Structure_Factor *p_sf, const bool is_pw, const Charge *const chr)
Definition stress_loc.cpp:12
void stress_ewa(const UnitCell &ucell, ModuleBase::matrix &sigma, ModulePW::PW_Basis *rho_basis, const ModuleBase::ComplexMatrix &struc_fac, const bool is_pw)
Definition stress_ewa.cpp:15
hamilt::cal_vq_op< FPTYPE, Device > cal_vq_op
Definition stress_func.h:329
pseudopot_cell_vnl * nlpp
Definition stress_func.h:336
void dqvan2(const pseudopot_cell_vnl &ppcell_in, const int ih, const int jh, const int itype, const int ipol, const int ng, const ModuleBase::Vector3< FPTYPE > *g, const FPTYPE *qnorm, const FPTYPE &tpiba, const ModuleBase::matrix &ylmk0, const ModuleBase::matrix &dylmk0, std::complex< FPTYPE > *dqg)
Compute the derivatives of the radial Fourier transform of the Q functions.
Definition stress_us.cpp:168
void stress_cc(ModuleBase::matrix &sigma, ModulePW::PW_Basis *rho_basis, UnitCell &ucell, const Structure_Factor *p_sf, const bool is_pw, const bool *numeric, const Charge *const chr, const int nspin, const bool domag, const bool domag_z, const int gga_grad, const bool gamma_only_pw)
Definition stress_cc.cpp:14
base_device::memory::synchronize_memory_op< FPTYPE, Device, base_device::DEVICE_CPU > syncmem_var_h2d_op
Definition stress_func.h:322
base_device::memory::set_memory_op< std::complex< FPTYPE >, Device > setmem_complex_op
Definition stress_func.h:309
void get_dvnl2(ModuleBase::ComplexMatrix &vkb, const int ik, Structure_Factor *p_sf, ModulePW::PW_Basis_K *wfc_basis)
Definition stress_nl.cpp:240
Device * ctx
Definition stress_func.h:298
base_device::memory::resize_memory_op< std::complex< FPTYPE >, Device > resmem_complex_op
Definition stress_func.h:307
void deriv_drhoc(const bool &numeric, const double &omega, const double &tpiba2, const int mesh, const FPTYPE *r, const FPTYPE *rab, const FPTYPE *rhoc, FPTYPE *drhocg, ModulePW::PW_Basis *rho_basis, int type)
Definition stress_cc.cpp:212
void stress_onsite(ModuleBase::matrix &sigma, const ModuleBase::matrix &wg, const ModulePW::PW_Basis_K *wfc_basis, const UnitCell &ucell_in, const Plus_U_Base &dftu, const void *psi_in, ModuleSymmetry::Symmetry *p_symm)
This routine computes the stress contribution from the DFT+U and DeltaSpin calculations Stress^{NL}...
Definition stress_onsite.cpp:25
base_device::memory::delete_memory_op< int, Device > delmem_int_op
Definition stress_func.h:326
base_device::AbacusDevice_t device
Definition stress_func.h:300
void stress_mgga(const UnitCell &ucell, ModuleBase::matrix &sigma, const ModuleBase::matrix &wg, const ModuleBase::matrix &v_ofk, const Charge *const chr, K_Vectors *p_kv, ModulePW::PW_Basis_K *wfc_basis, const psi::Psi< std::complex< FPTYPE >, Device > *psi_in)
Definition stress_mgga.cpp:15
base_device::memory::resize_memory_op< std::complex< FPTYPE >, base_device::DEVICE_CPU > resmem_complex_h_op
Definition stress_func.h:308
hamilt::cal_stress_nl_op< FPTYPE, Device > cal_stress_nl_op
Definition stress_func.h:304
base_device::memory::resize_memory_op< FPTYPE, Device > resmem_var_op
Definition stress_func.h:317
void dvloc_coulomb(const UnitCell &ucell, const FPTYPE &zp, FPTYPE *dvloc, ModulePW::PW_Basis *rho_basis)
compute the derivative of the coulomb potential in reciprocal space D V(g^2) / D g^2 = 4pi e^2/omegai...
Definition stress_loc.cpp:270
base_device::memory::synchronize_memory_op< std::complex< FPTYPE >, base_device::DEVICE_CPU, Device > syncmem_complex_d2h_op
Definition stress_func.h:314
const UnitCell * ucell
Definition stress_func.h:337
base_device::memory::delete_memory_op< FPTYPE, base_device::DEVICE_CPU > delmem_var_h_op
Definition stress_func.h:321
base_device::memory::resize_memory_op< FPTYPE, base_device::DEVICE_CPU > resmem_var_h_op
Definition stress_func.h:318
base_device::memory::resize_memory_op< int, Device > resmem_int_op
Definition stress_func.h:325
base_device::memory::synchronize_memory_op< int, Device, base_device::DEVICE_CPU > syncmem_int_h2d_op
Definition stress_func.h:327
hamilt::cal_dbecp_noevc_nl_op< FPTYPE, Device > cal_dbecp_noevc_nl_op
Definition stress_func.h:305
base_device::memory::set_memory_op< FPTYPE, Device > setmem_var_op
Definition stress_func.h:319
FPTYPE Polynomial_Interpolation_nl(const ModuleBase::realArray &table, const int &dim1, const int &dim2, const int &dim3, const FPTYPE &table_interval, const FPTYPE &x)
Definition stress_nl.cpp:359
Definition stru_fac.h:10
Provide the basic information about unitcell.
Definition unitcell.h:16
Definition vl_pw.h:13
Definition vnl_pw.h:23
Definition psi.h:37
AbacusDevice_t
Definition types.h:12
Definition math_kernel_op.h:298
Definition memory_op.h:115
Definition memory_op.h:17
Definition memory_op.h:31
Definition stress_op.h:14
Definition stress_op.h:57
Definition stress_op.h:194
Definition stress_op.h:178
Definition stress_op.h:232
Definition stress_op.h:215
Plus_U_Base dftu
Definition test_dftu_nao_op.cpp:11