ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
linear_low_rank.h
Go to the documentation of this file.
1#ifndef HSOLVER_LINEAR_LOW_RANK_H
2#define HSOLVER_LINEAR_LOW_RANK_H
5
6namespace hsolver
7{
9template <typename T, typename Device>
11{
12 private:
15 int rank_ = 0;
16
17 public:
18 int rank() const
19 {
20 return rank_;
21 }
22 void clear()
23 {
24 rank_ = 0;
25 }
26 const T* directions() const
27 {
28 return directions_.template data<T>();
29 }
30 const T* images() const
31 {
32 return images_.template data<T>();
33 }
34
36 void update(LinearAlgebra<T, Device>& algebra,
37 int ld,
38 int dim,
39 int bands,
40 const T* solution,
41 const T* seed,
42 const T* seed_residual,
43 double tolerance,
44 ct::Tensor* workspace);
45};
46
48template <typename T, typename Device>
49class LinearLowRank final : public LinearOperator<T, Device>
50{
51 private:
53 const T* diagonal_;
54 const int dim_;
55 const T* test_ = nullptr;
56 int rank_ = 0;
57 const LinearSmallLU* factor_ = nullptr;
58 const T* correction_ = nullptr;
59
60 public:
61 LinearLowRank(LinearAlgebra<T, Device>& algebra, const T* diagonal, int dim) : algebra_(algebra), diagonal_(diagonal), dim_(dim)
62 {
63 }
64 bool is_identity() const override
65 {
66 return diagonal_ == nullptr && rank_ == 0;
67 }
68 int rank() const
69 {
70 return rank_;
71 }
72
77 void prepare_response(int ld, int rank, const T* directions, const T* images, ct::Tensor* workspace);
83 void prepare_subspace(int ld, int rank, const T* basis, const T* images, const LinearSmallLU& factor, ct::Tensor* workspace);
85 void apply(const T* x, T* y, int ld, int nvec) const override;
86
87 private:
89 void prepare(int ld, int rank, const T* z, const T* w, const T* test, const LinearSmallLU* factor, ct::Tensor* workspace);
90};
91} // namespace hsolver
92#endif
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
Collective block algebra; only small coefficients cross the device boundary.
Definition linear_algebra.h:53
bool is_identity() const override
Allow solvers to bypass identity preconditioner copies.
Definition linear_low_rank.h:64
const T * diagonal_
Definition linear_low_rank.h:53
const T * correction_
Definition linear_low_rank.h:58
LinearAlgebra< T, Device > & algebra_
Definition linear_low_rank.h:52
const T * test_
Definition linear_low_rank.h:55
void apply(const T *x, T *y, int ld, int nvec) const override
Apply the fixed correction; throw LinearPreconditionerError if the coarse solve fails.
Definition linear_low_rank.cpp:128
int rank() const
Definition linear_low_rank.h:68
const int dim_
Definition linear_low_rank.h:54
void prepare_response(int ld, int rank, const T *directions, const T *images, ct::Tensor *workspace)
Prepare a response correction with orthonormal images.
Definition linear_low_rank.cpp:79
void prepare_subspace(int ld, int rank, const T *basis, const T *images, const LinearSmallLU &factor, ct::Tensor *workspace)
Prepare a Galerkin coarse correction.
Definition linear_low_rank.cpp:85
const LinearSmallLU * factor_
Definition linear_low_rank.h:57
int rank_
Definition linear_low_rank.h:56
LinearLowRank(LinearAlgebra< T, Device > &algebra, const T *diagonal, int dim)
Definition linear_low_rank.h:61
void prepare(int ld, int rank, const T *z, const T *w, const T *test, const LinearSmallLU *factor, ct::Tensor *workspace)
Form Z-D*W and retain the projection data for subsequent applications.
Definition linear_low_rank.cpp:96
Device-resident block operator for independent right-hand sides.
Definition linear_operator.h:31
A bounded, paired-orthogonalized response history for one k point.
Definition linear_low_rank.h:11
ct::Tensor images_
Definition linear_low_rank.h:14
const T * images() const
Definition linear_low_rank.h:30
void update(LinearAlgebra< T, Device > &algebra, int ld, int dim, int bands, const T *solution, const T *seed, const T *seed_residual, double tolerance, ct::Tensor *workspace)
Replace the history only after a successful solve; discard unresolved directions.
Definition linear_low_rank.cpp:9
int rank() const
Definition linear_low_rank.h:18
ct::Tensor directions_
Definition linear_low_rank.h:13
int rank_
Definition linear_low_rank.h:15
const T * directions() const
Definition linear_low_rank.h:26
void clear()
Definition linear_low_rank.h:22
Partial-pivoted factorization of a small column-major complex matrix.
Definition linear_algebra.h:31
#define T
Definition exp.cpp:237
Definition dense_eigensolver.cpp:23