ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
hamilt_hs_adapter.h
Go to the documentation of this file.
1#ifndef HAMILT_HS_ADAPTER_H
2#define HAMILT_HS_ADAPTER_H
3
9#include "source_psi/psi.h"
10
11namespace hamilt
12{
13
21template <typename T, typename Device = base_device::DEVICE_CPU>
22class HamiltHSOperator : public hsolver::HSOperator<T, Device>
23{
24 public:
25 HamiltHSOperator(Hamilt<T, Device> *hm, const ModulePW::PW_Basis_K *wfc_basis) : hm_(hm), wfc_basis_(wfc_basis) {}
26
27 void update_k(const int ik) override
28 {
29 hm_->updateHk(ik);
30 ik_ = ik;
31 npw_ = wfc_basis_->npwk[ik];
32 }
33
34 void hpsi(
35 const T *x,
36 T *hx,
37 const int ld,
38 const int nvec) const override
39 {
40 if (hm_->ops == nullptr)
41 {
42 ModuleBase::WARNING_QUIT("HamiltHSOperator::hpsi", "Operators in Hamilt are not allocated yet");
43 }
44 // non-owning view of x: one k point, nvec bands, leading dimension ld, npw valid rows
45 psi::Psi<T, Device> x_view(const_cast<T *>(x), 1, nvec, ld, npw_);
46 typename Operator<T, Device>::hpsi_info info(&x_view, psi::Range(true, 0, 0, nvec - 1), hx);
47 hm_->ops->hPsi(info);
48 }
49
50 void spsi(
51 const T *x,
52 T *sx,
53 const int ld,
54 const int nvec) const override
55 {
56 hm_->sPsi(x, sx, ld, npw_, nvec);
57 }
58
59 protected:
62 int ik_ = 0;
63 int npw_ = 0;
64};
65
70template <typename T>
72{
73 public:
74 explicit HamiltHSMatrix(Hamilt<T> *hm) : hm_(hm) {}
75
77 {
78 hm_->updateHk(ik);
79 hm_->matrix(hk, sk);
80 }
81
82 private:
83 Hamilt<T> *hm_ = nullptr;
84};
85
86} // namespace hamilt
87
88#endif // HAMILT_HS_ADAPTER_H
Special pw_basis class. It includes different k-points.
Definition pw_basis_k.h:56
void hs_at_k(const int ik, ModuleBase::MatrixBlock< T > &hk, ModuleBase::MatrixBlock< T > &sk) override
Definition hamilt_hs_adapter.h:76
HamiltHSMatrix(Hamilt< T > *hm)
Definition hamilt_hs_adapter.h:74
Hamilt< T > * hm_
Definition hamilt_hs_adapter.h:83
int npw_
number of plane waves of that k point (without npol)
Definition hamilt_hs_adapter.h:63
HamiltHSOperator(Hamilt< T, Device > *hm, const ModulePW::PW_Basis_K *wfc_basis)
Definition hamilt_hs_adapter.h:25
int ik_
k point set by the last update_k()
Definition hamilt_hs_adapter.h:62
void spsi(const T *x, T *sx, const int ld, const int nvec) const override
sx[:, 0:nvec) = S * x[:, 0:nvec), both with leading dimension ld
Definition hamilt_hs_adapter.h:50
void hpsi(const T *x, T *hx, const int ld, const int nvec) const override
hx[:, 0:nvec) = H * x[:, 0:nvec), both with leading dimension ld
Definition hamilt_hs_adapter.h:34
Hamilt< T, Device > * hm_
Definition hamilt_hs_adapter.h:60
void update_k(const int ik) override
switch H and S to k point ik; must precede hpsi()/spsi() for that k
Definition hamilt_hs_adapter.h:27
const ModulePW::PW_Basis_K * wfc_basis_
Definition hamilt_hs_adapter.h:61
Definition hamilt.h:17
std::tuple< const psi::Psi< T, Device > *, const psi::Range, T * > hpsi_info
input type of hPsi: (psi_input, range, hpsi_pointer)
Definition operator.h:53
What a direct (dense) eigensolver needs from the generalized eigenproblem H x = e S x: the matrices H...
Definition hs_matrix.h:19
What an iterative eigensolver needs from the generalized eigenproblem H x = e S x: the ability to app...
Definition hs_operator.h:24
Definition psi.h:37
#define T
Definition exp.cpp:237
void WARNING_QUIT(const std::string &, const std::string &)
Combine the functions of WARNING and QUIT.
Definition test_delley.cpp:15
Definition wf_op.cpp:6
A non-owning description of a matrix stored in memory.
Definition matrix_block.h:23
Definition psi.h:16