GQCP
Loading...
Searching...
No Matches
EigenproblemEnvironment.hpp
Go to the documentation of this file.
1// This file is part of GQCG-GQCP.
2//
3// Copyright (C) 2017-2020 the GQCG developers
4//
5// GQCG-GQCP is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// GQCG-GQCP is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with GQCG-GQCP. If not, see <http://www.gnu.org/licenses/>.
17
18#pragma once
19
20
24
25
26namespace GQCP {
27
28
34template <typename _Scalar>
36public:
37 // The scalar type of the matrix elements: real or complex.
38 using Scalar = _Scalar;
39
40
41public:
42 // A vector function that returns the matrix-vector product (i.e. the matrix-vector product representation of the matrix).
44
45
46 // The self-adjoint matrix whose eigenvalue problem should be solved.
48
49 // The diagonal of the matrix.
51
52 // The dimension of the diagonalization problem (the dimension of one eigenvector).
53 size_t dimension;
54
55
56 // The eigenvalues of the matrix A.
58
59 // The eigenvectors of the matrix A.
61
62 // The "subspace matrix": the projection of the matrix A onto the subspace spanned by the vectors in V.
64
65 // The (requested number of) eigenvalues of the subspace matrix S.
67
68 // The (requested number of) eigenvectors of the subspace matrix S.
70
71
72 // The subspace of guess vectors in an iterative diagonalization algorithm.
74
75 // VA = A * V (implicitly calculated through the matrix-vector product).
77
78 // Contains the new guesses for the eigenvectors (as a linear combination of the current subspace V).
80
81
82 // The residual vectors.
84
85 // The correction vectors, i.e. the solutions to the residual equations.
87
88
89public:
90 /*
91 * MARK: Constructors
92 */
93
98 A {A} {}
99
105 dimension {static_cast<size_t>(diagonal.size())},
108 V {V},
109 VA {MatrixX<Scalar>::Zero(V.rows(), 0)} {} // The initial environment should have no columns in VA.
110
111
112 /*
113 * MARK: Named constructors
114 */
115
122
131
139
140 const auto matrix_vector_product_function = [A](const VectorX<Scalar>& x) { return A * x; };
142 }
143
144
145 /*
146 * MARK: Access
147 */
148
154 std::vector<Eigenpair<double, Scalar>> eigenpairs(const size_t number_of_requested_eigenpairs = 1) const {
155
156 if (number_of_requested_eigenpairs > this->eigenvectors.cols()) {
157 throw std::invalid_argument("EigenproblemEnvironment::eigenpairs(const size_t): You cannot retrieve that many eigenpairs.");
158 }
159
160 std::vector<Eigenpair<double, Scalar>> eigenpairs {};
161 eigenpairs.reserve(number_of_requested_eigenpairs);
162
163 for (size_t i = 0; i < number_of_requested_eigenpairs; i++) {
164 const auto& eigenvalue = this->eigenvalues(i);
165 const auto& eigenvector = this->eigenvectors.col(i);
166
167 eigenpairs.emplace_back(eigenvalue, eigenvector);
168 }
169
170 return eigenpairs;
171 }
172};
173
174
175} // namespace GQCP
Definition: EigenproblemEnvironment.hpp:35
_Scalar Scalar
Definition: EigenproblemEnvironment.hpp:38
std::vector< Eigenpair< double, Scalar > > eigenpairs(const size_t number_of_requested_eigenpairs=1) const
Definition: EigenproblemEnvironment.hpp:154
MatrixX< Scalar > X
Definition: EigenproblemEnvironment.hpp:79
VectorX< Scalar > diagonal
Definition: EigenproblemEnvironment.hpp:50
VectorX< double > eigenvalues
Definition: EigenproblemEnvironment.hpp:57
MatrixX< Scalar > V
Definition: EigenproblemEnvironment.hpp:73
MatrixX< Scalar > Delta
Definition: EigenproblemEnvironment.hpp:86
size_t dimension
Definition: EigenproblemEnvironment.hpp:53
static EigenproblemEnvironment Iterative(const VectorFunction< Scalar > &matrix_vector_product_function, const VectorX< Scalar > &diagonal, const MatrixX< Scalar > &V)
Definition: EigenproblemEnvironment.hpp:130
EigenproblemEnvironment(const VectorFunction< Scalar > &matrix_vector_product_function, const VectorX< Scalar > &diagonal, const MatrixX< Scalar > &V)
Definition: EigenproblemEnvironment.hpp:104
MatrixX< Scalar > Z
Definition: EigenproblemEnvironment.hpp:69
static EigenproblemEnvironment Iterative(const SquareMatrix< Scalar > &A, const MatrixX< Scalar > &V)
Definition: EigenproblemEnvironment.hpp:138
SquareMatrix< Scalar > A
Definition: EigenproblemEnvironment.hpp:47
VectorFunction< Scalar > matrix_vector_product_function
Definition: EigenproblemEnvironment.hpp:43
VectorX< double > Lambda
Definition: EigenproblemEnvironment.hpp:66
SquareMatrix< Scalar > S
Definition: EigenproblemEnvironment.hpp:63
static EigenproblemEnvironment Dense(const SquareMatrix< Scalar > &A)
Definition: EigenproblemEnvironment.hpp:121
MatrixX< Scalar > VA
Definition: EigenproblemEnvironment.hpp:76
EigenproblemEnvironment(const SquareMatrix< Scalar > &A)
Definition: EigenproblemEnvironment.hpp:97
MatrixX< Scalar > eigenvectors
Definition: EigenproblemEnvironment.hpp:60
MatrixX< Scalar > R
Definition: EigenproblemEnvironment.hpp:83
Definition: Matrix.hpp:47
Definition: SquareMatrix.hpp:39
Definition: BaseOneElectronIntegralBuffer.hpp:25
@ x
Definition: CartesianDirection.hpp:28
std::function< VectorX< Scalar >(const VectorX< Scalar > &)> VectorFunction
Definition: Matrix.hpp:485