ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
diago_cg.h
Go to the documentation of this file.
1#ifndef MODULE_HSOLVER_DIAGO_CG_H_
2#define MODULE_HSOLVER_DIAGO_CG_H_
3
4#include <vector>
5
8
11
12#include <ATen/core/tensor.h>
14
15namespace hsolver {
16
17template <typename T, typename Device = base_device::DEVICE_CPU>
18class DiagoCG final
19{
20 // private: accessibility within class is private by default
21 // Note GetTypeReal<T>::type will
22 // return T if T is real type(float, double),
23 // otherwise return the real type of T(complex<float>, std::complex<double>)
24 using Real = typename GetTypeReal<T>::type;
26 public:
27 // Constructor need:
28 // 1. basis type and calculation type of ABACUS
29 // 2. diag_comm: the pool over which the subspace matrices are reduced
30 DiagoCG(const std::string& basis_type, const std::string& calculation);
31 DiagoCG(
32 const std::string& basis_type,
33 const std::string& calculation,
34 const bool& need_subspace,
35 const diag_comm_info& diag_comm,
36 const Real& pw_diag_thr,
37 const int& pw_diag_nmax);
38
39 ~DiagoCG();
40
41 // this is the diag() function for CG method
42 // returns avg_iter
43 double diag(const HSOperator<T, Device>& op,
44 const int ld_psi,
45 const int nband,
46 const int dim,
47 T* psi_in,
48 Real* eigenvalue_in,
49 const std::vector<double>& ethr_band,
50 const Real* prec = nullptr);
51
52 private:
53 Device * ctx_ = {};
56 int notconv_ = 0;
59 int n_band_ = 0;
61 int n_basis_ = 0;
63 double avg_iter_ = 0;
65 std::vector<int> iter_band;
73 std::string basis_type_ = {};
75 std::string calculation_ = {};
76
77 bool need_subspace_ = false;
79 const HSOperator<T, Device>* op_ = nullptr;
80
81 void calc_grad(
82 const ct::Tensor& prec,
83 ct::Tensor& grad,
84 ct::Tensor& hphi,
85 ct::Tensor& sphi,
86 ct::Tensor& pphi);
87
88 void orth_grad(
89 const ct::Tensor& psi,
90 const int& m,
91 ct::Tensor& grad,
92 ct::Tensor& scg,
93 ct::Tensor& lagrange);
94
95 void calc_gamma_cg(
96 const int& iter,
97 const Real& cg_norm,
98 const Real& theta,
99 const ct::Tensor& prec,
100 const ct::Tensor& scg,
101 const ct::Tensor& grad,
102 const ct::Tensor& phi_m,
103 Real& gg_last,
104 ct::Tensor& g0,
105 ct::Tensor& cg);
106
107 bool update_psi(
108 const ct::Tensor& pphi,
109 const ct::Tensor& cg,
110 const ct::Tensor& scg,
111 const double& ethreshold,
112 Real &cg_norm,
113 Real &theta,
114 Real &eigen,
115 ct::Tensor& phi_m,
116 ct::Tensor& sphi,
117 ct::Tensor& hphi);
118
119 void schmit_orth(const int& m, const ct::Tensor& psi, const ct::Tensor& sphi, ct::Tensor& phi_m);
120
121 // used in diag() for template replace Hamilt with Hamilt_PW
122 void diag_once(const ct::Tensor& prec,
124 ct::Tensor& eigen,
125 const std::vector<double>& ethr_band);
126
127 bool test_exit_cond(const int& ntry, const int& notconv) const;
128
130 void diag_subspace(const T* psi_in, T* psi_out, const int dim, const int nband, const bool S_orth);
131
133 const T * one_ = nullptr, * zero_ = nullptr, * neg_one_ = nullptr;
134};
135
136} // namespace hsolver
137
138#endif // MODULE_HSOLVER_DIAGO_CG_H_
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
bool need_subspace_
Definition diago_cg.h:77
void diag_subspace(const T *psi_in, T *psi_out, const int dim, const int nband, const bool S_orth)
subspace rotation of the current nband vectors (packed, leading dimension dim)
Definition diago_cg.cpp:583
Real pw_diag_thr_
threshold for cg diagonalization
Definition diago_cg.h:67
typename ct::PsiToContainer< Device >::type ct_Device
Definition diago_cg.h:25
void calc_grad(const ct::Tensor &prec, ct::Tensor &grad, ct::Tensor &hphi, ct::Tensor &sphi, ct::Tensor &pphi)
Definition diago_cg.cpp:221
void diag_once(const ct::Tensor &prec, ct::Tensor &psi, ct::Tensor &eigen, const std::vector< double > &ethr_band)
Definition diago_cg.cpp:62
void schmit_orth(const int &m, const ct::Tensor &psi, const ct::Tensor &sphi, ct::Tensor &phi_m)
Definition diago_cg.cpp:487
const diag_comm_info diag_comm_
communicator of the pool sharing the plane waves
Definition diago_cg.h:71
int pw_diag_nmax_
maximum iteration steps for cg diagonalization
Definition diago_cg.h:69
typename GetTypeReal< T >::type Real
Definition diago_cg.h:24
const T * one_
Definition diago_cg.h:133
DiagoCG(const std::string &basis_type, const std::string &calculation)
Definition diago_cg.cpp:20
bool test_exit_cond(const int &ntry, const int &notconv) const
Definition diago_cg.cpp:596
const HSOperator< T, Device > * op_
The H and S operator being diagonalized, set for the duration of diag().
Definition diago_cg.h:79
const T * neg_one_
Definition diago_cg.h:133
ModuleBase::dot_real_op< T, Device > dot_real_op
Definition diago_cg.h:132
int n_basis_
col size for input psi matrix
Definition diago_cg.h:61
~DiagoCG()
Definition diago_cg.cpp:54
double avg_iter_
average iteration steps for cg diagonalization
Definition diago_cg.h:63
int n_band_
Definition diago_cg.h:59
void calc_gamma_cg(const int &iter, const Real &cg_norm, const Real &theta, const ct::Tensor &prec, const ct::Tensor &scg, const ct::Tensor &grad, const ct::Tensor &phi_m, Real &gg_last, ct::Tensor &g0, ct::Tensor &cg)
Definition diago_cg.cpp:321
std::string calculation_
calculation type of ABACUS
Definition diago_cg.h:75
int notconv_
Definition diago_cg.h:56
std::string basis_type_
basis_type of psi
Definition diago_cg.h:73
Device * ctx_
Definition diago_cg.h:53
std::vector< int > iter_band
std::vector for iter count of each band
Definition diago_cg.h:65
void orth_grad(const ct::Tensor &psi, const int &m, ct::Tensor &grad, ct::Tensor &scg, ct::Tensor &lagrange)
Definition diago_cg.cpp:266
const T * zero_
Definition diago_cg.h:133
bool update_psi(const ct::Tensor &pphi, const ct::Tensor &cg, const ct::Tensor &scg, const double &ethreshold, Real &cg_norm, Real &theta, Real &eigen, ct::Tensor &phi_m, ct::Tensor &sphi, ct::Tensor &hphi)
Definition diago_cg.cpp:403
double diag(const HSOperator< T, Device > &op, 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=nullptr)
Definition diago_cg.cpp:610
What an iterative eigensolver needs from the generalized eigenproblem H x = e S x: the ability to app...
Definition hs_operator.h:24
#define T
Definition exp.cpp:237
Definition dense_eigensolver.cpp:23
bool DiagoIterAssist< T, Device >::need_subspace
Definition diago_iter_assist.h:173
Definition diag_lcao.h:14
T type
Definition macros.h:8
Definition math_kernel_op.h:230
T type
Definition tensor_types.h:76
Definition diag_comm_info.h:12
This file contains the definition of the DataType enum class.