ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
|
A class that implements the block-Davidson algorithm for solving generalized eigenvalue problems. More...
#include <diago_david.h>
Public Types | |
using | HPsiFunc = std::function< void(T *, T *, const int, const int)> |
A function type representing the HX function. | |
using | SPsiFunc = std::function< void(T *, T *, const int, const int)> |
A function type representing the SX function. | |
Public Member Functions | |
DiagoDavid (const Real *precondition_in, const int nband_in, const int dim_in, const int david_ndim_in, const bool use_paw_in, const diag_comm_info &diag_comm_in) | |
Constructor for the DiagoDavid class. | |
~DiagoDavid () | |
Destructor for the DiagoDavid class. | |
int | diag (const HPsiFunc &hpsi_func, const SPsiFunc &spsi_func, const int ld_psi, T *psi_in, Real *eigenvalue_in, const std::vector< double > ðr_band, const int david_maxiter, const int ntry_max=5, const int notconv_max=0) |
Performs iterative diagonalization using the David algorithm. | |
Private Member Functions | |
int | diag_once (const HPsiFunc &hpsi_func, const SPsiFunc &spsi_func, const int dim, const int nband, const int ld_psi, T *psi_in, Real *eigenvalue_in, const std::vector< double > ðr_band, const int david_maxiter) |
void | cal_grad (const HPsiFunc &hpsi_func, const SPsiFunc &spsi_func, const int &dim, const int &nbase, const int nbase_x, const int ¬conv, T *hpsi, T *spsi, const T *vcc, const int *unconv, const Real *eigenvalue) |
void | cal_elem (const int &dim, int &nbase, const int nbase_x, const int ¬conv, const T *hpsi, const T *spsi, T *hcc) |
void | refresh (const int &dim, const int &nband, int &nbase, const int nbase_x, const Real *eigenvalue, const T *psi_in, const int ld_psi, T *hpsi, T *spsi, T *hcc, T *vcc) |
void | SchmidtOrth (const int &dim, const int nband, const int m, const T *spsi, T *lagrange_m, const int mm_size, const int mv_size) |
void | planSchmidtOrth (const int nband, std::vector< int > &pre_matrix_mm_m, std::vector< int > &pre_matrix_mv_m) |
Plans the Schmidt orthogonalization for a given number of bands. | |
void | diag_zhegvx (const int &nbase, const int &nband, const T *hcc, const int &nbase_x, Real *eigenvalue, T *vcc) |
bool | check_block_conv (const int &ntry, const int ¬conv, const int &ntry_max, const int ¬conv_max) |
Check the convergence of block eigenvectors in the Davidson iteration. | |
Private Attributes | |
bool | use_paw = false |
int | test_david = 0 |
diag_comm_info | diag_comm |
const int | nband |
number of required eigenpairs | |
const int | dim |
dimension of the input matrix to be diagonalized | |
const int | nbase_x |
maximum dimension of the reduced basis set | |
const int | david_ndim = 4 |
dimension of the subspace allowed in Davidson | |
int | notconv = 0 |
number of unconverged eigenvalues | |
const Real * | precondition = nullptr |
precondition for diag, diagonal approximation of matrix A(i.e. Hamilt) | |
Real * | d_precondition = nullptr |
Real * | eigenvalue = nullptr |
eigenvalue results | |
T * | basis = nullptr |
T * | hpsi = nullptr |
pointer to basis set(dim, nbase_x), leading dimension = dim | |
T * | spsi = nullptr |
the product of H and psi in the reduced basis set | |
T * | hcc = nullptr |
the Product of S and psi in the reduced basis set | |
T * | vcc = nullptr |
Hamiltonian on the reduced basis. | |
T * | lagrange_matrix = nullptr |
eigenvectors of hc | |
Device * | ctx = {} |
device type of psi | |
base_device::DEVICE_CPU * | cpu_ctx = {} |
base_device::AbacusDevice_t | device = {} |
const T * | one = nullptr |
const T * | zero = nullptr |
const T * | neg_one = nullptr |
const T | one_ = static_cast<T>(1.0) |
const T | zero_ = static_cast<T>(0.0) |
const T | neg_one_ = static_cast<T>(-1.0) |
A class that implements the block-Davidson algorithm for solving generalized eigenvalue problems.
The DiagoDavid class provides methods for performing iterative diagonalization using the Davidson algorithm. It supports both real and complex data types and can be executed on different devices (CPU or GPU).
T | The data type of the matrices and arrays (e.g., float, double, std::complex<float>, std::complex<double>). |
Device | The device type (e.g., base_device::DEVICE_CPU or DEVICE_GPU). |
|
private |
|
private |
|
private |
using hsolver::DiagoDavid< T, Device >::HPsiFunc = std::function<void(T*, T*, const int, const int)> |
A function type representing the HX function.
This function type is used to define a matrix-blockvector operator H. For eigenvalue problem HX = λX or generalized eigenvalue problem HX = λSX, this function computes the product of the Hamiltonian matrix H and a blockvector X.
Called as follows: hpsi(X, HX, ld, nvec) where X and HX are (ld, nvec)-shaped blockvectors. Result HX = H * X is stored in HX.
[out] | X | Head address of input blockvector of type T* . |
[in] | HX | Head address of output blockvector of type T* . |
[in] | ld | Leading dimension of blockvector. |
[in] | nvec | Number of vectors in a block. |
|
private |
|
private |
|
private |
|
private |
|
private |
using hsolver::DiagoDavid< T, Device >::SPsiFunc = std::function<void(T*, T*, const int, const int)> |
A function type representing the SX function.
nrow is leading dimension of spsi, npw is leading dimension of psi, nbands is number of vecs
This function type is used to define a matrix-blockvector operator S. For generalized eigenvalue problem HX = λSX, this function computes the product of the overlap matrix S and a blockvector X.
[in] | X | Pointer to the input blockvector. |
[out] | SX | Pointer to the output blockvector. |
[in] | ld_psi | Leading dimension of psi and spsi. Dimension of X&SX: ld * nvec. |
[in] | nvec | Number of vectors. |
|
private |
|
private |
|
private |
|
private |
|
private |
hsolver::DiagoDavid< T, Device >::DiagoDavid | ( | const Real * | precondition_in, |
const int | nband_in, | ||
const int | dim_in, | ||
const int | david_ndim_in, | ||
const bool | use_paw_in, | ||
const diag_comm_info & | diag_comm_in | ||
) |
Constructor for the DiagoDavid class.
[in] | precondition_in | Pointer to the preconditioning matrix. |
[in] | nband_in | Number of eigenpairs required(i.e. bands). |
[in] | dim_in | Dimension of the matrix. |
[in] | david_ndim_in | Dimension of the reduced basis set of Davidson. david_ndim_in * nband_in is the maximum allowed size of the reduced basis set before restart of Davidson. |
[in] | use_paw_in | Flag indicating whether to use PAW. |
[in] | diag_comm_in | Communication information for diagonalization. |
T | The data type of the matrices and arrays. |
Device | The device type (base_device::DEVICE_CPU or DEVICE_GPU). |
initialize variables k_first = 0 means that nks is more like a dimension of "basis" to be contracted in "HPsi".In LR-TDDFT the formula writes : $$\sum_{ jb\mathbf{k}'}A^I_{ia\mathbf{k}, jb\mathbf{k}' }X ^ I_{ jb\mathbf{k}'}$$ In the code :
hsolver::DiagoDavid< T, Device >::~DiagoDavid | ( | ) |
Destructor for the DiagoDavid class.
This destructor releases the dynamically allocated memory used by the class members. It deletes the basis, hpsi, spsi, hcc, vcc, lagrange_matrix, and eigenvalue arrays.
|
private |
Calculates the elements of the diagonalization matrix for the DiagoDavid class.
dim | The dimension of the problem. |
nbase | The current dimension of the reduced basis. |
nbase_x | The maximum dimension of the reduced basis set. |
notconv | The number of newly added basis vectors. |
hpsi | The output array for the Hamiltonian H times blockvector psi. |
spsi | The output array for the overlap matrix S times blockvector psi. |
hcc | Pointer to the array where the calculated Hamiltonian matrix elements will be stored. |
|
private |
Calculates the preconditioned gradient of the eigenvectors in Davidson method.
hpsi_func | The function to calculate the matrix-blockvector product H * psi. |
spsi_func | The function to calculate the matrix-blockvector product overlap S * psi. |
dim | The dimension of the blockvector. |
nbase | The current dimension of the reduced basis. |
nbase_x | The maximum dimension of the reduced basis set. |
notconv | The number of unconverged eigenpairs. |
hpsi | The output array for the Hamiltonian H times blockvector psi. |
spsi | The output array for the overlap matrix S times blockvector psi. |
vcc | The input array for the eigenvector coefficients. |
unconv | The array of indices for the unconverged eigenpairs. |
eigenvalue | The array of eigenvalues. |
|
inlineprivate |
Check the convergence of block eigenvectors in the Davidson iteration.
This function determines whether the block eigenvectors have reached convergence during the iterative diagonalization process. Convergence is judged based on the number of eigenvectors that have not converged and the maximum allowed number of such eigenvectors.
T | The data type for the eigenvalues and eigenvectors (e.g., float, double). |
Device | The device type (e.g., base_device::DEVICE_CPU). |
ntry | The current number of tries for diagonalization. |
notconv | The current number of eigenvectors that have not converged. |
ntry_max | The maximum allowed number of tries for diagonalization. |
notconv_max | The maximum allowed number of eigenvectors that can fail to converge. |
int hsolver::DiagoDavid< T, Device >::diag | ( | const HPsiFunc & | hpsi_func, |
const SPsiFunc & | 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 = 5 , |
||
const int | notconv_max = 0 |
||
) |
Performs iterative diagonalization using the David algorithm.
HPsiFunc
for more information about the hpsi mat-vec interface.T | The type of the elements in the matrix. |
Device | The device type (CPU or GPU). |
hpsi_func | The function object that computes the matrix-blockvector product H * psi. |
spsi_func | The function object that computes the matrix-blockvector product overlap S * psi. |
ld_psi | The leading dimension of the psi_in array. |
psi_in | The input wavefunction. |
eigenvalue_in | The array to store the eigenvalues. |
david_diag_thr | The convergence threshold for the diagonalization. |
david_maxiter | The maximum number of iterations for the diagonalization. |
ntry_max | The maximum number of attempts for the diagonalization restart. |
notconv_max | The maximum number of bands unconverged allowed. |
record the times of trying iterative diagonalization
|
private |
|
private |
|
private |
Plans the Schmidt orthogonalization for a given number of bands.
T | The type of the elements in the vectors. |
Device | The device on which the computation will be performed. |
nband | The number of bands. |
pre_matrix_mm_m | The vector to store the matrix sizes. |
pre_matrix_mv_m | The vector to store the number of matrix-vector multiplications. |
|
private |
Refreshes the diagonalization solver by updating the basis and the reduced Hamiltonian.
dim | The dimension of the problem. |
nband | The number of bands. |
nbase | The number of basis states. |
nbase_x | The maximum dimension of the reduced basis set. |
eigenvalue_in | Pointer to the array of eigenvalues. |
psi_in | Pointer to the array of wavefunctions. |
ld_psi | The leading dimension of the wavefunction array. |
hpsi | Pointer to the output array for the updated basis set. |
spsi | Pointer to the output array for the updated basis set (nband-th column). |
hcc | Pointer to the output array for the updated reduced Hamiltonian. |
vcc | Pointer to the output array for the updated eigenvector matrix. |
|
private |
SchmidtOrth function performs orthogonalization of the starting eigenfunction to those already calculated. It takes the dimension of the basis, number of bands, index of the current band, starting eigenfunction psi_m, lagrange_m array, mm_size, and mv_size as input parameters.
dim | The dimension of the basis. |
nband | The number of bands. |
m | The index of the current band. |
spsi | Pointer to the starting eigenfunction psi_m. |
lagrange_m | Pointer to the lagrange_m array. |
mm_size | The size of the square matrix for future lagranges. |
mv_size | The size of the lagrange_m array. |
|
private |
|
private |
|
private |
device type of psi
|
private |
|
private |
dimension of the subspace allowed in Davidson
|
private |
|
private |
|
private |
dimension of the input matrix to be diagonalized
|
private |
eigenvalue results
|
private |
the Product of S and psi in the reduced basis set
|
private |
pointer to basis set(dim, nbase_x), leading dimension = dim
|
private |
eigenvectors of hc
|
private |
number of required eigenpairs
|
private |
maximum dimension of the reduced basis set
|
private |
|
private |
|
private |
number of unconverged eigenvalues
|
private |
|
private |
|
private |
precondition for diag, diagonal approximation of matrix A(i.e. Hamilt)
|
private |
the product of H and psi in the reduced basis set
|
private |
|
private |
|
private |
Hamiltonian on the reduced basis.
|
private |
|
private |